From 40c4fc71dfc7681cf54f3ba856419744b8c2aaeb Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:46:48 +0100 Subject: [PATCH 1/2] Add overmap area reference --- Mods/Core/Maps/references.json | 108 +++++++++++++++++++++++++++++++ Scripts/Gamedata/DOvermaparea.gd | 4 +- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/Mods/Core/Maps/references.json b/Mods/Core/Maps/references.json index d5dbafa9..67fbe4e0 100644 --- a/Mods/Core/Maps/references.json +++ b/Mods/Core/Maps/references.json @@ -1,4 +1,14 @@ { + "Generichouse": { + "overmapareas": [ + "city" + ] + }, + "Generichouse_00": { + "overmapareas": [ + "city" + ] + }, "RockyHill_NE": { "tacticalmaps": [ "RockyHill_00" @@ -22,9 +32,107 @@ "RockyHill_00" ] }, + "abandoned_building": { + "overmapareas": [ + "city" + ] + }, + "city_square": { + "overmapareas": [ + "city" + ] + }, + "field_grass_basic_00": { + "overmapareas": [ + "city" + ] + }, + "field_grass_flowers_00": { + "overmapareas": [ + "city" + ] + }, + "field_grass_hill_00": { + "overmapareas": [ + "city" + ] + }, + "field_grass_hole_00": { + "overmapareas": [ + "city" + ] + }, + "generichouse_corner": { + "overmapareas": [ + "city" + ] + }, + "generichouse_cross": { + "overmapareas": [ + "city" + ] + }, + "generichouse_end": { + "overmapareas": [ + "city" + ] + }, + "generichouse_t": { + "overmapareas": [ + "city" + ] + }, + "neighborhood_school": { + "overmapareas": [ + "city" + ] + }, + "office_building_00": { + "overmapareas": [ + "city" + ] + }, + "parking_garage": { + "overmapareas": [ + "city" + ] + }, "police_station": { + "overmapareas": [ + "city" + ], "quests": [ "starter_tutorial_00" ] + }, + "radio_tower": { + "overmapareas": [ + "city" + ] + }, + "skyscraper": { + "overmapareas": [ + "city" + ] + }, + "store_electronic_clothing": { + "overmapareas": [ + "city" + ] + }, + "store_groceries": { + "overmapareas": [ + "city" + ] + }, + "subway_station": { + "overmapareas": [ + "city" + ] + }, + "two_story_house": { + "overmapareas": [ + "city" + ] } } \ No newline at end of file diff --git a/Scripts/Gamedata/DOvermaparea.gd b/Scripts/Gamedata/DOvermaparea.gd index 742b9fc6..4cadd352 100644 --- a/Scripts/Gamedata/DOvermaparea.gd +++ b/Scripts/Gamedata/DOvermaparea.gd @@ -193,11 +193,11 @@ func changed(olddata: DOvermaparea): # Remove references to map IDs that are in the old data but not in the new data for map_id in old_map_ids: if map_id not in new_map_ids: - Gamedata.mods.by_id("Core").maps.remove_reference_from_map(map_id, "core", "overmapareas", id) + Gamedata.mods.remove_reference(DMod.ContentType.MAPS, map_id, DMod.ContentType.OVERMAPAREAS, id) # Add references to map IDs that are in the new data, even if they were already in the old data for map_id in new_map_ids: - Gamedata.mods.by_id("Core").maps.add_reference_to_map(map_id, "core", "overmapareas", id) + Gamedata.mods.add_reference(DMod.ContentType.MAPS, map_id, DMod.ContentType.OVERMAPAREAS, id) # Save the updated overmap area data to disk Gamedata.overmapareas.save_overmapareas_to_disk() From 8d7cfb152a48590ee7eb726b18c557a917b2aa80 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:58:18 +0100 Subject: [PATCH 2/2] Remove map from overmaparea --- Scripts/Gamedata/DMap.gd | 41 ++++++-------------------------- Scripts/Gamedata/DMaps.gd | 18 -------------- Scripts/Gamedata/DOvermaparea.gd | 16 +++++++++++-- 3 files changed, 21 insertions(+), 54 deletions(-) diff --git a/Scripts/Gamedata/DMap.gd b/Scripts/Gamedata/DMap.gd index 45ba55a6..0239f7e7 100644 --- a/Scripts/Gamedata/DMap.gd +++ b/Scripts/Gamedata/DMap.gd @@ -77,14 +77,7 @@ extends RefCounted # ], # "mapheight": 32, # "mapwidth": 32, -# "name": "Basic Grass Field", -# "references": { -# "core": { -# "overmapareas": [ -# "city" -# ] -# } -# }, +# "name": "Basic Grass Field" # "weight": 1000 #} @@ -98,7 +91,6 @@ var weight: int = 1000 var mapwidth: int = 32 var mapheight: int = 32 var levels: Array = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]] -var references: Dictionary = {} var areas: Array = [] var sprite: Texture = null # Variable to store connections. For example: {"south": "road","west": "ground"} default to ground @@ -145,7 +137,6 @@ func set_data(newdata: Dictionary) -> void: mapwidth = newdata.get("mapwidth", 32) mapheight = newdata.get("mapheight", 32) levels = newdata.get("levels", [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]) - references = newdata.get("references", {}) areas = newdata.get("areas", []) connections = newdata.get("connections", {}) # Set connections from data if present @@ -161,8 +152,6 @@ func get_data() -> Dictionary: mydata["mapwidth"] = mapwidth mydata["mapheight"] = mapheight mydata["levels"] = levels - if not references.is_empty(): - mydata["references"] = references if not areas.is_empty(): mydata["areas"] = areas if not connections.is_empty(): # Omit connections if empty @@ -228,6 +217,12 @@ func delete(): # Remove this map from the tacticalmaps in this map's references for ref in myreferences.get("tacticalmaps", []): remove_self_from_tacticalmap(ref) + + # Remove this map from the overmapareas in this map's references + for ref in myreferences.get("overmapareas", []): + var myareas: Array = Gamedata.mods.get_all_content_by_id(DMod.ContentType.OVERMAPAREAS, ref) + for area: DOvermaparea in myareas: + area.remove_map_from_all_regions(id) remove_my_reference_from_all_entities() @@ -476,28 +471,6 @@ func erase_entity_from_areas(entity_type: String, entity_id: String) -> void: ) -# Removes the provided reference from references -# For example, remove "town_00" from references.Core.tacticalmaps -# module: the mod that the entity belongs to, for example "Core" -# type: The type of entity, for example "tacticlmaps" -# refid: The id of the entity, for example "town_00" -func remove_reference(module: String, type: String, refid: String): - var changes_made = Gamedata.dremove_reference(references, module, type, refid) - if changes_made: - save_data_to_disk() - - -# Adds a reference to the references list -# For example, add "town_00" to references.Core.tacticalmaps -# module: the mod that the entity belongs to, for example "Core" -# type: The type of entity, for example "tacticlmaps" -# refid: The id of the entity, for example "town_00" -func add_reference(module: String, type: String, refid: String): - var changes_made = Gamedata.dadd_reference(references, module, type, refid) - if changes_made: - save_data_to_disk() - - # Function to remove a area from mapData.areas by its id func remove_area(area_id: String) -> void: # Iterate through the areas array to find and remove the area by id diff --git a/Scripts/Gamedata/DMaps.gd b/Scripts/Gamedata/DMaps.gd index fb6d6fea..47a28809 100644 --- a/Scripts/Gamedata/DMaps.gd +++ b/Scripts/Gamedata/DMaps.gd @@ -50,7 +50,6 @@ func load_maps_from_disk() -> void: mapdict[mapid] = map - func get_all() -> Dictionary: return mapdict @@ -110,23 +109,6 @@ func remove_entity_from_selected_maps(entity_type: String, entity_id: String, ma mapdict[map].remove_entity_from_map(entity_type, entity_id) -# Removes the reference from the selected map -func remove_reference_from_map(mapid: String, module: String, type: String, refid: String): - var mymap: DMap = by_id(mapid) - mymap.remove_reference(module, type, refid) - - -# Adds a reference to the references list -# For example, add "town_00" to references.Core.tacticalmaps -# mapid: The id of the map to add the reference to -# module: the mod that the entity belongs to, for example "Core" -# type: The type of entity, for example "tacticlmaps" -# refid: The id of the entity to reference, for example "town_00" -func add_reference_to_map(mapid: String, module: String, type: String, refid: String): - var mymap: DMap = by_id(mapid) - mymap.add_reference(module, type, refid) - - # Function to get maps by category func get_maps_by_category(category: String) -> Array[DMap]: var maplist: Array[DMap] = [] diff --git a/Scripts/Gamedata/DOvermaparea.gd b/Scripts/Gamedata/DOvermaparea.gd index 4cadd352..f46a8e98 100644 --- a/Scripts/Gamedata/DOvermaparea.gd +++ b/Scripts/Gamedata/DOvermaparea.gd @@ -166,14 +166,14 @@ func get_data() -> Dictionary: # Method to save any changes to the overmaparea back to disk func save_to_disk(): - Gamedata.overmapareas.save_overmapareas_to_disk() + Gamedata.mods.by_id("Core").overmapareas.save_overmapareas_to_disk() # Removes the provided reference from references func remove_reference(module: String, type: String, refid: String): var changes_made = Gamedata.dremove_reference(references, module, type, refid) if changes_made: - Gamedata.overmapareas.save_overmapareas_to_disk() + save_to_disk() # Adds a reference to the references list @@ -235,3 +235,15 @@ func get_all_map_ids() -> Array: if map_id not in unique_map_ids: unique_map_ids.append(map_id) return unique_map_ids + + +# Function to remove a specific map ID from all regions in the overmap area +func remove_map_from_all_regions(map_id: String) -> void: + for region_key in regions.keys(): + var region = regions[region_key] + # Filter out the map entries that do not match the given map_id + region.maps = region.maps.filter(func(map_entry): + return map_entry.get("id", "") != map_id + ) + # Save the updated overmap area data to disk + save_to_disk()