removed variable storage and converted it to dict
This commit is contained in:
parent
f061873ec3
commit
bad1dcb372
|
@ -16,20 +16,19 @@ signal command(command)
|
||||||
signal started
|
signal started
|
||||||
signal finished
|
signal finished
|
||||||
|
|
||||||
|
export(String, FILE, '*.wol,*.yarn') var path setget set_path
|
||||||
|
export(String) var start_node = 'Start'
|
||||||
|
export(bool) var auto_start = false
|
||||||
|
export var auto_show_options = true
|
||||||
|
|
||||||
|
export(Dictionary) var variable_storage = {}
|
||||||
|
|
||||||
const Constants = preload('res://addons/Wol/core/Constants.gd')
|
const Constants = preload('res://addons/Wol/core/Constants.gd')
|
||||||
const WolCompiler = preload('res://addons/Wol/core/compiler/Compiler.gd')
|
const WolCompiler = preload('res://addons/Wol/core/compiler/Compiler.gd')
|
||||||
const WolLibrary = preload('res://addons/Wol/core/Library.gd')
|
const WolLibrary = preload('res://addons/Wol/core/Library.gd')
|
||||||
const VirtualMachine = preload('res://addons/Wol/core/VirtualMachine.gd')
|
const VirtualMachine = preload('res://addons/Wol/core/VirtualMachine.gd')
|
||||||
const StandardLibrary = preload('res://addons/Wol/core/StandardLibrary.gd')
|
const StandardLibrary = preload('res://addons/Wol/core/StandardLibrary.gd')
|
||||||
|
|
||||||
export(String, FILE, '*.wol,*.yarn') var path setget set_path
|
|
||||||
export(String) var start_node = 'Start'
|
|
||||||
export(bool) var auto_start = false
|
|
||||||
export(NodePath) var variable_storage_path
|
|
||||||
export var auto_show_options = true
|
|
||||||
|
|
||||||
onready var variable_storage = get_node(variable_storage_path)
|
|
||||||
|
|
||||||
var virtual_machine
|
var virtual_machine
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -42,12 +41,6 @@ func _ready():
|
||||||
|
|
||||||
set_path(path)
|
set_path(path)
|
||||||
|
|
||||||
if not variable_storage:
|
|
||||||
variable_storage = Node.new()
|
|
||||||
variable_storage.name = 'VariableStorage'
|
|
||||||
variable_storage.set_script(load('res://addons/Wol/core/variable_storage.gd'))
|
|
||||||
add_child(variable_storage)
|
|
||||||
|
|
||||||
if auto_start:
|
if auto_start:
|
||||||
start()
|
start()
|
||||||
|
|
||||||
|
|
|
@ -215,13 +215,14 @@ func run_instruction(instruction):
|
||||||
|
|
||||||
Constants.ByteCode.PushVariable:
|
Constants.ByteCode.PushVariable:
|
||||||
var name = instruction.operands[0].value
|
var name = instruction.operands[0].value
|
||||||
var loaded = dialogue.variable_storage.get_value(name)
|
var godot_value = dialogue.variable_storage[name]
|
||||||
state.push_value(loaded)
|
var value = Value.new(godot_value)
|
||||||
|
state.push_value(value)
|
||||||
|
|
||||||
Constants.ByteCode.StoreVariable:
|
Constants.ByteCode.StoreVariable:
|
||||||
var top = state.peek_value()
|
var value = state.peek_value()
|
||||||
var destination = instruction.operands[0].value
|
var name = instruction.operands[0].value.replace('$', '')
|
||||||
dialogue.variable_storage.set_value(destination, top)
|
dialogue.variable_storage[name] = value.value()
|
||||||
|
|
||||||
Constants.ByteCode.Stop:
|
Constants.ByteCode.Stop:
|
||||||
node_finished_handler.call_func(current_node.name)
|
node_finished_handler.call_func(current_node.name)
|
||||||
|
|
|
@ -246,9 +246,9 @@ class CustomCommand extends ParseNode:
|
||||||
func tree_string(indent_level):
|
func tree_string(indent_level):
|
||||||
match type:
|
match type:
|
||||||
Type.Expression:
|
Type.Expression:
|
||||||
return tab(indent_level,'Expression: %s'% expression.tree_string(indent_level+1))
|
return tab(indent_level, 'Expression: %s' % expression.tree_string(indent_level+1))
|
||||||
Type.ClientCommand:
|
Type.ClientCommand:
|
||||||
return tab(indent_level,'Command: %s' % client_command)
|
return tab(indent_level, 'Command: %s' % client_command)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
static func can_parse(parser):
|
static func can_parse(parser):
|
||||||
|
@ -273,12 +273,12 @@ class ShortcutOptionGroup extends ParseNode:
|
||||||
func tree_string(indent_level):
|
func tree_string(indent_level):
|
||||||
var info = []
|
var info = []
|
||||||
|
|
||||||
info.append(tab(indent_level,'Shortcut Option Group{'))
|
info.append(tab(indent_level, 'Shortcut Option Group{'))
|
||||||
|
|
||||||
for option in options:
|
for option in options:
|
||||||
info.append(option.tree_string(indent_level+1))
|
info.append(option.tree_string(indent_level+1))
|
||||||
|
|
||||||
info.append(tab(indent_level,'}'))
|
info.append(tab(indent_level, '}'))
|
||||||
|
|
||||||
return PoolStringArray(info).join('')
|
return PoolStringArray(info).join('')
|
||||||
|
|
||||||
|
@ -295,7 +295,6 @@ class ShortCutOption extends ParseNode:
|
||||||
label = parser.expect_symbol([Constants.TokenType.Text]).value
|
label = parser.expect_symbol([Constants.TokenType.Text]).value
|
||||||
|
|
||||||
# NOTE: Parse the conditional << if $x >> when it exists
|
# NOTE: Parse the conditional << if $x >> when it exists
|
||||||
|
|
||||||
var tags = []
|
var tags = []
|
||||||
while parser.next_symbols_are([Constants.TokenType.BeginCommand, Constants.TokenType.IfToken]) \
|
while parser.next_symbols_are([Constants.TokenType.BeginCommand, Constants.TokenType.IfToken]) \
|
||||||
or parser.next_symbol_is([Constants.TokenType.TagMarker]):
|
or parser.next_symbol_is([Constants.TokenType.TagMarker]):
|
||||||
|
@ -397,7 +396,7 @@ class OptionStatement extends ParseNode:
|
||||||
|
|
||||||
func tree_string(indent_level):
|
func tree_string(indent_level):
|
||||||
if label != null:
|
if label != null:
|
||||||
return tab(indent_level,'Option: %s -> %s' % [label, destination])
|
return tab(indent_level, 'Option: %s -> %s' % [label, destination])
|
||||||
else:
|
else:
|
||||||
return tab(indent_level, 'Option: -> %s' % destination)
|
return tab(indent_level, 'Option: -> %s' % destination)
|
||||||
|
|
||||||
|
@ -491,11 +490,11 @@ class IfStatement extends ParseNode:
|
||||||
|
|
||||||
for clause in clauses:
|
for clause in clauses:
|
||||||
if first:
|
if first:
|
||||||
info.append(tab(indent_level,'if:'))
|
info.append(tab(indent_level, 'if:'))
|
||||||
elif clause.expression!=null:
|
elif clause.expression!=null:
|
||||||
info.append(tab(indent_level,'Else If'))
|
info.append(tab(indent_level, 'Else If'))
|
||||||
else:
|
else:
|
||||||
info.append(tab(indent_level,'Else:'))
|
info.append(tab(indent_level, 'Else:'))
|
||||||
|
|
||||||
info.append(clause.tree_string(indent_level +1))
|
info.append(clause.tree_string(indent_level +1))
|
||||||
|
|
||||||
|
@ -562,10 +561,10 @@ class ExpressionNode extends ParseNode:
|
||||||
return value.tree_string(indent_level)
|
return value.tree_string(indent_level)
|
||||||
|
|
||||||
Constants.ExpressionType.FunctionCall:
|
Constants.ExpressionType.FunctionCall:
|
||||||
info.append(tab(indent_level,'Func[%s - parameters(%s)]:{'%[function, parameters.size()]))
|
info.append(tab(indent_level, 'Func[%s - parameters(%s)]:{'%[function, parameters.size()]))
|
||||||
for param in parameters:
|
for param in parameters:
|
||||||
info.append(param.tree_string(indent_level+1))
|
info.append(param.tree_string(indent_level+1))
|
||||||
info.append(tab(indent_level,'}'))
|
info.append(tab(indent_level, '}'))
|
||||||
|
|
||||||
return info.join('')
|
return info.join('')
|
||||||
|
|
||||||
|
@ -799,10 +798,10 @@ class Assignment extends ParseNode:
|
||||||
|
|
||||||
func tree_string(indent_level):
|
func tree_string(indent_level):
|
||||||
var info = []
|
var info = []
|
||||||
info.append(tab(indent_level,'set:'))
|
info.append(tab(indent_level, 'set:'))
|
||||||
info.append(tab(indent_level+1, destination))
|
info.append(tab(indent_level + 1, destination))
|
||||||
info.append(tab(indent_level+1, Constants.token_type_name(operation)))
|
info.append(tab(indent_level + 1, Constants.token_type_name(operation)))
|
||||||
info.append(value.tree_string(indent_level+1))
|
info.append(value.tree_string(indent_level + 1))
|
||||||
return info.join('')
|
return info.join('')
|
||||||
|
|
||||||
|
|
||||||
|
@ -892,7 +891,6 @@ class Operator extends ParseNode:
|
||||||
Constants.TokenType.Xor
|
Constants.TokenType.Xor
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class OperatorInfo:
|
class OperatorInfo:
|
||||||
var associativity
|
var associativity
|
||||||
var precedence = -1
|
var precedence = -1
|
||||||
|
@ -921,7 +919,7 @@ class Clause:
|
||||||
for statement in statements:
|
for statement in statements:
|
||||||
info.append(statement.tree_string(indent_level + 1))
|
info.append(statement.tree_string(indent_level + 1))
|
||||||
|
|
||||||
info.append(tab(indent_level,'}'))
|
info.append(tab(indent_level, '}'))
|
||||||
return PoolStringArray(info).join('')
|
return PoolStringArray(info).join('')
|
||||||
|
|
||||||
func tab(indent_level, input, newline = true):
|
func tab(indent_level, input, newline = true):
|
||||||
|
|
|
@ -14,10 +14,10 @@ var variable = ''
|
||||||
var boolean = false
|
var boolean = false
|
||||||
|
|
||||||
func _init(value = NANI):
|
func _init(value = NANI):
|
||||||
if typeof(value) == TYPE_OBJECT && value.get_script() == self.get_script():
|
if typeof(value) == TYPE_OBJECT and value.get_script() == get_script():
|
||||||
if value.type == Constants.ValueType.Variable:
|
if value.type == Constants.ValueType.Variable:
|
||||||
self.type = value.type
|
type = value.type
|
||||||
self.variable = value.variable
|
variable = value.variable
|
||||||
else:
|
else:
|
||||||
set_value(value)
|
set_value(value)
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ func as_number():
|
||||||
return .0
|
return .0
|
||||||
|
|
||||||
func set_value(value):
|
func set_value(value):
|
||||||
if value == null || (typeof(value) == TYPE_STRING && value == NANI):
|
if value == null or (typeof(value) == TYPE_STRING and value == NANI):
|
||||||
type = Constants.ValueType.Nullean
|
type = Constants.ValueType.Nullean
|
||||||
return
|
return
|
||||||
|
|
||||||
match typeof(value):
|
match typeof(value):
|
||||||
TYPE_INT,TYPE_REAL:
|
TYPE_INT, TYPE_REAL:
|
||||||
type = Constants.ValueType.Number
|
type = Constants.ValueType.Number
|
||||||
number = value
|
number = value
|
||||||
TYPE_STRING:
|
TYPE_STRING:
|
||||||
|
@ -72,76 +72,66 @@ func set_value(value):
|
||||||
type = Constants.ValueType.Boolean
|
type = Constants.ValueType.Boolean
|
||||||
boolean = value
|
boolean = value
|
||||||
|
|
||||||
#operations >>
|
|
||||||
|
|
||||||
#addition
|
|
||||||
func add(other):
|
func add(other):
|
||||||
if self.type == Constants.ValueType.Str || other.type == Constants.ValueType.Str:
|
if type == Constants.ValueType.Str or other.type == Constants.ValueType.Str:
|
||||||
return get_script().new('%s%s'%[self.value(),other.value()])
|
return get_script().new('%s%s'%[value(),other.value()])
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
return get_script().new(self.number + other.number)
|
return get_script().new(number + other.number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func equals(other)->bool:
|
func equals(other):
|
||||||
if other.get_script() != self.get_script():
|
if other.get_script() != get_script():
|
||||||
return false
|
return false
|
||||||
if other.value() != self.value():
|
if other.value() != value():
|
||||||
return false
|
return false
|
||||||
return true #refine this
|
# TODO: Add more equality cases
|
||||||
|
return true
|
||||||
|
|
||||||
#subtract
|
|
||||||
func sub(other):
|
func sub(other):
|
||||||
if self.type == Constants.ValueType.Str || other.type == Constants.ValueType.Str:
|
if type == Constants.ValueType.Str or other.type == Constants.ValueType.Str:
|
||||||
return get_script().new(str(value()).replace(str(other.value()),''))
|
return get_script().new(str(value()).replace(str(other.value()),''))
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
return get_script().new(self.number - other.number)
|
return get_script().new(number - other.number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
#multiply
|
|
||||||
func mult(other):
|
func mult(other):
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
return get_script().new(self.number * other.number)
|
return get_script().new(number * other.number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
#division
|
|
||||||
func div(other):
|
func div(other):
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
return get_script().new(self.number / other.number)
|
return get_script().new(number / other.number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
#modulus
|
|
||||||
func mod(other):
|
func mod(other):
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
return get_script().new(self.number % other.number)
|
return get_script().new(number % other.number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func negative():
|
func negative():
|
||||||
if self.type == Constants.ValueType.Number:
|
if type == Constants.ValueType.Number:
|
||||||
return get_script().new(-self.number)
|
return get_script().new(-number)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
#greater than other
|
func greater(other):
|
||||||
func greater(other)->bool:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
return number > other.number
|
||||||
return self.number > other.number
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
#less than other
|
func less(other):
|
||||||
func less(other)->bool:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
return number < other.number
|
||||||
return self.number < other.number
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
#greater than or equal to other
|
func geq(other):
|
||||||
func geq(other)->bool:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
return number > other.number or equals(other)
|
||||||
return self.number > other.number || self.equals(other)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
#lesser than or equal to other
|
func leq(other):
|
||||||
func leq(other)->bool:
|
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
return number < other.number or equals(other)
|
||||||
return self.number < other.number || self.equals(other)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func _to_string():
|
func _to_string():
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
extends Node
|
|
||||||
|
|
||||||
signal values_changed
|
|
||||||
|
|
||||||
const Value = preload("res://addons/Wol/core/Value.gd")
|
|
||||||
|
|
||||||
var variables = {}
|
|
||||||
|
|
||||||
func set_value(name, value):
|
|
||||||
print('SETTING VALUES %s: %s' % [name, value])
|
|
||||||
if !(value is Value):
|
|
||||||
variables[name] = Value.new(value)
|
|
||||||
else:
|
|
||||||
variables[name] = value
|
|
||||||
|
|
||||||
emit_signal('values_changed')
|
|
||||||
|
|
||||||
func get_value(name):
|
|
||||||
return variables.get(name)
|
|
||||||
|
|
||||||
func clear_values():
|
|
||||||
variables.clear()
|
|
||||||
emit_signal('values_changed')
|
|
Reference in a new issue