habit game choose next puzzle pack

This commit is contained in:
2022-08-05 20:56:55 +00:00
parent a55b069dc5
commit 579d8c4634
2 changed files with 37 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ import HabitModel;
import sys.FileSystem;
import hx.strings.Strings;
import datetime.DateTime;
import flixel.ui.FlxButton;
using kiss_flixel.CameraTools;
using kiss_flixel.GroupTools;
import haxe.ds.Option;

View File

@@ -148,7 +148,8 @@
(set shortcutHandler (new FlxKeyShortcutHandler))
(let [p (m.totalPoints)
&mut i 0 ]
&mut i 0
&mut puzzleUnlocked -1]
// Find, load, and add the current reward image as big as possible:
(unless currentRewardFile
(set currentRewardFile (nth m.rewardFiles 0))
@@ -159,14 +160,9 @@
(when (>= ++i m.rewardFiles.length)
(let [lastStartingPoints .startingPoints (nth m.rewardFiles --i)
nextStartingPoints (+ lastStartingPoints TOTAL_PIECES)]
(if (> p nextStartingPoints)
{
// TODO give the player a puzzle pack choice using (availablePacks)
(m.addRewardFile .path (firstUnsolvedPuzzle m "puzzles/trentnelson") nextStartingPoints)
(setModel m)
(return)
}
(break))))))
(when (> p nextStartingPoints)
(set puzzleUnlocked nextStartingPoints))
(break)))))
(set save (new FlxSave))
(save.bind currentRewardFile.path)
@@ -321,7 +317,10 @@
(map (m.activeTodoEntries) makeText)
(set _color FlxColor.GRAY)
(_makeText "[SPACE] Cycle background color" 0)
(add entryTexts))
(add entryTexts)
(when !(= puzzleUnlocked -1)
(startPuzzlePackChoice puzzleUnlocked)))
(doFor e (m.allEntries)
(when (HabitModel.isActive e)
@@ -473,4 +472,30 @@
(unless (contains collected piece)
(collected.push piece)
(recursivelyConnectedPieces piece collected))))
collected)
collected)
(prop &mut :FlxGroup nextPuzzleChoiceGroup null)
(method startPuzzlePackChoice [nextStartingPoints]
(unless nextPuzzleChoiceGroup
(set nextPuzzleChoiceGroup (new FlxGroup))
(set nextPuzzleChoiceGroup.cameras [uiCamera])
// TODO position these aesthetically with a partly transparent background behind them
// like the habit ui window should also have
(let [x 0 &mut y 0]
(doFor pack (availablePacks model)
(let [text (new FlxText x y 0 "$(haxe.io.Path.withoutDirectory pack.path): ${pack.puzzlesDone}/${pack.puzzlesTotal}" textSize)]
// TODO not that color though
(set text.color FlxColor.LIME)
(nextPuzzleChoiceGroup.add text)
(whenLet [(Some np) pack.nextPuzzle]
(nextPuzzleChoiceGroup.add (new FlxButton (+ x text.width) y "CHOOSE" ->:Void {
(remove nextPuzzleChoiceGroup)
(set nextPuzzleChoiceGroup null)
(model.addRewardFile np.path nextStartingPoints)
(setModel model)
}))))
(+= y textSize)))
(add nextPuzzleChoiceGroup)))