mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +01:00
Convert space indentation to tabs
This commit is contained in:
parent
00247318a6
commit
132d7eea32
2 changed files with 133 additions and 133 deletions
116
game.gd
116
game.gd
|
@ -4,74 +4,74 @@ var _file = "user://savegame.json"
|
||||||
var state = {}
|
var state = {}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
load_state()
|
load_state()
|
||||||
|
|
||||||
func _initial_state():
|
func _initial_state():
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
func save_state() -> bool:
|
func save_state() -> bool:
|
||||||
var savegame = File.new()
|
var savegame = File.new()
|
||||||
|
|
||||||
savegame.open(_file, File.WRITE)
|
savegame.open(_file, File.WRITE)
|
||||||
savegame.store_line(to_json(state))
|
savegame.store_line(to_json(state))
|
||||||
savegame.close()
|
savegame.close()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func load_state() -> bool:
|
func load_state() -> bool:
|
||||||
var savegame = File.new()
|
var savegame = File.new()
|
||||||
if not savegame.file_exists(_file):
|
if not savegame.file_exists(_file):
|
||||||
return false
|
return false
|
||||||
|
|
||||||
savegame.open(_file, File.READ)
|
savegame.open(_file, File.READ)
|
||||||
|
|
||||||
state = _initial_state()
|
state = _initial_state()
|
||||||
var new_state = parse_json(savegame.get_line())
|
var new_state = parse_json(savegame.get_line())
|
||||||
for key in new_state:
|
for key in new_state:
|
||||||
state[key] = new_state[key]
|
state[key] = new_state[key]
|
||||||
savegame.close()
|
savegame.close()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# Run a simple command given as a string, blocking, using execute.
|
# Run a simple command given as a string, blocking, using execute.
|
||||||
func run(command):
|
func run(command):
|
||||||
print("run: "+command)
|
print("run: "+command)
|
||||||
var output = []
|
var output = []
|
||||||
OS.execute(command, [], true, output, true)
|
OS.execute(command, [], true, output, true)
|
||||||
# Remove trailing newline.
|
# Remove trailing newline.
|
||||||
return output[0].substr(0,len(output[0])-1)
|
return output[0].substr(0,len(output[0])-1)
|
||||||
|
|
||||||
func sh(command, wd="/tmp/"):
|
func sh(command, wd="/tmp/"):
|
||||||
print("sh in "+wd+": "+command)
|
print("sh in "+wd+": "+command)
|
||||||
var cwd = game.run("pwd")
|
var cwd = game.run("pwd")
|
||||||
var output = []
|
var output = []
|
||||||
|
|
||||||
var hacky_command = command
|
var hacky_command = command
|
||||||
hacky_command = "cd '"+wd+"';"+hacky_command
|
hacky_command = "cd '"+wd+"';"+hacky_command
|
||||||
hacky_command = "export EDITOR=fake-editor;"+hacky_command
|
hacky_command = "export EDITOR=fake-editor;"+hacky_command
|
||||||
hacky_command = "export PATH=\"$PATH\":"+cwd+"/scripts;"+hacky_command
|
hacky_command = "export PATH=\"$PATH\":"+cwd+"/scripts;"+hacky_command
|
||||||
OS.execute("/bin/sh", ["-c", hacky_command], true, output, true)
|
OS.execute("/bin/sh", ["-c", hacky_command], true, output, true)
|
||||||
return output[0]
|
return output[0]
|
||||||
|
|
||||||
func script(filename, wd="/tmp/"):
|
func script(filename, wd="/tmp/"):
|
||||||
print("sh script in "+wd+": "+filename)
|
print("sh script in "+wd+": "+filename)
|
||||||
var cwd = game.run("pwd")
|
var cwd = game.run("pwd")
|
||||||
var output = []
|
var output = []
|
||||||
|
|
||||||
var hacky_command = "/bin/sh " + filename
|
var hacky_command = "/bin/sh " + filename
|
||||||
hacky_command = "cd '"+wd+"';"+hacky_command
|
hacky_command = "cd '"+wd+"';"+hacky_command
|
||||||
OS.execute("/bin/sh", ["-c", hacky_command], true, output, true)
|
OS.execute("/bin/sh", ["-c", hacky_command], true, output, true)
|
||||||
return output[0]
|
return output[0]
|
||||||
|
|
||||||
func read_file(path):
|
func read_file(path):
|
||||||
print("read "+path)
|
print("read "+path)
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(path, File.READ)
|
file.open(path, File.READ)
|
||||||
var content = file.get_as_text()
|
var content = file.get_as_text()
|
||||||
file.close()
|
file.close()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
func write_file(path, content):
|
func write_file(path, content):
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(path, File.WRITE)
|
file.open(path, File.WRITE)
|
||||||
file.store_string(content)
|
file.store_string(content)
|
||||||
file.close()
|
file.close()
|
||||||
return true
|
return true
|
||||||
|
|
150
main.gd
150
main.gd
|
@ -11,76 +11,76 @@ onready var goal_repository = $Repositories/GoalRepository
|
||||||
onready var active_repository = $Repositories/ActiveRepository
|
onready var active_repository = $Repositories/ActiveRepository
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Initialize level select.
|
# Initialize level select.
|
||||||
var options = $LevelSelect.get_popup()
|
var options = $LevelSelect.get_popup()
|
||||||
for level in list_levels():
|
for level in list_levels():
|
||||||
options.add_item(level)
|
options.add_item(level)
|
||||||
options.connect("id_pressed", self, "load_level")
|
options.connect("id_pressed", self, "load_level")
|
||||||
|
|
||||||
# Initialize TCP server for fake editor.
|
# Initialize TCP server for fake editor.
|
||||||
server = TCP_Server.new()
|
server = TCP_Server.new()
|
||||||
server.listen(1234)
|
server.listen(1234)
|
||||||
|
|
||||||
# Load first level.
|
# Load first level.
|
||||||
load_level(0)
|
load_level(0)
|
||||||
input.grab_focus()
|
input.grab_focus()
|
||||||
|
|
||||||
func list_levels():
|
func list_levels():
|
||||||
var levels = []
|
var levels = []
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
dir.open("levels")
|
dir.open("levels")
|
||||||
dir.list_dir_begin()
|
dir.list_dir_begin()
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
var file = dir.get_next()
|
var file = dir.get_next()
|
||||||
if file == "":
|
if file == "":
|
||||||
break
|
break
|
||||||
elif not file.begins_with("."):
|
elif not file.begins_with("."):
|
||||||
levels.append(file)
|
levels.append(file)
|
||||||
|
|
||||||
dir.list_dir_end()
|
dir.list_dir_end()
|
||||||
levels.sort()
|
levels.sort()
|
||||||
return levels
|
return levels
|
||||||
|
|
||||||
func load_level(id):
|
func load_level(id):
|
||||||
var levels = list_levels()
|
var levels = list_levels()
|
||||||
|
|
||||||
var level = levels[id]
|
var level = levels[id]
|
||||||
var cwd = game.run("pwd")
|
var cwd = game.run("pwd")
|
||||||
var tmp_prefix = "/tmp/"
|
var tmp_prefix = "/tmp/"
|
||||||
var level_prefix = cwd + "/levels/"
|
var level_prefix = cwd + "/levels/"
|
||||||
|
|
||||||
var goal_repository_path = tmp_prefix+"goal/"
|
var goal_repository_path = tmp_prefix+"goal/"
|
||||||
var active_repository_path = tmp_prefix+"active/"
|
var active_repository_path = tmp_prefix+"active/"
|
||||||
var goal_script = level_prefix+level+"/goal"
|
var goal_script = level_prefix+level+"/goal"
|
||||||
var active_script = level_prefix+level+"/start"
|
var active_script = level_prefix+level+"/start"
|
||||||
|
|
||||||
var description = game.read_file(level_prefix+level+"/description")
|
var description = game.read_file(level_prefix+level+"/description")
|
||||||
$LevelDescription.bbcode_text = description
|
$LevelDescription.bbcode_text = description
|
||||||
|
|
||||||
OS.execute("rm", ["-r", active_repository_path], true)
|
OS.execute("rm", ["-r", active_repository_path], true)
|
||||||
OS.execute("rm", ["-r", goal_repository_path], true)
|
OS.execute("rm", ["-r", goal_repository_path], true)
|
||||||
construct_repo(goal_script, goal_repository_path)
|
construct_repo(goal_script, goal_repository_path)
|
||||||
construct_repo(active_script, active_repository_path)
|
construct_repo(active_script, active_repository_path)
|
||||||
|
|
||||||
goal_repository.path = goal_repository_path
|
goal_repository.path = goal_repository_path
|
||||||
active_repository.path = active_repository_path
|
active_repository.path = active_repository_path
|
||||||
|
|
||||||
func construct_repo(script, path):
|
func construct_repo(script, path):
|
||||||
print(path)
|
print(path)
|
||||||
game.sh("mkdir "+path)
|
game.sh("mkdir "+path)
|
||||||
game.sh("git init", path)
|
game.sh("git init", path)
|
||||||
print(game.script(script, path))
|
print(game.script(script, path))
|
||||||
#var commands = game.read_file(script).split("\n")
|
#var commands = game.read_file(script).split("\n")
|
||||||
#print(commands)
|
#print(commands)
|
||||||
#for command in commands:
|
#for command in commands:
|
||||||
# print(command)
|
# print(command)
|
||||||
# game.sh(command, path)
|
# game.sh(command, path)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if server.is_connection_available():
|
if server.is_connection_available():
|
||||||
client_connection = server.take_connection()
|
client_connection = server.take_connection()
|
||||||
read_commit_message()
|
read_commit_message()
|
||||||
# if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
|
# if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
|
||||||
# if Input.is_action_just_pressed("click"):
|
# if Input.is_action_just_pressed("click"):
|
||||||
# var mindist = 9999999
|
# var mindist = 9999999
|
||||||
|
@ -102,18 +102,18 @@ func _process(delta):
|
||||||
# OS.execute(cmd, a, true, output, true)
|
# OS.execute(cmd, a, true, output, true)
|
||||||
# print(command)
|
# print(command)
|
||||||
# print(output[0])
|
# print(output[0])
|
||||||
|
|
||||||
func read_commit_message():
|
func read_commit_message():
|
||||||
$CommitMessage.show()
|
$CommitMessage.show()
|
||||||
input.editable = false
|
input.editable = false
|
||||||
$CommitMessage.text = game.read_file(active_repository.path+"/.git/COMMIT_EDITMSG")
|
$CommitMessage.text = game.read_file(active_repository.path+"/.git/COMMIT_EDITMSG")
|
||||||
$CommitMessage.grab_focus()
|
$CommitMessage.grab_focus()
|
||||||
|
|
||||||
func save_commit_message():
|
func save_commit_message():
|
||||||
game.write_file(active_repository.path+"/.git/COMMIT_EDITMSG", $CommitMessage.text)
|
game.write_file(active_repository.path+"/.git/COMMIT_EDITMSG", $CommitMessage.text)
|
||||||
print("disconnect")
|
print("disconnect")
|
||||||
client_connection.disconnect_from_host()
|
client_connection.disconnect_from_host()
|
||||||
input.editable = true
|
input.editable = true
|
||||||
$CommitMessage.text = ""
|
$CommitMessage.text = ""
|
||||||
$CommitMessage.hide()
|
$CommitMessage.hide()
|
||||||
input.grab_focus()
|
input.grab_focus()
|
||||||
|
|
Loading…
Reference in a new issue