From 05fc9156b053637969df0eff6bd122448d57a5c9 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Thu, 15 Feb 2024 01:54:01 -0300 Subject: [PATCH] Working debug console, fix dialogue bugs --- src/Game.hx | 76 +++++++++++++++++-------- src/{ => dialogue}/DialogueBox.hx | 2 + src/{ => dialogue}/DialogueManager.hx | 70 +++++++++++++++-------- src/dialogue/event/DialogueComplete.hx | 11 ++++ src/dialogue/event/LineShown.hx | 36 ++++++++++++ src/dialogue/event/NextLine.hx | 7 +++ src/dialogue/event/OptionSelected.hx | 11 ++++ src/dialogue/event/OptionsShown.hx | 19 +++++++ src/dialogue/event/StartDialogueNode.hx | 11 ++++ src/event/EventBus.hx | 1 + 10 files changed, 195 insertions(+), 49 deletions(-) rename src/{ => dialogue}/DialogueBox.hx (99%) rename src/{ => dialogue}/DialogueManager.hx (64%) create mode 100644 src/dialogue/event/DialogueComplete.hx create mode 100644 src/dialogue/event/LineShown.hx create mode 100644 src/dialogue/event/NextLine.hx create mode 100644 src/dialogue/event/OptionSelected.hx create mode 100644 src/dialogue/event/OptionsShown.hx create mode 100644 src/dialogue/event/StartDialogueNode.hx diff --git a/src/Game.hx b/src/Game.hx index 51f3f63..0947396 100644 --- a/src/Game.hx +++ b/src/Game.hx @@ -8,9 +8,14 @@ import event.EventBus; import event.ChangeSceneEvent; import Const; -import DialogueBox; -import DialogueManager; -import DialogueManager.Option; +import dialogue.DialogueBox; +import dialogue.DialogueManager; + +import dialogue.event.LineShown; +import dialogue.event.OptionsShown; +import dialogue.event.OptionSelected; +import dialogue.event.DialogueComplete; +import dialogue.event.NextLine; @:uiComp("game-container") class GameContainer extends h2d.Flow implements h2d.domkit.Object { @@ -29,13 +34,13 @@ class GameContainer extends h2d.Flow implements h2d.domkit.Object { class Game extends hxd.App { public var font:h2d.Font; public var curDialogue:h2d.Object; - public var actions:Array = []; + public var options:Array = []; public var dialogueManager:DialogueManager; public var globalEventBus:EventBus; public static var current:Game; // Current Game (singleton) - // var layer:Layers; + var layer:Layers; public var root:GameContainer; var console:Console; var style = null; @@ -60,13 +65,20 @@ class Game extends hxd.App { style.allowInspect = true; style.addObject(root); + font = Res.font.minecraftia_regular_6.toFont(); + layer = new Layers(s2d); + + #if debug + console = new Console(font); + layer.addChildAt(console, 4); + #end + + font.resizeTo(20); + globalEventBus = new EventBus(console); globalEventBus.subscribe(ChangeSceneEvent, onChangeScene); - font = Res.font.minecraftia_regular_6.toFont(); - font.resizeTo(24); - - dialogueManager = new DialogueManager(dialogue, renderActions); + dialogueManager = new DialogueManager(globalEventBus); var yarnText = [ hxd.Res.text.intro.entry.getText(), @@ -76,6 +88,11 @@ class Game extends hxd.App { ]; dialogueManager.load(yarnText, yarnFileNames); + globalEventBus.subscribe(LineShown, dialogue); + globalEventBus.subscribe(OptionsShown, renderOptions); + globalEventBus.subscribe(OptionSelected, onOptionSelected); + globalEventBus.subscribe(DialogueComplete, onDialogueComplete); + #if debug setGameScene(new WorldMapScene(root)); #else @@ -97,19 +114,24 @@ class Game extends hxd.App { style.sync(); } - function dialogue(manager:DialogueManager, t:String) { - var d = new DialogueBox(Const.W, 100, t); + function dialogue(event:LineShown) { + if (curDialogue != null) { + curDialogue.remove(); + } + var d = new DialogueBox(Const.W, 100, event.line()); d.y = 0; d.onClick = function() { - manager.resume(); + globalEventBus.publishEvent(new NextLine()); }; curDialogue = d; } - function renderActions(manager:DialogueManager, t:Array