@@ -32,6 +32,9 @@ const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{const (?<const
3232## [codeblock]
3333## say {salute: STRING} | {fancy: BOOL}
3434## [/codeblock]
35+ ## If [member property_name] is set, this template is assumed to be a format
36+ ## string with a `%s` placeholder; in this case, any literal `%` signs must
37+ ## be escaped as `%%`.
3538@export var display_template : String
3639
3740## Template for the generated GDScript code. This must be valid GDScript. The
@@ -67,6 +70,10 @@ const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{const (?<const
6770## Empty except for blocks that have a defined scope.
6871var scope : String
6972
73+ ## Optional property name, for localizing it. Only relevant for property setters, changers and
74+ ## getters.
75+ var property_name : String
76+
7077static var _display_template_regex := RegEx .create_from_string (FORMAT_STRING_PATTERN )
7178
7279
@@ -198,42 +205,48 @@ static func has_category(block_definition, category: String) -> bool:
198205
199206static func new_property_setter (_class_name : String , property : Dictionary , category : String , default_value : Variant ) -> Resource :
200207 var type_string : String = Types .VARIANT_TYPE_TO_STRING [property .type ]
201- return new (
208+ var block_definition : Resource = new (
202209 & "% s_set_% s" % [_class_name , property .name ],
203210 _class_name ,
204211 "Set the %s property" % property .name ,
205212 category ,
206213 Types .BlockType .STATEMENT ,
207214 TYPE_NIL ,
208- "set %s to {value: %s} " % [ property . name . capitalize (). to_lower (), type_string ] ,
215+ "set %% s to {value: %s} " % type_string ,
209216 "%s = {value} " % property .name ,
210217 {"value" : default_value },
211218 )
219+ block_definition .property_name = property .name
220+ return block_definition
212221
213222
214223static func new_property_changer (_class_name : String , property : Dictionary , category : String , default_value : Variant ) -> Resource :
215224 var type_string : String = Types .VARIANT_TYPE_TO_STRING [property .type ]
216- return new (
225+ var block_definition : Resource = new (
217226 & "% s_change_% s" % [_class_name , property .name ],
218227 _class_name ,
219228 "Change the %s property" % property .name ,
220229 category ,
221230 Types .BlockType .STATEMENT ,
222231 TYPE_NIL ,
223- "change %s by {value: %s} " % [ property . name . capitalize (). to_lower (), type_string ] ,
232+ "change %% s by {value: %s} " % type_string ,
224233 "%s += {value} " % property .name ,
225234 {"value" : default_value },
226235 )
236+ block_definition .property_name = property .name
237+ return block_definition
227238
228239
229240static func new_property_getter (_class_name : String , property : Dictionary , category : String ) -> Resource :
230- return new (
241+ var block_definition : Resource = new (
231242 & "% s_get_% s" % [_class_name , property .name ],
232243 _class_name ,
233244 "The %s property" % property .name ,
234245 category ,
235246 Types .BlockType .VALUE ,
236247 property .type ,
237- "%s " % property . name . capitalize (). to_lower () ,
248+ "%s " ,
238249 "%s " % property .name ,
239250 )
251+ block_definition .property_name = property .name
252+ return block_definition
0 commit comments