From 39ceaea3da13ec7e21029f8d810318d293b25b23 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Sat, 14 Dec 2024 08:19:53 +0100 Subject: [PATCH 1/5] Create dimensionfall mod --- Mods/Dimensionfall/modinfo.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Mods/Dimensionfall/modinfo.json diff --git a/Mods/Dimensionfall/modinfo.json b/Mods/Dimensionfall/modinfo.json new file mode 100644 index 00000000..48356ae7 --- /dev/null +++ b/Mods/Dimensionfall/modinfo.json @@ -0,0 +1,12 @@ +{ + "author": "Khaligufzel", + "dependencies": [], + "description": "This is the core content mod of the game. It provides the foundational systems and data required for other mods to function.", + "homepage": "https://github.com/Khaligufzel/Dimensionfall", + "id": "Dimensionfall", + "license": "GPL-3.0 License", + "name": "Dimensionfall", + "tags": [ + "Dimensionfall" + ] +} From ca28e01fbd2c26badedef369d0d212b88528bf82 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Sat, 14 Dec 2024 09:48:16 +0100 Subject: [PATCH 2/5] Duplicate map to mod --- Scenes/ContentManager/Scripts/content_list.gd | 34 ++++++++++++++++--- Scenes/ContentManager/content_list.tscn | 22 +++++++++--- Scripts/Gamedata/DItems.gd | 3 -- Scripts/Gamedata/DMaps.gd | 22 ++++++++---- 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/Scenes/ContentManager/Scripts/content_list.gd b/Scenes/ContentManager/Scripts/content_list.gd index 2e2d06d7..564780a5 100644 --- a/Scenes/ContentManager/Scripts/content_list.gd +++ b/Scenes/ContentManager/Scripts/content_list.gd @@ -10,6 +10,10 @@ extends Control @export var collapseButton: Button = null @export var pupup_ID: Popup = null @export var popup_textedit: TextEdit = null +@export var to_mod_h_box_container: HBoxContainer = null +@export var mod_option_button: OptionButton = null + + signal item_activated(type: DMod.ContentType, itemID: String, list: Control) var popupAction: String = "" var datainstance: RefCounted # One of the data classes like DMap, DTile, DMob and so on @@ -36,8 +40,22 @@ var is_collapsed: bool = false: save_collapse_state() - func _ready(): + # Populate mod_option_button with IDs from all mods + mod_option_button.clear() # Clear any existing entries + var all_mod_ids: Array = Gamedata.mods.get_all_mod_ids() # Get all mod IDs + for mymod_id in all_mod_ids: + mod_option_button.add_item(mymod_id) # Add each mod ID to the OptionButton + + # Set the selected value to the current `mod_id` + var selected_index = all_mod_ids.find(mod_id) # Find the index of the current mod_id + if selected_index != -1: + mod_option_button.select(selected_index) # Select the current mod_id in the OptionButton + else: + mod_id = all_mod_ids[0] if all_mod_ids.size() > 0 else "Core" # Default to the first mod or "Core" + mod_option_button.select(0) + + # Other existing setup for the contentItems drag forwarding contentItems.set_drag_forwarding(_create_drag_data, Callable(), Callable()) @@ -70,7 +88,8 @@ func add_item_to_data(id: String): func _on_add_button_button_up(): popupAction = "Add" popup_textedit.text = "" - pupup_ID.show() + to_mod_h_box_container.show() + mod_option_button.hide() # This function requires that an item from the list is selected # Once clicked, it will show pupup_ID to ask the user for a new ID @@ -84,6 +103,7 @@ func _on_duplicate_button_button_up(): return popupAction = "Duplicate" popup_textedit.text = selected_id + to_mod_h_box_container.show() pupup_ID.show() # Called after the user enters an ID into the popup textbox and presses OK @@ -92,10 +112,15 @@ func _on_ok_button_up(): var myText = popup_textedit.text if myText == "": return + if popupAction == "Add": datainstance.add_new(myText) - if popupAction == "Duplicate": - datainstance.duplicate_to_disk(get_selected_item_text(), myText) + elif popupAction == "Duplicate": + # Get the selected mod ID from the mod_option_button + var selected_mod_id = mod_option_button.get_item_text(mod_option_button.get_selected_id()) + # Pass the selected mod ID to the duplicate_to_disk function + datainstance.duplicate_to_disk(get_selected_item_text(), myText, selected_mod_id) + popupAction = "" # Check if the list is collapsed and expand it if true if is_collapsed: @@ -103,6 +128,7 @@ func _on_ok_button_up(): load_data() + # Called after the users presses cancel on the popup asking for an ID func _on_cancel_button_up(): pupup_ID.hide() diff --git a/Scenes/ContentManager/content_list.tscn b/Scenes/ContentManager/content_list.tscn index d22345a3..88dfcc70 100644 --- a/Scenes/ContentManager/content_list.tscn +++ b/Scenes/ContentManager/content_list.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://Scenes/ContentManager/Scripts/content_list.gd" id="1_ly1kh"] -[node name="ContentList" type="Control" node_paths=PackedStringArray("contentItems", "collapseButton", "pupup_ID", "popup_textedit")] +[node name="ContentList" type="Control" node_paths=PackedStringArray("contentItems", "collapseButton", "pupup_ID", "popup_textedit", "to_mod_h_box_container", "mod_option_button")] custom_minimum_size = Vector2(200, 30) layout_mode = 3 anchors_preset = 15 @@ -16,7 +16,9 @@ script = ExtResource("1_ly1kh") contentItems = NodePath("Content/ContentItems") collapseButton = NodePath("Content/HBoxContainer/CollapseButton") pupup_ID = NodePath("ID_Input") -popup_textedit = NodePath("ID_Input/VBoxContainer/TextEdit") +popup_textedit = NodePath("ID_Input/VBoxContainer/IdTextEdit") +to_mod_h_box_container = NodePath("ID_Input/VBoxContainer/ToModHBoxContainer") +mod_option_button = NodePath("ID_Input/VBoxContainer/ToModHBoxContainer/ModOptionButton") [node name="Content" type="VBoxContainer" parent="."] layout_mode = 1 @@ -68,7 +70,7 @@ fixed_icon_size = Vector2i(32, 32) [node name="ID_Input" type="Popup" parent="."] title = "Input ID" initial_position = 2 -size = Vector2i(200, 150) +size = Vector2i(200, 152) unresizable = false borderless = false @@ -81,16 +83,26 @@ grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -[node name="Label" type="Label" parent="ID_Input/VBoxContainer"] +[node name="IdLabel" type="Label" parent="ID_Input/VBoxContainer"] layout_mode = 2 text = "Input an ID" -[node name="TextEdit" type="TextEdit" parent="ID_Input/VBoxContainer"] +[node name="IdTextEdit" type="TextEdit" parent="ID_Input/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 placeholder_text = "ex: pistol_9mm" scroll_fit_content_height = true +[node name="ToModHBoxContainer" type="HBoxContainer" parent="ID_Input/VBoxContainer"] +layout_mode = 2 + +[node name="ModLabel" type="Label" parent="ID_Input/VBoxContainer/ToModHBoxContainer"] +layout_mode = 2 +text = "To mod:" + +[node name="ModOptionButton" type="OptionButton" parent="ID_Input/VBoxContainer/ToModHBoxContainer"] +layout_mode = 2 + [node name="HBoxContainer" type="HBoxContainer" parent="ID_Input/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 diff --git a/Scripts/Gamedata/DItems.gd b/Scripts/Gamedata/DItems.gd index a68da67e..35bf4f76 100644 --- a/Scripts/Gamedata/DItems.gd +++ b/Scripts/Gamedata/DItems.gd @@ -62,9 +62,6 @@ func get_all() -> Dictionary: func duplicate_to_disk(itemid: String, newitemid: String) -> void: var itemdata: Dictionary = by_id(itemid).get_data().duplicate(true) - # A duplicated item is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - itemdata.erase("references") itemdata.id = newitemid var newitem: DItem = DItem.new(itemdata, self) itemdict[newitemid] = newitem diff --git a/Scripts/Gamedata/DMaps.gd b/Scripts/Gamedata/DMaps.gd index 47a28809..647984d1 100644 --- a/Scripts/Gamedata/DMaps.gd +++ b/Scripts/Gamedata/DMaps.gd @@ -20,10 +20,11 @@ extends RefCounted var dataPath: String = "./Mods/Core/Maps/" var mapdict: Dictionary = {} var references: Dictionary = {} - +var mod_id: String = "Core" # Load references from references.json during initialization -func _init(mod_id: String): +func _init(new_mod_id: String): + mod_id = new_mod_id dataPath = "./Mods/" + mod_id + "/Maps/" load_references() load_maps_from_disk() @@ -54,21 +55,28 @@ func get_all() -> Dictionary: return mapdict -func duplicate_to_disk(mapid: String, newmapid: String) -> void: +func duplicate_to_disk(mapid: String, newmapid: String, new_mod_id: String) -> void: + if new_mod_id != mod_id: + var other_maps: DMaps = Gamedata.mods.by_id(new_mod_id).maps + var newmap: DMap = other_maps.add_new(newmapid) + var newdata: Dictionary = by_id(mapid).get_data().duplicate(true) + newmap.set_data(newdata) + newmap.save_data_to_disk() + return # Exit the function if the mod IDs don't match + + # Proceed with duplication if mod IDs are equal var newmap: DMap = DMap.new(newmapid, dataPath, self) var newdata: Dictionary = by_id(mapid).get_data().duplicate(true) - # A duplicated map is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - newdata.erase("references") newmap.set_data(newdata) newmap.save_data_to_disk() mapdict[newmapid] = newmap -func add_new(newid: String) -> void: +func add_new(newid: String) -> DMap: var newmap: DMap = DMap.new(newid, dataPath, self) newmap.save_data_to_disk() mapdict[newid] = newmap + return newmap func delete_by_id(mapid: String) -> void: From 3956ee2ddd21834263591e11eff9056d560f4499 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:14:58 +0100 Subject: [PATCH 3/5] Duplicate items and furniture to mod --- Scenes/ContentManager/Scripts/content_list.gd | 4 +-- Scripts/Gamedata/DFurniture.gd | 2 +- Scripts/Gamedata/DFurnitures.gd | 31 ++++++++++++------- Scripts/Gamedata/DItems.gd | 26 ++++++++++++---- Scripts/Gamedata/DTacticalmaps.gd | 24 ++++++++++++-- 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Scenes/ContentManager/Scripts/content_list.gd b/Scenes/ContentManager/Scripts/content_list.gd index 564780a5..cb6b1d56 100644 --- a/Scenes/ContentManager/Scripts/content_list.gd +++ b/Scenes/ContentManager/Scripts/content_list.gd @@ -88,8 +88,8 @@ func add_item_to_data(id: String): func _on_add_button_button_up(): popupAction = "Add" popup_textedit.text = "" - to_mod_h_box_container.show() - mod_option_button.hide() + to_mod_h_box_container.hide() + pupup_ID.show() # This function requires that an item from the list is selected # Once clicked, it will show pupup_ID to ask the user for a new ID diff --git a/Scripts/Gamedata/DFurniture.gd b/Scripts/Gamedata/DFurniture.gd index 82041c17..820eeb2a 100644 --- a/Scripts/Gamedata/DFurniture.gd +++ b/Scripts/Gamedata/DFurniture.gd @@ -256,7 +256,7 @@ func on_data_changed(olddfurniture: DFurniture): func delete(): Gamedata.mods.remove_reference(DMod.ContentType.ITEMGROUPS, function.container_group, DMod.ContentType.FURNITURES, id) Gamedata.mods.remove_reference(DMod.ContentType.ITEMGROUPS, destruction.group, DMod.ContentType.FURNITURES, id) - Gamedata.mods.remove_reference(DMod.ContentType.ITEMGROUPS, disassembly.container_group, DMod.ContentType.FURNITURES, id) + Gamedata.mods.remove_reference(DMod.ContentType.ITEMGROUPS, disassembly.group, DMod.ContentType.FURNITURES, id) # Get a list of all maps that reference this mob var myreferences: Dictionary = parent.references.get(id, {}) diff --git a/Scripts/Gamedata/DFurnitures.gd b/Scripts/Gamedata/DFurnitures.gd index 7ad7d7ca..a34fd7bb 100644 --- a/Scripts/Gamedata/DFurnitures.gd +++ b/Scripts/Gamedata/DFurnitures.gd @@ -14,9 +14,11 @@ var sprites: Dictionary = {} var shader_materials: Dictionary = {} # Cache for shader materials by furniture ID var shape_materials: Dictionary = {} # Cache for shape materials by furniture ID var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Furniture/" filePath = "./Mods/" + mod_id + "/Furniture/Furniture.json" @@ -39,7 +41,7 @@ func load_furnitures_from_disk() -> void: var furniturelist: Array = Helper.json_helper.load_json_array_file(filePath) for furnitureitem in furniturelist: var furniture: DFurniture = DFurniture.new(furnitureitem, self) - if furniture.spriteid: + if furniture.spriteid and sprites.has(furniture.spriteid): furniture.sprite = sprites[furniture.spriteid] furnituredict[furniture.id] = furniture @@ -69,19 +71,26 @@ func get_all() -> Dictionary: return furnituredict -func duplicate_to_disk(furnitureid: String, newfurnitureid: String) -> void: +# Duplicate the furniture to disk. A new mod id may be provided to save the duplicate to +# furnitureid: The furniture to duplicate +# newfurnitureid: The id of the new duplicate (can be the same as furnitureid if new_mod_id equals mod_id) +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id +func duplicate_to_disk(furnitureid: String, newfurnitureid: String, new_mod_id: String) -> void: + # Duplicate the furniture data and set the new id var furnituredata: Dictionary = by_id(furnitureid).get_data().duplicate(true) - # A duplicated furniture is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - furnituredata.erase("references") furnituredata.id = newfurnitureid - var newfurniture: DFurniture = DFurniture.new(furnituredata, self) - furnituredict[newfurnitureid] = newfurniture - save_furnitures_to_disk() + # Determine the new parent based on the new_mod_id + var newparent: DFurnitures = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).furnitures + # Instantiate and append the new DFurniture instance + var newfurniture: DFurniture = DFurniture.new(furnituredata, newparent) + newparent.append_new(newfurniture) func add_new(newid: String) -> void: - var newfurniture: DFurniture = DFurniture.new({"id":newid}, self) + append_new(DFurniture.new({"id":newid}, self)) + + +func append_new(newfurniture: DFurniture) -> void: furnituredict[newfurniture.id] = newfurniture save_furnitures_to_disk() @@ -107,7 +116,7 @@ func sprite_by_id(furnitureid: String) -> Texture: # Returns the sprite of the furniture # furnitureid: The id of the furniture to return the sprite of func sprite_by_file(spritefile: String) -> Texture: - return sprites[spritefile] + return sprites[spritefile] if sprites.has(spritefile) else null func is_moveable(id: String) -> bool: diff --git a/Scripts/Gamedata/DItems.gd b/Scripts/Gamedata/DItems.gd index 35bf4f76..c20cc12d 100644 --- a/Scripts/Gamedata/DItems.gd +++ b/Scripts/Gamedata/DItems.gd @@ -12,9 +12,11 @@ var spritePath: String = "./Mods/Core/Items/" var itemdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Items/" filePath = "./Mods/" + mod_id + "/Items/Items.json" @@ -60,16 +62,28 @@ func get_all() -> Dictionary: return itemdict -func duplicate_to_disk(itemid: String, newitemid: String) -> void: +# Duplicate the item to disk. A new mod id may be provided to save the duplicate to. +# itemid: The item to duplicate. +# newitemid: The id of the new duplicate (can be the same as itemid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(itemid: String, newitemid: String, new_mod_id: String) -> void: + # Duplicate the item data and set the new id var itemdata: Dictionary = by_id(itemid).get_data().duplicate(true) itemdata.id = newitemid - var newitem: DItem = DItem.new(itemdata, self) - itemdict[newitemid] = newitem - save_items_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DItems = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).items + + # Instantiate and append the new DItem instance + var newitem: DItem = DItem.new(itemdata, newparent) + newparent.append_new(newitem) func add_new(newid: String) -> void: - var newitem: DItem = DItem.new({"id":newid}, self) + append_new(DItem.new({"id":newid}, self)) + + +func append_new(newitem: DItem) -> void: itemdict[newitem.id] = newitem save_items_to_disk() diff --git a/Scripts/Gamedata/DTacticalmaps.gd b/Scripts/Gamedata/DTacticalmaps.gd index 84573371..d27f54ec 100644 --- a/Scripts/Gamedata/DTacticalmaps.gd +++ b/Scripts/Gamedata/DTacticalmaps.gd @@ -7,8 +7,10 @@ extends RefCounted var dataPath: String = "./Mods/Core/TacticalMaps/" var mapdict: Dictionary = {} +var mod_id: String = "Core" -func _init(mod_id: String): +func _init(new_mod_id: String): + mod_id = new_mod_id # Update dataPath using the provided mod_id dataPath = "./Mods/" + mod_id + "/TacticalMaps/" load_maps_from_disk() @@ -25,16 +27,32 @@ func load_maps_from_disk() -> void: func get_all() -> Dictionary: return mapdict -func duplicate_to_disk(mapid: String, newmapid: String) -> void: +func duplicate_to_disk(mapid: String, newmapid: String, new_mod_id: String) -> void: + if new_mod_id != mod_id: + # Access the DTacticalmaps instance for the target mod + var other_maps: DTacticalmaps = Gamedata.mods.by_id(new_mod_id).tacticalmaps + + # Add a new tacticalmap to the target mod + var newmap: DTacticalmap = other_maps.add_new(newmapid) + + # Duplicate the data from the current map and set it in the new map + var newdata: Dictionary = mapdict[mapid].get_data().duplicate(true) + newmap.set_data(newdata) + newmap.save_data_to_disk() + return # Exit if mod IDs don't match + + # Proceed with duplication if mod IDs are equal var newmap: DTacticalmap = DTacticalmap.new(newmapid, dataPath, self) newmap.set_data(mapdict[mapid].get_data().duplicate(true)) newmap.save_data_to_disk() mapdict[newmapid] = newmap -func add_new(newid: String) -> void: + +func add_new(newid: String) -> DTacticalmap: var newmap: DTacticalmap = DTacticalmap.new(newid, dataPath, self) newmap.save_data_to_disk() mapdict[newid] = newmap + return newmap func delete_by_id(mapid: String) -> void: mapdict[mapid].delete() From 03e32f5014157a2ce1747af003ee9b07a8e65d55 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:35:22 +0100 Subject: [PATCH 4/5] Add mod id --- Scripts/Gamedata/DItemgroups.gd | 4 +++- Scripts/Gamedata/DMobfactions.gd | 4 +++- Scripts/Gamedata/DMobgroups.gd | 4 +++- Scripts/Gamedata/DMobs.gd | 4 +++- Scripts/Gamedata/DOvermapareas.gd | 4 +++- Scripts/Gamedata/DPlayerAttributes.gd | 4 +++- Scripts/Gamedata/DQuests.gd | 4 +++- Scripts/Gamedata/DSkills.gd | 4 +++- Scripts/Gamedata/DStats.gd | 4 +++- Scripts/Gamedata/DTiles.gd | 4 +++- Scripts/Gamedata/DWearableSlots.gd | 4 +++- 11 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Scripts/Gamedata/DItemgroups.gd b/Scripts/Gamedata/DItemgroups.gd index 5f0f384d..4041e2ab 100644 --- a/Scripts/Gamedata/DItemgroups.gd +++ b/Scripts/Gamedata/DItemgroups.gd @@ -12,9 +12,11 @@ var spritePath: String = "./Mods/Core/Items/" var itemgroupdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Itemgroups/" filePath = "./Mods/" + mod_id + "/Itemgroups/Itemgroups.json" diff --git a/Scripts/Gamedata/DMobfactions.gd b/Scripts/Gamedata/DMobfactions.gd index 259c12a1..766445df 100644 --- a/Scripts/Gamedata/DMobfactions.gd +++ b/Scripts/Gamedata/DMobfactions.gd @@ -11,9 +11,11 @@ var spritePath: String = "./Mods/Core/Items/" var mobfactiondict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Mobfaction/" filePath = "./Mods/" + mod_id + "/Mobfaction/Mobfactions.json" diff --git a/Scripts/Gamedata/DMobgroups.gd b/Scripts/Gamedata/DMobgroups.gd index 9ace5eee..164fb428 100644 --- a/Scripts/Gamedata/DMobgroups.gd +++ b/Scripts/Gamedata/DMobgroups.gd @@ -11,9 +11,11 @@ var spritePath: String = "./Mods/Core/Mobs/" var mobgroupdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Mobgroups/" filePath = "./Mods/" + mod_id + "/Mobgroups/Mobgroups.json" diff --git a/Scripts/Gamedata/DMobs.gd b/Scripts/Gamedata/DMobs.gd index 76d14ff4..5ee0d778 100644 --- a/Scripts/Gamedata/DMobs.gd +++ b/Scripts/Gamedata/DMobs.gd @@ -12,9 +12,11 @@ var spritePath: String = "./Mods/Core/Mobs/" var mobdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Mobs/" filePath = "./Mods/" + mod_id + "/Mobs/Mobs.json" diff --git a/Scripts/Gamedata/DOvermapareas.gd b/Scripts/Gamedata/DOvermapareas.gd index 8315d9f2..75dea5b3 100644 --- a/Scripts/Gamedata/DOvermapareas.gd +++ b/Scripts/Gamedata/DOvermapareas.gd @@ -10,9 +10,11 @@ var dataPath: String = "./Mods/Core/Overmapareas/" var filePath: String = "./Mods/Core/Overmapareas/Overmapareas.json" var overmapareadict: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Overmapareas/" filePath = "./Mods/" + mod_id + "/Overmapareas/Overmapareas.json" diff --git a/Scripts/Gamedata/DPlayerAttributes.gd b/Scripts/Gamedata/DPlayerAttributes.gd index e6b27f47..e0521d77 100644 --- a/Scripts/Gamedata/DPlayerAttributes.gd +++ b/Scripts/Gamedata/DPlayerAttributes.gd @@ -13,10 +13,12 @@ var playerattributedict: Dictionary = {} var sprites: Dictionary = {} var hardcoded: Array = ["player_inventory"] var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/PlayerAttributes/" filePath = "./Mods/" + mod_id + "/PlayerAttributes/PlayerAttributes.json" diff --git a/Scripts/Gamedata/DQuests.gd b/Scripts/Gamedata/DQuests.gd index 3da7a48a..30c58df3 100644 --- a/Scripts/Gamedata/DQuests.gd +++ b/Scripts/Gamedata/DQuests.gd @@ -12,10 +12,12 @@ var spritePath: String = "./Mods/Core/Items/" var questdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Quests/" filePath = "./Mods/" + mod_id + "/Quests/Quests.json" diff --git a/Scripts/Gamedata/DSkills.gd b/Scripts/Gamedata/DSkills.gd index 6bdcf5b3..3ea8c1a4 100644 --- a/Scripts/Gamedata/DSkills.gd +++ b/Scripts/Gamedata/DSkills.gd @@ -12,10 +12,12 @@ var spritePath: String = "./Mods/Core/Skills/" var skilldict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Skills/" filePath = "./Mods/" + mod_id + "/Skills/Skills.json" diff --git a/Scripts/Gamedata/DStats.gd b/Scripts/Gamedata/DStats.gd index 3febe268..d613e75e 100644 --- a/Scripts/Gamedata/DStats.gd +++ b/Scripts/Gamedata/DStats.gd @@ -10,9 +10,11 @@ var dataPath: String = "./Mods/Core/Stats/Stats.json" var spritePath: String = "./Mods/Core/Stats/" var statdict: Dictionary = {} var sprites: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Stats/Stats.json" spritePath = "./Mods/" + mod_id + "/Stats/" diff --git a/Scripts/Gamedata/DTiles.gd b/Scripts/Gamedata/DTiles.gd index 047cbffe..06d19d7b 100644 --- a/Scripts/Gamedata/DTiles.gd +++ b/Scripts/Gamedata/DTiles.gd @@ -12,10 +12,12 @@ var spritePath: String = "./Mods/Core/Tiles/" var tiledict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Tiles/" filePath = "./Mods/" + mod_id + "/Tiles/Tiles.json" diff --git a/Scripts/Gamedata/DWearableSlots.gd b/Scripts/Gamedata/DWearableSlots.gd index e4a08535..815c44aa 100644 --- a/Scripts/Gamedata/DWearableSlots.gd +++ b/Scripts/Gamedata/DWearableSlots.gd @@ -12,9 +12,11 @@ var spritePath: String = "./Mods/Core/Wearableslots/" var wearableslotdict: Dictionary = {} var sprites: Dictionary = {} var references: Dictionary = {} +var mod_id: String = "Core" # Add a mod_id parameter to dynamically initialize paths -func _init(mod_id: String) -> void: +func _init(new_mod_id: String) -> void: + mod_id = new_mod_id # Update dataPath and spritePath using the provided mod_id dataPath = "./Mods/" + mod_id + "/Wearableslots/" filePath = "./Mods/" + mod_id + "/Wearableslots/Wearableslots.json" From cdbb15956bf9986cacb54fdda00c55a0c8ab9dbf Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:29:54 +0100 Subject: [PATCH 5/5] Allow duplication to other mods --- Scripts/Gamedata/DItemgroups.gd | 27 ++++++++++++++------- Scripts/Gamedata/DMobfactions.gd | 30 ++++++++++++++++------- Scripts/Gamedata/DMobgroups.gd | 31 +++++++++++++++++------- Scripts/Gamedata/DMobs.gd | 28 +++++++++++++++------- Scripts/Gamedata/DOvermapareas.gd | 32 +++++++++++++++++-------- Scripts/Gamedata/DPlayerAttributes.gd | 28 +++++++++++++++------- Scripts/Gamedata/DQuests.gd | 30 ++++++++++++++++------- Scripts/Gamedata/DSkills.gd | 31 ++++++++++++++++-------- Scripts/Gamedata/DStats.gd | 34 ++++++++++++++++++--------- Scripts/Gamedata/DTiles.gd | 28 +++++++++++++++------- Scripts/Gamedata/DWearableSlots.gd | 28 +++++++++++++++------- 11 files changed, 229 insertions(+), 98 deletions(-) diff --git a/Scripts/Gamedata/DItemgroups.gd b/Scripts/Gamedata/DItemgroups.gd index 4041e2ab..57d0ecd8 100644 --- a/Scripts/Gamedata/DItemgroups.gd +++ b/Scripts/Gamedata/DItemgroups.gd @@ -70,19 +70,30 @@ func get_all() -> Dictionary: return itemgroupdict -func duplicate_to_disk(itemgroupid: String, newitemgroupid: String) -> void: +# Duplicate the itemgroup to disk. A new mod id may be provided to save the duplicate to. +# itemgroupid: The itemgroup to duplicate. +# newitemgroupid: The id of the new duplicate (can be the same as itemgroupid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(itemgroupid: String, newitemgroupid: String, new_mod_id: String) -> void: + # Duplicate the itemgroup data and set the new id var itemgroupdata: Dictionary = by_id(itemgroupid).get_data().duplicate(true) - # A duplicated itemgroup is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - itemgroupdata.erase("references") itemgroupdata.id = newitemgroupid - var newitemgroup: DItemgroup = DItemgroup.new(itemgroupdata, self) - itemgroupdict[newitemgroupid] = newitemgroup - save_itemgroups_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DItemgroups = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).itemgroups + + # Instantiate and append the new DItemgroup instance + var newitemgroup: DItemgroup = DItemgroup.new(itemgroupdata, newparent) + newparent.append_new(newitemgroup) +# Add a new itemgroup to the dictionary and save it to disk. func add_new(newid: String) -> void: - var newitemgroup: DItemgroup = DItemgroup.new({"id":newid}, self) + append_new(DItemgroup.new({"id": newid}, self)) + + +# Append a new itemgroup to the dictionary and save it to disk. +func append_new(newitemgroup: DItemgroup) -> void: itemgroupdict[newitemgroup.id] = newitemgroup save_itemgroups_to_disk() diff --git a/Scripts/Gamedata/DMobfactions.gd b/Scripts/Gamedata/DMobfactions.gd index 766445df..86f02976 100644 --- a/Scripts/Gamedata/DMobfactions.gd +++ b/Scripts/Gamedata/DMobfactions.gd @@ -67,22 +67,34 @@ func save_mobfactions_to_disk() -> void: func get_all() -> Dictionary: return mobfactiondict -func duplicate_to_disk(mobfactionid: String, newmobfactionid: String) -> void: +# Duplicate the mobfaction to disk. A new mod id may be provided to save the duplicate to. +# mobfactionid: The mobfaction to duplicate. +# newmobfactionid: The id of the new duplicate (can be the same as mobfactionid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(mobfactionid: String, newmobfactionid: String, new_mod_id: String) -> void: + # Duplicate the mobfaction data and set the new id var mobfactiondata: Dictionary = by_id(mobfactionid).get_data().duplicate(true) - # A duplicated mob faction is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - mobfactiondata.erase("references") mobfactiondata["id"] = newmobfactionid - var newmobfaction: DMobfaction = DMobfaction.new(mobfactiondata, self) - mobfactiondict[newmobfactionid] = newmobfaction - save_mobfactions_to_disk() -# Adds a new faction with a given ID + # Determine the new parent based on the new_mod_id + var newparent: DMobfactions = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).mobfactions + + # Instantiate and append the new DMobfaction instance + var newmobfaction: DMobfaction = DMobfaction.new(mobfactiondata, newparent) + newparent.append_new(newmobfaction) + + +# Add a new mobfaction with a given ID. func add_new(newid: String) -> void: - var newmobfaction: DMobfaction = DMobfaction.new({"id": newid}, self) + append_new(DMobfaction.new({"id": newid}, self)) + + +# Append a new mobfaction to the dictionary and save it to disk. +func append_new(newmobfaction: DMobfaction) -> void: mobfactiondict[newmobfaction.id] = newmobfaction save_mobfactions_to_disk() + # Deletes a faction by its ID and saves changes to disk func delete_by_id(mobfactionid: String) -> void: mobfactiondict[mobfactionid].delete() diff --git a/Scripts/Gamedata/DMobgroups.gd b/Scripts/Gamedata/DMobgroups.gd index 164fb428..f673ef9b 100644 --- a/Scripts/Gamedata/DMobgroups.gd +++ b/Scripts/Gamedata/DMobgroups.gd @@ -54,21 +54,34 @@ func save_mobgroups_to_disk() -> void: func get_all() -> Dictionary: return mobgroupdict -func duplicate_to_disk(mobgroupid: String, newmobgroupid: String) -> void: +# Duplicate the mobgroup to disk. A new mod id may be provided to save the duplicate to. +# mobgroupid: The mobgroup to duplicate. +# newmobgroupid: The id of the new duplicate (can be the same as mobgroupid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(mobgroupid: String, newmobgroupid: String, new_mod_id: String) -> void: + # Duplicate the mobgroup data and set the new id var mobgroupdata: Dictionary = by_id(mobgroupid).get_data().duplicate(true) - # A duplicated mob group is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - mobgroupdata.erase("references") - mobgroupdata.id = newmobgroupid - var newmobgroup: DMobgroup = DMobgroup.new(mobgroupdata, self) - mobgroupdict[newmobgroupid] = newmobgroup - save_mobgroups_to_disk() + mobgroupdata["id"] = newmobgroupid + + # Determine the new parent based on the new_mod_id + var newparent: DMobgroups = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).mobgroups + + # Instantiate and append the new DMobgroup instance + var newmobgroup: DMobgroup = DMobgroup.new(mobgroupdata, newparent) + newparent.append_new(newmobgroup) + +# Add a new mobgroup with a given ID. func add_new(newid: String) -> void: - var newmobgroup: DMobgroup = DMobgroup.new({"id": newid}, self) + append_new(DMobgroup.new({"id": newid}, self)) + + +# Append a new mobgroup to the dictionary and save it to disk. +func append_new(newmobgroup: DMobgroup) -> void: mobgroupdict[newmobgroup.id] = newmobgroup save_mobgroups_to_disk() + func delete_by_id(mobgroupid: String) -> void: mobgroupdict[mobgroupid].delete() mobgroupdict.erase(mobgroupid) diff --git a/Scripts/Gamedata/DMobs.gd b/Scripts/Gamedata/DMobs.gd index 5ee0d778..7032a221 100644 --- a/Scripts/Gamedata/DMobs.gd +++ b/Scripts/Gamedata/DMobs.gd @@ -71,23 +71,35 @@ func get_all() -> Dictionary: return mobdict -func duplicate_to_disk(mobid: String, newmobid: String) -> void: +# Duplicate the mob to disk. A new mod id may be provided to save the duplicate to. +# mobid: The mob to duplicate. +# newmobid: The id of the new duplicate (can be the same as mobid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(mobid: String, newmobid: String, new_mod_id: String) -> void: + # Duplicate the mob data and set the new id var mobdata: Dictionary = by_id(mobid).get_data().duplicate(true) - # A duplicated mob is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - mobdata.erase("references") mobdata.id = newmobid - var newmob: DMob = DMob.new(mobdata, self) - mobdict[newmobid] = newmob - save_mobs_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DMobs = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).mobs + + # Instantiate and append the new DMob instance + var newmob: DMob = DMob.new(mobdata, newparent) + newparent.append_new(newmob) +# Add a new mob to the dictionary and save it to disk. func add_new(newid: String) -> void: - var newmob: DMob = DMob.new({"id":newid}, self) + append_new(DMob.new({"id": newid}, self)) + + +# Append a new mob to the dictionary and save it to disk. +func append_new(newmob: DMob) -> void: mobdict[newmob.id] = newmob save_mobs_to_disk() + func delete_by_id(mobid: String) -> void: mobdict[mobid].delete() mobdict.erase(mobid) diff --git a/Scripts/Gamedata/DOvermapareas.gd b/Scripts/Gamedata/DOvermapareas.gd index 75dea5b3..d9cc716a 100644 --- a/Scripts/Gamedata/DOvermapareas.gd +++ b/Scripts/Gamedata/DOvermapareas.gd @@ -53,22 +53,34 @@ func get_all() -> Dictionary: return overmapareadict # Duplicates a overmaparea and saves it to disk with a new ID -func duplicate_to_disk(overmapareaid: String, newovermapareaid: String) -> void: +# Duplicate the overmaparea to disk. A new mod id may be provided to save the duplicate to. +# overmapareaid: The overmaparea to duplicate. +# newovermapareaid: The id of the new duplicate (can be the same as overmapareaid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(overmapareaid: String, newovermapareaid: String, new_mod_id: String) -> void: + # Duplicate the overmaparea data and set the new id var overmapareadata: Dictionary = by_id(overmapareaid).get_data().duplicate(true) - # A duplicated overmaparea is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - overmapareadata.erase("references") - overmapareadata.id = newovermapareaid - var newovermaparea: DOvermaparea = DOvermaparea.new(overmapareadata, self) - overmapareadict[newovermapareaid] = newovermaparea - save_overmapareas_to_disk() + overmapareadata["id"] = newovermapareaid + + # Determine the new parent based on the new_mod_id + var newparent: DOvermapareas = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).overmapareas + + # Instantiate and append the new DOvermaparea instance + var newovermaparea: DOvermaparea = DOvermaparea.new(overmapareadata, newparent) + newparent.append_new(newovermaparea) + -# Adds a new overmaparea with a given ID +# Add a new overmaparea with a given ID. func add_new(newid: String) -> void: - var newovermaparea: DOvermaparea = DOvermaparea.new({"id": newid}, self) + append_new(DOvermaparea.new({"id": newid}, self)) + + +# Append a new overmaparea to the dictionary and save it to disk. +func append_new(newovermaparea: DOvermaparea) -> void: overmapareadict[newovermaparea.id] = newovermaparea save_overmapareas_to_disk() + # Deletes a overmaparea by its ID and saves changes to disk func delete_by_id(overmapareaid: String) -> void: overmapareadict[overmapareaid].delete() diff --git a/Scripts/Gamedata/DPlayerAttributes.gd b/Scripts/Gamedata/DPlayerAttributes.gd index e0521d77..8ab04723 100644 --- a/Scripts/Gamedata/DPlayerAttributes.gd +++ b/Scripts/Gamedata/DPlayerAttributes.gd @@ -72,23 +72,35 @@ func get_all() -> Dictionary: return playerattributedict -func duplicate_to_disk(playerattributeid: String, newplayerattributeid: String) -> void: +# Duplicate the player attribute to disk. A new mod id may be provided to save the duplicate to. +# playerattributeid: The player attribute to duplicate. +# newplayerattributeid: The id of the new duplicate (can be the same as playerattributeid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(playerattributeid: String, newplayerattributeid: String, new_mod_id: String) -> void: + # Duplicate the player attribute data and set the new id var playerattributedata: Dictionary = by_id(playerattributeid).get_data().duplicate(true) - # A duplicated playerattribute is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - playerattributedata.erase("references") playerattributedata.id = newplayerattributeid - var newplayerattribute: DPlayerAttribute = DPlayerAttribute.new(playerattributedata, self) - playerattributedict[newplayerattributeid] = newplayerattribute - save_playerattributes_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DPlayerAttributes = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).playerattributes + + # Instantiate and append the new DPlayerAttribute instance + var newplayerattribute: DPlayerAttribute = DPlayerAttribute.new(playerattributedata, newparent) + newparent.append_new(newplayerattribute) +# Add a new player attribute to the dictionary and save it to disk. func add_new(newid: String) -> void: - var newplayerattribute: DPlayerAttribute = DPlayerAttribute.new({"id":newid}, self) + append_new(DPlayerAttribute.new({"id": newid}, self)) + + +# Append a new player attribute to the dictionary and save it to disk. +func append_new(newplayerattribute: DPlayerAttribute) -> void: playerattributedict[newplayerattribute.id] = newplayerattribute save_playerattributes_to_disk() + func delete_by_id(playerattributeid: String) -> void: playerattributedict[playerattributeid].delete() playerattributedict.erase(playerattributeid) diff --git a/Scripts/Gamedata/DQuests.gd b/Scripts/Gamedata/DQuests.gd index 30c58df3..a7288a33 100644 --- a/Scripts/Gamedata/DQuests.gd +++ b/Scripts/Gamedata/DQuests.gd @@ -61,22 +61,34 @@ func get_all() -> Dictionary: return questdict # Duplicates a quest and saves it to disk with a new ID -func duplicate_to_disk(questid: String, newquestid: String) -> void: +# Duplicate the quest to disk. A new mod id may be provided to save the duplicate to. +# questid: The quest to duplicate. +# newquestid: The id of the new duplicate (can be the same as questid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(questid: String, newquestid: String, new_mod_id: String) -> void: + # Duplicate the quest data and set the new id var questdata: Dictionary = by_id(questid).get_data().duplicate(true) - # A duplicated quest is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - questdata.erase("references") questdata["id"] = newquestid - var newquest: DQuest = DQuest.new(questdata, self) - questdict[newquestid] = newquest - save_quests_to_disk() -# Adds a new quest with a given ID + # Determine the new parent based on the new_mod_id + var newparent: DQuests = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).quests + + # Instantiate and append the new DQuest instance + var newquest: DQuest = DQuest.new(questdata, newparent) + newparent.append_new(newquest) + + +# Add a new quest with a given ID. func add_new(newid: String) -> void: - var newquest: DQuest = DQuest.new({"id": newid}, self) + append_new(DQuest.new({"id": newid}, self)) + + +# Append a new quest to the dictionary and save it to disk. +func append_new(newquest: DQuest) -> void: questdict[newquest.id] = newquest save_quests_to_disk() + # Deletes a quest by its ID and saves changes to disk func delete_by_id(questid: String) -> void: questdict[questid].delete() diff --git a/Scripts/Gamedata/DSkills.gd b/Scripts/Gamedata/DSkills.gd index 3ea8c1a4..8bfe25a5 100644 --- a/Scripts/Gamedata/DSkills.gd +++ b/Scripts/Gamedata/DSkills.gd @@ -71,23 +71,34 @@ func save_skills_to_disk() -> void: func get_all() -> Dictionary: return skilldict -# Duplicates a skill and saves it to disk with a new ID -func duplicate_to_disk(skillid: String, newskillid: String) -> void: +# Duplicate the skill to disk. A new mod id may be provided to save the duplicate to. +# skillid: The skill to duplicate. +# newskillid: The id of the new duplicate (can be the same as skillid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(skillid: String, newskillid: String, new_mod_id: String) -> void: + # Duplicate the skill data and set the new id var skilldata: Dictionary = by_id(skillid).get_data().duplicate(true) - # A duplicated quest is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - skilldata.erase("references") skilldata["id"] = newskillid - var newskill: DSkill = DSkill.new(skilldata, self) - skilldict[newskillid] = newskill - save_skills_to_disk() -# Adds a new skill with a given ID + # Determine the new parent based on the new_mod_id + var newparent: DSkills = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).skills + + # Instantiate and append the new DSkill instance + var newskill: DSkill = DSkill.new(skilldata, newparent) + newparent.append_new(newskill) + + +# Add a new skill with a given ID. func add_new(newid: String) -> void: - var newskill: DSkill = DSkill.new({"id": newid}, self) + append_new(DSkill.new({"id": newid}, self)) + + +# Append a new skill to the dictionary and save it to disk. +func append_new(newskill: DSkill) -> void: skilldict[newskill.id] = newskill save_skills_to_disk() + # Deletes a skill by its ID and saves changes to disk func delete_by_id(skillid: String) -> void: skilldict[skillid].delete() diff --git a/Scripts/Gamedata/DStats.gd b/Scripts/Gamedata/DStats.gd index d613e75e..16e24fe9 100644 --- a/Scripts/Gamedata/DStats.gd +++ b/Scripts/Gamedata/DStats.gd @@ -57,23 +57,35 @@ func save_stats_to_disk() -> void: func get_all() -> Dictionary: return statdict -# Duplicates a stat and saves it to disk with a new ID -func duplicate_to_disk(statid: String, newstatid: String) -> void: + +# Duplicate the stat to disk. A new mod id may be provided to save the duplicate to. +# statid: The stat to duplicate. +# newstatid: The id of the new duplicate (can be the same as statid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(statid: String, newstatid: String, new_mod_id: String) -> void: + # Duplicate the stat data and set the new id var statdata: Dictionary = by_id(statid).get_data().duplicate(true) - # A duplicated stat is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - statdata.erase("references") - statdata.id = newstatid - var newstat: DStat = DStat.new(statdata, self) - statdict[newstatid] = newstat - save_stats_to_disk() + statdata["id"] = newstatid + + # Determine the new parent based on the new_mod_id + var newparent: DStats = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).stats + + # Instantiate and append the new DStat instance + var newstat: DStat = DStat.new(statdata, newparent) + newparent.append_new(newstat) -# Adds a new stat with a given ID + +# Add a new stat with a given ID. func add_new(newid: String) -> void: - var newstat: DStat = DStat.new({"id": newid}, self) + append_new(DStat.new({"id": newid}, self)) + + +# Append a new stat to the dictionary and save it to disk. +func append_new(newstat: DStat) -> void: statdict[newstat.id] = newstat save_stats_to_disk() + # Deletes a stat by its ID and saves changes to disk func delete_by_id(statid: String) -> void: statdict[statid].delete() diff --git a/Scripts/Gamedata/DTiles.gd b/Scripts/Gamedata/DTiles.gd index 06d19d7b..765c8218 100644 --- a/Scripts/Gamedata/DTiles.gd +++ b/Scripts/Gamedata/DTiles.gd @@ -72,23 +72,35 @@ func get_all() -> Dictionary: return tiledict -func duplicate_to_disk(tileid: String, newtileid: String) -> void: +# Duplicate the tile to disk. A new mod id may be provided to save the duplicate to. +# tileid: The tile to duplicate. +# newtileid: The id of the new duplicate (can be the same as tileid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(tileid: String, newtileid: String, new_mod_id: String) -> void: + # Duplicate the tile data and set the new id var tiledata: Dictionary = by_id(tileid).get_data().duplicate(true) - # A duplicated tile is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - tiledata.erase("references") tiledata.id = newtileid - var newtile: DTile = DTile.new(tiledata, self) - tiledict[newtileid] = newtile - save_tiles_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DTiles = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).tiles + + # Instantiate and append the new DTile instance + var newtile: DTile = DTile.new(tiledata, newparent) + newparent.append_new(newtile) +# Add a new tile to the dictionary and save it to disk. func add_new(newid: String) -> void: - var newtile: DTile = DTile.new({"id":newid}, self) + append_new(DTile.new({"id": newid}, self)) + + +# Append a new tile to the dictionary and save it to disk. +func append_new(newtile: DTile) -> void: tiledict[newtile.id] = newtile save_tiles_to_disk() + func delete_by_id(tileid: String) -> void: tiledict[tileid].delete() tiledict.erase(tileid) diff --git a/Scripts/Gamedata/DWearableSlots.gd b/Scripts/Gamedata/DWearableSlots.gd index 815c44aa..a9ca31b2 100644 --- a/Scripts/Gamedata/DWearableSlots.gd +++ b/Scripts/Gamedata/DWearableSlots.gd @@ -70,23 +70,35 @@ func get_all() -> Dictionary: return wearableslotdict -func duplicate_to_disk(wearableslotid: String, newwearableslotid: String) -> void: +# Duplicate the wearable slot to disk. A new mod id may be provided to save the duplicate to. +# wearableslotid: The wearable slot to duplicate. +# newwearableslotid: The id of the new duplicate (can be the same as wearableslotid if new_mod_id equals mod_id). +# new_mod_id: The id of the mod that the duplicate will be entered into. May differ from mod_id. +func duplicate_to_disk(wearableslotid: String, newwearableslotid: String, new_mod_id: String) -> void: + # Duplicate the wearable slot data and set the new id var wearableslotdata: Dictionary = by_id(wearableslotid).get_data().duplicate(true) - # A duplicated wearableslot is brand new and can't already be referenced by something - # So we delete the references from the duplicated data if it is present - wearableslotdata.erase("references") wearableslotdata.id = newwearableslotid - var newwearableslot: DWearableSlot = DWearableSlot.new(wearableslotdata, self) - wearableslotdict[newwearableslotid] = newwearableslot - save_wearableslots_to_disk() + + # Determine the new parent based on the new_mod_id + var newparent: DWearableSlots = self if new_mod_id == mod_id else Gamedata.mods.by_id(new_mod_id).wearableslots + + # Instantiate and append the new DWearableSlot instance + var newwearableslot: DWearableSlot = DWearableSlot.new(wearableslotdata, newparent) + newparent.append_new(newwearableslot) +# Add a new wearable slot to the dictionary and save it to disk. func add_new(newid: String) -> void: - var newwearableslot: DWearableSlot = DWearableSlot.new({"id":newid}, self) + append_new(DWearableSlot.new({"id": newid}, self)) + + +# Append a new wearable slot to the dictionary and save it to disk. +func append_new(newwearableslot: DWearableSlot) -> void: wearableslotdict[newwearableslot.id] = newwearableslot save_wearableslots_to_disk() + func delete_by_id(wearableslotid: String) -> void: wearableslotdict[wearableslotid].delete() wearableslotdict.erase(wearableslotid)