mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-11 19:04:50 +01:00
When game is run with --sandbox, switch to sandbox
This commit is contained in:
parent
6e8a310a7a
commit
e439135ec9
6 changed files with 39 additions and 13 deletions
6
game.gd
6
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).
|
||||
|
|
12
helpers.gd
12
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
|
||||
|
|
12
main.gd
12
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
13
sandbox.gd
13
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)
|
||||
|
|
Loading…
Reference in a new issue