From 5a72c4fded288f47719a6ed7301124e79af7e8b7 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Sun, 14 Nov 2021 06:32:46 -0600 Subject: [PATCH] Debug: add loading and running scripts\ Ship: Validate alternate implementation of getExtents() --- godot_ship/script/debug/debug_menu.gd | 20 ++++++++++++++++++++ godot_ship/script/game/Gameplay/Ship.gd | 14 ++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/godot_ship/script/debug/debug_menu.gd b/godot_ship/script/debug/debug_menu.gd index 7e36f8e..4ef7654 100644 --- a/godot_ship/script/debug/debug_menu.gd +++ b/godot_ship/script/debug/debug_menu.gd @@ -38,6 +38,7 @@ var helptext = { "command_getprop": [" prop", "Get the value of property prop\n" ], "command_setprop": [" prop value", "Set the property prop to value.\n" ], + "command_script": [" path", "Load and execute a script at a given path.\n" ], "command_restart": ["", "Kill the current scene tree and plant a new Root.\n" ], "command_exit": ["", "Quits the program.\n" ], @@ -70,6 +71,7 @@ var commands = { ["getprop","get", "g"]: "command_getprop", ["setprop","set", "s"]: "command_setprop", + ["script", "sh"]: "command_script", ["restart", "killall"]: "command_restart", ["exit", "quit"]: "command_exit", @@ -519,6 +521,24 @@ func command_perf(command): else: debug_print_line(get_usage(command[0])) +# script: run a script from user:// +func command_script(command): + var script = [] + if (command.size() > 1): + var path = "user://" + command[1] + var f = File.new() + var err = f.open(path, File.READ) + if err == OK: + while not f.eof_reached(): + script.push_back(f.get_line()) + f.close() + for cmd in script: + _on_LineEdit_text_entered(cmd) + else: + debug_print_line("File not found: " + command[1] + "\n") + else: + debug_print_line(get_usage(command[0])) + func perf(attribute): if attribute.is_valid_integer(): return Performance.get_monitor(int(attribute)) diff --git a/godot_ship/script/game/Gameplay/Ship.gd b/godot_ship/script/game/Gameplay/Ship.gd index e39d8d1..6191e67 100644 --- a/godot_ship/script/game/Gameplay/Ship.gd +++ b/godot_ship/script/game/Gameplay/Ship.gd @@ -6,9 +6,9 @@ extends Control enum Orientation {X = 0, Y = 1} # Size of ship in board units -var size +var size = 2 # Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)] -var boardposition +var boardposition = Vector2(-1,-1) # Variable storing whether the ship is sunk, for rendering purposes var sunk = false # Orientation of the ship (see enum Orientation) @@ -46,17 +46,23 @@ func getSunk(): # returns an array of the positions that the ship occupies func getExtent(): var extent = [] + + for i in size: + var x = boardposition.x - int(!orientation) * ((size - 1) / 2) + int(!orientation) * i + var y = boardposition.y - orientation * ((size - 1) / 2) + orientation * i + print(Vector2(x,y)) + #vertical orientation if orientation == 1: for i in size: - var pos + var pos = Vector2(0,0) pos.x = boardposition.x pos.y = boardposition.y - ((size - 1) / 2) + i extent.append(pos) #horizontal orientation if orientation == 0: for i in size: - var pos + var pos = Vector2(0,0) pos.x = boardposition.x - ((size - 1) / 2) + i pos.y = boardposition.y extent.append(pos)