Added some more security to the runtime

This commit is contained in:
Bram Dingelstad 2021-12-06 22:24:06 +01:00
parent 588a0bcbec
commit c1bcd24694
6 changed files with 77 additions and 18 deletions

View file

@ -25,7 +25,7 @@ func parse_node():
return WolNode.new('Start', null, self)
func next_symbol_is(valid_types):
compiler.assert(tokens.size() != 0, 'Ran out of tokens!')
compiler.assert(tokens.size() != 0, 'Ran out of tokens looking for next symbol!')
return tokens.front() and tokens.front().type in valid_types
# NOTE: 0 look ahead for `<<` and `else`
@ -37,8 +37,12 @@ func next_symbols_are(valid_types):
return true
func expect_symbol(token_types = []):
compiler.assert(tokens.size() != 0, 'Ran out of tokens expecting next symbol!')
var token = tokens.pop_front() as Lexer.Token
if tokens.size() == 0:
return token
if token_types.size() == 0:
if token.type == Constants.TokenType.EndOfInput:
compiler.assert(false, 'Unexpected end of input')

View file

@ -21,9 +21,11 @@ func open_node(graph_node, node):
$Content.add_child(text_edit)
toggle_text_edit(text_edit)
show()
$HBoxContainer/TextEdit.disconnect('text_changed', self, '_on_title_changed')
$HBoxContainer/TextEdit.text = node.title
$HBoxContainer/TextEdit.connect('text_changed', self, '_on_title_changed')
# window_title = node.title
show()
func toggle_text_edit(text_edit):
text_edit.anchor_left = 0
@ -48,6 +50,10 @@ func toggle_text_edit(text_edit):
]:
text_edit.set(property, not text_edit.get(property))
func _on_title_changed():
current_graph_node.node.title = $HBoxContainer/TextEdit.text
current_graph_node.compile()
func _on_visibility_changed():
if not visible:
var text_edit = $Content/TextEdit

View file

@ -6,16 +6,46 @@ onready var GraphNodeTemplate = $GraphNodeTemplate
var path
var refreshed = false
var selected_node
onready var original_delete_node_dialog = $DeleteNodeDialog.dialog_text
func _ready():
for menu_button in [$Menu/File]:
menu_button.get_popup().connect('index_pressed', self, '_on_menu_pressed', [menu_button.get_popup()])
$GraphEdit.connect('gui_input', self, '_on_graph_edit_input')
$GraphEdit.connect('node_selected', self, '_on_node_selected', [true])
$GraphEdit.connect('node_unselected', self, '_on_node_selected', [false])
$DeleteNodeDialog.connect('confirmed', self, 'delete_node')
# TODO: Conditionally load in theme based on Editor or standalone
path = 'res://dialogue.wol'
build_nodes()
func create_node(position = Vector2.ZERO):
print('creating node!')
var graph_node = GraphNodeTemplate.duplicate()
$GraphEdit.add_child(graph_node)
var node = {
'title': 'NewNode',
'body': 'Wol: Hello world',
'position': position
}
graph_node.connect('recompiled', self, '_on_graph_node_recompiled', [graph_node])
graph_node.connect('gui_input', self, '_on_graph_node_input', [graph_node, node])
graph_node.node = node
graph_node.show()
func delete_node(node = selected_node):
$GraphEdit.remove_child(node)
node.queue_free()
func build_nodes():
for node in Compiler.new(path).get_nodes():
var graph_node = GraphNodeTemplate.duplicate()
@ -128,3 +158,22 @@ func _on_graph_node_input(event, graph_node, node):
and event.doubleclick and event.button_index == BUTTON_LEFT:
$HBoxContainer/Editor.open_node(graph_node, node)
accept_event()
func _on_node_selected(node, selected):
if not selected:
selected_node = null
else:
selected_node = node
func _on_graph_edit_input(event):
if event is InputEventMouseButton \
and event.doubleclick and event.button_index == BUTTON_LEFT:
create_node(event.global_position + $GraphEdit.scroll_offset)
func _input(event):
if event is InputEventKey \
and not event.pressed and event.scancode == KEY_DELETE \
and selected_node:
$DeleteNodeDialog.dialog_text = original_delete_node_dialog % selected_node.name
$DeleteNodeDialog.popup()

BIN
addons/Wol/editor/WolEditor.tscn (Stored with Git LFS)

Binary file not shown.

View file

@ -80,7 +80,7 @@ func set_node(_node):
compile()
func compile():
var text = '---\n%s\n===' % text_edit.text
var text = 'title: %s\n---\n%s\n===' % [node.title, text_edit.text]
compiler = Compiler.new(null, text, true)
compiler.connect('error', self, '_on_error')
program = compiler.compile()

View file

@ -28,18 +28,6 @@ Guy: WHY ARE YOU BUYING CLOTHES AT THE SOUP STORE?!
You: FUCK YOU!
[[Go home|Start]]
===
title: Talk
tags:
colorID:
position: 800, 400
---
Narrator: So how are you really?
You: I'm good!
Narrator: Do you want to continue talking?
-> Yes
[[Start]]
-> No
===
title: Start
tags:
colorID:
@ -67,4 +55,16 @@ Narrator: You wanna go somewhere?
[[Start]]
-> Lets stay here and talk
[[Talk]]
===
title: Talk
tags:
colorID:
position: 800, 400
---
Narrator: So how are you really?
You: I'm good!
Narrator: Do you want to continue talking?
-> Yes
[[Start]]
-> No
===