Skip to content

Commit

Permalink
Fix boolean condition not saving the bool state (#2015)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner authored Jan 12, 2024
1 parent 812bf10 commit 6c039ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion addons/dialogic/Editor/Events/Fields/field_bool_check.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func _load_display_info(info:Dictionary) -> void:
func _set_value(value:Variant) -> void:
match DialogicUtil.get_variable_value_type(value):
DialogicUtil.VarTypes.STRING:
self.button_pressed = value and not value == "false"
self.button_pressed = value and not value.strip_edges() == "false"
_:
self.button_pressed = value and true
#endregion
Expand Down
56 changes: 31 additions & 25 deletions addons/dialogic/Editor/Events/Fields/field_condition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extends DialogicVisualEditorField
var _current_value1 :Variant = ""
var _current_value2 :Variant = ""


#region MAIN METHODS
################################################################################

Expand All @@ -21,6 +20,7 @@ func _set_value(value:Variant) -> void:
load_simple_editor(value)



func _autofocus():
%Value1Variable.grab_focus()

Expand Down Expand Up @@ -63,6 +63,8 @@ func _ready() -> void:
%Value2Number.value_changed.connect(something_changed)
%Value1Text.value_changed.connect(something_changed)
%Value2Text.value_changed.connect(something_changed)
%Value1Bool.value_changed.connect(something_changed)
%Value2Bool.value_changed.connect(something_changed)

%ToggleComplex.icon = get_theme_icon("Enum", "EditorIcons")

Expand All @@ -77,7 +79,6 @@ func _ready() -> void:
]



func load_simple_editor(condition_string:String) -> void:
var data := complex2simple(condition_string)
%Value1Type.set_value(get_value_type(data[0], 2))
Expand Down Expand Up @@ -150,34 +151,41 @@ func trim_value(value:Variant, value_type:int) -> String:
match value_type:
0: return value.trim_prefix('"').trim_suffix('"').replace('\\"', '"')
2: return value.trim_prefix('{').trim_suffix('}')
3: return "true" if value else "false"
3:
if value == "true" or (value and (typeof(value) != TYPE_STRING or value != "false")):
return "true"
else:
return "false"
_: return value


func something_changed(fake_arg1=null, fake_arg2 = null):
if %ComplexEditor.visible:
value_changed.emit(property_name, %ComplexEditor.text)
return


match %Value1Type.current_value:
0: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value)
1: _current_value1 = str(%Value1Number.get_value())
2: _current_value1 = prep_value(%Value1Variable.current_value, %Value1Type.current_value)
3: _current_value1 = prep_value(%Value1Bool.button_pressed, %Value1Type.current_value)
_: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value)

match %Value2Type.current_value:
0: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value)
1: _current_value2 = str(%Value2Number.get_value())
2: _current_value2 = prep_value(%Value2Variable.current_value, %Value2Type.current_value)
3: _current_value2 = prep_value(%Value2Bool.button_pressed, %Value2Type.current_value)
_: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value)

if event_resource:
if not %Operator.text in ['==', '!='] and get_value_type(_current_value2, 0) in [0, 3]:
event_resource.ui_update_warning.emit("This operator doesn't work with strings and booleans.")
else:
event_resource.ui_update_warning.emit("")

else:
match %Value1Type.current_value:
0: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value)
1: _current_value1 = str(%Value1Number.get_value())
2: _current_value1 = prep_value(%Value1Variable.current_value, %Value1Type.current_value)
_: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value)

match %Value2Type.current_value:
0: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value)
1: _current_value2 = str(%Value2Number.get_value())
2: _current_value2 = prep_value(%Value2Variable.current_value, %Value2Type.current_value)
_: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value)

if event_resource:
if not %Operator.text in ['==', '!='] and get_value_type(_current_value2, 0) in [0, 3]:
event_resource.ui_update_warning.emit("This operator doesn't work with strings and booleans.")
else:
event_resource.ui_update_warning.emit("")

value_changed.emit(property_name, get_simple_condition())
value_changed.emit(property_name, get_simple_condition())


func is_too_complex(condition:String) -> bool:
Expand Down Expand Up @@ -237,7 +245,6 @@ func get_variable_suggestions(filter:String) -> Dictionary:

func _on_value_1_variable_value_changed(property_name: Variant, value: Variant) -> void:
var type := DialogicUtil.get_variable_type(value)
print(get_value_type(_current_value2, -1))
match type:
DialogicUtil.VarTypes.BOOL:
if not %Operator.text in ["==", "!="]:
Expand All @@ -252,7 +259,6 @@ func _on_value_1_variable_value_changed(property_name: Variant, value: Variant)
%Value2Type.insert_options()
%Value2Type.index_pressed(0)
DialogicUtil.VarTypes.FLOAT, DialogicUtil.VarTypes.INT:
print("lol")
if get_value_type(_current_value2, 1) in [0,3]:
%Value2Type.insert_options()
%Value2Type.index_pressed(1)
Expand Down

0 comments on commit 6c039ee

Please sign in to comment.