reusable Hank story window

This commit is contained in:
2025-10-31 15:06:58 -05:00
parent 26d5b60d33
commit f08d7868a1
3 changed files with 39 additions and 1 deletions

5
haxe_libraries/hank.hxml Normal file
View File

@@ -0,0 +1,5 @@
# @install: lix --silent download "git:https://k7izh9.gitea.cloud/NQN/hank#915f0ea58cc0940f47eb88171a36b7f39e1070e5" into hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5
# @run: haxelib run-dir hank "${HAXE_LIBCACHE}/hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5"
-lib hscript
-cp ${HAXE_LIBCACHE}/hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5/
-D hank=0.0.8

View File

@@ -22,6 +22,7 @@ import flixel.input.mouse.FlxMouseEvent;
import kiss_flixel.KissExtendedSprite;
import flixel.addons.plugin.FlxMouseControl;
import hx.strings.Strings;
import hank.Story;
using haxe.io.Path;
using StringTools;
@@ -46,5 +47,7 @@ typedef ConstructorArgs = {
?screenReaderAudioFolder:String
};
typedef HankChoiceTagEvent = String->Void;
@:build(kiss.Kiss.build())
class SimpleWindow extends FlxSprite {}

View File

@@ -1064,4 +1064,34 @@
(choiceWindow.moveTo mousePos)
(choiceWindow.resize
(+ (or choiceWindow.selectionMarker?.width 0) (* textSize 2) (or choiceWindow.xText?.width 0) (apply max (for control choiceWindow.controls control.width)))
(Std.int choiceWindow.nextControlY)))))
(Std.int choiceWindow.nextControlY)))))
(function hankStoryWindow [:String file :ConstructorArgs args &opt :Map<String,HankChoiceTagEvent> onChoiceTags]
(let [story (Story.FromFile file)
window (SimpleWindow.create args)]
(localFunction :Void showNextFrame []
(let [frame (story.nextFrame)]
(case frame
(Finished
(window.makeTextV2 "Done"
(object
onClick ->_ (window.hide))))
((HasText text)
(window.makeTextV2 text)
(showNextFrame))
((HasChoices choices tags)
(doFor [idx choice] (enumerate choices)
(window.makeTextV2 "[$(+ idx 1)] $choice"
(object onClick
->_ {
// Call events for tags
(doFor tag (nth tags idx)
(when (onChoiceTags?.exists tag)
((dictGet onChoiceTags tag) choice)))
(story.choose idx)
(window.clearControls)
(showNextFrame)
}))))
(never null))))
(showNextFrame)
window))