add interval entries to HabitModel
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
<haxelib name="haxe-strings" />
|
<haxelib name="haxe-strings" />
|
||||||
<haxelib name="kiss" />
|
<haxelib name="kiss" />
|
||||||
<haxelib name="kiss-tools" />
|
<haxelib name="kiss-tools" />
|
||||||
|
<haxelib name="datetime" />
|
||||||
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
||||||
|
|
||||||
<!--In case you want to use the addons package-->
|
<!--In case you want to use the addons package-->
|
||||||
|
@@ -4,9 +4,11 @@ import kiss.Prelude;
|
|||||||
import kiss.List;
|
import kiss.List;
|
||||||
import kiss.Stream;
|
import kiss.Stream;
|
||||||
import sys.io.File;
|
import sys.io.File;
|
||||||
|
import datetime.DateTime;
|
||||||
|
|
||||||
enum EntryType {
|
enum EntryType {
|
||||||
Daily(daysOfWeek:Array<Int>, lastDayDone:String);
|
Daily(daysOfWeek:Array<Int>, lastDayDone:String);
|
||||||
|
Interval(days:Int, lastDayDone:String);
|
||||||
Bonus;
|
Bonus;
|
||||||
Todo;
|
Todo;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
(prop :Array<Entry> dailyEntries [])
|
(prop :Array<Entry> dailyEntries [])
|
||||||
|
(prop :Array<Entry> intervalEntries [])
|
||||||
(prop :Array<Entry> bonusEntries [])
|
(prop :Array<Entry> bonusEntries [])
|
||||||
(prop :Array<Entry> todoEntries [])
|
(prop :Array<Entry> todoEntries [])
|
||||||
(prop :Array<RewardFile> rewardFiles [])
|
(prop :Array<RewardFile> rewardFiles [])
|
||||||
@@ -11,6 +12,8 @@
|
|||||||
(case (s.takeLine)
|
(case (s.takeLine)
|
||||||
((Some "DAILY")
|
((Some "DAILY")
|
||||||
(set lastHeader "DAILY"))
|
(set lastHeader "DAILY"))
|
||||||
|
((Some "INTERVAL")
|
||||||
|
(set lastHeader "INTERVAL"))
|
||||||
((Some "BONUS")
|
((Some "BONUS")
|
||||||
(set lastHeader "BONUS"))
|
(set lastHeader "BONUS"))
|
||||||
((Some "TODO")
|
((Some "TODO")
|
||||||
@@ -31,6 +34,7 @@
|
|||||||
(.push
|
(.push
|
||||||
(case lastHeader
|
(case lastHeader
|
||||||
("DAILY" dailyEntries)
|
("DAILY" dailyEntries)
|
||||||
|
("INTERVAL" intervalEntries)
|
||||||
("BONUS" bonusEntries)
|
("BONUS" bonusEntries)
|
||||||
("TODO" todoEntries)
|
("TODO" todoEntries)
|
||||||
(otherwise (throw "bad header")))
|
(otherwise (throw "bad header")))
|
||||||
@@ -68,6 +72,17 @@
|
|||||||
date
|
date
|
||||||
"")))
|
"")))
|
||||||
(otherwise (throw "bad line"))))
|
(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")))
|
(otherwise (throw "bad header")))
|
||||||
labels
|
labels
|
||||||
(for l (line.split "/")
|
(for l (line.split "/")
|
||||||
@@ -95,7 +110,9 @@
|
|||||||
" "
|
" "
|
||||||
lastDayDone
|
lastDayDone
|
||||||
": ")
|
": ")
|
||||||
"")$(.join (for label e.labels
|
(ifLet [(Interval days lastDayDone) e.type]
|
||||||
|
"$days ${lastDayDone}: "
|
||||||
|
""))$(.join (for label e.labels
|
||||||
"${label.label} $(* "|" label.points)") "/")")
|
"${label.label} $(* "|" label.points)") "/")")
|
||||||
|
|
||||||
(function :String stringifyRewardFile [:RewardFile rewardFile]
|
(function :String stringifyRewardFile [:RewardFile rewardFile]
|
||||||
@@ -104,6 +121,8 @@
|
|||||||
(method :Void save []
|
(method :Void save []
|
||||||
(localVar &mut content "DAILY\n-----\n")
|
(localVar &mut content "DAILY\n-----\n")
|
||||||
(+= content (.join (map dailyEntries stringify) "\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 "\nBONUS\n-----\n")
|
||||||
(+= content (.join (map bonusEntries stringify) "\n") "\n")
|
(+= content (.join (map bonusEntries stringify) "\n") "\n")
|
||||||
(+= content "\nTODO\n----\n")
|
(+= content "\nTODO\n----\n")
|
||||||
@@ -126,12 +145,17 @@
|
|||||||
(case e.type
|
(case e.type
|
||||||
((Daily days lastDayDone)
|
((Daily days lastDayDone)
|
||||||
(and !(= lastDayDone (todayString)) (contains days (.getDay (Date.now)))))
|
(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)))
|
(Todo (= 0 .points (activeLabel e)))
|
||||||
(otherwise true)))
|
(otherwise true)))
|
||||||
|
|
||||||
(method :Array<Entry> activeDailyEntries []
|
(method :Array<Entry> activeDailyEntries []
|
||||||
(filter dailyEntries isActive))
|
(filter dailyEntries isActive))
|
||||||
|
|
||||||
|
(method :Array<Entry> activeIntervalEntries []
|
||||||
|
(filter intervalEntries isActive))
|
||||||
|
|
||||||
(method :Array<Entry> activeBonusEntries []
|
(method :Array<Entry> activeBonusEntries []
|
||||||
(filter bonusEntries isActive))
|
(filter bonusEntries isActive))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user