22extends Resource
33
44const Types = preload ("res://addons/block_code/types/types.gd" )
5+ const VariableDefinition = preload ("res://addons/block_code/code_generation/variable_definition.gd" )
56
67const FORMAT_STRING_PATTERN = "\\ [(?<out_parameter>[^\\ ]]+)\\ ]|\\ {const (?<const_parameter>[^}]+)\\ }|\\ {(?!const )(?<in_parameter>[^}]+)\\ }|(?<label>[^\\ {\\ []+)"
78const PROPERTY_SETTER_NAME_PATTERN = "(?<class_name>[^\\ s]*)_set_(?<property_name>[^\\ s]+)"
@@ -10,6 +11,8 @@ const PROPERTY_CHANGER_NAME_PATTERN = "(?<class_name>[^\\s]*)_change_(?<property
1011const PROPERTY_CHANGER_NAME_FORMAT = & "% s_change_% s"
1112const PROPERTY_GETTER_NAME_PATTERN = "(?<class_name>[^\\ s]*)_get_(?<property_name>[^\\ s]+)"
1213const PROPERTY_GETTER_NAME_FORMAT = & "% s_get_% s"
14+ const VARIABLE_SETTER_NAME_FORMAT = & "set_var_% s"
15+ const VARIABLE_GETTER_NAME_FORMAT = & "get_var_% s"
1316
1417@export var name : StringName
1518
@@ -260,3 +263,32 @@ static func new_property_getter(_class_name: String, property: Dictionary, categ
260263 )
261264 block_definition .property_name = property .name
262265 return block_definition
266+
267+
268+ static func new_variable_setter (variable : VariableDefinition ) -> Resource :
269+ var _type_string : String = Types .VARIANT_TYPE_TO_STRING [variable .var_type ]
270+ var block_definition : Resource = new (
271+ VARIABLE_SETTER_NAME_FORMAT % variable .var_name ,
272+ "" ,
273+ Engine .tr ("Set the %s variable" ) % variable .var_name ,
274+ "Variables" ,
275+ Types .BlockType .STATEMENT ,
276+ TYPE_NIL ,
277+ Engine .tr ("set %s to {value: %s} " ) % [variable .var_name , _type_string ],
278+ "%s = {value} " % variable .var_name ,
279+ )
280+ return block_definition
281+
282+
283+ static func new_variable_getter (variable : VariableDefinition ) -> Resource :
284+ var block_definition : Resource = new (
285+ VARIABLE_GETTER_NAME_FORMAT % variable .var_name ,
286+ "" ,
287+ Engine .tr ("The %s variable" ) % variable .var_name ,
288+ "Variables" ,
289+ Types .BlockType .VALUE ,
290+ variable .var_type ,
291+ "%s " % variable .var_name ,
292+ "%s " ,
293+ )
294+ return block_definition
0 commit comments