|
| 1 | +extends SceneTree |
| 2 | + |
| 3 | +const TERRAIN_DATA = preload("res://scripts/world/campaign2_world_terrain_data.gd") |
| 4 | +const FEATURE_COMPOSER = preload("res://scripts/world/world_settlement_feature_composer.gd") |
| 5 | + |
| 6 | +var failures := 0 |
| 7 | + |
| 8 | +func _initialize() -> void: |
| 9 | + _test_warrens_source_layout() |
| 10 | + _test_warrens_streamed_hut_presentation() |
| 11 | + if failures > 0: |
| 12 | + push_error("%d Silverhart Warrens presentation test(s) failed." % failures) |
| 13 | + quit(1) |
| 14 | + return |
| 15 | + print("Silverhart Warrens presentation tests passed.") |
| 16 | + quit(0) |
| 17 | + |
| 18 | +func _test_warrens_source_layout() -> void: |
| 19 | + var data := TERRAIN_DATA.new() as Campaign2WorldTerrainData |
| 20 | + var entry := _silverhart_entry(data) |
| 21 | + _check(not entry.is_empty(), "Silverhart must resolve from the canonical settlement registry") |
| 22 | + if entry.is_empty(): |
| 23 | + return |
| 24 | + var layout: Dictionary = entry.get("definition", {}).get("layout", {}) |
| 25 | + var buildings: Array = layout.get("buildings", []) |
| 26 | + var expected := { |
| 27 | + "silverhart_warrens_shack_1": {"centre": Vector2i(2, -433), "door": Vector2i(2, -431), "side": "south"}, |
| 28 | + "silverhart_warrens_shack_2": {"centre": Vector2i(5, -427), "door": Vector2i(5, -429), "side": "north"}, |
| 29 | + "silverhart_warrens_shack_3": {"centre": Vector2i(11, -433), "door": Vector2i(11, -431), "side": "south"} |
| 30 | + } |
| 31 | + for building_id in expected: |
| 32 | + var building := _find_building(buildings, building_id) |
| 33 | + var expected_entry: Dictionary = expected[building_id] |
| 34 | + _check(not building.is_empty(), "The source Warrens should retain %s" % building_id) |
| 35 | + if building.is_empty(): |
| 36 | + continue |
| 37 | + _check(String(building.get("archetype", "")) == "hut", "%s should use the ramshackle hut exterior, not a prosperous cottage" % building_id) |
| 38 | + _check(_read_hex(building.get("center")) == expected_entry.get("centre", Vector2i.ZERO), "%s should retain its source position" % building_id) |
| 39 | + _check(_read_hex(building.get("door")) == expected_entry.get("door", Vector2i.ZERO), "%s should retain its source entrance" % building_id) |
| 40 | + _check(String(building.get("door_side", "")) == expected_entry.get("side", ""), "%s should retain its source-facing door" % building_id) |
| 41 | + |
| 42 | +func _test_warrens_streamed_hut_presentation() -> void: |
| 43 | + var data := TERRAIN_DATA.new() as Campaign2WorldTerrainData |
| 44 | + var entry := _silverhart_entry(data) |
| 45 | + if entry.is_empty(): |
| 46 | + return |
| 47 | + var parent := Node3D.new() |
| 48 | + root.add_child(parent) |
| 49 | + var north_chunk: Dictionary = FEATURE_COMPOSER.compose_chunk( |
| 50 | + parent, entry, Vector2i(0, -456), 24, HexGrid.DEFAULT_RADIUS_M |
| 51 | + ) |
| 52 | + var south_chunk: Dictionary = FEATURE_COMPOSER.compose_chunk( |
| 53 | + parent, entry, Vector2i(0, -432), 24, HexGrid.DEFAULT_RADIUS_M |
| 54 | + ) |
| 55 | + _check(bool(north_chunk.get("ok", false)), "The northern Warrens shack chunk should compose") |
| 56 | + _check(bool(south_chunk.get("ok", false)), "The southern Warrens shack chunk should compose") |
| 57 | + for building_id in [ |
| 58 | + "silverhart_warrens_shack_1", |
| 59 | + "silverhart_warrens_shack_2", |
| 60 | + "silverhart_warrens_shack_3" |
| 61 | + ]: |
| 62 | + var building := parent.get_node_or_null(building_id) |
| 63 | + _check(building != null, "%s should render in its owning streamed chunk" % building_id) |
| 64 | + if building != null: |
| 65 | + _check(String(building.get_meta("archetype", "")) == "hut", "%s should be built using the smaller hut shell" % building_id) |
| 66 | + _check(building.get_node_or_null("RoofLeftSlope") != null, "%s should retain its roof shell" % building_id) |
| 67 | + parent.free() |
| 68 | + |
| 69 | +func _silverhart_entry(data: Campaign2WorldTerrainData) -> Dictionary: |
| 70 | + for entry in data.settlement_layouts: |
| 71 | + if String(entry.get("id", "")) == "silverhart": |
| 72 | + return entry |
| 73 | + return {} |
| 74 | + |
| 75 | +func _find_building(buildings: Array, building_id: String) -> Dictionary: |
| 76 | + for building in buildings: |
| 77 | + if String(building.get("id", "")) == building_id: |
| 78 | + return building |
| 79 | + return {} |
| 80 | + |
| 81 | +func _read_hex(value: Variant) -> Vector2i: |
| 82 | + if value is Vector2i: |
| 83 | + return value |
| 84 | + if value is Dictionary: |
| 85 | + return Vector2i(int(value.get("q", 0)), int(value.get("r", 0))) |
| 86 | + return Vector2i.ZERO |
| 87 | + |
| 88 | +func _check(condition: bool, message: String) -> void: |
| 89 | + if not condition: |
| 90 | + failures += 1 |
| 91 | + push_error(message) |
0 commit comments