Skip to content

Commit a1fe589

Browse files
authored
🐛 do not use custom constructor for resource (#88)
1 parent f017ea6 commit a1fe589

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

addons/pandora/backend/entity_backend.gd

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func create_entity(name:String, category:PandoraCategory) -> PandoraEntity:
3939

4040
## Creates a new category on an optional parent category
4141
func create_category(name:String, parent_category:PandoraCategory = null) -> PandoraCategory:
42-
var category = PandoraCategory.new(_id_generator.generate(), name, "", "")
42+
var category = PandoraCategory.new()
43+
category.init_entity(_id_generator.generate(), name, "", "")
4344
if parent_category != null:
4445
parent_category._children.append(category)
4546
category._category_id = parent_category._id
@@ -226,7 +227,7 @@ func _deserialize_entities(data:Array) -> Dictionary:
226227
func _deserialize_categories(data:Array) -> Dictionary:
227228
var dict = {}
228229
for category_data in data:
229-
var category = PandoraCategory.new("", "", "", "")
230+
var category = PandoraCategory.new()
230231
category.load_data(category_data)
231232
dict[category._id] = category
232233
if category._category_id == "":
@@ -298,18 +299,25 @@ func _get_entity_class(path:String) -> GDScript:
298299

299300
func _create_entity_from_script(path:String, id:String, name:String, icon_path:String, category_id:String):
300301
var clazz = _get_entity_class(path)
301-
var new_method = _find_first_method_of_script(clazz, "_init")
302+
var new_method = _find_first_method_of_script(clazz, "init_entity")
302303
if not new_method.has("args"):
303304
push_error("ERROR - Pandora is unable to correctly resolve new() method.")
304-
return PandoraEntityScript.new(id, name, icon_path, category_id)
305-
var expected_method = _find_first_method_of_script(PandoraEntityScript, "_init")
305+
var entity = PandoraEntityScript.new()
306+
entity.init_entity(id, name, icon_path, category_id)
307+
return entity
308+
var expected_method = _find_first_method_of_script(PandoraEntityScript, "init_entity")
306309
if new_method["args"].size() != expected_method["args"].size():
307-
push_warning("_init() method has incorrect signature! Requires " + str(expected_method["args"].size()) + " arguments - defaulting to PandoraEntity instead.")
308-
return PandoraEntityScript.new(id, name, icon_path, category_id)
309-
var entity = clazz.new(id, name, icon_path, category_id)
310+
push_warning("init_entity() method has incorrect signature! Requires " + str(expected_method["args"].size()) + " arguments - defaulting to PandoraEntity instead.")
311+
var entity = PandoraEntityScript.new()
312+
entity.init_entity(id, name, icon_path, category_id)
313+
return entity
314+
315+
var entity = clazz.new()
310316
if not entity is PandoraEntity:
311317
push_warning("Script '" + path + "' must extend PandoraEntity - defaulting to PandoraEntity instead.")
312-
entity = PandoraEntityScript.new(id, name, icon_path, category_id)
318+
entity = PandoraEntityScript.new()
319+
320+
entity.init_entity(id, name, icon_path, category_id)
313321
return entity
314322

315323

addons/pandora/model/entity.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ var _generate_ids = false
138138
var _ids_generation_class = ""
139139

140140

141-
func _init(id:String, name:String, icon_path:String, category_id:String) -> void:
141+
## do not rely on _init as it breaks .tres files that may still
142+
## point to a migrated PandoraEntity custom script.
143+
func init_entity(id:String, name:String, icon_path:String, category_id:String) -> void:
142144
self._id = id
143145
self._name = name
144146
self._icon_path = icon_path

addons/pandora/model/entity_proxy.gd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ class_name PandoraEntityProxy extends PandoraEntity
1111

1212

1313
@export var proxied_entity_id:String
14-
15-
16-
func _init() -> void:
17-
super._init("", "", "", "")
1814

1915

2016
func instantiate() -> PandoraEntityInstance:

0 commit comments

Comments
 (0)