habit game fix launching with no puzzles started

This commit is contained in:
2022-08-16 15:39:58 +00:00
parent 8169536271
commit f3c5fdb71e

View File

@@ -39,6 +39,7 @@
(#when debug (#when debug
(debugLayer.clear) (debugLayer.clear)
(when model.rewardFiles
(doFor s rewardSprites (doFor s rewardSprites
null null
// Uncomment for debugging piece rotation: // Uncomment for debugging piece rotation:
@@ -48,8 +49,9 @@
**(let [matchZones [(matchZoneLeft s) (matchZoneRight s)(matchZoneUp s)(matchZoneDown s)]] **(let [matchZones [(matchZoneLeft s) (matchZoneRight s)(matchZoneUp s)(matchZoneDown s)]]
(doFor z matchZones (doFor z matchZones
(unless z.isEmpty (unless z.isEmpty
(debugLayer.drawFlxRect z FlxColor.RED)))))) (debugLayer.drawFlxRect z FlxColor.RED)))))))
(when model.rewardFiles
(let [zoom pieceCamera.zoom (let [zoom pieceCamera.zoom
scroll (pieceCamera.scroll.copyTo)] scroll (pieceCamera.scroll.copyTo)]
(pieceCamera.updateScrollWheelZoom elapsed 5) (pieceCamera.updateScrollWheelZoom elapsed 5)
@@ -65,6 +67,13 @@
(entryWindow.hide) (entryWindow.hide)
(entryWindow.show)))) (entryWindow.show))))
(when (and FlxG.keys.justPressed.SPACE !entryNameText)
(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 debug (#when debug
(when FlxG.keys.justPressed.SEMICOLON (when FlxG.keys.justPressed.SEMICOLON
(set pieceCamera.zoom 1)) (set pieceCamera.zoom 1))
@@ -72,7 +81,7 @@
(set save.data.storedPositions (new Map<Int,FlxPoint>)) (set save.data.storedPositions (new Map<Int,FlxPoint>))
(set save.data.storedAngles (new Map<Int,Float>)) (set save.data.storedAngles (new Map<Int,Float>))
(set save.data.storedOrigins (new Map<Int,FlxPoint>)) (set save.data.storedOrigins (new Map<Int,FlxPoint>))
(save.flush))) (save.flush))))
(when FlxG.keys.justPressed.DELETE (when FlxG.keys.justPressed.DELETE
(Sys.exit 0)) (Sys.exit 0))
@@ -87,12 +96,7 @@
(dictSet (the Map<Int,FlxPoint> save.data.storedOrigins) (dictGet indexMap s) s.origin)) (dictSet (the Map<Int,FlxPoint> save.data.storedOrigins) (dictGet indexMap s) s.origin))
(save.flush))) (save.flush)))
(when (and FlxG.keys.justPressed.SPACE !entryNameText)
(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)))
(method startAdding [:EntryType type] (method startAdding [:EntryType type]
(set typeAdding type) (set typeAdding type)
@@ -180,6 +184,8 @@
// Find, load, and add the current reward image as big as possible: // Find, load, and add the current reward image as big as possible:
(unless currentRewardFile (unless currentRewardFile
(set currentRewardFile (nth m.rewardFiles 0)) (set currentRewardFile (nth m.rewardFiles 0))
(if 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))
@@ -191,8 +197,59 @@
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)))
(when m.rewardFiles
(makeRewardSprites m p currentRewardFile))
(localVar &mut windowWasShown true)
(when entryWindow
(set windowWasShown (entryWindow.isShown))
(entryWindow.hide))
(set entryWindow (new SimpleWindow "" (FlxColor.fromRGBFloat 0 0 0 0.5) FlxColor.WHITE 0.9 0.9))
(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))))))
(set entryWindow.textColor FlxColor.ORANGE)
(map (m.activeDailyEntries) makeText)
(set entryWindow.textColor FlxColor.GREEN)
(map (m.activeMonthlyEntries) makeText)
(set entryWindow.textColor FlxColor.BLUE)
(map (m.activeIntervalEntries) makeText)
(set entryWindow.textColor FlxColor.WHITE)
(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))
(when windowWasShown
(entryWindow.show))
(when !(= puzzleUnlocked -1)
(startPuzzlePackChoice puzzleUnlocked)))
(unless debugLayer
(set debugLayer (new DebugLayer))
(set debugLayer.cameras [pieceCamera]))
(remove debugLayer)
(add debugLayer))
(method refreshModel [&opt m]
(let [m (or m model)]
(setModel m (nth m.rewardFiles rewardFileIndex))))
(prop &mut textY 0)
(prop :Array<FlxColor> backgroundOptions [
FlxColor.BLACK
FlxColor.WHITE
FlxColor.GRAY
])
(method makeRewardSprites [m p currentRewardFile]
(set save (new FlxSave)) (set save (new FlxSave))
(save.bind currentRewardFile.path) (save.bind currentRewardFile.path)
(unless save.data.storedPositions (unless save.data.storedPositions
@@ -348,51 +405,7 @@
(prop &mut lastTotalPoints -1) (prop &mut lastTotalPoints -1)
(set lastTotalPoints (m.totalPoints)) (set lastTotalPoints (m.totalPoints))
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN) (pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN))
(localVar &mut windowWasShown true)
(when entryWindow
(set windowWasShown (entryWindow.isShown))
(entryWindow.hide))
(set entryWindow (new SimpleWindow "" (FlxColor.fromRGBFloat 0 0 0 0.5) FlxColor.WHITE 0.9 0.9))
(set entryWindow.cameras [uiCamera])
(set entryWindow.textColor FlxColor.LIME)
(_makeText "Puzzle #$(+ 1 rewardFileIndex) / ${model.rewardFiles.length}" (max 0 (- TOTAL_PIECES (* currentRewardFile.piecesPerPoint (- p currentRewardFile.startingPoints)))))
(set entryWindow.textColor FlxColor.ORANGE)
(map (m.activeDailyEntries) makeText)
(set entryWindow.textColor FlxColor.GREEN)
(map (m.activeMonthlyEntries) makeText)
(set entryWindow.textColor FlxColor.BLUE)
(map (m.activeIntervalEntries) makeText)
(set entryWindow.textColor FlxColor.WHITE)
(map (m.activeBonusEntries) makeText)
(set entryWindow.textColor FlxColor.YELLOW)
(map (m.activeTodoEntries) makeText)
(set entryWindow.textColor FlxColor.GRAY)
(_makeText "[SPACE] Cycle background color" 0)
(when windowWasShown
(entryWindow.show))
(when !(= puzzleUnlocked -1)
(startPuzzlePackChoice puzzleUnlocked)))
(unless debugLayer
(set debugLayer (new DebugLayer))
(set debugLayer.cameras [pieceCamera]))
(remove debugLayer)
(add debugLayer))
(method refreshModel [&opt m]
(let [m (or m model)]
(setModel m (nth m.rewardFiles rewardFileIndex))))
(prop &mut textY 0)
(prop :Array<FlxColor> backgroundOptions [
FlxColor.BLACK
FlxColor.WHITE
FlxColor.GRAY
])
(method makeText [:Entry e] (method makeText [:Entry e]
(let [label (HabitModel.activeLabel e)] (let [label (HabitModel.activeLabel e)]