Move map data to its own .scn, split map_rebuilder into two steps

This commit is contained in:
Jens Pitkänen 2026-07-30 23:45:35 +03:00
parent 57b562d545
commit dd8c25052d
7 changed files with 67 additions and 6142 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -19,24 +19,50 @@ extends Node
# --headless --editor --path godot res://maps/${MAP_BASE_NAME}/${MAP_BASE_NAME}.tscn -- --rebuild-map # --headless --editor --path godot res://maps/${MAP_BASE_NAME}/${MAP_BASE_NAME}.tscn -- --rebuild-map
# Another step might be useful for actually running the game. # Another step might be useful for actually running the game.
enum MapPart { MAP_MAIN, MAP_STATIC }
@export var map_part: MapPart = MapPart.MAP_MAIN
func _ready() -> void: func _ready() -> void:
if not Engine.is_editor_hint():
return
var args: PackedStringArray = OS.get_cmdline_user_args() var args: PackedStringArray = OS.get_cmdline_user_args()
if args.has("--rebuild-map"): if args.has("--rebuild-map"):
var success: bool = rebuild_map() var success: bool = rebuild_map()
get_tree().quit(0 if success else 1) get_tree().quit(0 if success else 1)
func rebuild_map() -> bool: func rebuild_map() -> bool:
var map: Map = get_parent() var parent: Node = get_parent()
if parent != get_tree().edited_scene_root:
# This map_rebuilder is likely the static one, but the scene open in the
# editor is the main one. Skip!
print("[map_rebuilder] Skipping ", MapPart.find_key(map_part), " processing due to not being the currently open scene. (This is expected.)")
return true
# Ensure the map has actually changed since this scene was last saved
var scene_path = get_tree().edited_scene_root.scene_file_path
var scene_modified = FileAccess.get_modified_time(scene_path)
var map_path = scene_path.replace("_static.scn", ".map").replace(".tscn", ".map")
var map_modified = FileAccess.get_modified_time(map_path)
if scene_modified > map_modified:
print("[map_rebuilder] ", MapPart.find_key(map_part), " is already up to date with the .map file, skipping.")
return true
# Rebuild func_godot_map # Rebuild func_godot_map
var func_godot_maps: Array = map.find_children("*", "FuncGodotMap") if map_part == MapPart.MAP_STATIC:
print("[map_rebuilder] Rebuilding FuncGodotMap...")
var scene: Node3D = parent
var func_godot_maps: Array = scene.find_children("*", "FuncGodotMap")
assert(len(func_godot_maps) == 1) assert(len(func_godot_maps) == 1)
var func_godot_map: FuncGodotMap = func_godot_maps[0] var func_godot_map: FuncGodotMap = func_godot_maps[0]
print("Rebuilding ", func_godot_map.name, "...")
func_godot_map.build() func_godot_map.build()
print(func_godot_map.name, " rebuilt. Registering spawners...") print("[map_rebuilder] ", func_godot_map.name, " rebuilt.")
# Hook up team and ball spawns # Hook up team and ball spawns
if map_part == MapPart.MAP_MAIN:
print("[map_rebuilder] Hooking up spawners for the map...")
var map: Map = parent
map.spawners = [] map.spawners = []
var spawner_count: int = 0 var spawner_count: int = 0
var spawn_entities: Array = map.find_children("*", "SpawnEntity") var spawn_entities: Array = map.find_children("*", "SpawnEntity")
@ -50,11 +76,12 @@ func rebuild_map() -> bool:
map.spawners.push_back(null) map.spawners.push_back(null)
map.spawners[spawn_entity.team_index] = spawn_entity map.spawners[spawn_entity.team_index] = spawn_entity
spawner_count += 1 spawner_count += 1
print(spawner_count, " spawners registered. Saving scene...") print("[map_rebuilder] ", spawner_count, " spawners registered.")
# Save current scene
var packed_scene = PackedScene.new() var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().edited_scene_root) packed_scene.pack(get_tree().edited_scene_root)
ResourceSaver.save(packed_scene, get_tree().edited_scene_root.scene_file_path) ResourceSaver.save(packed_scene, scene_path)
print("Scene saved. All rebuilding steps complete!") print("[map_rebuilder] Scene saved.")
return true return true

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.