|
|
@@ -23,10 +23,10 @@ protected:
|
|
|
};
|
|
|
|
|
|
TEST_F(SerializationTest, EntitySerializationBasic) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
ASSERT_NE(entity, nullptr);
|
|
|
|
|
|
- auto entity_id = entity->getId();
|
|
|
+ auto entity_id = entity->get_id();
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -36,8 +36,8 @@ TEST_F(SerializationTest, EntitySerializationBasic) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, TransformComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *transform = entity->addComponent<TransformComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *transform = entity->add_component<TransformComponent>();
|
|
|
|
|
|
transform->position.x = 10.5F;
|
|
|
transform->position.y = 20.3F;
|
|
|
@@ -48,30 +48,30 @@ TEST_F(SerializationTest, TransformComponentSerialization) {
|
|
|
transform->scale.x = 2.0F;
|
|
|
transform->scale.y = 2.5F;
|
|
|
transform->scale.z = 3.0F;
|
|
|
- transform->hasDesiredYaw = true;
|
|
|
- transform->desiredYaw = 45.0F;
|
|
|
+ transform->has_desired_yaw = true;
|
|
|
+ transform->desired_yaw = 45.0F;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
ASSERT_TRUE(json.contains("transform"));
|
|
|
QJsonObject transform_obj = json["transform"].toObject();
|
|
|
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["posX"].toDouble(), 10.5);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["posY"].toDouble(), 20.3);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["posZ"].toDouble(), 30.1);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["rotX"].toDouble(), 0.5);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["rotY"].toDouble(), 1.0);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["rotZ"].toDouble(), 1.5);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["pos_x"].toDouble(), 10.5);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["pos_y"].toDouble(), 20.3);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["pos_z"].toDouble(), 30.1);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["rot_x"].toDouble(), 0.5);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["rot_y"].toDouble(), 1.0);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["rot_z"].toDouble(), 1.5);
|
|
|
EXPECT_FLOAT_EQ(transform_obj["scale_x"].toDouble(), 2.0);
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["scaleY"].toDouble(), 2.5);
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["scale_y"].toDouble(), 2.5);
|
|
|
EXPECT_FLOAT_EQ(transform_obj["scale_z"].toDouble(), 3.0);
|
|
|
- EXPECT_TRUE(transform_obj["hasDesiredYaw"].toBool());
|
|
|
- EXPECT_FLOAT_EQ(transform_obj["desiredYaw"].toDouble(), 45.0);
|
|
|
+ EXPECT_TRUE(transform_obj["has_desired_yaw"].toBool());
|
|
|
+ EXPECT_FLOAT_EQ(transform_obj["desired_yaw"].toDouble(), 45.0);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, UnitComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *unit = entity->addComponent<UnitComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *unit = entity->add_component<UnitComponent>();
|
|
|
|
|
|
unit->health = 80;
|
|
|
unit->max_health = 100;
|
|
|
@@ -96,22 +96,22 @@ TEST_F(SerializationTest, UnitComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, MovementComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *movement = entity->addComponent<MovementComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *movement = entity->add_component<MovementComponent>();
|
|
|
|
|
|
- movement->hasTarget = true;
|
|
|
+ movement->has_target = true;
|
|
|
movement->target_x = 50.0F;
|
|
|
movement->target_y = 60.0F;
|
|
|
- movement->goalX = 55.0F;
|
|
|
- movement->goalY = 65.0F;
|
|
|
+ movement->goal_x = 55.0F;
|
|
|
+ movement->goal_y = 65.0F;
|
|
|
movement->vx = 1.5F;
|
|
|
movement->vz = 2.0F;
|
|
|
- movement->pathPending = false;
|
|
|
- movement->pendingRequestId = 42;
|
|
|
- movement->repathCooldown = 1.0F;
|
|
|
- movement->lastGoalX = 45.0F;
|
|
|
- movement->lastGoalY = 55.0F;
|
|
|
- movement->timeSinceLastPathRequest = 0.5F;
|
|
|
+ movement->path_pending = false;
|
|
|
+ movement->pending_request_id = 42;
|
|
|
+ movement->repath_cooldown = 1.0F;
|
|
|
+ movement->last_goal_x = 45.0F;
|
|
|
+ movement->last_goal_y = 55.0F;
|
|
|
+ movement->time_since_last_path_request = 0.5F;
|
|
|
|
|
|
movement->path.emplace_back(10.0F, 20.0F);
|
|
|
movement->path.emplace_back(30.0F, 40.0F);
|
|
|
@@ -121,15 +121,16 @@ TEST_F(SerializationTest, MovementComponentSerialization) {
|
|
|
ASSERT_TRUE(json.contains("movement"));
|
|
|
QJsonObject movement_obj = json["movement"].toObject();
|
|
|
|
|
|
- EXPECT_TRUE(movement_obj["hasTarget"].toBool());
|
|
|
+ EXPECT_TRUE(movement_obj["has_target"].toBool());
|
|
|
EXPECT_FLOAT_EQ(movement_obj["target_x"].toDouble(), 50.0);
|
|
|
EXPECT_FLOAT_EQ(movement_obj["target_y"].toDouble(), 60.0);
|
|
|
- EXPECT_FLOAT_EQ(movement_obj["goalX"].toDouble(), 55.0);
|
|
|
- EXPECT_FLOAT_EQ(movement_obj["goalY"].toDouble(), 65.0);
|
|
|
+ EXPECT_FLOAT_EQ(movement_obj["goal_x"].toDouble(), 55.0);
|
|
|
+ EXPECT_FLOAT_EQ(movement_obj["goal_y"].toDouble(), 65.0);
|
|
|
EXPECT_FLOAT_EQ(movement_obj["vx"].toDouble(), 1.5);
|
|
|
EXPECT_FLOAT_EQ(movement_obj["vz"].toDouble(), 2.0);
|
|
|
- EXPECT_FALSE(movement_obj["pathPending"].toBool());
|
|
|
- EXPECT_EQ(movement_obj["pendingRequestId"].toVariant().toULongLong(), 42ULL);
|
|
|
+ EXPECT_FALSE(movement_obj["path_pending"].toBool());
|
|
|
+ EXPECT_EQ(movement_obj["pending_request_id"].toVariant().toULongLong(),
|
|
|
+ 42ULL);
|
|
|
|
|
|
ASSERT_TRUE(movement_obj.contains("path"));
|
|
|
QJsonArray path_array = movement_obj["path"].toArray();
|
|
|
@@ -145,23 +146,23 @@ TEST_F(SerializationTest, MovementComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, AttackComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *attack = entity->addComponent<AttackComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *attack = entity->add_component<AttackComponent>();
|
|
|
|
|
|
attack->range = 10.0F;
|
|
|
attack->damage = 25;
|
|
|
attack->cooldown = 2.0F;
|
|
|
- attack->timeSinceLast = 0.5F;
|
|
|
- attack->meleeRange = 2.0F;
|
|
|
- attack->meleeDamage = 15;
|
|
|
- attack->meleeCooldown = 1.5F;
|
|
|
- attack->preferredMode = AttackComponent::CombatMode::Ranged;
|
|
|
- attack->currentMode = AttackComponent::CombatMode::Ranged;
|
|
|
- attack->canMelee = true;
|
|
|
- attack->canRanged = true;
|
|
|
- attack->max_heightDifference = 5.0F;
|
|
|
- attack->inMeleeLock = false;
|
|
|
- attack->meleeLockTargetId = 0;
|
|
|
+ attack->time_since_last = 0.5F;
|
|
|
+ attack->melee_range = 2.0F;
|
|
|
+ attack->melee_damage = 15;
|
|
|
+ attack->melee_cooldown = 1.5F;
|
|
|
+ attack->preferred_mode = AttackComponent::CombatMode::Ranged;
|
|
|
+ attack->current_mode = AttackComponent::CombatMode::Ranged;
|
|
|
+ attack->can_melee = true;
|
|
|
+ attack->can_ranged = true;
|
|
|
+ attack->max_height_difference = 5.0F;
|
|
|
+ attack->in_melee_lock = false;
|
|
|
+ attack->melee_lock_target_id = 0;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -171,42 +172,43 @@ TEST_F(SerializationTest, AttackComponentSerialization) {
|
|
|
EXPECT_FLOAT_EQ(attack_obj["range"].toDouble(), 10.0);
|
|
|
EXPECT_EQ(attack_obj["damage"].toInt(), 25);
|
|
|
EXPECT_FLOAT_EQ(attack_obj["cooldown"].toDouble(), 2.0);
|
|
|
- EXPECT_FLOAT_EQ(attack_obj["timeSinceLast"].toDouble(), 0.5);
|
|
|
- EXPECT_FLOAT_EQ(attack_obj["meleeRange"].toDouble(), 2.0);
|
|
|
- EXPECT_EQ(attack_obj["meleeDamage"].toInt(), 15);
|
|
|
- EXPECT_FLOAT_EQ(attack_obj["meleeCooldown"].toDouble(), 1.5);
|
|
|
- EXPECT_EQ(attack_obj["preferredMode"].toString(), QString("ranged"));
|
|
|
- EXPECT_EQ(attack_obj["currentMode"].toString(), QString("ranged"));
|
|
|
- EXPECT_TRUE(attack_obj["canMelee"].toBool());
|
|
|
- EXPECT_TRUE(attack_obj["canRanged"].toBool());
|
|
|
- EXPECT_FLOAT_EQ(attack_obj["max_heightDifference"].toDouble(), 5.0);
|
|
|
- EXPECT_FALSE(attack_obj["inMeleeLock"].toBool());
|
|
|
+ EXPECT_FLOAT_EQ(attack_obj["time_since_last"].toDouble(), 0.5);
|
|
|
+ EXPECT_FLOAT_EQ(attack_obj["melee_range"].toDouble(), 2.0);
|
|
|
+ EXPECT_EQ(attack_obj["melee_damage"].toInt(), 15);
|
|
|
+ EXPECT_FLOAT_EQ(attack_obj["melee_cooldown"].toDouble(), 1.5);
|
|
|
+ EXPECT_EQ(attack_obj["preferred_mode"].toString(), QString("ranged"));
|
|
|
+ EXPECT_EQ(attack_obj["current_mode"].toString(), QString("ranged"));
|
|
|
+ EXPECT_TRUE(attack_obj["can_melee"].toBool());
|
|
|
+ EXPECT_TRUE(attack_obj["can_ranged"].toBool());
|
|
|
+ EXPECT_FLOAT_EQ(attack_obj["max_height_difference"].toDouble(), 5.0);
|
|
|
+ EXPECT_FALSE(attack_obj["in_melee_lock"].toBool());
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, EntityDeserializationRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- auto *transform = original_entity->addComponent<TransformComponent>();
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ auto *transform = original_entity->add_component<TransformComponent>();
|
|
|
transform->position.x = 100.0F;
|
|
|
transform->position.y = 200.0F;
|
|
|
transform->position.z = 300.0F;
|
|
|
|
|
|
- auto *unit = original_entity->addComponent<UnitComponent>();
|
|
|
+ auto *unit = original_entity->add_component<UnitComponent>();
|
|
|
unit->health = 75;
|
|
|
unit->max_health = 100;
|
|
|
unit->speed = 6.0F;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized_transform = new_entity->getComponent<TransformComponent>();
|
|
|
+ auto *deserialized_transform =
|
|
|
+ new_entity->get_component<TransformComponent>();
|
|
|
ASSERT_NE(deserialized_transform, nullptr);
|
|
|
EXPECT_FLOAT_EQ(deserialized_transform->position.x, 100.0F);
|
|
|
EXPECT_FLOAT_EQ(deserialized_transform->position.y, 200.0F);
|
|
|
EXPECT_FLOAT_EQ(deserialized_transform->position.z, 300.0F);
|
|
|
|
|
|
- auto *deserialized_unit = new_entity->getComponent<UnitComponent>();
|
|
|
+ auto *deserialized_unit = new_entity->get_component<UnitComponent>();
|
|
|
ASSERT_NE(deserialized_unit, nullptr);
|
|
|
EXPECT_EQ(deserialized_unit->health, 75);
|
|
|
EXPECT_EQ(deserialized_unit->max_health, 100);
|
|
|
@@ -221,10 +223,10 @@ TEST_F(SerializationTest, DeserializationWithMissingFields) {
|
|
|
unit_obj["health"] = 50;
|
|
|
json["unit"] = unit_obj;
|
|
|
|
|
|
- auto *entity = world->createEntity();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(entity, json);
|
|
|
|
|
|
- auto *unit = entity->getComponent<UnitComponent>();
|
|
|
+ auto *unit = entity->get_component<UnitComponent>();
|
|
|
ASSERT_NE(unit, nullptr);
|
|
|
EXPECT_EQ(unit->health, 50);
|
|
|
EXPECT_EQ(unit->max_health, Defaults::kUnitDefaultHealth);
|
|
|
@@ -235,25 +237,25 @@ TEST_F(SerializationTest, DeserializationWithMalformedJSON) {
|
|
|
json["id"] = 1;
|
|
|
|
|
|
QJsonObject transform_obj;
|
|
|
- transform_obj["posX"] = "not_a_number";
|
|
|
+ transform_obj["pos_x"] = "not_a_number";
|
|
|
json["transform"] = transform_obj;
|
|
|
|
|
|
- auto *entity = world->createEntity();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
|
|
|
EXPECT_NO_THROW({ Serialization::deserializeEntity(entity, json); });
|
|
|
|
|
|
- auto *transform = entity->getComponent<TransformComponent>();
|
|
|
+ auto *transform = entity->get_component<TransformComponent>();
|
|
|
ASSERT_NE(transform, nullptr);
|
|
|
EXPECT_FLOAT_EQ(transform->position.x, 0.0F);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, WorldSerializationRoundTrip) {
|
|
|
- auto *entity1 = world->createEntity();
|
|
|
- auto *transform1 = entity1->addComponent<TransformComponent>();
|
|
|
+ auto *entity1 = world->create_entity();
|
|
|
+ auto *transform1 = entity1->add_component<TransformComponent>();
|
|
|
transform1->position.x = 10.0F;
|
|
|
|
|
|
- auto *entity2 = world->createEntity();
|
|
|
- auto *transform2 = entity2->addComponent<TransformComponent>();
|
|
|
+ auto *entity2 = world->create_entity();
|
|
|
+ auto *transform2 = entity2->add_component<TransformComponent>();
|
|
|
transform2->position.x = 20.0F;
|
|
|
|
|
|
QJsonDocument doc = Serialization::serializeWorld(world.get());
|
|
|
@@ -267,13 +269,13 @@ TEST_F(SerializationTest, WorldSerializationRoundTrip) {
|
|
|
auto new_world = std::make_unique<World>();
|
|
|
Serialization::deserializeWorld(new_world.get(), doc);
|
|
|
|
|
|
- const auto &entities = new_world->getEntities();
|
|
|
+ const auto &entities = new_world->get_entities();
|
|
|
EXPECT_EQ(entities.size(), 2UL);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, SaveAndLoadFromFile) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *transform = entity->addComponent<TransformComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *transform = entity->add_component<TransformComponent>();
|
|
|
transform->position.x = 42.0F;
|
|
|
transform->position.y = 43.0F;
|
|
|
transform->position.z = 44.0F;
|
|
|
@@ -293,12 +295,12 @@ TEST_F(SerializationTest, SaveAndLoadFromFile) {
|
|
|
auto new_world = std::make_unique<World>();
|
|
|
Serialization::deserializeWorld(new_world.get(), loaded_doc);
|
|
|
|
|
|
- const auto &entities = new_world->getEntities();
|
|
|
+ const auto &entities = new_world->get_entities();
|
|
|
EXPECT_EQ(entities.size(), 1UL);
|
|
|
|
|
|
if (!entities.empty()) {
|
|
|
auto *loaded_entity = entities.begin()->second.get();
|
|
|
- auto *loaded_transform = loaded_entity->getComponent<TransformComponent>();
|
|
|
+ auto *loaded_transform = loaded_entity->get_component<TransformComponent>();
|
|
|
ASSERT_NE(loaded_transform, nullptr);
|
|
|
EXPECT_FLOAT_EQ(loaded_transform->position.x, 42.0F);
|
|
|
EXPECT_FLOAT_EQ(loaded_transform->position.y, 43.0F);
|
|
|
@@ -307,37 +309,37 @@ TEST_F(SerializationTest, SaveAndLoadFromFile) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, ProductionComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *production = entity->addComponent<ProductionComponent>();
|
|
|
-
|
|
|
- production->inProgress = true;
|
|
|
- production->buildTime = 10.0F;
|
|
|
- production->timeRemaining = 5.0F;
|
|
|
- production->producedCount = 3;
|
|
|
- production->maxUnits = 10;
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *production = entity->add_component<ProductionComponent>();
|
|
|
+
|
|
|
+ production->in_progress = true;
|
|
|
+ production->build_time = 10.0F;
|
|
|
+ production->time_remaining = 5.0F;
|
|
|
+ production->produced_count = 3;
|
|
|
+ production->max_units = 10;
|
|
|
production->product_type = Game::Units::TroopType::Archer;
|
|
|
- production->rallyX = 100.0F;
|
|
|
- production->rallyZ = 200.0F;
|
|
|
- production->rallySet = true;
|
|
|
- production->villagerCost = 2;
|
|
|
- production->productionQueue.push_back(Game::Units::TroopType::Spearman);
|
|
|
- production->productionQueue.push_back(Game::Units::TroopType::Archer);
|
|
|
+ production->rally_x = 100.0F;
|
|
|
+ production->rally_z = 200.0F;
|
|
|
+ production->rally_set = true;
|
|
|
+ production->villager_cost = 2;
|
|
|
+ production->production_queue.push_back(Game::Units::TroopType::Spearman);
|
|
|
+ production->production_queue.push_back(Game::Units::TroopType::Archer);
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
ASSERT_TRUE(json.contains("production"));
|
|
|
QJsonObject prod_obj = json["production"].toObject();
|
|
|
|
|
|
- EXPECT_TRUE(prod_obj["inProgress"].toBool());
|
|
|
- EXPECT_FLOAT_EQ(prod_obj["buildTime"].toDouble(), 10.0);
|
|
|
- EXPECT_FLOAT_EQ(prod_obj["timeRemaining"].toDouble(), 5.0);
|
|
|
- EXPECT_EQ(prod_obj["producedCount"].toInt(), 3);
|
|
|
- EXPECT_EQ(prod_obj["maxUnits"].toInt(), 10);
|
|
|
+ EXPECT_TRUE(prod_obj["in_progress"].toBool());
|
|
|
+ EXPECT_FLOAT_EQ(prod_obj["build_time"].toDouble(), 10.0);
|
|
|
+ EXPECT_FLOAT_EQ(prod_obj["time_remaining"].toDouble(), 5.0);
|
|
|
+ EXPECT_EQ(prod_obj["produced_count"].toInt(), 3);
|
|
|
+ EXPECT_EQ(prod_obj["max_units"].toInt(), 10);
|
|
|
EXPECT_EQ(prod_obj["product_type"].toString(), QString("archer"));
|
|
|
- EXPECT_FLOAT_EQ(prod_obj["rallyX"].toDouble(), 100.0);
|
|
|
- EXPECT_FLOAT_EQ(prod_obj["rallyZ"].toDouble(), 200.0);
|
|
|
- EXPECT_TRUE(prod_obj["rallySet"].toBool());
|
|
|
- EXPECT_EQ(prod_obj["villagerCost"].toInt(), 2);
|
|
|
+ EXPECT_FLOAT_EQ(prod_obj["rally_x"].toDouble(), 100.0);
|
|
|
+ EXPECT_FLOAT_EQ(prod_obj["rally_z"].toDouble(), 200.0);
|
|
|
+ EXPECT_TRUE(prod_obj["rally_set"].toBool());
|
|
|
+ EXPECT_EQ(prod_obj["villager_cost"].toInt(), 2);
|
|
|
|
|
|
ASSERT_TRUE(prod_obj.contains("queue"));
|
|
|
QJsonArray queue = prod_obj["queue"].toArray();
|
|
|
@@ -347,10 +349,10 @@ TEST_F(SerializationTest, ProductionComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, PatrolComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *patrol = entity->addComponent<PatrolComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *patrol = entity->add_component<PatrolComponent>();
|
|
|
|
|
|
- patrol->currentWaypoint = 1;
|
|
|
+ patrol->current_waypoint = 1;
|
|
|
patrol->patrolling = true;
|
|
|
patrol->waypoints.emplace_back(10.0F, 20.0F);
|
|
|
patrol->waypoints.emplace_back(30.0F, 40.0F);
|
|
|
@@ -361,7 +363,7 @@ TEST_F(SerializationTest, PatrolComponentSerialization) {
|
|
|
ASSERT_TRUE(json.contains("patrol"));
|
|
|
QJsonObject patrol_obj = json["patrol"].toObject();
|
|
|
|
|
|
- EXPECT_EQ(patrol_obj["currentWaypoint"].toInt(), 1);
|
|
|
+ EXPECT_EQ(patrol_obj["current_waypoint"].toInt(), 1);
|
|
|
EXPECT_TRUE(patrol_obj["patrolling"].toBool());
|
|
|
|
|
|
ASSERT_TRUE(patrol_obj.contains("waypoints"));
|
|
|
@@ -374,13 +376,13 @@ TEST_F(SerializationTest, PatrolComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, RenderableComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
auto *renderable =
|
|
|
- entity->addComponent<RenderableComponent>("mesh.obj", "texture.png");
|
|
|
+ entity->add_component<RenderableComponent>("mesh.obj", "texture.png");
|
|
|
|
|
|
- renderable->meshPath = "models/archer.obj";
|
|
|
- renderable->texturePath = "textures/archer_diffuse.png";
|
|
|
- renderable->rendererId = "archer_renderer";
|
|
|
+ renderable->mesh_path = "models/archer.obj";
|
|
|
+ renderable->texture_path = "textures/archer_diffuse.png";
|
|
|
+ renderable->renderer_id = "archer_renderer";
|
|
|
renderable->visible = true;
|
|
|
renderable->mesh = RenderableComponent::MeshKind::Capsule;
|
|
|
renderable->color = {0.8F, 0.2F, 0.5F};
|
|
|
@@ -390,11 +392,11 @@ TEST_F(SerializationTest, RenderableComponentSerialization) {
|
|
|
ASSERT_TRUE(json.contains("renderable"));
|
|
|
QJsonObject renderable_obj = json["renderable"].toObject();
|
|
|
|
|
|
- EXPECT_EQ(renderable_obj["meshPath"].toString(),
|
|
|
+ EXPECT_EQ(renderable_obj["mesh_path"].toString(),
|
|
|
QString("models/archer.obj"));
|
|
|
- EXPECT_EQ(renderable_obj["texturePath"].toString(),
|
|
|
+ EXPECT_EQ(renderable_obj["texture_path"].toString(),
|
|
|
QString("textures/archer_diffuse.png"));
|
|
|
- EXPECT_EQ(renderable_obj["rendererId"].toString(),
|
|
|
+ EXPECT_EQ(renderable_obj["renderer_id"].toString(),
|
|
|
QString("archer_renderer"));
|
|
|
EXPECT_TRUE(renderable_obj["visible"].toBool());
|
|
|
EXPECT_EQ(renderable_obj["mesh"].toInt(),
|
|
|
@@ -409,24 +411,24 @@ TEST_F(SerializationTest, RenderableComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, RenderableComponentRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- auto *renderable = original_entity->addComponent<RenderableComponent>(
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ auto *renderable = original_entity->add_component<RenderableComponent>(
|
|
|
"test.obj", "test.png");
|
|
|
- renderable->meshPath = "models/building.obj";
|
|
|
- renderable->texturePath = "textures/building.png";
|
|
|
+ renderable->mesh_path = "models/building.obj";
|
|
|
+ renderable->texture_path = "textures/building.png";
|
|
|
renderable->visible = false;
|
|
|
renderable->mesh = RenderableComponent::MeshKind::Quad;
|
|
|
renderable->color = {1.0F, 0.5F, 0.25F};
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized = new_entity->getComponent<RenderableComponent>();
|
|
|
+ auto *deserialized = new_entity->get_component<RenderableComponent>();
|
|
|
ASSERT_NE(deserialized, nullptr);
|
|
|
- EXPECT_EQ(deserialized->meshPath, "models/building.obj");
|
|
|
- EXPECT_EQ(deserialized->texturePath, "textures/building.png");
|
|
|
+ EXPECT_EQ(deserialized->mesh_path, "models/building.obj");
|
|
|
+ EXPECT_EQ(deserialized->texture_path, "textures/building.png");
|
|
|
EXPECT_FALSE(deserialized->visible);
|
|
|
EXPECT_EQ(deserialized->mesh, RenderableComponent::MeshKind::Quad);
|
|
|
EXPECT_FLOAT_EQ(deserialized->color[0], 1.0F);
|
|
|
@@ -435,11 +437,11 @@ TEST_F(SerializationTest, RenderableComponentRoundTrip) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, AttackTargetComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *attack_target = entity->addComponent<AttackTargetComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *attack_target = entity->add_component<AttackTargetComponent>();
|
|
|
|
|
|
attack_target->target_id = 42;
|
|
|
- attack_target->shouldChase = true;
|
|
|
+ attack_target->should_chase = true;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -447,29 +449,29 @@ TEST_F(SerializationTest, AttackTargetComponentSerialization) {
|
|
|
QJsonObject attack_target_obj = json["attack_target"].toObject();
|
|
|
|
|
|
EXPECT_EQ(attack_target_obj["target_id"].toVariant().toULongLong(), 42ULL);
|
|
|
- EXPECT_TRUE(attack_target_obj["shouldChase"].toBool());
|
|
|
+ EXPECT_TRUE(attack_target_obj["should_chase"].toBool());
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, AttackTargetComponentRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- auto *attack_target = original_entity->addComponent<AttackTargetComponent>();
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ auto *attack_target = original_entity->add_component<AttackTargetComponent>();
|
|
|
attack_target->target_id = 123;
|
|
|
- attack_target->shouldChase = false;
|
|
|
+ attack_target->should_chase = false;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized = new_entity->getComponent<AttackTargetComponent>();
|
|
|
+ auto *deserialized = new_entity->get_component<AttackTargetComponent>();
|
|
|
ASSERT_NE(deserialized, nullptr);
|
|
|
EXPECT_EQ(deserialized->target_id, 123U);
|
|
|
- EXPECT_FALSE(deserialized->shouldChase);
|
|
|
+ EXPECT_FALSE(deserialized->should_chase);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, BuildingComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- entity->addComponent<BuildingComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ entity->add_component<BuildingComponent>();
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -478,21 +480,21 @@ TEST_F(SerializationTest, BuildingComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, BuildingComponentRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- original_entity->addComponent<BuildingComponent>();
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ original_entity->add_component<BuildingComponent>();
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized = new_entity->getComponent<BuildingComponent>();
|
|
|
+ auto *deserialized = new_entity->get_component<BuildingComponent>();
|
|
|
ASSERT_NE(deserialized, nullptr);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, AIControlledComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- entity->addComponent<AIControlledComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ entity->add_component<AIControlledComponent>();
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -501,26 +503,26 @@ TEST_F(SerializationTest, AIControlledComponentSerialization) {
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, AIControlledComponentRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- original_entity->addComponent<AIControlledComponent>();
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ original_entity->add_component<AIControlledComponent>();
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized = new_entity->getComponent<AIControlledComponent>();
|
|
|
+ auto *deserialized = new_entity->get_component<AIControlledComponent>();
|
|
|
ASSERT_NE(deserialized, nullptr);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, CaptureComponentSerialization) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
- auto *capture = entity->addComponent<CaptureComponent>();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
+ auto *capture = entity->add_component<CaptureComponent>();
|
|
|
|
|
|
capture->capturing_player_id = 2;
|
|
|
- capture->captureProgress = 7.5F;
|
|
|
- capture->requiredTime = 15.0F;
|
|
|
- capture->isBeingCaptured = true;
|
|
|
+ capture->capture_progress = 7.5F;
|
|
|
+ capture->required_time = 15.0F;
|
|
|
+ capture->is_being_captured = true;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -528,67 +530,67 @@ TEST_F(SerializationTest, CaptureComponentSerialization) {
|
|
|
QJsonObject capture_obj = json["capture"].toObject();
|
|
|
|
|
|
EXPECT_EQ(capture_obj["capturing_player_id"].toInt(), 2);
|
|
|
- EXPECT_FLOAT_EQ(capture_obj["captureProgress"].toDouble(), 7.5);
|
|
|
- EXPECT_FLOAT_EQ(capture_obj["requiredTime"].toDouble(), 15.0);
|
|
|
- EXPECT_TRUE(capture_obj["isBeingCaptured"].toBool());
|
|
|
+ EXPECT_FLOAT_EQ(capture_obj["capture_progress"].toDouble(), 7.5);
|
|
|
+ EXPECT_FLOAT_EQ(capture_obj["required_time"].toDouble(), 15.0);
|
|
|
+ EXPECT_TRUE(capture_obj["is_being_captured"].toBool());
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, CaptureComponentRoundTrip) {
|
|
|
- auto *original_entity = world->createEntity();
|
|
|
- auto *capture = original_entity->addComponent<CaptureComponent>();
|
|
|
+ auto *original_entity = world->create_entity();
|
|
|
+ auto *capture = original_entity->add_component<CaptureComponent>();
|
|
|
capture->capturing_player_id = 3;
|
|
|
- capture->captureProgress = 10.0F;
|
|
|
- capture->requiredTime = 20.0F;
|
|
|
- capture->isBeingCaptured = false;
|
|
|
+ capture->capture_progress = 10.0F;
|
|
|
+ capture->required_time = 20.0F;
|
|
|
+ capture->is_being_captured = false;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(original_entity);
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- auto *deserialized = new_entity->getComponent<CaptureComponent>();
|
|
|
+ auto *deserialized = new_entity->get_component<CaptureComponent>();
|
|
|
ASSERT_NE(deserialized, nullptr);
|
|
|
EXPECT_EQ(deserialized->capturing_player_id, 3);
|
|
|
- EXPECT_FLOAT_EQ(deserialized->captureProgress, 10.0F);
|
|
|
- EXPECT_FLOAT_EQ(deserialized->requiredTime, 20.0F);
|
|
|
- EXPECT_FALSE(deserialized->isBeingCaptured);
|
|
|
+ EXPECT_FLOAT_EQ(deserialized->capture_progress, 10.0F);
|
|
|
+ EXPECT_FLOAT_EQ(deserialized->required_time, 20.0F);
|
|
|
+ EXPECT_FALSE(deserialized->is_being_captured);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, CompleteEntityWithAllComponents) {
|
|
|
- auto *entity = world->createEntity();
|
|
|
+ auto *entity = world->create_entity();
|
|
|
|
|
|
- auto *transform = entity->addComponent<TransformComponent>();
|
|
|
+ auto *transform = entity->add_component<TransformComponent>();
|
|
|
transform->position.x = 50.0F;
|
|
|
transform->position.y = 10.0F;
|
|
|
transform->position.z = 30.0F;
|
|
|
|
|
|
auto *renderable =
|
|
|
- entity->addComponent<RenderableComponent>("mesh.obj", "tex.png");
|
|
|
+ entity->add_component<RenderableComponent>("mesh.obj", "tex.png");
|
|
|
renderable->visible = true;
|
|
|
|
|
|
- auto *unit = entity->addComponent<UnitComponent>();
|
|
|
+ auto *unit = entity->add_component<UnitComponent>();
|
|
|
unit->health = 100;
|
|
|
unit->max_health = 100;
|
|
|
|
|
|
- auto *movement = entity->addComponent<MovementComponent>();
|
|
|
- movement->hasTarget = true;
|
|
|
+ auto *movement = entity->add_component<MovementComponent>();
|
|
|
+ movement->has_target = true;
|
|
|
movement->target_x = 100.0F;
|
|
|
|
|
|
- auto *attack = entity->addComponent<AttackComponent>();
|
|
|
+ auto *attack = entity->add_component<AttackComponent>();
|
|
|
attack->damage = 25;
|
|
|
|
|
|
- auto *attack_target = entity->addComponent<AttackTargetComponent>();
|
|
|
+ auto *attack_target = entity->add_component<AttackTargetComponent>();
|
|
|
attack_target->target_id = 99;
|
|
|
|
|
|
- entity->addComponent<BuildingComponent>();
|
|
|
+ entity->add_component<BuildingComponent>();
|
|
|
|
|
|
- auto *production = entity->addComponent<ProductionComponent>();
|
|
|
- production->inProgress = true;
|
|
|
+ auto *production = entity->add_component<ProductionComponent>();
|
|
|
+ production->in_progress = true;
|
|
|
|
|
|
- entity->addComponent<AIControlledComponent>();
|
|
|
+ entity->add_component<AIControlledComponent>();
|
|
|
|
|
|
- auto *capture = entity->addComponent<CaptureComponent>();
|
|
|
- capture->isBeingCaptured = true;
|
|
|
+ auto *capture = entity->add_component<CaptureComponent>();
|
|
|
+ capture->is_being_captured = true;
|
|
|
|
|
|
QJsonObject json = Serialization::serializeEntity(entity);
|
|
|
|
|
|
@@ -603,19 +605,19 @@ TEST_F(SerializationTest, CompleteEntityWithAllComponents) {
|
|
|
EXPECT_TRUE(json.contains("aiControlled"));
|
|
|
EXPECT_TRUE(json.contains("capture"));
|
|
|
|
|
|
- auto *new_entity = world->createEntity();
|
|
|
+ auto *new_entity = world->create_entity();
|
|
|
Serialization::deserializeEntity(new_entity, json);
|
|
|
|
|
|
- EXPECT_NE(new_entity->getComponent<TransformComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<RenderableComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<UnitComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<MovementComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<AttackComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<AttackTargetComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<BuildingComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<ProductionComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<AIControlledComponent>(), nullptr);
|
|
|
- EXPECT_NE(new_entity->getComponent<CaptureComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<TransformComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<RenderableComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<UnitComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<MovementComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<AttackComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<AttackTargetComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<BuildingComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<ProductionComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<AIControlledComponent>(), nullptr);
|
|
|
+ EXPECT_NE(new_entity->get_component<CaptureComponent>(), nullptr);
|
|
|
}
|
|
|
|
|
|
TEST_F(SerializationTest, EmptyWorldSerialization) {
|