# HG changeset patch # User Alys Brooks # Date 2021-02-21 09:31:59 # Node ID 63ef771a34d81f73baadaf5b1443e531bbcb43b1 # Parent 93647912d2baf28335f94d5e45204ef56f92c1ca Add support for reading in news stories from YAML. diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -71,7 +71,7 @@ private Node currentNode; private Queue> remainingDialog; - private NewsItem[] newsItems; + private List newsItems; private bool showGrid; @@ -203,11 +203,17 @@ grammar.AddModifier("toUpper", toUpper); - this.newsItems = new[] {new NewsItem{hed="test", contents="#city.toUpper# - This is where the lede would go.", source="Wire"}, - new NewsItem{hed="Politicians Debate Stimulus Package", contents="WASHINGTON - Politicians 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"}, + var newItems = new[] {new NewsItem{hed="test", contents="#city.toUpper# - This is where the lede would go.", source="Wire"}, + 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"}, new NewsItem{hed="The Rare Subspecies of Spruce Making a Comeback", contents="Maeve Redding didn't think", source="Arborist"}, }; - this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToArray(); + + this.newsItems = newItems.ToList(); + this.newsItems.AddRange(NewsItem.FromYaml(@" +- hed: deserialized + contents: abc + source: Wire")); + this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToList(); this.remainingDialog = new Queue>(); diff --git a/isometric-park-fna/UI/Menu.cs b/isometric-park-fna/UI/Menu.cs --- a/isometric-park-fna/UI/Menu.cs +++ b/isometric-park-fna/UI/Menu.cs @@ -64,7 +64,7 @@ show_forest = !show_forest; } - if (Menu.activeButton("! News", show_news, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) + if (Menu.activeButton("\ue0bf News", show_news, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) { show_news = !show_news; diff --git a/isometric-park-fna/UI/NewsWindow.cs b/isometric-park-fna/UI/NewsWindow.cs --- a/isometric-park-fna/UI/NewsWindow.cs +++ b/isometric-park-fna/UI/NewsWindow.cs @@ -3,13 +3,16 @@ using Num = System.Numerics; using System.Linq; +using System.IO; +using System.Collections.Generic; +using YamlDotNet.Serialization; namespace isometricparkfna.UI { public struct NewsItem { - public string hed; - public string contents; + public string hed; + public string contents; public string source; public NewsItem Flatten(TraceryNet.Grammar grammar) { @@ -19,12 +22,26 @@ source = grammar.Flatten(this.source) }; } + + + + public static List FromYaml(string yamlString) { + var input = new StringReader(yamlString); + + var deserializer = new DeserializerBuilder() + .Build(); + + //Dictionary + var items = deserializer.Deserialize>(input); + + return items; + } } public static class NewsWindow { - public static void Render(ref bool show, ImFontPtr font, Simulation sim, NewsItem[] content) + public static void Render(ref bool show, ImFontPtr font, Simulation sim, List content) { if (show) { @@ -67,7 +84,7 @@ ImGui.EndTabItem(); } ImGui.EndTabItem(); - if (ImGui.BeginTabItem("Arborist")) { + if (ImGui.BeginTabItem("The Naturalist")) { foreach (NewsItem story in content.Where( s => (s.source == "Arborist" ) )) { if (ImGui.TreeNode(story.hed)) { ImGui.TextWrapped(story.contents); diff --git a/isometric-park-fna/packages.config b/isometric-park-fna/packages.config --- a/isometric-park-fna/packages.config +++ b/isometric-park-fna/packages.config @@ -9,5 +9,6 @@ - - \ No newline at end of file + + +