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)
|
||||||
|
|
|
@ -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]):
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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,7 +57,7 @@ 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
|
||||||
|
|
||||||
|
@ -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