From 9321ecb9ecd80a7e900210f2dc0b1a53466d4b85 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 10 Aug 2022 20:27:33 +0000 Subject: [PATCH] ACTUALLY approximate square pieces for any puzzle aspect ratio --- .../source/HabitState.kiss | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 15e3a85c..620a042d 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -455,6 +455,7 @@ (prop &mut :FlxGroup nextPuzzleChoiceGroup null) +(var BASE_PUZZLE_SIZE 5) (method startPuzzlePackChoice [nextStartingPoints] (unless nextPuzzleChoiceGroup (set nextPuzzleChoiceGroup (new FlxGroup)) @@ -472,8 +473,14 @@ (nextPuzzleChoiceGroup.add (new FlxButton (+ x text.width) y "CHOOSE" ->:Void { (remove nextPuzzleChoiceGroup) (set nextPuzzleChoiceGroup null) - // TODO generate a good width and height while respecting user settings - (model.addRewardFile np.path nextStartingPoints 6 5) + (let [bmd (BitmapData.fromFile np.path) + aspectRatioX (/ bmd.width bmd.height) + aspectRatioY (/ bmd.height bmd.width) + w (max 1 (Math.round (* aspectRatioX BASE_PUZZLE_SIZE))) + h (max 1 (Math.round (* aspectRatioY BASE_PUZZLE_SIZE)))] + (model.addRewardFile np.path nextStartingPoints w h 1)) + + (setModel model) }))))