extends Node const GAME := preload("res://scenes/game/game.tscn") func weapon(damage: float, interval: float = 0.5, missile: bool = false) -> ItemInstance: var item := ItemInstance.new() item.definition = preload("res://resources/items/plasma_cannon.tres").duplicate() item.definition.fire_interval = interval if missile: item.definition.weapon_kind = ItemDefinition.WeaponKind.MISSILE item.damage_min = damage item.damage_max = damage return item func modifier(item: ItemInstance, key: String, value: float) -> void: var addon := ItemStatModifier.new() addon.stat_key = key addon.value = value item.additional_modifiers.append(addon) func delta_for(comparison: Dictionary, key: String) -> float: for row in comparison["stats"]: if row["key"] == key: return row["delta"] return 0.0 func _ready() -> void: GameState.start_new_run() var game := GAME.instantiate() add_child(game) game.set_physics_process(false) var ship := game.get_node("PlayerShip") ship.set_physics_process(false) ship.get_node("WeaponController").set_physics_process(false) for enemy in get_tree().get_nodes_in_group("enemies"): enemy.set_physics_process(false) var inventory: ShipInventory = ship.get_node("ShipInventory") var old_first := weapon(10) var old_second := weapon(20) inventory.weapon_slots.assign([old_first, old_second, null]) var candidate := weapon(12, 0.4) for index in 3: assert(is_equal_approx(inventory.get_weapon_comparison(candidate, index)["dps_delta"], [10.0, -10.0, 30.0][index])) modifier(old_first, "credits_percent", 4) modifier(old_second, "credits_percent", 9) modifier(candidate, "credits_percent", 6) for index in 3: assert(is_equal_approx(delta_for(inventory.get_weapon_comparison(candidate, index), "credits_percent"), [2.0, -3.0, 6.0][index])) modifier(old_first, "missile_cooldown_reduction", 0.5) var rocket := weapon(40, 0.1, true) modifier(rocket, "missile_cooldown_reduction", 2) assert(is_equal_approx(inventory.get_weapon_comparison(rocket, 0)["dps_delta"], 40.0 / 3.0 - 20.0)) assert(is_equal_approx(inventory.get_weapon_comparison(rocket, 2)["dps_delta"], 40.0 / 2.5)) modifier(rocket, "missile_cooldown_reduction", 100) assert(is_equal_approx(inventory.get_weapon_comparison(rocket, 2)["dps_delta"], 40.0)) modifier(old_first, "damage_percent", 5) modifier(candidate, "damage_percent", 20) modifier(candidate, "critical_chance_percent", 10) assert(is_equal_approx(inventory.get_weapon_comparison(candidate, 0)["dps_delta"], 39.6 - 21.0)) assert(is_equal_approx(inventory.get_weapon_comparison(candidate, 1)["dps_delta"], 41.25 - 42.0)) modifier(candidate, "damage", 3) assert(is_equal_approx(delta_for(inventory.get_weapon_comparison(candidate, 0), "flat_damage_addon"), 3.0)) assert(is_equal_approx(inventory.get_weapon_comparison(candidate, 0)["dps_delta"], 49.5 - 21.0)) assert(inventory.weapon_slots[0] == old_first and inventory.weapon_slots[1] == old_second and inventory.weapon_slots[2] == null) assert(inventory.missile_ammunition == ShipInventory.STARTING_MISSILE_AMMUNITION) assert(inventory.add_item(candidate)) inventory._recalculate_ship_stats() inventory.inventory_changed.emit() var hud := game.get_node("HUD/HUDRoot") var slot := preload("res://scenes/ui/inventory_slot_view.tscn").instantiate() slot.slot_index = inventory.cargo.find(candidate) hud.add_child(slot) slot.hide() var tooltip: PanelContainer = slot._make_custom_tooltip(candidate.get_tooltip_text()) hud.add_child(tooltip) tooltip.position = Vector2(340, 100) assert(tooltip.get_child(0).get_child(2).name == "WeaponComparison") await get_tree().process_frame await get_tree().process_frame assert(tooltip.size.x < 1100 and tooltip.size.y < 620) print("WEAPON_COMPARISON_TEST: PASS three slot DPS, empty slot, affix gains/losses, projected global bonuses, crits, missile cooldown and clamp, no inventory mutation, compact table")