Finished debug/cheat console

This commit is contained in:
Tony Bark 2021-05-20 21:25:41 -04:00
parent 59ea5dd6f0
commit f6438a9bee
7 changed files with 95 additions and 16 deletions

View file

@ -1,7 +1,6 @@
[gd_scene format=2]
[node name="Credits" type="WindowDialog"]
visible = true
anchor_left = 0.394043
anchor_top = 0.293333
anchor_right = 0.605957

View file

@ -1,8 +1,10 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://scripts/debug_console.gd" type="Script" id=1]
[ext_resource path="res://scripts/command_handler.gd" type="Script" id=2]
[node name="DebugConsole" type="Control"]
pause_mode = 2
anchor_right = 1.0
margin_bottom = 113.0
script = ExtResource( 1 )
@ -10,6 +12,9 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="CommandHandler" type="Node" parent="."]
script = ExtResource( 2 )
[node name="Output" type="TextEdit" parent="."]
anchor_right = 1.0
anchor_bottom = 0.752212
@ -28,3 +33,5 @@ caret_blink_speed = 0.5
__meta__ = {
"_edit_use_anchors_": true
}
[connection signal="text_entered" from="Input" to="." method="_on_Input_text_entered"]

View file

@ -43,9 +43,9 @@ autostart = true
[node name="Controls" type="CanvasLayer" parent="."]
[node name="Core" type="Control" parent="Controls"]
anchor_left = -0.000731155
anchor_left = -0.00137095
anchor_top = -0.000954026
anchor_right = 0.999269
anchor_right = 0.998629
anchor_bottom = 0.999044
margin_left = -0.172424
margin_top = 2.77234
@ -68,9 +68,10 @@ avatar = ExtResource( 30 )
[node name="StatusPanel" type="Panel" parent="Controls/Core"]
anchor_left = 0.52832
anchor_top = 0.830002
anchor_top = 0.836668
anchor_right = 0.640625
anchor_bottom = 1.0
anchor_bottom = 1.01
margin_bottom = -2.0
__meta__ = {
"_edit_use_anchors_": true
}
@ -78,15 +79,17 @@ __meta__ = {
[node name="StatusCtr" type="CenterContainer" parent="Controls/Core/StatusPanel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 1.65512
margin_bottom = 1.65512
__meta__ = {
"_edit_use_anchors_": false
}
[node name="InfoBox" type="VBoxContainer" parent="Controls/Core/StatusPanel/StatusCtr"]
margin_left = 24.0
margin_top = 26.0
margin_top = 25.0
margin_right = 90.0
margin_bottom = 76.0
margin_bottom = 75.0
alignment = 1
script = ExtResource( 3 )
__meta__ = {
@ -129,9 +132,9 @@ text = "0"
[node name="BuyPanel" type="Panel" parent="Controls/Core"]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
anchor_top = 1.00667
anchor_right = 1.00488
anchor_bottom = 1.00667
margin_left = -370.0
margin_top = -101.999
margin_right = -0.000244141
@ -145,6 +148,7 @@ anchor_left = 0.00144509
anchor_top = -0.0294118
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -2.38419e-07
__meta__ = {
"_edit_use_anchors_": true
}

View file

@ -4,9 +4,7 @@ onready var city_name = $CityNameLbl
onready var money = $Money/MoneyLbl
onready var year = $YearLbl
func _ready():
city_name.text = SimData.city_name
func _process(delta):
city_name.text = SimData.city_name
money.text = str(SimData.budget)
year.text = "Y" + str(SimData.year)

View file

@ -0,0 +1,20 @@
extends Node
enum {
ARG_INT,
ARG_STRING,
ARG_BOOL,
ARG_FLOAT
}
const valid_commands = [
["motherlode", [null],
["whereyoufrom", [ARG_STRING]]
]
]
func motherlode():
SimData.budget += 50000
func whereyoufrom(city_name):
SimData.city_name = city_name

View file

@ -2,6 +2,7 @@ extends Control
onready var debug_console = $Console
onready var advisor = $AdvsiorNotice
# onready var news_ticker = $TickerPanel/ScrollContainer
func _ready():
advisor.show()
@ -9,3 +10,4 @@ func _ready():
func _process(delta):
if Input.is_action_just_released("ui_cheats"):
debug_console.show()
get_tree().paused = true

View file

@ -2,13 +2,62 @@ extends Control
onready var input_box = $Input
onready var output_box = $Output
onready var command_handler = $CommandHandler
func _ready():
input_box.grab_focus()
func process_command(text: String):
var words = text.split(" ")
words = Array(words)
for i in range(words.count("")):
words.erase("")
if words.size() == 0:
return
var cmd_word = words.pop_front()
for cmd in command_handler.valid_commands:
if cmd[0] == cmd_word:
if words.size() != cmd[1].size():
output_text(str('Failure executing command "', cmd_word,
'", expected ', cmd[1].size(), ' parameters'))
return
for i in range(words.size()):
if not check_type(words[i], cmd[1][i]):
output_text(str('Failure executing command "', cmd_word, '", parameter ', (i + 1),
' ("', words[i], '") is of the wrong type'))
return
output_text(command_handler.callv(cmd_word, words))
return
output_text(str('Command: "', cmd_word, '" does not exist'))
func check_type(string: String, type):
if type == command_handler.ARG_INT:
return string.is_valid_integer()
if type == command_handler.ARG_FLOAT:
return string.is_valid_float()
if type == command_handler.ARG_STRING:
return true
if type == command_handler.ARG_BOOL:
return (string == "true" or string == "false")
return false
func output_text(text):
output_box.text = text + "\n"
output_box.text = str(output_box.text + "\n", text)
func _on_Input_text_entered(new_text):
input_box.clear()
output_text(new_text)
process_command(new_text)