1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00

Debug: add loading and running scripts\ Ship: Validate alternate implementation of getExtents()

This commit is contained in:
John 2021-11-14 06:32:46 -06:00
parent 7af638d1ea
commit 5a72c4fded
2 changed files with 30 additions and 4 deletions

View File

@ -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))

View File

@ -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)