From ffb5028e55201cef4faa633e40e88bcc1f7f6583 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 3 Feb 2022 23:11:41 -0700 Subject: [PATCH] habit game track model and remove finished texts --- .../habit-puzzle-game/source/HabitModel.hx | 3 +- .../habit-puzzle-game/source/HabitModel.kiss | 3 +- .../habit-puzzle-game/source/HabitState.hx | 1 + .../habit-puzzle-game/source/HabitState.kiss | 36 ++++++++++++++----- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/projects/habit-puzzle-game/source/HabitModel.hx b/projects/habit-puzzle-game/source/HabitModel.hx index b488d84d..c7ebd695 100644 --- a/projects/habit-puzzle-game/source/HabitModel.hx +++ b/projects/habit-puzzle-game/source/HabitModel.hx @@ -18,7 +18,8 @@ typedef EntryLabel = { typedef Entry = { type: EntryType, - labels: Array + labels: Array, + doneToday: Bool }; @:build(kiss.Kiss.build()) diff --git a/projects/habit-puzzle-game/source/HabitModel.kiss b/projects/habit-puzzle-game/source/HabitModel.kiss index fc68411e..ff43d9d3 100644 --- a/projects/habit-puzzle-game/source/HabitModel.kiss +++ b/projects/habit-puzzle-game/source/HabitModel.kiss @@ -25,6 +25,7 @@ ("TODO" todoEntries) (otherwise (throw "bad header"))) (object + doneToday false type (case lastHeader ("BONUS" Bonus) @@ -90,5 +91,5 @@ (function isActive [:Entry e] (case e.type ((Daily days) - (contains days (.getDay (Date.now)))) + (and !e.doneToday (contains days (.getDay (Date.now))))) (otherwise true))) \ No newline at end of file diff --git a/projects/habit-puzzle-game/source/HabitState.hx b/projects/habit-puzzle-game/source/HabitState.hx index 422b7ce3..5404ee54 100644 --- a/projects/habit-puzzle-game/source/HabitState.hx +++ b/projects/habit-puzzle-game/source/HabitState.hx @@ -10,6 +10,7 @@ import kiss.Prelude; import kiss.List; import kiss_tools.KeyShortcutHandler; import HabitModel; +import flixel.input.keyboard.FlxKey; @:build(kiss.Kiss.build()) class HabitState extends FlxState {} diff --git a/projects/habit-puzzle-game/source/HabitState.kiss b/projects/habit-puzzle-game/source/HabitState.kiss index 32dbae3b..d50fb1ae 100644 --- a/projects/habit-puzzle-game/source/HabitState.kiss +++ b/projects/habit-puzzle-game/source/HabitState.kiss @@ -1,19 +1,18 @@ (method &override :Void create [] (super.create)) -(method &override :Void update [:Float elapsed] (super.update elapsed)) +(method &override :Void update [:Float elapsed] + (super.update elapsed) + (let [:FlxKey id (FlxG.keys.firstJustPressed)] + (unless (= id -1) + (shortcutHandler.handleKey (.toLowerCase (id.toString)))))) (prop &mut :FlxTypedGroup entryTexts null) -(prop &mut :KeyShortcutHandler shortcutHandler null) +(prop &mut :KeyShortcutHandler shortcutHandler null) (prop &mut :HabitModel model null) (method setModel [m] (set model m) (set shortcutHandler (new KeyShortcutHandler)) - (doFor e (the Array (concat m.dailyEntries m.bonusEntries m.todoEntries)) - (let [label (HabitModel.activeLabel e)] - (shortcutHandler.registerItem label.label label))) - ~shortcutHandler.rootMap - (when entryTexts (remove entryTexts)) (set entryTexts (new FlxTypedGroup)) (set textY 0) @@ -23,7 +22,28 @@ (map m.bonusEntries makeText) (set color FlxColor.YELLOW) (map m.todoEntries makeText) - (add entryTexts)) + (add entryTexts) + + (doFor e (the Array (concat m.dailyEntries m.bonusEntries m.todoEntries)) + (let [label (HabitModel.activeLabel e)] + (shortcutHandler.registerItem label.label e))) + + **(set shortcutHandler.onBadKey ->:Void [_ _] {}) + (set shortcutHandler.onSelectItem ->:Void [:Entry e] + (let [label (HabitModel.activeLabel e)] + **(TODO reveal a piece of the current puzzle) + (+= label.points 1) + (case e.type + (Todo + (m.todoEntries.remove e)) + (Bonus) + ((Daily _) + (set e.doneToday true)) + (otherwise (throw "bad type"))) + (m.save) + (setModel m) + (shortcutHandler.start))) + (shortcutHandler.start)) (prop &mut textY 0) (prop &mut :FlxColor color null)