Skip to content

Commit

Permalink
Merge pull request #517 from snipercup/rmaps
Browse files Browse the repository at this point in the history
Allow maps to be modded
  • Loading branch information
snipercup authored Dec 3, 2024
2 parents 3ce34a3 + ad3f3c7 commit 3f961ce
Show file tree
Hide file tree
Showing 34 changed files with 697 additions and 112 deletions.
30 changes: 30 additions & 0 deletions Mods/Core/Maps/references.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"RockyHill_NE": {
"tacticalmaps": [
"RockyHill_00"
]
},
"RockyHill_NW": {
"tacticalmaps": [
"RockyHill_00"
]
},
"RockyHill_SE": {
"tacticalmaps": [
"RockyHill_00"
]
},
"RockyHill_SW": {
"quests": [
"starter_tutorial_00"
],
"tacticalmaps": [
"RockyHill_00"
]
},
"police_station": {
"quests": [
"starter_tutorial_00"
]
}
}
2 changes: 1 addition & 1 deletion Mods/Core/TacticalMaps/RockyHill_00.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
],
"mapheight": 2,
"mapwidth": 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://Scenes/ContentManager/Custom_Editors/Scripts/OvermapAreaEditor.gd" id="1_g1n4r"]
[ext_resource type="PackedScene" uid="uid://2kp6gjwaextr" path="res://Scenes/ContentManager/Custom_Widgets/Overmap_Area_Region_editor.tscn" id="2_jtxai"]
[ext_resource type="PackedScene" uid="uid://neuhnehifngf" path="res://Scenes/ContentManager/OtherTools/overmap_area_visualization.tscn" id="3_y3jo3"]
[ext_resource type="PackedScene" uid="uid://neuhnehifngf" path="res://Scenes/ContentManager/Custom_Widgets/overmap_area_visualization.tscn" id="3_y3jo3"]

[node name="OvermapAreaEditor" type="Control" node_paths=PackedStringArray("IDTextLabel", "NameTextEdit", "DescriptionTextEdit", "min_width_spin_box", "min_height_spin_box", "max_width_spin_box", "max_height_spin_box", "region_name_text_edit", "region_h_box_container", "overmap_area_visualization")]
layout_mode = 3
Expand Down
11 changes: 7 additions & 4 deletions Scenes/ContentManager/Custom_Editors/Scripts/QuestEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ func add_kill_step(step: Dictionary) -> HBoxContainer:
hbox.add_child(label_instance)

# Add the dropable text edit for the mob or mobgroup ID
var entity_type: String = "mob" if step.has("mob") else "mobgroup" if step.has("mobgroup") else ""
var dropable_textedit_instance: HBoxContainer = dropabletextedit.instantiate()
dropable_textedit_instance.set_text(step.get("mob", step.get("mobgroup", "")))
dropable_textedit_instance.set_meta("step_type", "kill")
# Set metadata to specify if this is a mob or mobgroup
dropable_textedit_instance.set_meta("entity_type", entity_type)
dropable_textedit_instance.myplaceholdertext = "Drop a mob or mobgroup from the left menu"
set_drop_functions(dropable_textedit_instance)
hbox.add_child(dropable_textedit_instance)
Expand Down Expand Up @@ -398,14 +401,14 @@ func entity_drop(dropped_data: Dictionary, texteditcontrol: HBoxContainer) -> vo
"craft", "collect":
valid_data = Gamedata.items.has_id(dropped_data["id"])
"kill":
if Gamedata.mobs.has_id(dropped_data["id"]):
if dropped_data["contentType"] == DMod.ContentType.MOBS:
valid_data = true
entity_type = "mob"
elif Gamedata.mobgroups.has_id(dropped_data["id"]):
elif dropped_data["contentType"] == DMod.ContentType.MOBGROUPS:
valid_data = true
entity_type = "mobgroup"
"enter":
valid_data = Gamedata.maps.has_id(dropped_data["id"])
valid_data = Gamedata.mods.by_id(dropped_data["mod_id"]).maps.has_id(dropped_data["id"])

if valid_data:
texteditcontrol.set_text(dropped_data["id"])
Expand All @@ -428,7 +431,7 @@ func can_entity_drop(dropped_data: Dictionary, texteditcontrol: HBoxContainer) -
"kill":
valid_data = Gamedata.mobs.has_id(dropped_data["id"]) or Gamedata.mobgroups.has_id(dropped_data["id"])
"enter":
valid_data = Gamedata.maps.has_id(dropped_data["id"])
valid_data = Gamedata.mods.by_id(dropped_data["mod_id"]).maps.has_id(dropped_data["id"])

return valid_data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func _ready():
loadMaps()


# loop over Gamedata.maps and creates tilebrushes for each map sprite in the list.
# loop over Gamedata.mods.by_id("Core").maps and creates tilebrushes for each map sprite in the list.
func loadMaps():
var mapsList: Dictionary = Gamedata.maps.get_all()
var mapsList: Dictionary = Gamedata.mods.by_id("Core").maps.get_all()
var newTilesList: Control = scrolling_Flow_Container.instantiate()
newTilesList.header = "maps"
add_child(newTilesList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var tileData: DTacticalmap.TChunk = DTacticalmap.TChunk.new({}):
set(data):
tileData = data
if not tileData.id == "":
$TileSprite.texture = Gamedata.maps.by_id(tileData.id).sprite
$TileSprite.texture = Gamedata.mods.get_content_by_id(DMod.ContentType.MAPS, tileData.id).sprite
set_rotation_amount(tileData.rotation)
else:
$TileSprite.texture = load(defaultTexture)
Expand Down Expand Up @@ -39,7 +39,7 @@ func set_tile_id(id: String) -> void:
if id == "":
$TileSprite.texture = load(defaultTexture)
else:
$TileSprite.texture = Gamedata.maps.by_id(id).sprite
$TileSprite.texture = Gamedata.mods.get_content_by_id(DMod.ContentType.MAPS, tileData.id).sprite


func _on_texture_rect_mouse_entered() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func save_map_json_file():
storeLevelData()
mapEditor.currentMap.save_data_to_disk()
mapEditor.currentMap.changed(mapEditor.oldmap)
mapEditor.oldmap = DTacticalmap.new(mapEditor.currentMap.id,"")
mapEditor.oldmap = DTacticalmap.new(mapEditor.currentMap.id,"", null)
mapEditor.oldmap.set_data(mapEditor.currentMap.get_data().duplicate(true))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func _get_maps_from_ui() -> Array:
var children = maps_grid_container.get_children()

# Loop through the children and extract map information
for i in range(0, children.size(), 4): # Step by 4 to handle sprite-label-spinbox-delete quatuplets
var label = children[i + 1] as Label # The label containing the map ID
for i in range(0, children.size(), 4): # Step by 5 to handle sprite-id-label-label-spinbox-delete entries
var id_label = children[i + 1] as Label # The label containing the map ID
var spinbox = children[i + 2] as SpinBox # The spinbox containing the map weight

# Append map data to the list as a dictionary
maps.append({"id": label.text, "weight": int(spinbox.value)})
maps.append({"id": id_label.text, "weight": int(spinbox.value)})

return maps

Expand All @@ -111,7 +111,7 @@ func _can_drop_map_data(_newpos, data) -> bool:
return false

# Fetch map by ID from the Gamedata to ensure it exists and is valid
if not Gamedata.maps.has_id(data["id"]):
if not Gamedata.mods.by_id(data["mod_id"]).maps.has_id(data["id"]):
return false

# Check if the map ID already exists in the maps grid
Expand All @@ -138,19 +138,19 @@ func _handle_map_drop(dropped_data, _newpos) -> void:
# dropped_data is a Dictionary that includes an 'id'
if dropped_data and "id" in dropped_data:
var map_id = dropped_data["id"]
if not Gamedata.maps.has_id(map_id):
if not Gamedata.mods.by_id(dropped_data["mod_id"]).maps.has_id(map_id):
print_debug("No map data found for ID: " + map_id)
return

# Add the map entry using the new function
_add_map_entry({"id": map_id, "weight": 100}) # Default weight set to 100
_add_map_entry({"id": map_id, "weight": 100, "mod_id": dropped_data["mod_id"]}) # Default weight set to 100
else:
print_debug("Dropped data does not contain an 'id' key.")


# Function to add a new map entry to the maps_grid_container
func _add_map_entry(map_data: Dictionary) -> void:
var mymap = Gamedata.maps.by_id(map_data.id)
var mymap = Gamedata.mods.get_content_by_id(DMod.ContentType.MAPS, map_data.id)

# Create a TextureRect for the map sprite
var texture_rect = TextureRect.new()
Expand All @@ -161,9 +161,9 @@ func _add_map_entry(map_data: Dictionary) -> void:
maps_grid_container.add_child(texture_rect)

# Create a Label for the map ID
var label = Label.new()
label.text = mymap.id
maps_grid_container.add_child(label)
var id_label = Label.new()
id_label.text = mymap.id
maps_grid_container.add_child(id_label)

# Create a SpinBox for the map weight
var weight_spinbox = SpinBox.new()
Expand All @@ -184,7 +184,7 @@ func _add_map_entry(map_data: Dictionary) -> void:

# Connect the delete button's button_up signal to remove the map entry
delete_button.button_up.connect(func():
_remove_map_entry(texture_rect, label, weight_spinbox, delete_button)
_remove_map_entry(texture_rect, id_label, weight_spinbox, delete_button)
)


Expand All @@ -206,12 +206,12 @@ func _on_delete_button_button_up() -> void:


# Function to remove a map entry (called when the delete button is pressed)
func _remove_map_entry(texture_rect: TextureRect, label: Label, weight_spinbox: SpinBox, delete_button: Button) -> void:
func _remove_map_entry(texture_rect: TextureRect, id_label: Label, weight_spinbox: SpinBox, delete_button: Button) -> void:
maps_grid_container.remove_child(texture_rect)
texture_rect.queue_free()

maps_grid_container.remove_child(label)
label.queue_free()
maps_grid_container.remove_child(id_label)
id_label.queue_free()

maps_grid_container.remove_child(weight_spinbox)
weight_spinbox.queue_free()
Expand Down
4 changes: 2 additions & 2 deletions Scenes/ContentManager/Mapeditor/Scripts/GridContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func _on_mapeditor_ready() -> void:


func on_map_data_changed():
oldmap = DMap.new(mapEditor.currentMap.id, "")
oldmap = DMap.new(mapEditor.currentMap.id, "", null)
oldmap.set_data(mapEditor.currentMap.get_data().duplicate(true))
loadLevelData(currentLevel)
load_area_data()
Expand Down Expand Up @@ -614,7 +614,7 @@ func save_map_json_file():
mapEditor.update_settings_values()
mapEditor.currentMap.save_data_to_disk()
mapEditor.currentMap.data_changed(oldmap)
oldmap = DMap.new(mapEditor.currentMap.id,"")
oldmap = DMap.new(mapEditor.currentMap.id,"", null)
oldmap.set_data(mapEditor.currentMap.get_data().duplicate(true))
# We wrote to mapEditor.currentMap, which means it's out of sync with each mapeditortile
# instance's data. We have to reload it
Expand Down
19 changes: 14 additions & 5 deletions Scenes/ContentManager/Scripts/content_list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ var mod_id: String = "Core"
var contentType: DMod.ContentType:
set(newData):
contentType = newData
if newData == DMod.ContentType.STATS or newData == DMod.ContentType.TACTICALMAPS:
if newData == DMod.ContentType.STATS or newData == DMod.ContentType.TACTICALMAPS or newData == DMod.ContentType.MAPS:
# Use mod-specific data for these content types
datainstance = Gamedata.mods.by_id(mod_id).get_data_of_type(contentType)
else:
# Use global data for other content types
datainstance = Gamedata.get_data_of_type(contentType)
load_data()


var header: String = "Items":
set(newName):
header = newName
Expand Down Expand Up @@ -149,11 +152,17 @@ func _get_drag_data(_newpos):
var selected_item_id = contentItems.get_item_metadata(selected_index)

# Create a drag preview
# var preview = _create_drag_preview(selected_item_id)
# set_drag_preview(preview)
var preview = _create_drag_preview(selected_item_id)
set_drag_preview(preview)

# Return an object with the necessary data, including mod_id and contentType
return {
"id": selected_item_id,
"text": selected_item_text,
"mod_id": mod_id,
"contentType": contentType
}

# Return an object with the necessary data
return {"id": selected_item_id, "text": selected_item_text}


# This function should return true if the dragged data can be dropped here
Expand Down
7 changes: 4 additions & 3 deletions Scenes/ContentManager/Scripts/contenteditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ func instantiate_editor(type: DMod.ContentType, itemID: String, newEditor: Packe
newContentEditor.name = itemID
tabContainer.add_child(newContentEditor)
tabContainer.current_tab = tabContainer.get_child_count() - 1
var currentmod: DMod = Gamedata.mods.by_id(selectedMod)

match type:
DMod.ContentType.MAPS:
newContentEditor.currentMap = Gamedata.maps.by_id(itemID)
newContentEditor.currentMap = currentmod.maps.by_id(itemID)
newContentEditor.data_changed.connect(list.load_data)

DMod.ContentType.TACTICALMAPS:
newContentEditor.currentMap = Gamedata.mods.by_id(selectedMod).tacticalmaps.by_id(itemID)
newContentEditor.currentMap = currentmod.tacticalmaps.by_id(itemID)

DMod.ContentType.FURNITURES:
newContentEditor.dfurniture = Gamedata.furnitures.by_id(itemID)
Expand Down Expand Up @@ -177,7 +178,7 @@ func instantiate_editor(type: DMod.ContentType, itemID: String, newEditor: Packe
newContentEditor.data_changed.connect(list.load_data)

DMod.ContentType.STATS:
newContentEditor.dstat = Gamedata.mods.by_id(selectedMod).stats.by_id(itemID)
newContentEditor.dstat = currentmod.stats.by_id(itemID)
newContentEditor.data_changed.connect(list.load_data)

DMod.ContentType.SKILLS:
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Chunk.gd
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func initialize_chunk_data():
chunk_data["id"] = Helper.test_map_name
if is_new_chunk(): # This chunk is created for the first time
#This contains the data of one map, loaded from maps.data, for example generichouse.json
var mapsegmentData: Dictionary = Gamedata.maps.by_id(chunk_data.id).get_data().duplicate(true)
var mapsegmentData: Dictionary = Runtimedata.maps.by_id(chunk_data.id).get_data().duplicate(true)
await Helper.task_manager.create_task(generate_new_chunk.bind(mapsegmentData)).completed
# Run the main spawn function on the main thread and let the furniturespawner
# handle offloading the work onto a thread.
Expand Down
9 changes: 6 additions & 3 deletions Scripts/Gamedata/DFurniture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ func delete():
Gamedata.itemgroups.remove_reference(destruction.group, "core", "furniture", id)
Gamedata.itemgroups.remove_reference(disassembly.group, "core", "furniture", id)

var mapsdata = Helper.json_helper.get_nested_data(references, "core.maps")
if mapsdata:
Gamedata.maps.remove_entity_from_selected_maps("furniture", id, mapsdata)
# Remove references to maps
var mapsdata: Array = Helper.json_helper.get_nested_data(references, "core.maps")
for mymap: String in mapsdata:
var mymaps: Array = Gamedata.mods.get_all_content_by_id(DMod.ContentType.MAPS, mymap)
for dmap: DMaps in mymaps:
dmap.remove_entity_from_selected_maps("furniture", id, mapsdata)


# Removes any instance of an itemgroup from the furniture
Expand Down
10 changes: 6 additions & 4 deletions Scripts/Gamedata/DItemgroup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ func delete():
for item in items:
Gamedata.items.remove_reference(item.id, "core", "itemgroups", id)

# Remove references to this itemgroup from maps.
var mapsdata = Helper.json_helper.get_nested_data(references,"core.maps")
if mapsdata:
Gamedata.maps.remove_entity_from_selected_maps("itemgroup", id, mapsdata)
# Remove references to maps
var mapsdata: Array = Helper.json_helper.get_nested_data(references, "core.maps")
for mymap: String in mapsdata:
var mymaps: Array = Gamedata.mods.get_all_content_by_id(DMod.ContentType.MAPS, mymap)
for dmap: DMaps in mymaps:
dmap.remove_entity_from_selected_maps("itemgroup", id, mapsdata)


# Executes a callable function on each reference of the given type
Expand Down
Loading

0 comments on commit 3f961ce

Please sign in to comment.