diff --git a/game.gd b/game.gd index de7accd..df6ac4c 100644 --- a/game.gd +++ b/game.gd @@ -27,15 +27,14 @@ func _ready(): func _initial_state(): return {"history": []} -func save_state() -> bool: +func save_state(): var savegame = File.new() savegame.open(_file, File.WRITE) savegame.store_line(to_json(state)) savegame.close() - return true -func load_state() -> bool: +func load_state(): var savegame = File.new() if not savegame.file_exists(_file): save_state() @@ -47,7 +46,6 @@ func load_state() -> bool: for key in new_state: state[key] = new_state[key] savegame.close() - return true func copy_file_to_game_env(filename): # Copy fake-editor to tmp directory (because the original might be in a .pck file). diff --git a/helpers.gd b/helpers.gd index 2f23c30..a304a5b 100644 --- a/helpers.gd +++ b/helpers.gd @@ -54,3 +54,15 @@ func write_file(path, content): file.store_string(content) file.close() return true + +func parse_args(): + var arguments = {} + for argument in OS.get_cmdline_args(): + if argument.substr(0, 2) == "--": + # Parse valid command-line arguments into a dictionary + if argument.find("=") > -1: + var key_value = argument.split("=") + arguments[key_value[0].lstrip("--")] = key_value[1] + else: + arguments[argument.lstrip("--")] = true + return arguments diff --git a/main.gd b/main.gd index eb37dab..638122a 100644 --- a/main.gd +++ b/main.gd @@ -18,6 +18,14 @@ onready var level_description = $Columns/RightSide/TopStuff/LevelPanel/Text/Leve onready var level_congrats = $Columns/RightSide/TopStuff/LevelPanel/Text/LevelCongrats func _ready(): + var args = helpers.parse_args() + + if args.has("sandbox"): + var err = get_tree().change_scene("res://sandbox.tscn") + if err != OK: + helpers.crash("Could not change to sandbox scene") + return + # Initialize level select. level_select.connect("item_selected", self, "load_level") repopulate_levels() @@ -200,5 +208,5 @@ func repopulate_levels(): func repopulate_chapters(): chapter_select.clear() - for chapter in list_chapters(): - chapter_select.add_item(chapter) + for c in list_chapters(): + chapter_select.add_item(c) diff --git a/node.tscn b/node.tscn index 7fc1ab2..8b21267 100644 --- a/node.tscn +++ b/node.tscn @@ -20,7 +20,6 @@ corner_radius_bottom_left = 5 script = ExtResource( 1 ) [node name="Arrows" type="Node2D" parent="."] -z_index = -1 [node name="Rect" type="ColorRect" parent="."] margin_left = -29.0 diff --git a/repository.tscn b/repository.tscn index 1fb365f..bff0b4d 100644 --- a/repository.tscn +++ b/repository.tscn @@ -99,10 +99,10 @@ __meta__ = { } [node name="Path" type="LineEdit" parent="Rows/RepoVis"] -margin_left = 23.3361 -margin_top = 12.3197 -margin_right = 574.336 -margin_bottom = 61.3197 +margin_left = 23.0 +margin_top = 12.0 +margin_right = 374.0 +margin_bottom = 61.0 __meta__ = { "_edit_use_anchors_": false } diff --git a/sandbox.gd b/sandbox.gd index df55c2a..0ed10f5 100644 --- a/sandbox.gd +++ b/sandbox.gd @@ -1,7 +1,16 @@ extends Control func _ready(): - var pwd = "/tmp/active/" # OS.get_environment("PWD") - $HSplitContainer/Repository.path = pwd + var args = helpers.parse_args() + var path = game.tmp_prefix_inside + if args.has("sandbox"): + if args["sandbox"] is String: + var dir = Directory.new() + if dir.dir_exists(args["sandbox"]): + path = args["sandbox"] + else: + helpers.crash("Directory %s does not exist" % args["sandbox"]) + + $HSplitContainer/Repository.path = path get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, Vector2(1920, 1080), 1.5)