Description:
Refactor dialog into separate Engine. (grafted from 93578fea7b5a3227975305bcc32e2e2fb2f7f7bc)
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r405:3308ea479431 -

@@ -0,0 +1,55
1
2 VAR GovernorOpinion = 0
3
4 //This is needed to make both including and for jumpting to dialog sections work:
5 === placeholder ===
6
7 -> END
8
9 === Once ===
10
11 Once upon a time...
12
13 * There were two choices.
14 * There were four lines of content.
15
16 - They lived happily ever after.
17 -> END
18
19
20 === IntroGovernor ===
21
22 Governor: Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.
23
24 * [Okay]
25
26 Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!
27
28 * * [And I need to keep the forest healthy, too, right?]
29 ~ GovernorOpinion = GovernorOpinion - 1
30
31
32 Governor: Ummm, yeah
33 * * * [\...]
34 -> END
35 * * [Sounds good!]
36 ~ GovernorOpinion = GovernorOpinion + 1
37
38
39 Governor: I'll check in soon.
40
41
42 -> END
43
44
45 === IntroAssistant ===
46
47 \#assistantName\#: \#whatever\#
48 * [Hi]
49
50 \#assistantName\#: Bye
51 -> END
52 * [How are you?]
53
54 \#assistantName\#: \#howdoing\#
55 -> END No newline at end of file
@@ -0,0 +1,1
1 {"inkVersion":20,"root":[[["done",{"#f":5,"#n":"g-0"}],null],"done",{"placeholder":["end",{"#f":1}],"Once":[["^Once upon a time...","\n",["ev",{"^->":"Once.0.2.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^There were two choices.",{"->":"$r","var":true},null]}],["ev",{"^->":"Once.0.3.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-1","flg":18},{"s":["^There were four lines of content.",{"->":"$r","var":true},null]}],{"c-0":["ev",{"^->":"Once.0.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.2.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"c-1":["ev",{"^->":"Once.0.c-1.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.3.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"g-0":["^They lived happily ever after.","\n","end",{"#f":5}]}],{"#f":1}],"IntroGovernor":[["^Governor: Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.","\n","ev","str","^Okay","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!","\n",["ev","str","^And I need to keep the forest healthy, too, right?","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Sounds good!","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["^ ","\n","ev",{"VAR?":"GovernorOpinion"},1,"-","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: Ummm, yeah","\n",["ev","str","^...","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","end",{"#f":5}]}],{"#f":5}],"c-1":["\n","ev",{"VAR?":"GovernorOpinion"},1,"+","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: I'll check in soon.","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"IntroAssistant":[["^#assistantName#: #whatever#","\n","ev","str","^Hi","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^How are you?","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["\n","^#assistantName#: Bye","\n","end",{"#f":5}],"c-1":["\n","^#assistantName#: #howdoing#","\n","end",{"#f":5}]}],{"#f":1}],"global decl":["ev",0,{"VAR=":"GovernorOpinion"},"/ev","end",null],"#f":1}],"listDefs":{}} No newline at end of file
@@ -0,0 +1,122
1 using System;
2 using System.Text.RegularExpressions;
3 using System.Linq;
4
5 using Encompass;
6 using Ink.Runtime;
7 using TraceryNet;
8
9 using isometricparkfna.Messages;
10 using isometricparkfna.Components;
11
12 namespace isometricparkfna.Engines
13 {
14
15 [Receives(typeof(SetDialogMessage),
16 typeof(DialogChoiceMessage))]
17 [Reads(typeof(DialogComponent)) ]
18 [Writes( typeof(DialogComponent))]
19 class DialogEngine : Engine
20 {
21 public Story Story;
22 public Grammar Grammar;
23
24 public DialogEngine(Story story, Grammar grammar)
25 {
26 this.Story = story;
27 this.Grammar = grammar;
28 }
29
30 public override void Update(double dt)
31 {
32
33 foreach (ref readonly var dialogMessage in ReadMessages<SetDialogMessage>())
34 {
35 if (dialogMessage.newOption != null)
36 {
37 // SetComponent(dialogMessage.Entity,
38 // new DialogComponent {CurrentDialog = dialogMessage.newOption
39 // });
40 }
41 else
42 {
43 Destroy(dialogMessage.Entity);
44
45 }
46 }
47
48 foreach (ref readonly var choiceMessage in ReadMessages<DialogChoiceMessage>())
49 {
50
51 if (Story.currentChoices.Count > 0)
52 {
53 //Advance the story
54 Logging.Debug("Advancing story.");
55 Story.ChooseChoiceIndex(choiceMessage.Choice);
56
57 //Update the dialog component with the new speaker, dialog, and options:
58 var continuation = this.Grammar.Flatten(this.Story.ContinueMaximally());
59 var parts = Regex.Split(continuation, ":", 0);
60 var speaker = (parts.Length == 2) ? this.Grammar.Flatten(parts[0]) : "Dialog";
61 var dialog = (parts.Length == 2) ? this.Grammar.Flatten(parts[1]) : continuation;
62
63 SetComponent(choiceMessage.Entity, new DialogComponent {
64 CurrentDialog = dialog,
65 CurrentSpeaker = speaker,
66 Options = this.Story.currentChoices
67 .Select(option => option.text)
68 .ToList()});}
69 else
70 {
71 Logging.Debug(String.Format("Destroying Dialog (Entity ID {0}).", choiceMessage.Entity.ID));
72 Destroy(choiceMessage.Entity);
73
74 var lowestID = Int32.MaxValue;
75 Entity lowestEntity = default;
76
77
78 foreach(ref var entity in ReadEntities<DialogComponent>())
79 {
80 if ((entity.ID < lowestID)
81 //Don't try to use entity we just destroyed:
82 && (entity.ID != choiceMessage.Entity.ID)
83
84 && (!GetComponent<DialogComponent>(entity).Hydrated))
85 {
86 lowestID = entity.ID;
87 lowestEntity = entity;
88 Logging.Spy(lowestID, "ID");
89 }
90 }
91
92 if (lowestID != Int32.MaxValue
93 && EntityExists(lowestEntity))
94 {
95 Logging.Debug("Hydrating Dialog.");
96
97
98 var Knot = GetComponent<DialogComponent>(lowestEntity).Knot;
99
100 Story.ChoosePathString(Knot);
101 var continuation = this.Story.ContinueMaximally();
102 var parts = Regex.Split(continuation, ":", 0);
103 var speaker = (parts.Length == 2) ? this.Grammar.Flatten(parts[0]) : "Dialog";
104 var dialog = (parts.Length == 2) ? this.Grammar.Flatten(parts[1]) : continuation;
105 SetComponent(lowestEntity, new DialogComponent {
106 Knot = Knot,
107 CurrentDialog = dialog,
108 CurrentSpeaker = speaker,
109 Options = this.Story.currentChoices
110 .Select(option => option.text)
111 .ToList()});
112
113 }
114 }
115
116
117
118
119 }
120 }
121 }
122 }
@@ -0,0 +1,85
1
2
3 using System;
4 using System.Collections.Generic;
5 using System.Text.RegularExpressions;
6 using System.Linq;
7
8 using Microsoft.Xna.Framework;
9
10 using isometricparkfna.Messages;
11 using isometricparkfna.Components;
12 using static isometricparkfna.CellMap;
13 using isometricparkfna.UI;
14
15 using Encompass;
16 using TraceryNet;
17 using Ink.Runtime;
18
19
20 namespace isometricparkfna.Spawners {
21
22 [Reads(typeof(DialogComponent))]
23 [Receives(typeof(SpawnDialogMessage))]
24 class DialogSpawner : Spawner<SpawnDialogMessage>
25
26 {
27 Story Story;
28 Grammar Grammar;
29
30 public DialogSpawner(Story story, Grammar grammar)
31 {
32 this.Story = story;
33 this.Grammar = grammar;
34 }
35
36 protected override void Spawn(in SpawnDialogMessage message)
37 {
38 Logging.Spy(this.Story.currentChoices.Count(), "Count");
39 Logging.Spy(this.Story.canContinue, "CanContinue");
40 //If there are no existing dialog:
41 if(ReadEntities<DialogComponent>().Length == 0
42 && this.Story.currentChoices.Count() == 0
43 && !this.Story.canContinue)
44 {
45 Logging.Debug("Creating and hydrating new Dialog.");
46 //Jump to the specified part of the story:
47 Story.ChoosePathString(message.Path);
48
49 var newDialog = CreateEntity();
50 var continuation = this.Story.ContinueMaximally();
51
52 var parts = Regex.Split(continuation, ":", 0);
53 var speaker = (parts.Length == 2) ? parts[0] : "";
54 var dialog = (parts.Length == 2) ? parts[1] : continuation;
55
56 AddComponent(newDialog, new DialogComponent {
57 Knot = message.Path,
58 CurrentDialog = this.Grammar.Flatten(dialog),
59 CurrentSpeaker = this.Grammar.Flatten(speaker),
60 Options = this.Story.currentChoices
61 .Select(option => option.text)
62 .ToList()});
63
64 AddComponent(newDialog, new WindowTypeComponent {
65 type = Window.Dialog});
66 AddComponent(newDialog,
67 new VisibilityComponent{ visible = true});
68
69 Logging.Success("Spawned new dialog.");
70 }
71 else
72 {
73
74 Logging.Debug("Creating new Dialog without hydrating.");
75 var newDialog = CreateEntity();
76 AddComponent(newDialog, new DialogComponent {
77 Knot = message.Path});
78 AddComponent(newDialog, new WindowTypeComponent {
79 type = Window.Dialog});
80 AddComponent(newDialog,
81 new VisibilityComponent{ visible = true});
82 }
83 }
84 }
85 }
@@ -0,0 +1,17
1
2 using Encompass;
3
4 using isometricparkfna.Utils;
5 using isometricparkfna.UI;
6
7 namespace isometricparkfna.Messages
8 {
9
10 //You must specify both or you get 0 for a window, which is the default window :(
11 public struct DialogChoiceMessage : IMessage, IHasEntity
12 {
13
14 public Entity Entity { set; get; }
15 public int Choice;
16 }
17 }
@@ -0,0 +1,15
1
2
3 using Microsoft.Xna.Framework;
4 using Encompass;
5
6 using isometricparkfna.Spawners;
7
8 #nullable enable
9
10 namespace isometricparkfna.Messages {
11 public struct SpawnDialogMessage : IMessage
12 {
13 public string Path;
14 }
15 }
@@ -33,4 +33,8
33 <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
33 <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
34 <PackageReference Include="LinqFaster" Version="1.0.0" />
34 <PackageReference Include="LinqFaster" Version="1.0.0" />
35 </ItemGroup>
35 </ItemGroup>
36
37 <ItemGroup>
38 <PackageReference Include="Ink.Engine.Runtime-Unofficial" Version="1.0.0-nightly-21061600" />
39 </ItemGroup>
36 </Project>
40 </Project>
@@ -1,3 +1,4
1 using System.Collections.Generic;
1
2
2
3
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework;
@@ -9,7 +10,13
9
10
10 namespace isometricparkfna.Components {
11 namespace isometricparkfna.Components {
11
12
12 public struct DialogComponent : IComponent {
13 public struct DialogComponent : IComponent/*, IHasEntity*/ {
13 public Node<DialogOption> Dialog;
14 public string Knot;
15 public string CurrentDialog;
16 public string CurrentSpeaker;
17 public List<string> Options;
18 public bool Hydrated { get {
19 return (this.CurrentDialog != null)
20 && (this.CurrentSpeaker != null); }}
14 }
21 }
15 }
22 }
@@ -1,5 +1,6
1 using System;
1 using System;
2 using System.Collections.Generic;
2 using System.Collections.Generic;
3 using Encompass;
3 using System.Linq;
4 using System.Linq;
4
5
5 using Encompass;
6 using Encompass;
@@ -23,13 +24,16
23 typeof(SetTrespassingPolicyMessage),
24 typeof(SetTrespassingPolicyMessage),
24 typeof(SpawnGameMessage),
25 typeof(SpawnGameMessage),
25 typeof(SetTextVariableMessage),
26 typeof(SetTextVariableMessage),
26 typeof(SetDialogMessage))]
27 typeof(SetDialogMessage),
28 typeof(DialogChoiceMessage))]
27 [Reads(typeof(VisibilityComponent),
29 [Reads(typeof(VisibilityComponent),
28 typeof(WindowTypeComponent),
30 typeof(WindowTypeComponent),
29 typeof(TrespassingPolicyComponent),
31 typeof(TrespassingPolicyComponent),
30 typeof(ContractStatusComponent),
32 typeof(ContractStatusComponent),
31 typeof(RelatedOrganizationComponent),
33 typeof(RelatedOrganizationComponent),
32 typeof(NameAndDescriptionComponent))]
34 typeof(NameAndDescriptionComponent)
35 )]
36 // [Writes(typeof(SelectedComponent))]
33 public class ImGuiWindowBridgeEngine : Engine
37 public class ImGuiWindowBridgeEngine : Engine
34 {
38 {
35
39
@@ -45,6 +49,7
45 public List<SpawnGameMessage> spawnGameMessages;
49 public List<SpawnGameMessage> spawnGameMessages;
46 public List<SetTextVariableMessage> setTextVariableMessages;
50 public List<SetTextVariableMessage> setTextVariableMessages;
47 public List<SetDialogMessage> setDialogMessages;
51 public List<SetDialogMessage> setDialogMessages;
52 public List<DialogChoiceMessage> dialogChoiceMessages;
48
53
49 bool showBudget {get;}
54 bool showBudget {get;}
50 bool showForest {get;}
55 bool showForest {get;}
@@ -83,6 +88,7
83 this.spawnGameMessages = new List<SpawnGameMessage>();
88 this.spawnGameMessages = new List<SpawnGameMessage>();
84 this.setTextVariableMessages = new List<SetTextVariableMessage>();
89 this.setTextVariableMessages = new List<SetTextVariableMessage>();
85 this.setDialogMessages = new List<SetDialogMessage>();
90 this.setDialogMessages = new List<SetDialogMessage>();
91 this.dialogChoiceMessages = new List<DialogChoiceMessage>();
86 this.windowStatuses = new Dictionary<Window, bool>();
92 this.windowStatuses = new Dictionary<Window, bool>();
87
93
88 this.showContractIndicator = false;
94 this.showContractIndicator = false;
@@ -172,6 +178,10
172 {
178 {
173 SendMessage(message);
179 SendMessage(message);
174 }
180 }
181 foreach (var message in this.dialogChoiceMessages)
182 {
183 SendMessage(message);
184 }
175
185
176
186
177
187
@@ -220,6 +230,7
220 this.spawnGameMessages.Clear();
230 this.spawnGameMessages.Clear();
221 this.setTextVariableMessages.Clear();
231 this.setTextVariableMessages.Clear();
222 this.setDialogMessages.Clear();
232 this.setDialogMessages.Clear();
233 this.dialogChoiceMessages.Clear();
223 }
234 }
224 }
235 }
225 }
236 }
@@ -17,10 +17,11
17 [Receives(typeof(SpawnGameMessage))]
17 [Receives(typeof(SpawnGameMessage))]
18 [Sends(typeof(SpawnContractMessage),
18 [Sends(typeof(SpawnContractMessage),
19 typeof(SpawnOrganizationtMessage),
19 typeof(SpawnOrganizationtMessage),
20 typeof(ToggleWindowMessage))]
20 typeof(ToggleWindowMessage),
21 typeof(SpawnDialogMessage))]
21 [Writes(typeof(WindowTypeComponent)
22 [Writes(typeof(WindowTypeComponent)
22 //, typeof(DialogComponent)
23 //, typeof(DialogComponent)
23 )]
24 )]
24 class GameSpawner : Spawner<SpawnGameMessage>
25 class GameSpawner : Spawner<SpawnGameMessage>
25
26
26 {
27 {
@@ -111,34 +112,9
111 #endregion
112 #endregion
112 #region dialog
113 #region dialog
113
114
114 // this.game.enqueueDialog(DialogTrees.flatten(DialogTrees.testTree, this.grammar));
115 SendMessage(new SpawnDialogMessage { Path = "IntroGovernor"});
115 //
116 // SendMessage(new SpawnDialogMessage { Path = "Once"});
116
117 SendMessage(new SpawnDialogMessage { Path = "IntroAssistant"});
117 var dialogInitial = CreateEntity();
118 // SetComponent(dialogInitial, new VisibilityComponent { visible = true });
119 AddComponent(dialogInitial, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
120 AddComponent(dialogInitial,
121 new DialogComponent {Dialog = DialogTrees.introTree });
122 AddComponent(dialogInitial,
123 new VisibilityComponent{ visible = true});
124 // SendMessage(new SetWindowVisibilityMessage {
125 // Entity = dialogInitial,
126 // Visibility = true });
127
128
129 var dialogTest = CreateEntity();
130 // SetComponent(dialogTest, new VisibilityComponent { visible = true });
131 AddComponent(dialogTest, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
132 AddComponent(dialogTest,
133 new DialogComponent {Dialog = DialogTrees.flatten(DialogTrees.testTree, this.grammar)});
134 // SendMessage(new SetWindowVisibilityMessage {
135 // Entity = dialogTest,
136 // Visibility = true
137 // });
138 AddComponent(dialogTest,
139 new VisibilityComponent{ visible = true});
140
141
142 #endregion
118 #endregion
143 this.simulation.Subsidy = message.Difficulty switch {
119 this.simulation.Subsidy = message.Difficulty switch {
144 DifficultyLevel.Hard => 0M,
120 DifficultyLevel.Hard => 0M,
@@ -1,6 +1,12
1 using System;
2 using System.Text.RegularExpressions;
3 using System.Linq;
4
1 using Microsoft.Xna.Framework.Input;
5 using Microsoft.Xna.Framework.Input;
2
6
3 using Encompass;
7 using Encompass;
8 using Ink.Runtime;
9 using TraceryNet;
4
10
5 using isometricparkfna.Messages;
11 using isometricparkfna.Messages;
6 using isometricparkfna.Components;
12 using isometricparkfna.Components;
@@ -13,15 +19,23
13 typeof(ToggleVisibilityMessage),
19 typeof(ToggleVisibilityMessage),
14 typeof(SetWindowVisibilityMessage),
20 typeof(SetWindowVisibilityMessage),
15 typeof(SelectMessage),
21 typeof(SelectMessage),
16 typeof(SetDialogMessage))]
22 typeof(SetDialogMessage),
17 [Reads(typeof(WindowTypeComponent),
23 typeof(DialogChoiceMessage))]
24 [Reads(typeof(DialogComponent),
25 typeof(WindowTypeComponent),
18 typeof(VisibilityComponent),
26 typeof(VisibilityComponent),
19 typeof(SelectedComponent))]
27 typeof(SelectedComponent))]
20 [Writes(typeof(VisibilityComponent),
28 [Writes(typeof(VisibilityComponent),
21 typeof(SelectedComponent),
29 typeof(SelectedComponent))]
22 typeof(DialogComponent))]
23 class UIEngine : Engine
30 class UIEngine : Engine
24 {
31 {
32 public Story Story;
33
34 public UIEngine(Story story)
35 {
36 this.Story = story;
37 }
38
25 public override void Update(double dt)
39 public override void Update(double dt)
26 {
40 {
27 foreach (var entity in ReadEntities<SelectedComponent>())
41 foreach (var entity in ReadEntities<SelectedComponent>())
@@ -31,31 +45,43
31
45
32 foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>())
46 foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>())
33 {
47 {
48 Logging.Spy(windowMessage, "message");
49 Logging.Spy(windowMessage.Entity, "message.Entity");
50 Logging.Spy(windowMessage.Entity.ID, "message.Entity.ID");
51 Logging.Spy(windowMessage.Visibility, "message.Visibility");
34 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
52 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
35 {
53 {
54 Logging.Spy(entity.ID, "ID");
36 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
55 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
37 {
56 {
38 SetComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility });
57 AddComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility });
39 Logging.Success("Set Visibility.");
58 Logging.Success("Set Visibility.");
59
40 }
60 }
41 }
61 }
42 }
62 }
43 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
63 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
44 {
64 {
65 Logging.Spy(windowMessage, "message");
66 Logging.Spy(windowMessage.Window, "message.Window");
67 Logging.Spy(windowMessage.Entity, "message.Entity");
45 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
68 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
46 {
69 {
47 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
70 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
48 {
71 {
49 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
72 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
50 SetComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
73 AddComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
51
74
52 }
75 }
53 }
76 }
54 }
77 }
55 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowTypeMessage>())
78 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowTypeMessage>())
56 {
79 {
80 Logging.Spy(windowMessage, "message");
81 Logging.Spy(windowMessage.Window, "message.Window");
57 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
82 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
58 {
83 {
84
59 var window_type = GetComponent<WindowTypeComponent>(entity).type;
85 var window_type = GetComponent<WindowTypeComponent>(entity).type;
60 if (window_type == windowMessage.Window)
86 if (window_type == windowMessage.Window)
61 {
87 {
@@ -72,19 +98,7
72 new SelectedComponent { selected = true });
98 new SelectedComponent { selected = true });
73 }
99 }
74
100
75 foreach (ref readonly var dialogMessage in ReadMessages<SetDialogMessage>())
101
76 {
77 if (dialogMessage.newOption != null)
78 {
79 SetComponent(dialogMessage.Entity,
80 new DialogComponent {Dialog = dialogMessage.newOption
81 });
82 }
83 else
84 {
85 Destroy(dialogMessage.Entity);
86 }
87 }
88 }
102 }
89 }
103 }
90 }
104 }
@@ -12,8 +12,8
12 using System.Collections.Generic;
12 using System.Collections.Generic;
13 using System.Linq;
13 using System.Linq;
14 using SpriteFontPlus;
14 using SpriteFontPlus;
15
15 using isometricparkfna;
16 using isometricparkfna;
16
17 using static isometricparkfna.CellMap;
17 using static isometricparkfna.CellMap;
18 using isometricparkfna.Utils;
18 using isometricparkfna.Utils;
19 using isometricparkfna.UI;
19 using isometricparkfna.UI;
@@ -28,6 +28,7
28 using ImGuiNET;
28 using ImGuiNET;
29 using TraceryNet;
29 using TraceryNet;
30 using Encompass;
30 using Encompass;
31 using Ink.Runtime;
31
32
32 //Let's let core builds be deterministic
33 //Let's let core builds be deterministic
33 #if NETCOREAPP
34 #if NETCOREAPP
@@ -86,6 +87,8
86 private bool showInitial;
87 private bool showInitial;
87 int messageIndex;
88 int messageIndex;
88
89
90 public Story Story;
91
89 //buggy
92 //buggy
90 private static bool enableCulling = false;
93 private static bool enableCulling = false;
91
94
@@ -110,6 +113,8
110
113
111 private ImGuiWindowBridgeEngine imGuiWindowBridgeEngine;
114 private ImGuiWindowBridgeEngine imGuiWindowBridgeEngine;
112
115
116
117
113 private static void Main(string[] args)
118 private static void Main(string[] args)
114 {
119 {
115 #if NETCOREAPP
120 #if NETCOREAPP
@@ -246,8 +251,13
246 //Has to happen after Grammar initialization.
251 //Has to happen after Grammar initialization.
247 NewGameWindow.Initialize(this.grammar);
252 NewGameWindow.Initialize(this.grammar);
248
253
254 this.Story = new Story(File.ReadAllText(@"Content/dialog.json"));
255
256 Logging.Debug(this.Story.ContinueMaximally());
257
249 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm));
258 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm));
250 WorldBuilder.AddEngine(new UIEngine());
259 WorldBuilder.AddEngine(new UIEngine(this.Story));
260 WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar));
251
261
252 var gameBridgeEngine = new GameBridgeEngine(this);
262 var gameBridgeEngine = new GameBridgeEngine(this);
253
263
@@ -262,6 +272,7
262 WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar));
272 WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar));
263 WorldBuilder.AddEngine(new GameSpawner(this.simulation, this, this.grammar));
273 WorldBuilder.AddEngine(new GameSpawner(this.simulation, this, this.grammar));
264 WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
274 WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
275 WorldBuilder.AddEngine(new DialogSpawner(this.Story, this.grammar));
265 WorldBuilder.AddEngine(new PolicyEngine());
276 WorldBuilder.AddEngine(new PolicyEngine());
266 WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar));
277 WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar));
267
278
@@ -86,7 +86,7
86 var width = gdm.PreferredBackBufferWidth;
86 var width = gdm.PreferredBackBufferWidth;
87
87
88 Entity dialogEntity = default;
88 Entity dialogEntity = default;
89 Node<DialogOption> dialogNode = default;
89 DialogComponent dialogNode = default;
90
90
91
91
92
92
@@ -134,7 +134,7
134 break;
134 break;
135 case Window.Dialog:
135 case Window.Dialog:
136
136
137 var dialog = GetComponent<DialogComponent>(entity).Dialog;
137 var dialog = GetComponent<DialogComponent>(entity);
138
138
139 if ((dialogEntity == null)
139 if ((dialogEntity == null)
140 || (dialogEntity.ID == 0)
140 || (dialogEntity.ID == 0)
@@ -151,7 +151,7
151
151
152 }
152 }
153 }
153 }
154 if (dialogNode != null)
154 if (dialogNode.Hydrated)
155 {
155 {
156 var show = true;
156 var show = true;
157 var paused = true;
157 var paused = true;
@@ -8,6 +8,7
8 using Encompass;
8 using Encompass;
9
9
10 using isometricparkfna.Engines;
10 using isometricparkfna.Engines;
11 using isometricparkfna.Components;
11 using isometricparkfna.Messages;
12 using isometricparkfna.Messages;
12
13
13 #nullable enable
14 #nullable enable
@@ -111,10 +112,10
111 {
112 {
112
113
113 public static bool hadFocus = false;
114 public static bool hadFocus = false;
114 public static Node<DialogOption> RenderDialog(Entity entity,
115 public static void RenderDialog(Entity entity,
115 ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, Node<DialogOption> currentNode)
116 ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent)
116 {
117 {
117 Node<DialogOption> new_child = currentNode;
118 Node<DialogOption> new_child = default;
118 if (show)
119 if (show)
119 {
120 {
120 ImGui.PushFont(font);
121 ImGui.PushFont(font);
@@ -127,7 +128,8
127 {
128 {
128 ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
129 ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
129 }
130 }
130 ImGui.Begin(currentNode.data.speaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
131
132 ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
131 if (DialogInterface.hadFocus)
133 if (DialogInterface.hadFocus)
132 {
134 {
133 ImGui.PopStyleColor();
135 ImGui.PopStyleColor();
@@ -135,21 +137,24
135 DialogInterface.hadFocus = ImGui.IsWindowFocused();
137 DialogInterface.hadFocus = ImGui.IsWindowFocused();
136
138
137
139
138 if (currentNode.data.response != null)
140 if (dialogComponent.CurrentDialog != null)
139 {
141 {
140 string messageText = currentNode.data.response;
142 string messageText = dialogComponent.CurrentDialog;
141 ImGui.TextWrapped(messageText);
143 ImGui.TextWrapped(messageText);
142 }
144 }
143
145
144 if ((currentNode.children != null) && currentNode.children.Length > 0)
146 if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0)
145 {
147 {
146 //Filter out nulls
148 for(int i = 0; i < dialogComponent.Options.Count; i++)
147 foreach ((Node<DialogOption> child, string choice) in currentNode.children.Select((child) => (child, child.data.choice)).Where( (pair, choice) => pair.choice != null))
148 {
149 {
149 string buttonText = choice;
150 string buttonText = dialogComponent.Options[i];
150 if (ImGui.Button(buttonText))
151 if (ImGui.Button(buttonText))
151 {
152 {
152 new_child = child;
153 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
154
155 Entity = entity,
156 Choice = i });
157
153 }
158 }
154 }
159 }
155 }
160 }
@@ -159,14 +164,14
159 {
164 {
160 show = false;
165 show = false;
161 paused = false;
166 paused = false;
162 bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
167 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
163
168
164 Entity = entity,
169 Entity = entity,
165 newOption = null });
170 Choice = -1 });
166 }
171 }
167 }
172 }
168
173
169 if (currentNode.data.response == null)
174 if (dialogComponent.CurrentDialog == null)
170 {
175 {
171 show = false;
176 show = false;
172 paused = false;
177 paused = false;
@@ -177,11 +182,6
177 StyleSets.defaultSet.pop();
182 StyleSets.defaultSet.pop();
178 ImGui.PopFont();
183 ImGui.PopFont();
179 }
184 }
180 bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
181
182 Entity = entity,
183 newOption = new_child });
184 return new_child;
185 }
185 }
186 }
186 }
187 }
187 }
@@ -46,6 +46,7
46 <!-- <Import Project="..\build\CopyFNALibs.targets"/> -->
46 <!-- <Import Project="..\build\CopyFNALibs.targets"/> -->
47 <ItemGroup>
47 <ItemGroup>
48 <PackageReference Include="ImGui.NET" Version="1.78.0" />
48 <PackageReference Include="ImGui.NET" Version="1.78.0" />
49 <PackageReference Include="Ink.Engine.Runtime-Unofficial" Version="1.0.0-nightly-21061600" />
49 <PackageReference Include="Tracery.Net" Version="1.0.0" />
50 <PackageReference Include="Tracery.Net" Version="1.0.0" />
50 <PackageReference Include="YamlDotNet" Version="11.0.1" />
51 <PackageReference Include="YamlDotNet" Version="11.0.1" />
51 <PackageReference Include="JM.LinqFaster" Version="1.1.2" />
52 <PackageReference Include="JM.LinqFaster" Version="1.1.2" />
@@ -148,6 +148,9
148 <None Include="Content\grammar.json">
148 <None Include="Content\grammar.json">
149 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
150 </None>
150 </None>
151 <None Include="Content\dialog.json">
152 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
153 </None>
151 <None Include="Content\news_items.yaml">
154 <None Include="Content\news_items.yaml">
152 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
155 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
153 </None>
156 </None>
@@ -228,6 +231,9
228 <ItemGroup>
231 <ItemGroup>
229 <Folder Include="Utils\" />
232 <Folder Include="Utils\" />
230 </ItemGroup>
233 </ItemGroup>
234 <ItemGroup>
235 <PackageReference Include="Ink.Engine.Runtime-Unofficial" Version="1.0.0-nightly-21061600" />
236 </ItemGroup>
231 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
237 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
232 <Import Project="..\packages\ImGui.NET.1.78.0\build\net40\ImGui.NET.targets" Condition="Exists('..\packages\ImGui.NET.1.78.0\build\net40\ImGui.NET.targets')" />
238 <Import Project="..\packages\ImGui.NET.1.78.0\build\net40\ImGui.NET.targets" Condition="Exists('..\packages\ImGui.NET.1.78.0\build\net40\ImGui.NET.targets')" />
233 </Project>
239 </Project>
You need to be logged in to leave comments. Login now