minor bug fix & general test cases made for EC
This commit is contained in:
parent
cf2eb575fc
commit
e4412bcdaa
@ -341,13 +341,13 @@ EntityConverter::convertPlayerSpawn(std::vector<std::string> &lines)
|
|||||||
if ( ! isModeRace ) {
|
if ( ! isModeRace ) {
|
||||||
switch (team) {
|
switch (team) {
|
||||||
case 0:
|
case 0:
|
||||||
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"" );
|
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" );
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
convertedLines.push_back ( "\"classname\" \"info_player_team1\"" );
|
convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" );
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
convertedLines.push_back ( "\"classname\" \"info_player_team2\"" );
|
convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,26 +476,25 @@ EntityConverter::convertTarget(std::vector<std::string> &lines)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( havePosition && haveName) {
|
if ( havePosition && haveName) {
|
||||||
//**! no way to tell if teleporter or jump pad dest from targetName alone
|
|
||||||
if ( targetMap_[targetName] == "Teleporter") {
|
if ( targetMap_[targetName] == "Teleporter") {
|
||||||
convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" );
|
convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" );
|
||||||
}
|
}
|
||||||
else if ( targetMap_[targetName] == "JumpPad") {
|
else if ( targetMap_[targetName] == "JumpPad") {
|
||||||
convertedLines.push_back ( "\"classname\" \"target_push\"\n" );
|
convertedLines.push_back ( "\"classname\" \"target_position\"\n" );
|
||||||
}
|
}
|
||||||
std::stringstream oss;
|
|
||||||
oss << "\"targetname\" \"" << targetName << "\"\n";
|
|
||||||
convertedLines.push_back ( oss.str() );
|
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
std::stringstream oss2;
|
std::stringstream oss2;
|
||||||
oss2 << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
oss2 << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
coords[1] << "\"" << std::endl;
|
coords[1] << "\"" << std::endl;
|
||||||
convertedLines.push_back ( oss2.str() );
|
convertedLines.push_back ( oss2.str() );
|
||||||
|
std::stringstream oss;
|
||||||
|
oss << "\"targetname\" \"" << targetName << "\"" << std::endl;
|
||||||
|
convertedLines.push_back ( oss.str() );
|
||||||
|
|
||||||
// Write angle only if position and name exist
|
// Write angle only if position and name exist
|
||||||
if ( haveAngle ) {
|
if ( haveAngle ) {
|
||||||
std::stringstream oss3;
|
std::stringstream oss3;
|
||||||
oss3 << "\"angle\" \"" << angle << "\"\n";
|
oss3 << "\"angle\" \"" << angle << "\"" << std::endl;
|
||||||
convertedLines.push_back (oss3.str() );
|
convertedLines.push_back (oss3.str() );
|
||||||
}
|
}
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
@ -512,9 +511,9 @@ std::vector<std::string>
|
|||||||
EntityConverter::convertRaceStart(std::vector<std::string> &lines)
|
EntityConverter::convertRaceStart(std::vector<std::string> &lines)
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"");
|
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
convertedLines.push_back ("\"targetname\" \"cp1\"");
|
convertedLines.push_back ("\"targetname\" \"cp1\"\n");
|
||||||
convertedLines.push_back ("\"cnt\" \"1\"");
|
convertedLines.push_back ("\"cnt\" \"1\"\n");
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,9 +523,9 @@ std::vector<std::string>
|
|||||||
EntityConverter::convertRaceFinish(std::vector<std::string> &lines)
|
EntityConverter::convertRaceFinish(std::vector<std::string> &lines)
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"");
|
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
convertedLines.push_back ("\"targetname\" \"finish\"");
|
convertedLines.push_back ("\"targetname\" \"finish\"\n");
|
||||||
convertedLines.push_back ("\"cnt\" \"0\"");
|
convertedLines.push_back ("\"cnt\" \"0\"\n");
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single pickup entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE( "r2x: a single Pickup entity can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (PICKUP_FILENAME);
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
@ -41,14 +41,172 @@ TEST_CASE( "r2x: a single pickup entity can be converted", "[EntityConverter]" )
|
|||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.matchRelated( q );
|
ec.matchRelated( q );
|
||||||
|
|
||||||
// (only a single pickup entity)
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n" );
|
REQUIRE( converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "r2x: a single PlayerSpawn (teamA) entity can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
|
// Instantiate object
|
||||||
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
|
|
||||||
|
// Mock up entity
|
||||||
|
std::vector<std::string> entity;
|
||||||
|
entity.push_back(" type PlayerSpawn");
|
||||||
|
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
|
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
|
entity.push_back(" Bool8 teamB 0");
|
||||||
|
entity.push_back(" Bool8 modeRace 0");
|
||||||
|
|
||||||
|
// Mock up entity queue
|
||||||
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
|
||||||
|
// Match related entities (none)
|
||||||
|
ec.matchRelated( q );
|
||||||
|
|
||||||
|
// Convert a single entity
|
||||||
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
|
REQUIRE( converted[0] == "\"classname\" \"info_player_team1\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
||||||
|
REQUIRE( converted[2] == "\"angle\" \"180.00000\"\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "r2x: a single RaceStart entity can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
|
// Instantiate object
|
||||||
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
|
|
||||||
|
// Mock up entity
|
||||||
|
std::vector<std::string> entity;
|
||||||
|
entity.push_back(" type RaceStart");
|
||||||
|
|
||||||
|
// Mock up entity queue
|
||||||
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
|
||||||
|
// Match related entities (none)
|
||||||
|
ec.matchRelated( q );
|
||||||
|
|
||||||
|
// Convert a single entity
|
||||||
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
|
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"targetname\" \"cp1\"\n" );
|
||||||
|
REQUIRE( converted[2] == "\"cnt\" \"1\"\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "r2x: a single RaceFinish entity can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
|
// Instantiate object
|
||||||
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
|
|
||||||
|
// Mock up entity
|
||||||
|
std::vector<std::string> entity;
|
||||||
|
entity.push_back(" type RaceFinish");
|
||||||
|
|
||||||
|
// Mock up entity queue
|
||||||
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
|
||||||
|
// Match related entities (none)
|
||||||
|
ec.matchRelated( q );
|
||||||
|
|
||||||
|
// Convert a single entity
|
||||||
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
|
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"targetname\" \"finish\"\n" );
|
||||||
|
REQUIRE( converted[2] == "\"cnt\" \"0\"\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
|
// Instantiate object
|
||||||
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
|
|
||||||
|
// Mock up Teleporter entity
|
||||||
|
std::vector<std::string> entity;
|
||||||
|
entity.push_back(" type Teleporter");
|
||||||
|
entity.push_back(" String32 target tp1");
|
||||||
|
|
||||||
|
// Mock up Target entity
|
||||||
|
std::vector<std::string> entity2;
|
||||||
|
entity2.push_back(" type Target");
|
||||||
|
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
|
entity2.push_back(" String32 name tp1");
|
||||||
|
|
||||||
|
// Mock up entity queue
|
||||||
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
q.push( entity2 );
|
||||||
|
|
||||||
|
// Match related entities (one pair)
|
||||||
|
ec.matchRelated( q );
|
||||||
|
|
||||||
|
// Convert two entities
|
||||||
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
REQUIRE( converted[0] == "\"classname\" \"trigger_teleport\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"target\" \"tp1\"\n" );
|
||||||
|
|
||||||
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
||||||
|
REQUIRE( converted2[0] == "\"classname\" \"misc_teleporter_dest\"\n" );
|
||||||
|
REQUIRE( converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
||||||
|
REQUIRE( converted2[2] == "\"targetname\" \"tp1\"\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "r2x: a single JumpPad and related Target can be converted", "[EntityConverter]" ) {
|
||||||
|
|
||||||
|
// Instantiate object
|
||||||
|
EntityConverter ec (PICKUP_FILENAME);
|
||||||
|
|
||||||
|
// Mock up JumpPad entity
|
||||||
|
std::vector<std::string> entity;
|
||||||
|
entity.push_back(" type JumpPad");
|
||||||
|
entity.push_back(" String32 target jp1");
|
||||||
|
|
||||||
|
// Mock up Target entity
|
||||||
|
std::vector<std::string> entity2;
|
||||||
|
entity2.push_back(" type Target");
|
||||||
|
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
|
entity2.push_back(" String32 name jp1");
|
||||||
|
|
||||||
|
// Mock up entity queue
|
||||||
|
std::queue<std::vector<std::string>> q;
|
||||||
|
q.push( entity );
|
||||||
|
q.push( entity2 );
|
||||||
|
|
||||||
|
// Match related entities (one pair)
|
||||||
|
ec.matchRelated( q );
|
||||||
|
|
||||||
|
// Convert two entities
|
||||||
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
REQUIRE( converted[0] == "\"classname\" \"trigger_push\"\n" );
|
||||||
|
REQUIRE( converted[1] == "\"target\" \"jp1\"\n" );
|
||||||
|
|
||||||
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
||||||
|
REQUIRE( converted2[0] == "\"classname\" \"target_position\"\n" );
|
||||||
|
REQUIRE( converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
||||||
|
REQUIRE( converted2[2] == "\"targetname\" \"jp1\"\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,4 +218,9 @@ TEST_CASE( "r2x: a single pickup entity can be converted", "[EntityConverter]" )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //CATCH_CONFIG_MAIN
|
#endif //CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user