diff --git a/helpers.gd b/helpers.gd index a304a5b..d5d9a27 100644 --- a/helpers.gd +++ b/helpers.gd @@ -66,3 +66,20 @@ func parse_args(): else: arguments[argument.lstrip("--")] = true return arguments + +func careful_delete(path_inside): + var expected_prefix + + var os = OS.get_name() + + if os == "X11": + expected_prefix = "/home/%s/.local/share/git-hydra/tmp/" % OS.get_environment("USER") + elif os == "Windows": + helpers.crash("Need to figure out delete_prefix on Windows") + else: + helpers.crash("Unsupported OS: %s" % os) + + if path_inside.substr(0,expected_prefix.length()) != expected_prefix: + helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix]) + else: + game.global_shell.run("rm -rf '%s'" % path_inside) diff --git a/main.gd b/main.gd index 638122a..d8a664c 100644 --- a/main.gd +++ b/main.gd @@ -129,8 +129,8 @@ func load_level(id): # We're actually destroying stuff here. # Make sure that active_repository is in a temporary directory. - _careful_delete(active_repository_path) - _careful_delete(goal_repository_path) + helpers.careful_delete(active_repository_path) + helpers.careful_delete(goal_repository_path) var goal_script_content = helpers.read_file(goal_script, "") var active_script_content = helpers.read_file(active_script, "") @@ -156,23 +156,6 @@ func load_level(id): yield(t, "timeout") AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false) # FIXME: Need to clean these up when switching levels somehow. - -func _careful_delete(path_inside): - var expected_prefix - - var os = OS.get_name() - - if os == "X11": - expected_prefix = "/home/%s/.local/share/git-hydra/tmp/" % OS.get_environment("USER") - elif os == "Windows": - helpers.crash("Need to figure out delete_prefix on Windows") - else: - helpers.crash("Unsupported OS: %s" % os) - - if path_inside.substr(0,expected_prefix.length()) != expected_prefix: - helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix]) - else: - game.global_shell.run("rm -rf '%s'" % path_inside) func reload_level(): load_level(current_level) diff --git a/sandbox.gd b/sandbox.gd index 0ed10f5..b289fa0 100644 --- a/sandbox.gd +++ b/sandbox.gd @@ -1,16 +1,28 @@ extends Control func _ready(): + var path = null + var args = helpers.parse_args() - var path = game.tmp_prefix_inside if args.has("sandbox"): if args["sandbox"] is String: + if args["sandbox"] == ".": + args["sandbox"] = OS.get_environment("PWD") var dir = Directory.new() if dir.dir_exists(args["sandbox"]): path = args["sandbox"] else: helpers.crash("Directory %s does not exist" % args["sandbox"]) + if path == null: + path = game.tmp_prefix_inside+"/repos/sandbox/" + helpers.careful_delete(path) + + game.global_shell.run("mkdir " + path) + game.global_shell.cd(path) + game.global_shell.run("git init") + game.global_shell.run("git symbolic-ref HEAD refs/heads/main") + $HSplitContainer/Repository.path = path get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, Vector2(1920, 1080), 1.5)