Description:
Add support for reading in news stories from YAML.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -71,7 +71,7 | |||
|
71 | 71 | |
|
72 | 72 | private Node<DialogOption> currentNode; |
|
73 | 73 | private Queue<Node<DialogOption>> remainingDialog; |
|
74 |
private NewsItem |
|
|
74 | private List<NewsItem> newsItems; | |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | private bool showGrid; |
@@ -203,11 +203,17 | |||
|
203 | 203 | |
|
204 | 204 | grammar.AddModifier("toUpper", toUpper); |
|
205 | 205 | |
|
206 |
|
|
|
207 |
new NewsItem{hed="Politicians Debate Stimulus Package", contents="WASHINGTON - Poli |
|
|
206 | var newItems = new[] {new NewsItem{hed="test", contents="#city.toUpper# - This is where the lede would go.", source="Wire"}, | |
|
207 | new NewsItem{hed="Politicians Debate Stimulus Package", contents="WASHINGTON - Poliicians debate the latest stimulus package, which opponents argue might help some people who don't deserve it. So it's impossible to say whether it's good or bad.", source="Wire"}, | |
|
208 | 208 | new NewsItem{hed="The Rare Subspecies of Spruce Making a Comeback", contents="Maeve Redding didn't think", source="Arborist"}, |
|
209 | 209 | }; |
|
210 | this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToArray(); | |
|
210 | ||
|
211 | this.newsItems = newItems.ToList(); | |
|
212 | this.newsItems.AddRange(NewsItem.FromYaml(@" | |
|
213 | - hed: deserialized | |
|
214 | contents: abc | |
|
215 | source: Wire")); | |
|
216 | this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToList(); | |
|
211 | 217 | |
|
212 | 218 | this.remainingDialog = new Queue<Node<DialogOption>>(); |
|
213 | 219 |
@@ -64,7 +64,7 | |||
|
64 | 64 | show_forest = !show_forest; |
|
65 | 65 | |
|
66 | 66 | } |
|
67 |
if (Menu.activeButton(" |
|
|
67 | if (Menu.activeButton("\ue0bf News", show_news, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) | |
|
68 | 68 | { |
|
69 | 69 | show_news = !show_news; |
|
70 | 70 |
@@ -3,13 +3,16 | |||
|
3 | 3 | |
|
4 | 4 | using Num = System.Numerics; |
|
5 | 5 | using System.Linq; |
|
6 | using System.IO; | |
|
7 | using System.Collections.Generic; | |
|
8 | using YamlDotNet.Serialization; | |
|
6 | 9 | |
|
7 | 10 | namespace isometricparkfna.UI |
|
8 | 11 | { |
|
9 | 12 | |
|
10 | 13 | public struct NewsItem { |
|
11 | public string hed; | |
|
12 | public string contents; | |
|
14 | public string hed; | |
|
15 | public string contents; | |
|
13 | 16 | public string source; |
|
14 | 17 | |
|
15 | 18 | public NewsItem Flatten(TraceryNet.Grammar grammar) { |
@@ -19,12 +22,26 | |||
|
19 | 22 | source = grammar.Flatten(this.source) |
|
20 | 23 | }; |
|
21 | 24 | } |
|
25 | ||
|
26 | ||
|
27 | ||
|
28 | public static List<NewsItem> FromYaml(string yamlString) { | |
|
29 | var input = new StringReader(yamlString); | |
|
30 | ||
|
31 | var deserializer = new DeserializerBuilder() | |
|
32 | .Build(); | |
|
33 | ||
|
34 | //Dictionary<string, string> | |
|
35 | var items = deserializer.Deserialize<List<NewsItem>>(input); | |
|
36 | ||
|
37 | return items; | |
|
38 | } | |
|
22 | 39 | } |
|
23 | 40 | |
|
24 | 41 | public static class NewsWindow |
|
25 | 42 | { |
|
26 | 43 | |
|
27 |
public static void Render(ref bool show, ImFontPtr font, Simulation sim, NewsItem |
|
|
44 | public static void Render(ref bool show, ImFontPtr font, Simulation sim, List<NewsItem> content) | |
|
28 | 45 | { |
|
29 | 46 | if (show) |
|
30 | 47 | { |
@@ -67,7 +84,7 | |||
|
67 | 84 | ImGui.EndTabItem(); |
|
68 | 85 | } |
|
69 | 86 | ImGui.EndTabItem(); |
|
70 |
if (ImGui.BeginTabItem(" |
|
|
87 | if (ImGui.BeginTabItem("The Naturalist")) { | |
|
71 | 88 | foreach (NewsItem story in content.Where( s => (s.source == "Arborist" ) )) { |
|
72 | 89 | if (ImGui.TreeNode(story.hed)) { |
|
73 | 90 | ImGui.TextWrapped(story.contents); |
@@ -9,5 +9,6 | |||
|
9 | 9 | <package id="System.Security.Permissions" version="5.0.0" targetFramework="net461" /> |
|
10 | 10 | <package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net461" /> |
|
11 | 11 | <package id="Tracery.Net" version="1.0.0" targetFramework="net461" /> |
|
12 | <package id="YamlDotNet" version="4.0.0" targetFramework="net461" /> | |
|
13 | </packages> No newline at end of file | |
|
12 | <!-- <package id="YamlDotNet" version="4.0.0" targetFramework="net461" /> --> | |
|
13 | <package id="YamlDotNet" version="9.1.4" targetFramework="net461" /> | |
|
14 | </packages> |
You need to be logged in to leave comments.
Login now