From e58118c8c02fc69b66c0193414f81db38517f401 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 28 Feb 2022 14:58:04 -0700 Subject: [PATCH] add interval entries to HabitModel --- projects/habit-puzzle-game/Project.xml | 1 + .../habit-puzzle-game/source/HabitModel.hx | 2 ++ .../habit-puzzle-game/source/HabitModel.kiss | 26 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/projects/habit-puzzle-game/Project.xml b/projects/habit-puzzle-game/Project.xml index 12216e64..ba0967e6 100644 --- a/projects/habit-puzzle-game/Project.xml +++ b/projects/habit-puzzle-game/Project.xml @@ -36,6 +36,7 @@ + diff --git a/projects/habit-puzzle-game/source/HabitModel.hx b/projects/habit-puzzle-game/source/HabitModel.hx index fc9cac1e..a33842ba 100644 --- a/projects/habit-puzzle-game/source/HabitModel.hx +++ b/projects/habit-puzzle-game/source/HabitModel.hx @@ -4,9 +4,11 @@ import kiss.Prelude; import kiss.List; import kiss.Stream; import sys.io.File; +import datetime.DateTime; enum EntryType { Daily(daysOfWeek:Array, lastDayDone:String); + Interval(days:Int, lastDayDone:String); Bonus; Todo; } diff --git a/projects/habit-puzzle-game/source/HabitModel.kiss b/projects/habit-puzzle-game/source/HabitModel.kiss index ba6ee54e..675c3beb 100644 --- a/projects/habit-puzzle-game/source/HabitModel.kiss +++ b/projects/habit-puzzle-game/source/HabitModel.kiss @@ -1,4 +1,5 @@ (prop :Array dailyEntries []) +(prop :Array intervalEntries []) (prop :Array bonusEntries []) (prop :Array todoEntries []) (prop :Array rewardFiles []) @@ -11,6 +12,8 @@ (case (s.takeLine) ((Some "DAILY") (set lastHeader "DAILY")) + ((Some "INTERVAL") + (set lastHeader "INTERVAL")) ((Some "BONUS") (set lastHeader "BONUS")) ((Some "TODO") @@ -31,6 +34,7 @@ (.push (case lastHeader ("DAILY" dailyEntries) + ("INTERVAL" intervalEntries) ("BONUS" bonusEntries) ("TODO" todoEntries) (otherwise (throw "bad header"))) @@ -68,6 +72,17 @@ date ""))) (otherwise (throw "bad line")))) + ("INTERVAL" + (case (line.split ":") + ([::&mut preColon ...afterColon] + (set line (afterColon.join ":")) + (case (preColon.split " ") + ([days] + (Interval (Std.parseInt days) "")) + ([days lastDayDone] + (Interval (Std.parseInt days) lastDayDone)) + (otherwise (throw "bad line")))) + (otherwise (throw "bad line")))) (otherwise (throw "bad header"))) labels (for l (line.split "/") @@ -95,7 +110,9 @@ " " lastDayDone ": ") - "")$(.join (for label e.labels + (ifLet [(Interval days lastDayDone) e.type] + "$days ${lastDayDone}: " + ""))$(.join (for label e.labels "${label.label} $(* "|" label.points)") "/")") (function :String stringifyRewardFile [:RewardFile rewardFile] @@ -104,6 +121,8 @@ (method :Void save [] (localVar &mut content "DAILY\n-----\n") (+= content (.join (map dailyEntries stringify) "\n") "\n") + (+= content "\nINTERVAL\n--------\n") + (+= content (.join (map intervalEntries stringify) "\n") "\n") (+= content "\nBONUS\n-----\n") (+= content (.join (map bonusEntries stringify) "\n") "\n") (+= content "\nTODO\n----\n") @@ -126,12 +145,17 @@ (case e.type ((Daily days lastDayDone) (and !(= lastDayDone (todayString)) (contains days (.getDay (Date.now))))) + ((Interval days lastDayDone) + (or !lastDayDone (<= days #|(DateTime.fromDate(Date.now()) - DateTime.fromString(lastDayDone)).getTotalDays()|#))) (Todo (= 0 .points (activeLabel e))) (otherwise true))) (method :Array activeDailyEntries [] (filter dailyEntries isActive)) +(method :Array activeIntervalEntries [] + (filter intervalEntries isActive)) + (method :Array activeBonusEntries [] (filter bonusEntries isActive))