Skip to content

Commit

Permalink
Merge pull request #521 from snipercup/map-ref
Browse files Browse the repository at this point in the history
Remove map reference functions, remove map from overmaparea
  • Loading branch information
snipercup authored Dec 3, 2024
2 parents bba9c95 + 8d7cfb1 commit 76dd061
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 56 deletions.
108 changes: 108 additions & 0 deletions Mods/Core/Maps/references.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"Generichouse": {
"overmapareas": [
"city"
]
},
"Generichouse_00": {
"overmapareas": [
"city"
]
},
"RockyHill_NE": {
"tacticalmaps": [
"RockyHill_00"
Expand All @@ -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"
]
}
}
41 changes: 7 additions & 34 deletions Scripts/Gamedata/DMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ extends RefCounted
# ],
# "mapheight": 32,
# "mapwidth": 32,
# "name": "Basic Grass Field",
# "references": {
# "core": {
# "overmapareas": [
# "city"
# ]
# }
# },
# "name": "Basic Grass Field"
# "weight": 1000
#}

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

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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions Scripts/Gamedata/DMaps.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func load_maps_from_disk() -> void:
mapdict[mapid] = map



func get_all() -> Dictionary:
return mapdict

Expand Down Expand Up @@ -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] = []
Expand Down
20 changes: 16 additions & 4 deletions Scripts/Gamedata/DOvermaparea.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 76dd061

Please sign in to comment.