extends TestCase ## A4: every item has a model, an icon and attachment data; models are painted from the ## Palette with their tier's treatment; figures hold what their players hold, and items ## lying in the world are drawn with their models. const SIDE: Vector3 = Vector3(1.0, 0.0, 0.0) func after_each() -> void: ItemModels.clear() super.after_each() func test_every_item_has_a_model_an_icon_and_a_grip() -> void: var ids: Array[String] = ItemModels.ids() assert_eq(ids.size(), ItemCatalog.count() + 1, "the boathook and every catalog item") for id: String in ids: var mesh: ArrayMesh = ItemModels.model(id) assert_not_null(mesh, "%s has a model" % id) var picture: Texture2D = ItemModels.icon(id) assert_not_null(picture, "%s has an icon" % id) if picture != null: assert_eq(picture.get_size(), Vector2(128, 128), "%s's icon size" % id) var info: Dictionary = ItemModels.info(id) assert_eq(info.get("generator", ""), "tools/models/items.py", "%s says what made it" % id) if mesh == null: continue var bounds: AABB = mesh.get_aabb() assert_true(bounds.has_point(Vector3.ZERO) or bounds.grow(0.05).has_point(Vector3.ZERO), "%s's grip is on the model" % id) assert_true(bounds.size.length() > 0.08 and bounds.size.length() < 2.5, "%s is item-sized: %s" % [id, bounds.size]) func test_weapons_point_forward_and_long_ones_have_a_support_point() -> void: for id: String in ["fowling_piece", "dock_carbine", "whalers_longgun", "line_thrower", "harpoon_gun", "rivet_repeater", "boathook"]: var bounds: AABB = ItemModels.model(id).get_aabb() assert_true(bounds.end.z > -bounds.position.z, "%s's working end is toward +Z" % id) var support: Variant = ItemModels.info(id).get("support") assert_true(support is Array, "%s has a place for the left hand" % id) if support is Array: assert_true(float(support[2]) > 0.1, "%s's support is ahead of the grip" % id) func test_silhouettes_differ() -> void: var seen: Dictionary = {} for id: String in ItemModels.ids(): var size: Vector3 = ItemModels.model(id).get_aabb().size var key: String = "%.2f,%.2f,%.2f" % [size.x, size.y, size.z] assert_false(seen.has(key), "%s has its own outline, not %s's" % [id, seen.get(key, "")]) seen[key] = id func test_models_are_painted_from_the_palette() -> void: for id: String in ItemModels.ids(): var mesh: ArrayMesh = ItemModels.model(id, 3) for surface: int in mesh.get_surface_count(): var name: String = mesh.surface_get_name(surface) assert_not_null(ItemModels.colour_of(name, 1), "%s's material %s is a Palette colour" % [id, name]) var paint: StandardMaterial3D = mesh.surface_get_material(surface) as StandardMaterial3D assert_eq(paint.albedo_color, ItemModels.colour_of(name, 3)) func test_tiers_add_trim_and_tier_zero_is_weathered() -> void: var counts: Array[int] = [] for tier: int in 4: counts.append(ItemModels.model("dock_carbine", tier).get_surface_count()) assert_eq(counts[0], counts[1], "tiers 0 and 1 have the same parts") assert_true(counts[2] > counts[1], "rope whipping from tier 2: %s" % [counts]) assert_true(counts[3] > counts[2], "brass bands from tier 3: %s" % [counts]) assert_ne(ItemModels.colour_of("SALVAGE_IRON", 0), ItemModels.colour_of("SALVAGE_IRON", 1), "tier 0 is faded") assert_eq(ItemModels.trim_level("TRIM3_GILT"), 3) assert_eq(ItemModels.colour_of("TRIM3_GILT", 3), Palette.GILT) assert_null(ItemModels.colour_of("NEON", 1)) func _world_with_player(code: int, tier: int) -> Array: var sim: Simulation = Simulation.new(4, SimGround.flat(0.0)) var player: SimEntity = sim.entities.find(sim.add_player()) player.drop_state = Drop.NONE if code >= 0: player.slot_items[0] = code player.slot_counts[0] = 1 player.slot_tiers[0] = tier player.selected = 1 return [sim, player] func test_figures_hold_their_players_item_in_the_right_hand() -> void: var made: Array = _world_with_player(ItemCatalog.code_of("whalers_longgun"), 3) var sim: Simulation = made[0] var player: SimEntity = made[1] var view: EntityView = EntityView.new() view.setup(sim) var figure: FigureRig = view.figure_of(player.id) var held: MeshInstance3D = figure.held() assert_eq(held.mesh, ItemModels.model("whalers_longgun", 3)) assert_true(figure.relative(figure.hand()).origin.x < 0.0, "the right hand, on the figure's -X side") player.selected = 0 view.sync() assert_eq(held.mesh, ItemModels.model("boathook", 1), "the boathook when nothing else is held") player.pitch = PlayerCommand.PITCH_MAX / 2 view.sync() figure.drive(player, 0.1) figure.advance(0.1) var muzzle: Vector3 = figure.hand_basis() * Vector3(0.0, 0.0, 1.0) assert_true(muzzle.y > 0.5, "looking up points the item up") player.drop_state = Drop.GLIDING view.sync() assert_false(figure.hand().visible, "both hands on the wing-sail") view.free() func test_others_hold_what_the_snapshot_says() -> void: var sim: Simulation = Simulation.new(4, SimGround.flat(0.0)) var player: SimEntity = sim.entities.create(SimEntity.ARCHETYPE_PLAYER) player.item = ItemCatalog.code_of("harpoon_gun") assert_eq(EntityView.held_code(player), player.item, "no slots known: the snapshot's held code") player.slot_items = PackedInt32Array([ItemCatalog.code_of("dock_carbine"), -1]) player.selected = 1 assert_eq(EntityView.held_code(player), ItemCatalog.code_of("dock_carbine")) player.selected = 0 assert_eq(EntityView.held_code(player), -1, "the boathook") func test_pickups_are_drawn_with_their_models() -> void: var sim: Simulation = Simulation.new(4, SimGround.flat(0.0)) Inventory.spawn_pickup(sim, Vector3(5, 0, 5), ItemCatalog.code_of("brine_tonic"), 1) Inventory.spawn_pickup(sim, Vector3(6, 0, 5), ItemCatalog.code_of("brine_tonic"), 1) Inventory.spawn_pickup(sim, Vector3(7, 0, 5), ItemCatalog.code_of("fowling_piece"), 1, 2, 2) var view: EntityView = EntityView.new() view.setup(sim) assert_eq(view.pickup_count(), 3) var field: MultiMeshInstance3D = view.get_node("Pickups/brine_tonic_1") assert_not_null(field, "one field per model and tier") assert_eq(field.multimesh.instance_count, 2) assert_eq(field.multimesh.mesh, ItemModels.model("brine_tonic", 1), "consumables have no tiers") for id: String in ItemModels.ids(): var mesh: ArrayMesh = ItemModels.model(id) var lowest: float = EntityView.pickup_lift(mesh) + mesh.get_aabb().position.y * EntityView.PICKUP_SCALE assert_near(lowest, 0.02, 0.001, "%s rests on the ground, not sunk into it" % id) sim.pickups.clear() view.sync() assert_eq(view.pickup_count(), 0) view.free() func test_the_hotbar_shows_icons() -> void: var made: Array = _world_with_player(ItemCatalog.code_of("dock_carbine"), 1) var player: SimEntity = made[1] var state: HudState = HudState.new() state.playing = true HudState._fill_carried(state, player) assert_eq(state.slots[0]["id"], ItemCatalog.BOATHOOK) assert_eq(state.slots[1]["id"], "dock_carbine") assert_not_null(ItemModels.icon(String(state.slots[1]["id"])))