mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
Handle --sandbox on its own (create blank repo) and --sandbox=.
This commit is contained in:
parent
e439135ec9
commit
473d7508c2
3 changed files with 32 additions and 20 deletions
17
helpers.gd
17
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)
|
||||
|
|
21
main.gd
21
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)
|
||||
|
|
14
sandbox.gd
14
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)
|
||||
|
|
Loading…
Reference in a new issue