diff --git a/levels/2d/2d-test b/levels/2d/2d-test new file mode 100644 index 0000000..268bdd5 --- /dev/null +++ b/levels/2d/2d-test @@ -0,0 +1,14 @@ +title = Apples +cards = checkout commit-auto reset-hard branch-delete + +[description] + +Testlevel for 2d interactive files. + +[setup] + +echo "x = 10 +y = 5 +color = red" > apple +git add . +git commit -m "An apple a day" diff --git a/project.godot b/project.godot index cca3e67..35676e9 100644 --- a/project.godot +++ b/project.godot @@ -140,6 +140,12 @@ clear={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":76,"unicode":0,"echo":false,"script":null) ] } +pickup={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) + ] +} [network] diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index a398545..b86713e 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -19,6 +19,7 @@ onready var world = $Panel/Margin/Rows/World onready var text_edit = $Panel/TextEdit onready var save_button = $Panel/TextEdit/SaveButton onready var title_label = $Panel/Margin/Rows/Title +onready var player = $Panel/Margin/Rows/World/You func _ready(): update() @@ -30,11 +31,29 @@ func _input(event): if event.is_action_pressed("save"): if text_edit.visible: save() + if event.is_action_pressed("down", true): + player.move(Vector2(0,1)) + if event.is_action_pressed("up", true): + player.move(Vector2(0,-1)) + if event.is_action_pressed("right", true): + player.move(Vector2(1,0)) + if event.is_action_pressed("left", true): + player.move(Vector2(-1,0)) + if event.is_action_pressed("pickup"): + if player.held: + player.held = null + else: + for item in world.get_children(): + if item.label != "": + if item.position == player.position: + player.held = item + print("player picked up item " + item.label) func clear(): pass for item in world.get_children(): - item.queue_free() + if item.label != "": + item.queue_free() func substr2(s): return s.substr(2) @@ -65,12 +84,14 @@ func update(): #is_visible = true var item = preload("res://scenes/item.tscn").instance() item.label = file_path + item.file_browser = self #item.connect("clicked", self, "item_clicked") #item.connect("deleted", self, "item_deleted") item.status = get_file_status(file_path, shell, 1) seed(item.label.hash()) item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y)) randomize() + item.content = shell.run("cat " + file_path) world.add_child(item) #visible = is_visible diff --git a/scenes/file_browser.tscn b/scenes/file_browser.tscn index ee6c0a3..daa9eff 100644 --- a/scenes/file_browser.tscn +++ b/scenes/file_browser.tscn @@ -77,6 +77,9 @@ margin_bottom = 1064.0 size_flags_horizontal = 3 size_flags_vertical = 3 +[node name="You" parent="Panel/Margin/Rows/World" instance=ExtResource( 6 )] +editable = false + [node name="TextEdit" type="TextEdit" parent="Panel"] visible = false anchor_right = 1.0 @@ -121,9 +124,5 @@ __meta__ = { [node name="PopupMenu" type="PopupMenu" parent="."] margin_right = 20.0 margin_bottom = 20.0 - -[node name="You" parent="." instance=ExtResource( 6 )] -position = Vector2( 175.746, 148.807 ) -editable = false [connection signal="pressed" from="Panel/TextEdit/SaveButton" to="." method="save"] [connection signal="pressed" from="Panel/TextEdit/CloseButton" to="." method="close"] diff --git a/scenes/helpers.gd b/scenes/helpers.gd index feff683..f6da2a6 100644 --- a/scenes/helpers.gd +++ b/scenes/helpers.gd @@ -93,8 +93,7 @@ func careful_delete(path_inside): game.global_shell.cd(game.tmp_prefix) game.global_shell.run("rm -rf '%s'" % path_inside) -func parse(file): - var text = read_file(file) +func parse(text): var result = {} var current_section @@ -118,7 +117,7 @@ func parse(file): # Parse a direct=assignment. m = assignment_regex.search(line) - if m: + if m and current_section == null: var key = m.get_string(1).strip_edges() var value = m.get_string(2).strip_edges() result[key] = value diff --git a/scenes/item.gd b/scenes/item.gd index 32b7c2b..0a6c6aa 100644 --- a/scenes/item.gd +++ b/scenes/item.gd @@ -6,6 +6,10 @@ export(IconStatus) var status setget _set_status export var label: String setget _set_label var type = "file" export var editable = true +var content setget _set_content +var held +var GRID_SIZE = 60 +var file_browser onready var label_node = $Label onready var status_icon = $Status @@ -51,3 +55,18 @@ func _set_status(new_status): status_icon.texture = null status = new_status + +func _set_content(new_content): + content = new_content + var attributes = helpers.parse(content) + if attributes.has("x") and attributes.has("y"): + position.x = int(attributes["x"]) * GRID_SIZE + position.y = int(attributes["y"]) * GRID_SIZE + +func move(direction): + position += direction * GRID_SIZE + if label != "": + file_browser.shell.run("echo \"x = "+ String(position.x / GRID_SIZE) +"\ny = "+ String(position.y / GRID_SIZE) +"\" > " + label) + if held: + held.move(direction) + diff --git a/scenes/level.gd b/scenes/level.gd index a74d216..47fe442 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -16,7 +16,7 @@ func load(path): var dir = Directory.new() if dir.file_exists(path): # This is a new-style level. - var config = helpers.parse(path) + var config = helpers.parse(helpers.read_file(path)) title = config.get("title", slug) description = config.get("description", "(no description)")