diff --git a/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss b/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss index 869f8323..0caf8e9a 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss @@ -24,4 +24,4 @@ ((Interval days lastDayDone) "$days ${lastDayDone}: ") (otherwise ""))$(.join (for label labels - "${label.label} $(* "|" label.points)") "/")") \ No newline at end of file + "${label.label} $(HabitModel.pointsStr label.points)") "/")") \ No newline at end of file diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss index 052c3f28..01d2c880 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss @@ -110,8 +110,8 @@ (otherwise (throw "bad header: $lastHeader"))) (for l (line.split "/") (object - label (StringTools.trim (StringTools.replace l "|" "")) - points (count (l.split "") ->c (= c "|")))) + label (StringTools.trim (withoutPointsStr l)) + points (countPoints l))) topPriority)))) (otherwise (break)))))) @@ -273,4 +273,26 @@ (set e.type (Monthly days (.toString (DateTime.now))))) (whenLet [(Interval days lastDayDone) e.type] (set e.type (Interval days (.toString (DateTime.now))))))) - (save)) \ No newline at end of file + (save)) + +(var tallyUnit 5) +(function pointsStr [points] + (let [&mut str "" symbols ["+" "*" "\$"]] + (doFor i (reverse (collect (range symbols.length))) + (let [scaledTallyUnit (^ tallyUnit i) + tallies (Math.floor (/ points scaledTallyUnit))] + (+= str (* (nth symbols i) tallies)) + (-= points (* tallies scaledTallyUnit)))) + str)) + +(function withoutPointsStr [:String label] + (doFor c (.split "|+*\$" "") (set label (label.replace c "")))) + +(function countPoints [:String pointStr] + (apply + (for char (pointStr.split "") + (case char + ("|" 1) + ("+" 1) + ("*" tallyUnit) + ("\$" (^ tallyUnit 2)) + (otherwise 0))))) \ No newline at end of file diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 76daa3e2..318a039c 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -139,6 +139,7 @@ (localVar title "Add a label for this ${typeDescriptor}, or use SHIFT+ENTER to add a ${multipleLabelDescriptor}:") (set entryCreationWindow (new SimpleWindow title null null 0.9 0.9)) + // TODO don't allow /, +, $, * (set entryNameText (new FlxInputText 0 0 FlxG.width "" textSize true)) (entryCreationWindow.addControl entryNameText) (entryCreationWindow.makeText "Create" FlxColor.LIME ->:Void _ (addCreatedEntry)) @@ -608,7 +609,7 @@ // TODO configurable text size (method _makeText [:String s :Int points &opt :Action action] - (entryWindow.makeText (+ s (pointsStr points)) action)) + (entryWindow.makeText (+ s (HabitModel.pointsStr points)) action)) (method :Void log [:String message] (trace message) @@ -822,15 +823,6 @@ (method createTaskEntry [] (startAdding Todo)) (method createBonusEntry [] (startAdding Bonus)) -(function pointsStr [points] - (let [&mut str "" tallyUnit 5 symbols ["+" "*" "\$"]] - (doFor i (reverse (collect (range symbols.length))) - (let [scaledTallyUnit (^ tallyUnit i) - tallies (Math.floor (/ points scaledTallyUnit))] - (+= str (* (nth symbols i) tallies)) - (-= points (* tallies scaledTallyUnit)))) - str)) - (method addCreatedEntry [] // addEntry() calls save() (when (entryNameText.text.trim)