Skip to content

Commit

Permalink
Merge pull request #568 from snipercup/split-core
Browse files Browse the repository at this point in the history
Duplicate entries to a different mod
  • Loading branch information
Elshad19 authored Dec 14, 2024
2 parents 0080f38 + cdbb159 commit 27a58e4
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 148 deletions.
12 changes: 12 additions & 0 deletions Mods/Dimensionfall/modinfo.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
32 changes: 29 additions & 3 deletions Scenes/ContentManager/Scripts/content_list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())


Expand Down Expand Up @@ -70,6 +88,7 @@ func add_item_to_data(id: String):
func _on_add_button_button_up():
popupAction = "Add"
popup_textedit.text = ""
to_mod_h_box_container.hide()
pupup_ID.show()

# This function requires that an item from the list is selected
Expand All @@ -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
Expand All @@ -92,17 +112,23 @@ 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:
is_collapsed = false
load_data()



# Called after the users presses cancel on the popup asking for an ID
func _on_cancel_button_up():
pupup_ID.hide()
Expand Down
22 changes: 17 additions & 5 deletions Scenes/ContentManager/content_list.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Gamedata/DFurniture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand Down
31 changes: 20 additions & 11 deletions Scripts/Gamedata/DFurnitures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down
31 changes: 22 additions & 9 deletions Scripts/Gamedata/DItemgroups.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -68,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()

Expand Down
29 changes: 20 additions & 9 deletions Scripts/Gamedata/DItems.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -60,19 +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)
# 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
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()

Expand Down
22 changes: 15 additions & 7 deletions Scripts/Gamedata/DMaps.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 27a58e4

Please sign in to comment.