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 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 WolCompiler = preload('res://addons/Wol/core/compiler/Compiler.gd')
|
||||
const WolLibrary = preload('res://addons/Wol/core/Library.gd')
|
||||
const VirtualMachine = preload('res://addons/Wol/core/VirtualMachine.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
|
||||
|
||||
func _ready():
|
||||
|
@ -42,12 +41,6 @@ func _ready():
|
|||
|
||||
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:
|
||||
start()
|
||||
|
||||
|
|
|
@ -215,13 +215,14 @@ func run_instruction(instruction):
|
|||
|
||||
Constants.ByteCode.PushVariable:
|
||||
var name = instruction.operands[0].value
|
||||
var loaded = dialogue.variable_storage.get_value(name)
|
||||
state.push_value(loaded)
|
||||
var godot_value = dialogue.variable_storage[name]
|
||||
var value = Value.new(godot_value)
|
||||
state.push_value(value)
|
||||
|
||||
Constants.ByteCode.StoreVariable:
|
||||
var top = state.peek_value()
|
||||
var destination = instruction.operands[0].value
|
||||
dialogue.variable_storage.set_value(destination, top)
|
||||
var value = state.peek_value()
|
||||
var name = instruction.operands[0].value.replace('$', '')
|
||||
dialogue.variable_storage[name] = value.value()
|
||||
|
||||
Constants.ByteCode.Stop:
|
||||
node_finished_handler.call_func(current_node.name)
|
||||
|
|
|
@ -295,7 +295,6 @@ class ShortCutOption extends ParseNode:
|
|||
label = parser.expect_symbol([Constants.TokenType.Text]).value
|
||||
|
||||
# NOTE: Parse the conditional << if $x >> when it exists
|
||||
|
||||
var tags = []
|
||||
while parser.next_symbols_are([Constants.TokenType.BeginCommand, Constants.TokenType.IfToken]) \
|
||||
or parser.next_symbol_is([Constants.TokenType.TagMarker]):
|
||||
|
@ -892,7 +891,6 @@ class Operator extends ParseNode:
|
|||
Constants.TokenType.Xor
|
||||
]
|
||||
|
||||
|
||||
class OperatorInfo:
|
||||
var associativity
|
||||
var precedence = -1
|
||||
|
|
|
@ -14,10 +14,10 @@ var variable = ''
|
|||
var boolean = false
|
||||
|
||||
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:
|
||||
self.type = value.type
|
||||
self.variable = value.variable
|
||||
type = value.type
|
||||
variable = value.variable
|
||||
else:
|
||||
set_value(value)
|
||||
|
||||
|
@ -57,7 +57,7 @@ func as_number():
|
|||
return .0
|
||||
|
||||
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
|
||||
return
|
||||
|
||||
|
@ -72,76 +72,66 @@ func set_value(value):
|
|||
type = Constants.ValueType.Boolean
|
||||
boolean = value
|
||||
|
||||
#operations >>
|
||||
|
||||
#addition
|
||||
func add(other):
|
||||
if self.type == Constants.ValueType.Str || other.type == Constants.ValueType.Str:
|
||||
return get_script().new('%s%s'%[self.value(),other.value()])
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return get_script().new(self.number + other.number)
|
||||
if type == Constants.ValueType.Str or other.type == Constants.ValueType.Str:
|
||||
return get_script().new('%s%s'%[value(),other.value()])
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return get_script().new(number + other.number)
|
||||
return null
|
||||
|
||||
func equals(other)->bool:
|
||||
if other.get_script() != self.get_script():
|
||||
func equals(other):
|
||||
if other.get_script() != get_script():
|
||||
return false
|
||||
if other.value() != self.value():
|
||||
if other.value() != value():
|
||||
return false
|
||||
return true #refine this
|
||||
# TODO: Add more equality cases
|
||||
return true
|
||||
|
||||
#subtract
|
||||
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()),''))
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return get_script().new(self.number - other.number)
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return get_script().new(number - other.number)
|
||||
return null
|
||||
|
||||
#multiply
|
||||
func mult(other):
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return get_script().new(self.number * other.number)
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return get_script().new(number * other.number)
|
||||
return null
|
||||
|
||||
#division
|
||||
func div(other):
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return get_script().new(self.number / other.number)
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return get_script().new(number / other.number)
|
||||
return null
|
||||
|
||||
#modulus
|
||||
func mod(other):
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return get_script().new(self.number % other.number)
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return get_script().new(number % other.number)
|
||||
return null
|
||||
|
||||
func negative():
|
||||
if self.type == Constants.ValueType.Number:
|
||||
return get_script().new(-self.number)
|
||||
if type == Constants.ValueType.Number:
|
||||
return get_script().new(-number)
|
||||
return null
|
||||
|
||||
#greater than other
|
||||
func greater(other)->bool:
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return self.number > other.number
|
||||
func greater(other):
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return number > other.number
|
||||
return false
|
||||
|
||||
#less than other
|
||||
func less(other)->bool:
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return self.number < other.number
|
||||
func less(other):
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return number < other.number
|
||||
return false
|
||||
|
||||
#greater than or equal to other
|
||||
func geq(other)->bool:
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return self.number > other.number || self.equals(other)
|
||||
func geq(other):
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return number > other.number or equals(other)
|
||||
return false
|
||||
|
||||
#lesser than or equal to other
|
||||
func leq(other)->bool:
|
||||
if self.type == Constants.ValueType.Number && other.type == Constants.ValueType.Number:
|
||||
return self.number < other.number || self.equals(other)
|
||||
func leq(other):
|
||||
if type == Constants.ValueType.Number and other.type == Constants.ValueType.Number:
|
||||
return number < other.number or equals(other)
|
||||
return false
|
||||
|
||||
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