Make habit Entry toStringable

This commit is contained in:
2022-08-29 20:35:42 +00:00
parent ffd8cae013
commit e60115818a
4 changed files with 98 additions and 92 deletions

View File

@@ -0,0 +1,8 @@
package;
import kiss.Prelude;
import kiss.List;
import HabitModel;
@:build(kiss.Kiss.build())
class Entry {}

View File

@@ -0,0 +1,26 @@
(defNew [&prop &mut :EntryType type
&prop :Array<EntryLabel> labels])
(method toString []
"$(case type
((Daily days lastDayDone)
(+
(.join (for day days
(case day
(0 "Su")
(1 "M")
(2 "T")
(3 "W")
(4 "Th")
(5 "F")
(6 "S")
(otherwise (throw "bad day")))) "")
" "
lastDayDone
": "))
((Monthly days lastDayDone)
"$(days.join ",") ${lastDayDone}: ")
((Interval days lastDayDone)
"$days ${lastDayDone}: ")
(otherwise ""))$(.join (for label labels
"${label.label} $(* "|" label.points)") "/")")

View File

@@ -23,11 +23,6 @@ typedef EntryLabel = {
points:Int
};
typedef Entry = {
type: EntryType,
labels: Array<EntryLabel>,
};
typedef RewardFile = {
path: String,
startingPoints: Int,

View File

@@ -49,8 +49,7 @@
("BONUS" bonusEntries)
("TODO" todoEntries)
(otherwise (throw "bad header")))
(object
type
(new Entry
(case lastHeader
("BONUS" Bonus)
("TODO" Todo)
@@ -107,7 +106,6 @@
(otherwise (throw "bad interval habit: $line"))))
(otherwise (throw "bad interval habit: $line"))))
(otherwise (throw "bad header: $lastHeader")))
labels
(for l (line.split "/")
(object
label (StringTools.trim (StringTools.replace l "|" ""))
@@ -120,29 +118,8 @@
(method :Int totalPoints []
(apply + (for l (flatten (for e (allEntries) e.labels)) l.points)))
(function :String stringify [:Entry e]
"$(case e.type
((Daily days lastDayDone)
(+
(.join (for day days
(case day
(0 "Su")
(1 "M")
(2 "T")
(3 "W")
(4 "Th")
(5 "F")
(6 "S")
(otherwise (throw "bad day")))) "")
" "
lastDayDone
": "))
((Monthly days lastDayDone)
"$(days.join ",") ${lastDayDone}: ")
((Interval days lastDayDone)
"$days ${lastDayDone}: ")
(otherwise ""))$(.join (for label e.labels
"${label.label} $(* "|" label.points)") "/")")
(function stringify [:Entry e]
(e.toString))
(function :String stringifyRewardFile [:RewardFile rewardFile]
"${rewardFile.path} ${rewardFile.startingPoints} ${rewardFile.puzzleWidth} ${rewardFile.puzzleHeight} ${rewardFile.piecesPerPoint} ${rewardFile.skipped}")
@@ -223,7 +200,7 @@
((Daily _ _) dailyEntries)
((Monthly _ _) monthlyEntries)
(otherwise (throw "")))
(objectWith [labels (for label labels (objectWith [points 0] label))] type))
(new Entry type (for label labels (objectWith [points 0] label))))
(save))
(method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint]