From db99dbc9390114e7a767b92ab39284270d6c0a94 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 26 Jul 2022 17:00:11 +0000 Subject: [PATCH] Close #98: 30s refresh for habit puzzles --- .../source/HabitState.kiss | 2 ++ .../flixel-desktop-habit-puzzle-game/source/Main.hx | 11 +++++++++-- 2 files changed, 11 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 39005bdf..9a2fcfa7 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -84,6 +84,8 @@ (prop &mut :FlxExtendedSprite draggingSprite null) (prop &mut :FlxPoint draggingLastPos null) +// Main.hx sets off 99% of the app's logic by parsing the model file and calling setModel on startup and on a 30s loop: + (method setModel [m &opt :RewardFile currentRewardFile] (set model m) (set shortcutHandler (new FlxKeyShortcutHandler)) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/Main.hx b/projects/flixel-desktop-habit-puzzle-game/source/Main.hx index 316ada0d..ec14465e 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/Main.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/Main.hx @@ -3,6 +3,7 @@ package; import flixel.FlxG; import flixel.FlxGame; import openfl.display.Sprite; +import flixel.util.FlxTimer; class Main extends Sprite { @@ -16,7 +17,13 @@ class Main extends Sprite } else { "habits/default.txt"; }; - t.setModel(new HabitModel(habitFile)); - t.model.save(); + function reloadModel(_) { + t.setModel(new HabitModel(habitFile)); + t.model.save(); + } + reloadModel(null); + new FlxTimer().start(30, reloadModel, 0); + } + }