Description:
Support multiple dialog entities.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -10,7 +10,7 | |||||
|
10 | namespace isometricparkfna.Components { |
|
10 | namespace isometricparkfna.Components { |
|
11 |
|
11 | ||
|
12 | public struct DialogComponent : IComponent/*, IHasEntity*/ { |
|
12 | public struct DialogComponent : IComponent/*, IHasEntity*/ { |
|
13 | public Node<DialogOption> Dialog; |
|
13 | public string Knot; |
|
14 | public string CurrentDialog; |
|
14 | public string CurrentDialog; |
|
15 | // public Entity Entity {get; set;} |
|
15 | // public Entity Entity {get; set;} |
|
16 | public string CurrentSpeaker; |
|
16 | public string CurrentSpeaker; |
@@ -1,8 +1,9 | |||||
|
1 |
|
1 | ||
|
2 | VAR GovernorOpinion = 0 |
|
2 | VAR GovernorOpinion = 0 |
|
3 |
|
3 | ||
|
4 | -> IntroGovernor |
|
4 | //-> IntroGovernor |
|
5 |
|
5 | This is a test. | |
|
|
6 | -> END | ||
|
6 |
|
7 | ||
|
7 | === Once === |
|
8 | === Once === |
|
8 |
|
9 | ||
@@ -19,7 +20,7 | |||||
|
19 |
|
20 | ||
|
20 | 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. |
|
21 | 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. |
|
21 |
|
22 | ||
|
22 | * [Okay] |
|
23 | * [Okay] |
|
23 |
|
24 | ||
|
24 | 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! |
|
25 | 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! |
|
25 |
|
26 | ||
@@ -31,6 +32,8 | |||||
|
31 | * * * \... |
|
32 | * * * \... |
|
32 | -> END |
|
33 | -> END |
|
33 | * * [Sounds good!] |
|
34 | * * [Sounds good!] |
|
|
35 | ~ GovernorOpinion = GovernorOpinion + 1 | ||
|
|
36 | |||
|
34 |
|
37 | ||
|
35 | Governor: I'll check in soon. |
|
38 | Governor: I'll check in soon. |
|
36 |
|
39 |
@@ -1,1 +1,1 | |||||
|
1 |
{"inkVersion":20,"root":[[{"->":"IntroGovernor" |
|
1 | {"inkVersion":20,"root":[["^This is a test.","\n","end",["done",{"#f":5,"#n":"g-0"}],null],"done",{"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",{"^->":"IntroGovernor.0.c-0.3.c-0.10.0.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^...",{"->":"$r","var":true},null]}],{"c-0":["ev",{"^->":"IntroGovernor.0.c-0.3.c-0.10.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.0.s"},[{"#n":"$r2"}],"\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}],"global decl":["ev",0,{"VAR=":"GovernorOpinion"},"/ev","end",null],"#f":1}],"listDefs":{}} No newline at end of file |
@@ -19,6 +19,7 | |||||
|
19 |
|
19 | ||
|
20 | namespace isometricparkfna.Spawners { |
|
20 | namespace isometricparkfna.Spawners { |
|
21 |
|
21 | ||
|
|
22 | [Reads(typeof(DialogComponent))] | ||
|
22 | [Receives(typeof(SpawnDialogMessage))] |
|
23 | [Receives(typeof(SpawnDialogMessage))] |
|
23 | class DialogSpawner : Spawner<SpawnDialogMessage> |
|
24 | class DialogSpawner : Spawner<SpawnDialogMessage> |
|
24 |
|
25 | ||
@@ -34,6 +35,14 | |||||
|
34 |
|
35 | ||
|
35 | protected override void Spawn(in SpawnDialogMessage message) |
|
36 | protected override void Spawn(in SpawnDialogMessage message) |
|
36 | { |
|
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."); | ||
|
37 | //Jump to the specified part of the story: |
|
46 | //Jump to the specified part of the story: |
|
38 | Story.ChoosePathString(message.Path); |
|
47 | Story.ChoosePathString(message.Path); |
|
39 |
|
48 | ||
@@ -45,6 +54,7 | |||||
|
45 | var dialog = (parts.Length == 2) ? parts[1] : continuation; |
|
54 | var dialog = (parts.Length == 2) ? parts[1] : continuation; |
|
46 |
|
55 | ||
|
47 | AddComponent(newDialog, new DialogComponent { |
|
56 | AddComponent(newDialog, new DialogComponent { |
|
|
57 | Knot = message.Path, | ||
|
48 | CurrentDialog = dialog, |
|
58 | CurrentDialog = dialog, |
|
49 | CurrentSpeaker = speaker, |
|
59 | CurrentSpeaker = speaker, |
|
50 | Options = this.Story.currentChoices |
|
60 | Options = this.Story.currentChoices |
@@ -57,6 +67,19 | |||||
|
57 | new VisibilityComponent{ visible = true}); |
|
67 | new VisibilityComponent{ visible = true}); |
|
58 |
|
68 | ||
|
59 | Logging.Success("Spawned new dialog."); |
|
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 | } | ||
|
60 | } |
|
83 | } |
|
61 | } |
|
84 | } |
|
62 | } |
|
85 | } |
@@ -111,6 +111,7 | |||||
|
111 | #region dialog |
|
111 | #region dialog |
|
112 |
|
112 | ||
|
113 | SendMessage(new SpawnDialogMessage { Path = "IntroGovernor"}); |
|
113 | SendMessage(new SpawnDialogMessage { Path = "IntroGovernor"}); |
|
|
114 | SendMessage(new SpawnDialogMessage { Path = "Once"}); | ||
|
114 | #endregion |
|
115 | #endregion |
|
115 | this.simulation.Subsidy = message.Difficulty switch { |
|
116 | this.simulation.Subsidy = message.Difficulty switch { |
|
116 | DifficultyLevel.Hard => 0M, |
|
117 | DifficultyLevel.Hard => 0M, |
@@ -1,3 +1,4 | |||||
|
|
1 | using System; | ||
|
1 | using System.Text.RegularExpressions; |
|
2 | using System.Text.RegularExpressions; |
|
2 | using System.Linq; |
|
3 | using System.Linq; |
|
3 |
|
4 | ||
@@ -19,7 +20,8 | |||||
|
19 | typeof(SelectMessage), |
|
20 | typeof(SelectMessage), |
|
20 | typeof(SetDialogMessage), |
|
21 | typeof(SetDialogMessage), |
|
21 | typeof(DialogChoiceMessage))] |
|
22 | typeof(DialogChoiceMessage))] |
|
22 |
[Reads(typeof( |
|
23 | [Reads(typeof(DialogComponent), |
|
|
24 | typeof(WindowTypeComponent), | ||
|
23 | typeof(VisibilityComponent), |
|
25 | typeof(VisibilityComponent), |
|
24 | typeof(SelectedComponent))] |
|
26 | typeof(SelectedComponent))] |
|
25 | [Writes(typeof(VisibilityComponent), |
|
27 | [Writes(typeof(VisibilityComponent), |
@@ -100,9 +102,9 | |||||
|
100 | { |
|
102 | { |
|
101 | if (dialogMessage.newOption != null) |
|
103 | if (dialogMessage.newOption != null) |
|
102 | { |
|
104 | { |
|
103 | SetComponent(dialogMessage.Entity, |
|
105 | // SetComponent(dialogMessage.Entity, |
|
104 | new DialogComponent {Dialog = dialogMessage.newOption |
|
106 | // new DialogComponent {CurrentDialog = dialogMessage.newOption |
|
105 | }); |
|
107 | // }); |
|
106 | } |
|
108 | } |
|
107 | else |
|
109 | else |
|
108 | { |
|
110 | { |
@@ -117,6 +119,7 | |||||
|
117 | if (Story.currentChoices.Count > 0) |
|
119 | if (Story.currentChoices.Count > 0) |
|
118 | { |
|
120 | { |
|
119 | //Advance the story |
|
121 | //Advance the story |
|
|
122 | Logging.Debug("Advancing story."); | ||
|
120 | Story.ChooseChoiceIndex(choiceMessage.Choice); |
|
123 | Story.ChooseChoiceIndex(choiceMessage.Choice); |
|
121 |
|
124 | ||
|
122 | //Update the dialog component with the new speaker, dialog, and options: |
|
125 | //Update the dialog component with the new speaker, dialog, and options: |
@@ -134,10 +137,55 | |||||
|
134 | } |
|
137 | } |
|
135 | else |
|
138 | else |
|
136 | { |
|
139 | { |
|
|
140 | Logging.Debug(String.Format("Destroying Dialog (Entity ID {0}).", choiceMessage.Entity.ID)); | ||
|
137 | Destroy(choiceMessage.Entity); |
|
141 | Destroy(choiceMessage.Entity); |
|
|
142 | |||
|
|
143 | var lowestID = Int32.MaxValue; | ||
|
|
144 | Entity lowestEntity = default; | ||
|
|
145 | |||
|
|
146 | |||
|
|
147 | foreach(ref var entity in ReadEntities<DialogComponent>()) | ||
|
|
148 | { | ||
|
|
149 | if ((entity.ID < lowestID) | ||
|
|
150 | //Don't try to use entity we just destroyed: | ||
|
|
151 | && (entity.ID != choiceMessage.Entity.ID) | ||
|
|
152 | |||
|
|
153 | && (GetComponent<DialogComponent>(entity).CurrentDialog == null)) | ||
|
|
154 | { | ||
|
|
155 | lowestID = entity.ID; | ||
|
|
156 | lowestEntity = entity; | ||
|
|
157 | Logging.Spy(lowestID, "ID"); | ||
|
|
158 | } | ||
|
|
159 | } | ||
|
|
160 | |||
|
|
161 | if (lowestID != Int32.MaxValue | ||
|
|
162 | && EntityExists(lowestEntity)) | ||
|
|
163 | { | ||
|
|
164 | Logging.Debug("Hydrating Dialog."); | ||
|
|
165 | |||
|
|
166 | |||
|
|
167 | var Knot = GetComponent<DialogComponent>(lowestEntity).Knot; | ||
|
|
168 | |||
|
|
169 | Story.ChoosePathString(Knot); | ||
|
|
170 | var continuation = this.Story.ContinueMaximally(); | ||
|
|
171 | var parts = Regex.Split(continuation, ":", 0); | ||
|
|
172 | var speaker = (parts.Length == 2) ? parts[0] : ""; | ||
|
|
173 | var dialog = (parts.Length == 2) ? parts[1] : continuation; | ||
|
|
174 | SetComponent(lowestEntity, new DialogComponent { | ||
|
|
175 | Knot = Knot, | ||
|
|
176 | CurrentDialog = dialog, | ||
|
|
177 | CurrentSpeaker = speaker, | ||
|
|
178 | Options = this.Story.currentChoices | ||
|
|
179 | .Select(option => option.text) | ||
|
|
180 | .ToList()}); | ||
|
|
181 | |||
|
|
182 | } | ||
|
138 | } |
|
183 | } |
|
139 |
|
184 | ||
|
|
185 | |||
|
|
186 | |||
|
|
187 | |||
|
140 | } |
|
188 | } |
|
141 | } |
|
189 | } |
|
142 | } |
|
190 | } |
|
143 | } |
|
191 | } |
@@ -246,7 +246,7 | |||||
|
246 |
|
246 | ||
|
247 | this.Story = new Story(File.ReadAllText(@"Content/dialog.json")); |
|
247 | this.Story = new Story(File.ReadAllText(@"Content/dialog.json")); |
|
248 |
|
248 | ||
|
249 |
|
|
249 | Logging.Debug(this.Story.ContinueMaximally()); |
|
250 |
|
250 | ||
|
251 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm)); |
|
251 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm)); |
|
252 | WorldBuilder.AddEngine(new UIEngine(this.Story)); |
|
252 | WorldBuilder.AddEngine(new UIEngine(this.Story)); |
@@ -145,7 +145,6 | |||||
|
145 |
|
145 | ||
|
146 | if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0) |
|
146 | if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0) |
|
147 | { |
|
147 | { |
|
148 | // foreach (var choice in dialogComponent.Options) |
|
||
|
149 | for(int i = 0; i < dialogComponent.Options.Count; i++) |
|
148 | for(int i = 0; i < dialogComponent.Options.Count; i++) |
|
150 | { |
|
149 | { |
|
151 | string buttonText = dialogComponent.Options[i]; |
|
150 | string buttonText = dialogComponent.Options[i]; |
You need to be logged in to leave comments.
Login now