# HG changeset patch # User Alys Brooks # Date 2021-03-22 07:01:39 # Node ID 16a78cafe246521cedbbc7a46b528ffa32bf18f2 # Parent b3d2a5ea49bec293bf7941ea6b8dfa85deabeabd Add updates. diff --git a/TODO.taskpaper b/TODO.taskpaper --- a/TODO.taskpaper +++ b/TODO.taskpaper @@ -19,9 +19,9 @@ - Write a small number of testing @done(2021-03-15) - Write five stories for each source - Arborist - - Wire + - Wire @done(2021-03-22) - True - - Figure out update interval + - Figure out update interval @done(2021-03-22) - Better NEWS tab - Images for some stories - More stories—a dozen for each source? 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 @@ -208,15 +208,17 @@ this.newsItems = newItems.ToList(); - using (var sr = new StreamReader(@"Content/news_items.yaml")) - { - this.newsItems.AddRange(NewsItem.FromYaml(sr.ReadToEnd())); - } - using (var sr_pregenerated = new StreamReader(@"Content/news_items_pregenerated.yaml")) - { - this.newsItems.AddRange(NewsItem.FromYaml(sr_pregenerated.ReadToEnd())); - } - this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToList().Shuffle(); + using (var sr = new StreamReader(@"Content/news_items.yaml")) + { + this.newsItems.AddRange(NewsItem.FromYaml(sr.ReadToEnd())); + } + using (var sr_pregenerated = new StreamReader(@"Content/news_items_pregenerated.yaml")) + { + this.newsItems.AddRange(NewsItem.FromYaml(sr_pregenerated.ReadToEnd())); + } + this.simulation.LoadContent(this.newsItems, this.grammar); + // this.newsItems = this.newsItems.Select(s => s.Flatten(this.grammar)).ToList().Shuffle(); + this.remainingDialog = new Queue>(); @@ -905,7 +907,7 @@ if (this.showNews) { - NewsWindow.Render(ref this.showNews, debugWindow.monoFont, this.simulation, this.newsItems); + NewsWindow.Render(ref this.showNews, debugWindow.monoFont, this.simulation); } bool quit = false; diff --git a/isometric-park-fna/Simulation.cs b/isometric-park-fna/Simulation.cs --- a/isometric-park-fna/Simulation.cs +++ b/isometric-park-fna/Simulation.cs @@ -3,6 +3,10 @@ using static isometricparkfna.CellMap; using System.Linq; +using isometricparkfna.UI; //purely for news item + +using TraceryNet; + namespace isometricparkfna { public struct Budget @@ -109,18 +113,23 @@ } } + + private Grammar grammar; + private List sourceNewsItems; + public List latestNewsItems; + public float[] millisecondsPerAdvance { get; private set; } public String Season { get { - if (MathUtils.Between(this.DateTime.Month, 3, 5)) + if (MathUtils.BetweenInclusive(this.DateTime.Month, 3, 5)) { return "Spring"; } - else if (MathUtils.Between(this.DateTime.Month, 6, 8)) + else if (MathUtils.BetweenInclusive(this.DateTime.Month, 6, 8)) { return "Summer"; } - else if (MathUtils.Between(this.DateTime.Month, 9, 11)) + else if (MathUtils.BetweenInclusive(this.DateTime.Month, 9, 11)) { return "Fall"; } @@ -213,7 +222,12 @@ private void advanceSimulation() { + var oldSeason = this.Season; this.DateTime = this.DateTime.AddMonths(1); + var newSeason = this.Season; + var seasonChanged = oldSeason != newSeason; + + foreach (Cell cell in this.map.iterate_cells()) @@ -281,6 +295,10 @@ newBudget = this.applyBudget(newBudget); ; this.budgets.Add(newBudget); + + if (seasonChanged) { + this.updateNews(); + } } public Budget applyBudget(Budget budget) @@ -302,6 +320,19 @@ this.currentRate = newRate; } } + + public void updateNews() { + this.latestNewsItems = this.sourceNewsItems.Select(s => s.Flatten(this.grammar)).ToList().Shuffle(); + } + + public void LoadContent(List sourceNewsItems, Grammar grammar) { + this.sourceNewsItems = sourceNewsItems; + this.grammar = grammar; + + this.updateNews(); + + + } public void update(TimeSpan deltaTime) { 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 @@ -59,7 +59,7 @@ public static class NewsWindow { - public static void Render(ref bool show, ImFontPtr font, Simulation sim, List content) + public static void Render(ref bool show, ImFontPtr font, Simulation sim) { if (show) { @@ -90,6 +90,8 @@ ImGui.PushStyleColor(ImGuiCol.Text, new Num.Vector4(0f, 0f, 0f, 1f)); ImGui.SetNextWindowSize(new Num.Vector2(400, 400)); ImGui.Begin("NEWS", ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); + + var content = sim.latestNewsItems; if (ImGui.BeginTabBar("Sources", 0)) { diff --git a/isometric-park-fna/Utils/MathUtils.cs b/isometric-park-fna/Utils/MathUtils.cs --- a/isometric-park-fna/Utils/MathUtils.cs +++ b/isometric-park-fna/Utils/MathUtils.cs @@ -13,11 +13,23 @@ } - public static bool Between(int val, int x, int y) - { - return ((x < val && val < y) || (y < val && val < x)); + public static bool Between(int val, int x, int y) + { + return ((x < val && val < y) || (y < val && val < x)); + + } - } + public static bool BetweenInclusive(float val, float x, float y) + { + return ((x <= val && val <= y) || (y <= val && val <= x)); + + } + + public static bool BetweenInclusive(int val, int x, int y) + { + return ((x <= val && val <= y) || (y <= val && val <= x)); + + } public static int Clamp(int val, int min, int max) {