From e303c6665580671e23e3b07eee48692d855b3ddf Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 3 Feb 2022 22:04:00 -0700 Subject: [PATCH] HabitModel get activeLabel of Entry --- projects/habit-puzzle-game/source/HabitModel.kiss | 6 ++++++ projects/habit-puzzle-game/source/HabitState.kiss | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/habit-puzzle-game/source/HabitModel.kiss b/projects/habit-puzzle-game/source/HabitModel.kiss index 1a220bdb..1e129487 100644 --- a/projects/habit-puzzle-game/source/HabitModel.kiss +++ b/projects/habit-puzzle-game/source/HabitModel.kiss @@ -80,3 +80,9 @@ (+= content (.join (map todoEntries stringify) "\n") "\n") (File.saveContent textFile content)) + +// With rotating entries, the active one is the first one with the lowest score: +(function :EntryLabel activeLabel [:Entry e] + (let [lowScore (apply min (for label e.labels label.points))] + (doFor label e.labels (when (= lowScore label.points) (return label))) + (throw "no active?!"))) diff --git a/projects/habit-puzzle-game/source/HabitState.kiss b/projects/habit-puzzle-game/source/HabitState.kiss index 98353351..9548f331 100644 --- a/projects/habit-puzzle-game/source/HabitState.kiss +++ b/projects/habit-puzzle-game/source/HabitState.kiss @@ -2,4 +2,6 @@ (method &override :Void update [:Float elapsed] (super.update elapsed)) (prop &mut :HabitModel model null) -(method setModel [m] (set model ~m)) \ No newline at end of file +(method setModel [m] + (set model m) + (doFor e model.bonusEntries ~(HabitModel.activeLabel e))) \ No newline at end of file