1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-06 10:47:45 +00:00

quest_parser: Fix case for constants

The generated onBNpcKill and onEObjHit functions were using the wrong
case for the constants they used. Ensure that they use the same case as
the declared constants, and reduce duplicate code.

Also, fix a typo in the onEObjHit function prototype which was causing
generated scripts to not compile properly, and revert the incorrect
addition (by me in an earlier commit) of "override".
This commit is contained in:
Sophie Hamilton 2020-02-29 17:33:55 +00:00
parent 850fa47520
commit 8981955ddd

View file

@ -64,6 +64,17 @@ std::string titleCase( const std::string& str )
return retStr; return retStr;
} }
std::string titleCaseNoUnderscores( const std::string& str )
{
std::string result = titleCase( str );
result.erase( std::remove_if( result.begin(), result.end(), []( const char c ) {
return c == '_';
}), result.end());
return result;
}
void void
createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< std::string >& additionalList, int questId ) createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< std::string >& additionalList, int questId )
{ {
@ -132,12 +143,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
} }
else else
{ {
std::string seqName = titleCase( entry ); std::string seqName = titleCaseNoUnderscores( entry );
seqName.erase( std::remove_if( seqName.begin(), seqName.end(), []( const char c ) {
return c == '_';
}), seqName.end());
std::string seqId = entry.substr( 4 ); std::string seqId = entry.substr( 4 );
seqStr += " " + seqName + " = " + seqId + ",\n"; seqStr += " " + seqName + " = " + seqId + ",\n";
} }
@ -195,12 +201,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
std::sort( script_entities.begin(), script_entities.end() ); std::sort( script_entities.begin(), script_entities.end() );
for( auto& entity : script_entities ) for( auto& entity : script_entities )
{ {
auto name = titleCase( entity ); auto name = titleCaseNoUnderscores( entity );
name.erase( std::remove_if( name.begin(), name.end(), []( const char c ) {
return c == '_';
}), name.end());
sentities += " static constexpr auto " + name + ";\n"; sentities += " static constexpr auto " + name + ";\n";
} }
@ -239,7 +240,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
for( auto enemy : enemy_strings ) for( auto enemy : enemy_strings )
{ {
scriptEntry += " case " + enemy + ": { break; }\n"; scriptEntry += " case " + titleCaseNoUnderscores( enemy ) + ": { break; }\n";
} }
if( !enemy_ids.empty() ) if( !enemy_ids.empty() )
@ -248,14 +249,14 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
if( !action_ids.empty() ) if( !action_ids.empty() )
actionEntry += std::string( actionEntry += std::string(
" void onEObjHit( uint32_t npcId, Entity::Player& player, uin32_t actionId ) override\n" " void onEObjHit( uint32_t npcId, Entity::Player& player, uint32_t actionId )\n"
" {\n" " {\n"
" switch( actionId )\n" " switch( actionId )\n"
" {\n" ); " {\n" );
for( auto action : action_names ) for( auto action : action_names )
{ {
actionEntry += " case " + action + ": { break; }\n"; actionEntry += " case " + titleCaseNoUnderscores( action ) + ": { break; }\n";
} }
if( !action_ids.empty() ) if( !action_ids.empty() )