oh-my-git/game.gd

45 lines
896 B
GDScript3
Raw Normal View History

2020-01-29 20:25:13 +01:00
extends Node
var tmp_prefix = "/tmp/"
var cwd
var global_shell
2020-01-29 20:25:13 +01:00
func _ready():
global_shell = Shell.new()
global_shell.cd(tmp_prefix)
cwd = global_shell.run("pwd")
# Remove trailing newline.
cwd = cwd.substr(0,len(cwd)-1)
# Run a simple command with arguments, blocking, using OS.execute.
func exec(command, args=[]):
var debug = true
if debug:
print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")])
2020-09-04 14:57:37 +02:00
var output = []
OS.execute(command, args, true, output, true)
output = output[0]
2020-09-04 14:57:37 +02:00
if debug:
print(output)
return output
func read_file(path):
print ("reading " + path)
2020-09-04 14:57:37 +02:00
var file = File.new()
file.open(path, File.READ)
var content = file.get_as_text()
file.close()
return content
func write_file(path, content):
print ("writing " + path)
2020-09-04 14:57:37 +02:00
var file = File.new()
file.open(path, File.WRITE)
file.store_string(content)
file.close()
return true