added more functionality to the dev console and made it less buggy.

hopefully you cant crash the game from it now.
This commit is contained in:
Harmony Monroe 2020-09-28 15:32:13 -04:00
parent 1882272a0d
commit a1e284b361
5 changed files with 128 additions and 58 deletions

3
.gitignore vendored
View file

@ -12,4 +12,5 @@ data_*/
# custom
*.import
Export/
Export/
Build/

View file

@ -3,7 +3,7 @@
[ext_resource path="res://Font/m3x6.tres" type="DynamicFont" id=1]
[ext_resource path="res://Script/DevConsole.gd" type="Script" id=2]
[sub_resource type="StyleBoxFlat" id=3]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.247059, 0.247059, 0.247059, 0.247059 )
border_width_left = 4
border_width_top = 4
@ -16,10 +16,10 @@ corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
anti_aliasing = false
[sub_resource type="StyleBoxFlat" id=1]
[sub_resource type="StyleBoxFlat" id=2]
draw_center = false
[sub_resource type="StyleBoxFlat" id=2]
[sub_resource type="StyleBoxFlat" id=3]
draw_center = false
[sub_resource type="StyleBoxFlat" id=4]
@ -43,7 +43,7 @@ margin_left = 2.0
margin_top = 2.0
margin_right = 318.0
margin_bottom = 156.0
custom_styles/panel = SubResource( 3 )
custom_styles/panel = SubResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
@ -54,8 +54,8 @@ margin_top = 8.0
margin_right = 312.0
margin_bottom = 150.0
focus_mode = 2
custom_styles/focus = SubResource( 1 )
custom_styles/normal = SubResource( 2 )
custom_styles/focus = SubResource( 2 )
custom_styles/normal = SubResource( 3 )
custom_fonts/normal_font = ExtResource( 1 )
custom_colors/default_color = Color( 0.705882, 0.823529, 0.45098, 1 )
custom_colors/selection_color = Color( 1, 1, 1, 0.247059 )
@ -81,7 +81,7 @@ margin_left = 2.0
margin_top = 158.0
margin_right = 318.0
margin_bottom = 178.0
custom_styles/panel = SubResource( 3 )
custom_styles/panel = SubResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -5,6 +5,7 @@ var node_log : RichTextLabel
var node_input : LineEdit
var is_open := false
var last_text = ""
func _ready():
node_control= $Control
@ -23,69 +24,137 @@ func _process(delta):
if btn.p("ui_cancel"):
close()
func open():
# always grab focus when typing
func _input(event):
if is_open:
if event is InputEventKey and event.pressed:
node_input.grab_focus()
# press up
if event.scancode == KEY_UP:
node_input.text = last_text
# signal when pressing enter
# solve input string and call method
func _on_Input_text_entered(new_text):
node_input.clear()
last_text = new_text
if not is_open:
return
if new_text.begins_with("_"):
out("error: '_' in '" + new_text + "' - private methods disabled")
return
var method = new_text.split(" ")[0]
var arg = new_text.substr(method.length() + 1)
if has_method(method):
call(method, arg)
else:
out("can't find: " + method)
#open console
func open(arg = null):
is_open = true
node_control.visible = true
node_input.grab_focus()
func close():
# close console
func close(arg = null):
is_open = false
node_control.visible = false
node_input.clear()
# always grab focus when typing
func _input(event):
if event is InputEventKey and event.pressed:
node_input.grab_focus()
# signal when pressing enter
func _on_Input_text_entered(new_text):
if not is_open:
return
var method = new_text.split(" ")[0]
var args = new_text.substr(method.length() + 1)
if has_method(method):
if args:
call(method, args)
else:
call(method)
else:
out("can't find: " + method)
node_input.clear()
func out(arg = ""):
node_log.text += arg + "\n"
# print to console
func out(arg = "", newline = true):
node_log.text += str(arg) + ("\n" if newline else "")
print("dev.out: ", arg)
func clear():
# clear console
func clear(arg = null):
node_log.clear()
func quit():
out("bye bye")
# quit game
func quit(arg = null):
out("(quit) bye bye")
get_tree().quit()
func reset():
out("reset scene")
# reset scene
func reset(arg = null):
get_tree().reload_current_scene()
out("(reset) '" + str(get_tree().current_scene.filename) + "' loaded")
# load map scene by name
func map(arg = "map0"):
if get_tree().change_scene("res://Map/" + arg + ".tscn"):
out("error loading map: " + "res://Map/" + arg + ".tscn")
out("(map) error loading '" + arg + "' from " + "res://Map/" + arg + ".tscn")
else:
out("loading map: " + "res://Map/" + arg + ".tscn")
out("(map) loaded '" + arg + "' from: " + "res://Map/" + arg + ".tscn")
func box():
# spawn box at Vector2 coordinates
func box(arg := ""):
var pos = null
if arg.split(" ").size() > 1:
pos = Vector2(int(arg.split(" ")[0]), int(arg.split(" ")[1]))
for i in get_tree().get_nodes_in_group("player"):
i.debug_box()
i.debug_box(pos)
# set window scale
func winscale(arg = 0):
if int(arg) == 0:
Shared.set_window_scale()
else:
Shared.set_window_scale(int(arg))
out("(winscale) " + str(Shared.set_window_scale(int(arg))))
func kill():
# kill player
func kill(arg = null):
out("(kill) ", false)
for i in get_tree().get_nodes_in_group("player"):
i.death()
# show help text
func help(arg = null):
var s = []
for m in get_script().get_script_method_list():
if not m.name.begins_with("_"):
s.append(m.name)
s.sort()
out("(help) methods: " + str(s))
# list nodes in group, actor by default
func list(arg = null):
arg = arg if arg else "actor"
var l = []
for a in get_tree().get_nodes_in_group(arg):
l.append(a.name)
out("(list) " + str(l.size()) + " " + str(arg) + " nodes: " + str(l))
# set a variable from an actor by actor_name variable_name and value
func setvar(arg := ""):
var split = arg.split(" ")
if split.size() > 2:
var _name = split[0]
var _var = split[1]
var _val = split[2]
for a in get_tree().get_nodes_in_group("actor"):
if a.name.to_lower() == _name.to_lower():
a.set(_var, str2var(_val))
out("(setvar) " + str(a.name) + "." + str(_var) + " = " + str(a.get(_var)))
return
out("(setvar) " + str(_name) + " not found")
else:
out("(setvar) '" + arg + "' invalid syntax. use 'setvar <name> <var> <val>'")
# get a variable from an actor by actor_name and variable_name
func getvar(arg := ""):
var split = arg.split(" ")
if split.size() > 1:
var _name = split[0]
var _var = split[1]
for a in get_tree().get_nodes_in_group("actor"):
if a.name.to_lower() == _name.to_lower():
out("(getvar) " + str(a.name) + "." + str(_var) + " = " + str(a.get(_var)))
return
out("(getvar) " + str(_name) + " not found")
else:
out("(getvar) '" + arg + "' invalid syntax. use 'getvar <name> <var>'")

View file

@ -267,8 +267,8 @@ func try_anim(arg : String):
node_anim.advance(0)
# spawn box
func debug_box():
func debug_box(arg = null):
var box = scene_box.instance()
box.position = Vector2(position.x, position.y - 8)
box.position = arg if arg is Vector2 else Vector2(position.x, position.y - 8)
get_parent().add_child(box)
dev.out("box spawned")
dev.out("(box) spawned at: " + str(box.position))

View file

@ -24,14 +24,14 @@ func _ready():
#OS.set_window_position(OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5)
func set_window_scale(arg := _window_scale):
_window_scale = arg
_window_scale = arg if arg else _window_scale
_window_scale = max(1, _window_scale)
OS.window_size = Vector2(320 * _window_scale, 180 * _window_scale)
# center window
OS.set_window_position(OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5)
#print("_window_scale: ", _window_scale, " - ", OS.get_window_size())
dev.out("_window_scale: " + str(_window_scale) + " - " + str(OS.get_window_size()))
return "_window_scale: " + str(_window_scale) + " - resolution: " + str(OS.get_window_size())
func _process(delta):
# reset timer
@ -44,10 +44,10 @@ func _process(delta):
#get_tree().reload_current_scene()
# window size
if Input.is_action_just_pressed("window_shrink"):
set_window_scale(_window_scale - 1)
elif Input.is_action_just_pressed("window_expand"):
set_window_scale(_window_scale + 1)
# if Input.is_action_just_pressed("window_shrink"):
# set_window_scale(_window_scale - 1)
# elif Input.is_action_just_pressed("window_expand"):
# set_window_scale(_window_scale + 1)
# quit
# if btn.p("ui_cancel"):