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,42 +19,69 @@ 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:
assert(len(func_godot_maps) == 1) print("[map_rebuilder] Rebuilding FuncGodotMap...")
var func_godot_map: FuncGodotMap = func_godot_maps[0] var scene: Node3D = parent
print("Rebuilding ", func_godot_map.name, "...") var func_godot_maps: Array = scene.find_children("*", "FuncGodotMap")
func_godot_map.build() assert(len(func_godot_maps) == 1)
print(func_godot_map.name, " rebuilt. Registering spawners...") var func_godot_map: FuncGodotMap = func_godot_maps[0]
func_godot_map.build()
print("[map_rebuilder] ", func_godot_map.name, " rebuilt.")
# Hook up team and ball spawns # Hook up team and ball spawns
map.spawners = [] if map_part == MapPart.MAP_MAIN:
var spawner_count: int = 0 print("[map_rebuilder] Hooking up spawners for the map...")
var spawn_entities: Array = map.find_children("*", "SpawnEntity") var map: Map = parent
for node in spawn_entities: map.spawners = []
var spawn_entity: SpawnEntity = node var spawner_count: int = 0
if spawn_entity.is_ball_spawn: var spawn_entities: Array = map.find_children("*", "SpawnEntity")
map.ball_spawner = spawn_entity for node in spawn_entities:
spawner_count += 1 var spawn_entity: SpawnEntity = node
if spawn_entity.team_index >= 0: if spawn_entity.is_ball_spawn:
while len(map.spawners) <= spawn_entity.team_index: map.ball_spawner = spawn_entity
map.spawners.push_back(null) spawner_count += 1
map.spawners[spawn_entity.team_index] = spawn_entity if spawn_entity.team_index >= 0:
spawner_count += 1 while len(map.spawners) <= spawn_entity.team_index:
print(spawner_count, " spawners registered. Saving scene...") map.spawners.push_back(null)
map.spawners[spawn_entity.team_index] = spawn_entity
spawner_count += 1
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.