move ecs related code to own folder

This commit is contained in:
2026-05-25 08:46:58 +02:00
parent 8ad7530740
commit 25ff3c56c5
54 changed files with 877 additions and 680 deletions

View File

@@ -5,14 +5,20 @@
#include <QVector2D>
#include "BuildingId.h"
#include "ConfigLoader.h"
#include "DynamicBodyComponent.h"
#include "EcsComponents.h"
#include "EntityAdmin.h"
#include "BuildingId.h"
#include "Ship.h"
#include "HealthComponent.h"
#include "RepairBehaviorComponent.h"
#include "RepairToolComponent.h"
#include "SalvageBehaviorComponent.h"
#include "SalvageCargoComponent.h"
#include "SensorRangeComponent.h"
#include "ShipSystem.h"
#include "Tick.h"
#include "ThreatResponseBehaviorComponent.h"
#include "WeaponComponent.h"
static GameConfig loadConfig()
{
@@ -33,12 +39,12 @@ TEST_CASE("ShipSystem: interceptor spawn has weapon and threatResponse, no cargo
const entt::entity e = ss.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
REQUIRE(admin.isValid(e));
REQUIRE(admin.hasAll<Weapon>(e));
REQUIRE(admin.hasAll<ThreatResponseBehavior>(e));
REQUIRE_FALSE(admin.hasAll<SalvageCargo>(e));
REQUIRE_FALSE(admin.hasAll<RepairTool>(e));
REQUIRE_FALSE(admin.hasAll<RepairBehavior>(e));
REQUIRE_FALSE(admin.hasAll<SalvageBehavior>(e));
REQUIRE(admin.hasAll<WeaponComponent>(e));
REQUIRE(admin.hasAll<ThreatResponseBehaviorComponent>(e));
REQUIRE_FALSE(admin.hasAll<SalvageCargoComponent>(e));
REQUIRE_FALSE(admin.hasAll<RepairToolComponent>(e));
REQUIRE_FALSE(admin.hasAll<RepairBehaviorComponent>(e));
REQUIRE_FALSE(admin.hasAll<SalvageBehaviorComponent>(e));
}
TEST_CASE("ShipSystem: interceptor level 1 stats match config formulas", "[ship]")
@@ -50,16 +56,16 @@ TEST_CASE("ShipSystem: interceptor level 1 stats match config formulas", "[ship]
const entt::entity e = ss.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
// hp_formula = "40 + 5*x" at x=1 → 45
REQUIRE(admin.get<Health>(e).maxHp == Approx(45.0f));
REQUIRE(admin.get<Health>(e).hp == Approx(45.0f));
REQUIRE(admin.get<HealthComponent>(e).maxHp == Approx(45.0f));
REQUIRE(admin.get<HealthComponent>(e).hp == Approx(45.0f));
// damage_formula = "10 + 2*x" at x=1 → 12
REQUIRE(admin.get<Weapon>(e).damage == Approx(12.0f));
REQUIRE(admin.get<WeaponComponent>(e).damage == Approx(12.0f));
// attack_range_formula = "150"
REQUIRE(admin.get<Weapon>(e).range == Approx(150.0f));
REQUIRE(admin.get<WeaponComponent>(e).range == Approx(150.0f));
// sensor_range_formula = "200"
REQUIRE(admin.get<SensorRange>(e).value == Approx(200.0f));
REQUIRE(admin.get<SensorRangeComponent>(e).value == Approx(200.0f));
// cooldownTicks starts at 0
REQUIRE(admin.get<Weapon>(e).cooldownTicks == Approx(0.0f));
REQUIRE(admin.get<WeaponComponent>(e).cooldownTicks == Approx(0.0f));
}
TEST_CASE("ShipSystem: interceptor level 5 hp matches formula", "[ship]")
@@ -71,7 +77,7 @@ TEST_CASE("ShipSystem: interceptor level 5 hp matches formula", "[ship]")
const entt::entity e = ss.spawn("interceptor", 5, QVector2D(0.0f, 0.0f));
// hp_formula = "40 + 5*x" at x=5 → 65
REQUIRE(admin.get<Health>(e).maxHp == Approx(65.0f));
REQUIRE(admin.get<HealthComponent>(e).maxHp == Approx(65.0f));
}
TEST_CASE("ShipSystem: interceptor level 0 maxSpeedPerTick matches formula / kTickRateHz", "[ship]")
@@ -100,10 +106,10 @@ TEST_CASE("ShipSystem: salvage_ship spawn has cargo and scrapCollector, no weapo
const entt::entity e = ss.spawn("salvage_ship", 1, QVector2D(0.0f, 0.0f));
REQUIRE(admin.hasAll<SalvageCargo>(e));
REQUIRE(admin.hasAll<SalvageBehavior>(e));
REQUIRE_FALSE(admin.hasAll<Weapon>(e));
REQUIRE_FALSE(admin.hasAll<RepairTool>(e));
REQUIRE(admin.hasAll<SalvageCargoComponent>(e));
REQUIRE(admin.hasAll<SalvageBehaviorComponent>(e));
REQUIRE_FALSE(admin.hasAll<WeaponComponent>(e));
REQUIRE_FALSE(admin.hasAll<RepairToolComponent>(e));
}
TEST_CASE("ShipSystem: salvage_ship cargo capacity matches config", "[ship]")
@@ -115,10 +121,10 @@ TEST_CASE("ShipSystem: salvage_ship cargo capacity matches config", "[ship]")
const entt::entity e = ss.spawn("salvage_ship", 1, QVector2D(0.0f, 0.0f));
// cargo_capacity = 10
REQUIRE(admin.get<SalvageCargo>(e).capacity == 10);
REQUIRE(admin.get<SalvageCargo>(e).current == 0);
REQUIRE(admin.get<SalvageBehavior>(e).deliveryBay == kInvalidBuildingId);
REQUIRE_FALSE(admin.get<SalvageBehavior>(e).scrapTarget.has_value());
REQUIRE(admin.get<SalvageCargoComponent>(e).capacity == 10);
REQUIRE(admin.get<SalvageCargoComponent>(e).current == 0);
REQUIRE(admin.get<SalvageBehaviorComponent>(e).deliveryBay == kInvalidBuildingId);
REQUIRE_FALSE(admin.get<SalvageBehaviorComponent>(e).scrapTarget.has_value());
}
// ---------------------------------------------------------------------------
@@ -134,10 +140,10 @@ TEST_CASE("ShipSystem: repair_ship spawn has repairTool and repairBehavior, no w
const entt::entity e = ss.spawn("repair_ship", 1, QVector2D(0.0f, 0.0f));
REQUIRE(admin.hasAll<RepairTool>(e));
REQUIRE(admin.hasAll<RepairBehavior>(e));
REQUIRE_FALSE(admin.hasAll<Weapon>(e));
REQUIRE_FALSE(admin.hasAll<SalvageCargo>(e));
REQUIRE(admin.hasAll<RepairToolComponent>(e));
REQUIRE(admin.hasAll<RepairBehaviorComponent>(e));
REQUIRE_FALSE(admin.hasAll<WeaponComponent>(e));
REQUIRE_FALSE(admin.hasAll<SalvageCargoComponent>(e));
}
TEST_CASE("ShipSystem: repair_ship level 1 repair stats match config formulas", "[ship]")
@@ -149,9 +155,9 @@ TEST_CASE("ShipSystem: repair_ship level 1 repair stats match config formulas",
const entt::entity e = ss.spawn("repair_ship", 1, QVector2D(0.0f, 0.0f));
// repair_rate_formula = "5 + x" at x=1 → 6
REQUIRE(admin.get<RepairTool>(e).ratePerTick == Approx(6.0f));
REQUIRE(admin.get<RepairToolComponent>(e).ratePerTick == Approx(6.0f));
// repair_range_formula = "80"
REQUIRE(admin.get<RepairTool>(e).range == Approx(80.0f));
REQUIRE(admin.get<RepairToolComponent>(e).range == Approx(80.0f));
}
// ---------------------------------------------------------------------------