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,
puzzleWidth: Int,
puzzleHeight: Int,
piecesPerPoint: Int
piecesPerPoint: Int,
skipped: Bool
};
typedef Puzzle = {

View File

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

View File

@@ -135,19 +135,23 @@
// Left and right arrow keys can switch between unlocked puzzles
(unless entryNameText
(unless (or entryNameText (tempWindowIsShown))
(when FlxG.keys.justPressed.LEFT
(defAndCall method clearBar
(when bar
(remove bar)
(remove asyncLoop)))
(unless (= rewardFileIndex 0)
(-= rewardFileIndex 1)
(unless (= rewardFileIndex minRewardFile)
--rewardFileIndex
(while .skipped (nth model.rewardFiles rewardFileIndex)
--rewardFileIndex)
(refreshModel)))
(when FlxG.keys.justPressed.RIGHT
(clearBar)
(unless (= rewardFileIndex maxRewardFile)
(+= rewardFileIndex 1)
++rewardFileIndex
(while .skipped (nth model.rewardFiles rewardFileIndex)
++rewardFileIndex)
(refreshModel)))))
(prop &mut :FlxSave save null)
@@ -195,7 +199,8 @@
(prop &mut lastRewardFileIndex -1)
(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))
@@ -218,11 +223,16 @@
(unless currentRewardFile
(set currentRewardFile (nth m.rewardFiles 0))
(if m.rewardFiles
(cond
((and m.rewardFiles !.skipped (last m.rewardFiles))
(while (> p .startingPoints (nth m.rewardFiles i))
(set rewardFileIndex 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)
--i
(let [lastStartingPoints .startingPoints (nth m.rewardFiles i)
@@ -230,8 +240,11 @@
nextStartingPoints (+ lastStartingPoints (Math.ceil (/ TOTAL_PIECES piecesPerPoint)))]
(when (> p nextStartingPoints)
(set puzzleUnlocked nextStartingPoints))
(break))))
(set puzzleUnlocked 0)))
(break)))))
((and m.rewardFiles .skipped (last m.rewardFiles))
(set puzzleUnlocked (- p 1)))
(true
(set puzzleUnlocked 0))))
(when m.rewardFiles
(makeRewardSprites m p currentRewardFile))
@@ -244,7 +257,20 @@
(set entryWindow.cameras [uiCamera])
(set entryWindow.textColor FlxColor.LIME)
(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)
(map (m.activeDailyEntries) makeText)
(set entryWindow.textColor FlxColor.GREEN)
@@ -255,15 +281,7 @@
(map (m.activeBonusEntries) makeText)
(set entryWindow.textColor FlxColor.YELLOW)
(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
(entryWindow.show))