Make habit Entry toStringable
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import kiss.List;
|
||||||
|
import HabitModel;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class Entry {}
|
||||||
26
projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss
Normal file
26
projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss
Normal 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)") "/")")
|
||||||
@@ -23,11 +23,6 @@ typedef EntryLabel = {
|
|||||||
points:Int
|
points:Int
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Entry = {
|
|
||||||
type: EntryType,
|
|
||||||
labels: Array<EntryLabel>,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef RewardFile = {
|
typedef RewardFile = {
|
||||||
path: String,
|
path: String,
|
||||||
startingPoints: Int,
|
startingPoints: Int,
|
||||||
|
|||||||
@@ -49,8 +49,7 @@
|
|||||||
("BONUS" bonusEntries)
|
("BONUS" bonusEntries)
|
||||||
("TODO" todoEntries)
|
("TODO" todoEntries)
|
||||||
(otherwise (throw "bad header")))
|
(otherwise (throw "bad header")))
|
||||||
(object
|
(new Entry
|
||||||
type
|
|
||||||
(case lastHeader
|
(case lastHeader
|
||||||
("BONUS" Bonus)
|
("BONUS" Bonus)
|
||||||
("TODO" Todo)
|
("TODO" Todo)
|
||||||
@@ -107,7 +106,6 @@
|
|||||||
(otherwise (throw "bad interval habit: $line"))))
|
(otherwise (throw "bad interval habit: $line"))))
|
||||||
(otherwise (throw "bad interval habit: $line"))))
|
(otherwise (throw "bad interval habit: $line"))))
|
||||||
(otherwise (throw "bad header: $lastHeader")))
|
(otherwise (throw "bad header: $lastHeader")))
|
||||||
labels
|
|
||||||
(for l (line.split "/")
|
(for l (line.split "/")
|
||||||
(object
|
(object
|
||||||
label (StringTools.trim (StringTools.replace l "|" ""))
|
label (StringTools.trim (StringTools.replace l "|" ""))
|
||||||
@@ -120,29 +118,8 @@
|
|||||||
(method :Int totalPoints []
|
(method :Int totalPoints []
|
||||||
(apply + (for l (flatten (for e (allEntries) e.labels)) l.points)))
|
(apply + (for l (flatten (for e (allEntries) e.labels)) l.points)))
|
||||||
|
|
||||||
(function :String stringify [:Entry e]
|
(function stringify [:Entry e]
|
||||||
"$(case e.type
|
(e.toString))
|
||||||
((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 :String stringifyRewardFile [:RewardFile rewardFile]
|
(function :String stringifyRewardFile [:RewardFile rewardFile]
|
||||||
"${rewardFile.path} ${rewardFile.startingPoints} ${rewardFile.puzzleWidth} ${rewardFile.puzzleHeight} ${rewardFile.piecesPerPoint} ${rewardFile.skipped}")
|
"${rewardFile.path} ${rewardFile.startingPoints} ${rewardFile.puzzleWidth} ${rewardFile.puzzleHeight} ${rewardFile.piecesPerPoint} ${rewardFile.skipped}")
|
||||||
@@ -223,7 +200,7 @@
|
|||||||
((Daily _ _) dailyEntries)
|
((Daily _ _) dailyEntries)
|
||||||
((Monthly _ _) monthlyEntries)
|
((Monthly _ _) monthlyEntries)
|
||||||
(otherwise (throw "")))
|
(otherwise (throw "")))
|
||||||
(objectWith [labels (for label labels (objectWith [points 0] label))] type))
|
(new Entry type (for label labels (objectWith [points 0] label))))
|
||||||
(save))
|
(save))
|
||||||
|
|
||||||
(method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint]
|
(method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint]
|
||||||
|
|||||||
Reference in New Issue
Block a user