From 85d979a98b2295421e876cee3851574e961d4207 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 16 Aug 2022 15:48:24 +0000 Subject: [PATCH] put habits file in user Documents --- .../flixel-desktop-habit-puzzle-game/source/Main.hx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/Main.hx b/projects/flixel-desktop-habit-puzzle-game/source/Main.hx index de5b6981..27099ff0 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/Main.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/Main.hx @@ -1,9 +1,12 @@ package; +import sys.io.File; +import sys.FileSystem; import flixel.FlxG; import flixel.FlxGame; import openfl.display.Sprite; import flixel.util.FlxTimer; +import kiss.Prelude; class Main extends Sprite { @@ -12,10 +15,18 @@ class Main extends Sprite super(); addChild(new FlxGame(0, 0, HabitState, 1, 60, 60, true)); var t:HabitState = cast FlxG.state; + + var saveFolder = Prelude.joinPath(Prelude.userHome(), "Documents", "HabitPuzzles"); + var habitFile = Prelude.joinPath(saveFolder, "habits.txt"); + if (!(FileSystem.exists(saveFolder) && FileSystem.isDirectory(saveFolder))) { + FileSystem.createDirectory(saveFolder); + File.saveContent(habitFile, File.getContent("habits/default.txt")); + } + var habitFile = if (Sys.args().length > 0 && Sys.args()[0].length > 0) { Sys.args()[0]; } else { - "habits/default.txt"; + habitFile; }; function reloadModel(_) { if (t.draggingSprite == null) {