From 007cf764bf101250c1dd464abc91a71465d6ed50 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 24 Nov 2020 15:11:00 +0100 Subject: [PATCH] Add drop and take scripts, which add/remove items from the inventory --- scenes/game.gd | 11 +++++++---- scenes/level.gd | 1 + scripts/drop | 9 +++++++++ scripts/take | 5 +++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 scripts/drop create mode 100755 scripts/take diff --git a/scenes/game.gd b/scenes/game.gd index 5157148..0dfcaec 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -2,7 +2,6 @@ extends Node var tmp_prefix = OS.get_user_data_dir() + "/tmp/" var global_shell -var fake_editor var dragged_object var energy = 2 @@ -15,11 +14,15 @@ func _ready(): create_file_in_game_env(".gitconfig", helpers.read_file("res://scripts/gitconfig")) - create_file_in_game_env("fake-editor", helpers.read_file("res://scripts/fake-editor")) - fake_editor = tmp_prefix + "fake-editor" - global_shell.run("chmod u+x '%s'" % fake_editor) + create_verb("fake-editor") + create_verb("take") + create_verb("drop") load_state() + +func create_verb(name): + create_file_in_game_env(name, helpers.read_file("res://scripts/%s" % name)) + global_shell.run("chmod u+x '%s'" % name) func _initial_state(): return {"history": []} diff --git a/scenes/level.gd b/scenes/level.gd index 2b96e33..0d68d3c 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -87,6 +87,7 @@ func construct(): game.global_shell.cd(repo.path) game.global_shell.run("git init") game.global_shell.run("git symbolic-ref HEAD refs/heads/main") + game.global_shell.run("test -f ~/fake-editor && rm -rf ~/inventory || exit 1") # Add other repos as remotes. for r2 in repos: diff --git a/scripts/drop b/scripts/drop new file mode 100755 index 0000000..4d65670 --- /dev/null +++ b/scripts/drop @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +echo "Dropping $1!" +mv "$HOME/inventory/$1" . + +if [ "$#" -eq 3 ]; then + echo "x = $2" > "$1" + echo "y = $3" >> "$1" +fi diff --git a/scripts/take b/scripts/take new file mode 100755 index 0000000..1aa490c --- /dev/null +++ b/scripts/take @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "Taking $1!" +mkdir -p ~/inventory +mv "$1" ~/inventory