allow abandoning a puzzle

This commit is contained in:
2022-08-20 23:35:21 +00:00
parent 738c876c89
commit 888d0b2178
3 changed files with 52 additions and 24 deletions

View File

@@ -33,7 +33,9 @@ typedef RewardFile = {
startingPoints: Int, startingPoints: Int,
puzzleWidth: Int, puzzleWidth: Int,
puzzleHeight: Int, puzzleHeight: Int,
piecesPerPoint: Int piecesPerPoint: Int,
skipped: Bool
}; };
typedef Puzzle = { typedef Puzzle = {

View File

@@ -3,7 +3,7 @@
(prop :Array<Entry> intervalEntries []) (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 :kiss.List<RewardFile> rewardFiles [])
(defNew [&prop :String textFile] (defNew [&prop :String textFile]
(let [s (Stream.fromFile textFile) (let [s (Stream.fromFile textFile)
@@ -30,12 +30,16 @@
((when (= lastHeader "FILES") (Some line)) ((when (= lastHeader "FILES") (Some line))
(rewardFiles.push (rewardFiles.push
(let [parts (line.split " ") (let [parts (line.split " ")
skipped (case (parts.pop)
("true" true)
("false" false)
(otherwise (throw "bad bool")))
piecesPerPoint (Std.parseInt (parts.pop)) piecesPerPoint (Std.parseInt (parts.pop))
puzzleHeight (Std.parseInt (parts.pop)) puzzleHeight (Std.parseInt (parts.pop))
puzzleWidth (Std.parseInt (parts.pop)) puzzleWidth (Std.parseInt (parts.pop))
startingPoints (Std.parseInt (parts.pop)) startingPoints (Std.parseInt (parts.pop))
path (parts.join " ")] path (parts.join " ")]
(objectWith path startingPoints puzzleWidth puzzleHeight piecesPerPoint)))) (objectWith path startingPoints puzzleWidth puzzleHeight piecesPerPoint skipped))))
((Some line) ((Some line)
(.push (.push
(case lastHeader (case lastHeader
@@ -141,7 +145,7 @@
"${label.label} $(* "|" label.points)") "/")") "${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.path} ${rewardFile.startingPoints} ${rewardFile.puzzleWidth} ${rewardFile.puzzleHeight} ${rewardFile.piecesPerPoint} ${rewardFile.skipped}")
(method :Void save [] (method :Void save []
(localVar &mut content "DAILY\n-----\n") (localVar &mut content "DAILY\n-----\n")
@@ -223,5 +227,9 @@
(save)) (save))
(method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint] (method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint]
(rewardFiles.push (objectWith path startingPoints puzzleWidth puzzleHeight piecesPerPoint)) (rewardFiles.push (objectWith [skipped false] path startingPoints puzzleWidth puzzleHeight piecesPerPoint))
(save))
(method skipRewardFile []
(set .skipped (last rewardFiles) true)
(save)) (save))

View File

@@ -135,19 +135,23 @@
// Left and right arrow keys can switch between unlocked puzzles // Left and right arrow keys can switch between unlocked puzzles
(unless entryNameText (unless (or entryNameText (tempWindowIsShown))
(when FlxG.keys.justPressed.LEFT (when FlxG.keys.justPressed.LEFT
(defAndCall method clearBar (defAndCall method clearBar
(when bar (when bar
(remove bar) (remove bar)
(remove asyncLoop))) (remove asyncLoop)))
(unless (= rewardFileIndex 0) (unless (= rewardFileIndex minRewardFile)
(-= rewardFileIndex 1) --rewardFileIndex
(while .skipped (nth model.rewardFiles rewardFileIndex)
--rewardFileIndex)
(refreshModel))) (refreshModel)))
(when FlxG.keys.justPressed.RIGHT (when FlxG.keys.justPressed.RIGHT
(clearBar) (clearBar)
(unless (= rewardFileIndex maxRewardFile) (unless (= rewardFileIndex maxRewardFile)
(+= rewardFileIndex 1) ++rewardFileIndex
(while .skipped (nth model.rewardFiles rewardFileIndex)
++rewardFileIndex)
(refreshModel))))) (refreshModel)))))
(prop &mut :FlxSave save null) (prop &mut :FlxSave save null)
@@ -195,7 +199,8 @@
(prop &mut lastRewardFileIndex -1) (prop &mut lastRewardFileIndex -1)
(prop &mut rewardFileIndex 0) (prop &mut rewardFileIndex 0)
(prop &mut maxRewardFile 0) (prop &mut :Null<Int> minRewardFile null)
(prop &mut :Null<Int> maxRewardFile null)
(defAlias &ident SCROLL_BOUND_MARGIN (scrollBoundMargin)) (defAlias &ident SCROLL_BOUND_MARGIN (scrollBoundMargin))
@@ -218,11 +223,16 @@
(unless currentRewardFile (unless currentRewardFile
(set currentRewardFile (nth m.rewardFiles 0)) (set currentRewardFile (nth m.rewardFiles 0))
(if m.rewardFiles (cond
((and m.rewardFiles !.skipped (last m.rewardFiles))
(while (> p .startingPoints (nth m.rewardFiles i)) (while (> p .startingPoints (nth m.rewardFiles i))
(set rewardFileIndex i) (set rewardFileIndex i)
(set currentRewardFile (nth m.rewardFiles i)) (set currentRewardFile (nth m.rewardFiles i))
(set maxRewardFile i) (unless minRewardFile
(unless .skipped (nth m.rewardFiles i)
(set minRewardFile i)))
(unless .skipped (nth m.rewardFiles i)
(set maxRewardFile i))
(when (>= ++i m.rewardFiles.length) (when (>= ++i m.rewardFiles.length)
--i --i
(let [lastStartingPoints .startingPoints (nth m.rewardFiles i) (let [lastStartingPoints .startingPoints (nth m.rewardFiles i)
@@ -230,8 +240,11 @@
nextStartingPoints (+ lastStartingPoints (Math.ceil (/ TOTAL_PIECES piecesPerPoint)))] nextStartingPoints (+ lastStartingPoints (Math.ceil (/ TOTAL_PIECES piecesPerPoint)))]
(when (> p nextStartingPoints) (when (> p nextStartingPoints)
(set puzzleUnlocked nextStartingPoints)) (set puzzleUnlocked nextStartingPoints))
(break)))) (break)))))
(set puzzleUnlocked 0))) ((and m.rewardFiles .skipped (last m.rewardFiles))
(set puzzleUnlocked (- p 1)))
(true
(set puzzleUnlocked 0))))
(when m.rewardFiles (when m.rewardFiles
(makeRewardSprites m p currentRewardFile)) (makeRewardSprites m p currentRewardFile))
@@ -244,7 +257,20 @@
(set entryWindow.cameras [uiCamera]) (set entryWindow.cameras [uiCamera])
(set entryWindow.textColor FlxColor.LIME) (set entryWindow.textColor FlxColor.LIME)
(when m.rewardFiles (when m.rewardFiles
(_makeText "Puzzle #$(+ 1 rewardFileIndex) / ${model.rewardFiles.length}" (max 0 (- TOTAL_PIECES (* currentRewardFile.piecesPerPoint (- p currentRewardFile.startingPoints)))))) (_makeText "Puzzle #$(+ 1 rewardFileIndex) / ${model.rewardFiles.length}" (max 0 (- TOTAL_PIECES (* currentRewardFile.piecesPerPoint (- p currentRewardFile.startingPoints)))))
(set entryWindow.textColor FlxColor.GRAY)
(_makeText "{space} Cycle background color" 0
->_
(defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
(save.flush)
(refreshModel)))
(when (= rewardFileIndex (- m.rewardFiles.length 1))
(_makeText "Abandon this puzzle" 0
->_
(defAndCall method skipPuzzle
(model.skipRewardFile)
(setModel model)))))
(set entryWindow.textColor FlxColor.ORANGE) (set entryWindow.textColor FlxColor.ORANGE)
(map (m.activeDailyEntries) makeText) (map (m.activeDailyEntries) makeText)
(set entryWindow.textColor FlxColor.GREEN) (set entryWindow.textColor FlxColor.GREEN)
@@ -255,15 +281,7 @@
(map (m.activeBonusEntries) makeText) (map (m.activeBonusEntries) makeText)
(set entryWindow.textColor FlxColor.YELLOW) (set entryWindow.textColor FlxColor.YELLOW)
(map (m.activeTodoEntries) makeText) (map (m.activeTodoEntries) makeText)
(set entryWindow.textColor FlxColor.GRAY)
(when m.rewardFiles
(_makeText "{space} Cycle background color" 0
->_
(defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
(save.flush)
// setModel so the entry text gets remade in inverted/lightened colors when necessary
(refreshModel))))
(when windowWasShown (when windowWasShown
(entryWindow.show)) (entryWindow.show))