1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-04 17:57:47 +00:00

Included the ex.json

This commit is contained in:
Mordred 2017-10-12 23:40:45 +02:00
parent 56610fb07c
commit 778ca63c37
3 changed files with 9317 additions and 11 deletions

View file

@ -16,6 +16,8 @@ namespace Data {
class ExdDataGenerated; class ExdDataGenerated;
FORWARDS
STRUCTS STRUCTS
class ExdDataGenerated class ExdDataGenerated

File diff suppressed because it is too large Load diff

View file

@ -85,6 +85,9 @@ std::string generateDirectGetterDef( const std::string& exd )
} }
std::map< uint32_t, std::string > indexToNameMap; std::map< uint32_t, std::string > indexToNameMap;
std::map< uint32_t, std::string > indexToTypeMap; std::map< uint32_t, std::string > indexToTypeMap;
std::map< uint32_t, std::string > indexToTarget;
std::map< std::string, std::string > nameTaken;
std::string generateStruct( const std::string &exd ) std::string generateStruct( const std::string &exd )
{ {
@ -103,11 +106,11 @@ std::string generateStruct( const std::string &exd )
std::string name = sheet.second.get< std::string >( "sheet" ); std::string name = sheet.second.get< std::string >( "sheet" );
if( name != exd ) if( name != exd )
continue; continue;
// g_log.info( name + " ---- " );
BOOST_FOREACH( boost::property_tree::ptree::value_type &show, sheet.second.get_child( "definitions" ) ) BOOST_FOREACH( boost::property_tree::ptree::value_type &show, sheet.second.get_child( "definitions" ) )
{ {
uint32_t index; uint32_t index;
std::string converterTarget = "";
try try
{ {
index = show.second.get< uint32_t >("index"); index = show.second.get< uint32_t >("index");
@ -116,12 +119,22 @@ std::string generateStruct( const std::string &exd )
{ {
index = 0; index = 0;
} }
try { try
{
std::string fieldName = show.second.get< std::string >( "name" ); std::string fieldName = show.second.get< std::string >( "name" );
indexToNameMap[index] = fieldName; indexToNameMap[index] = fieldName;
} }
catch(...){} catch( ... ) {}
// g_log.info( std::to_string( index ) );
try
{
converterTarget = show.second.get< std::string >( "converter.target" );
if( nameTaken.find( converterTarget ) != nameTaken.end() )
indexToTarget[index] = converterTarget;
}
catch( ... ) {}
} }
} }
@ -158,8 +171,10 @@ std::string generateStruct( const std::string &exd )
fieldName.erase( boost::remove_if( fieldName, boost::is_any_of(",-':![](){}<>% \x02\x1f\x01\x03") ), fieldName.end() ); fieldName.erase( boost::remove_if( fieldName, boost::is_any_of(",-':![](){}<>% \x02\x1f\x01\x03") ), fieldName.end() );
indexToNameMap[count] = fieldName; indexToNameMap[count] = fieldName;
indexToTypeMap[count] = type; indexToTypeMap[count] = type;
if( indexToTarget.find( count ) != indexToTarget.end() )
result += " " + type + " " + fieldName + ";\n"; result += " boost::shared_ptr< " + indexToTarget[count] + "> " + fieldName + ";\n";
else
result += " " + type + " " + fieldName + ";\n";
count++; count++;
} }
@ -189,13 +204,18 @@ std::string generateConstructorsDecl( const std::string& exd )
{ {
if( indexToNameMap.find( count ) == indexToNameMap.end() ) if( indexToNameMap.find( count ) == indexToNameMap.end() )
{ count++; continue; } { count++; continue; }
result += indent + indexToNameMap[count] + " = exdData->getField< " + indexToTypeMap[count] + " >( row, " + std::to_string( count) + " );\n"; if( indexToTarget.find( count ) != indexToTarget.end() )
result += indent + indexToNameMap[count] + " = boost::make_shared< " + indexToTarget[count] + ">( exdData->getField< " +
indexToTypeMap[count] + " >( row, " + std::to_string( count ) + " ), exdData );\n";
else
result += indent + indexToNameMap[count] + " = exdData->getField< " + indexToTypeMap[count] + " >( row, " + std::to_string( count ) + " );\n";
count++; count++;
} }
result += " }\n"; result += " }\n";
indexToNameMap.clear(); indexToNameMap.clear();
indexToTypeMap.clear(); indexToTypeMap.clear();
indexToTarget.clear();
return result; return result;
} }
@ -239,12 +259,19 @@ int main()
std::string datAccCall; std::string datAccCall;
std::string getterDef; std::string getterDef;
std::string constructorDecl; std::string constructorDecl;
std::string forwards;
//BOOST_FOREACH( boost::property_tree::ptree::value_type &sheet, m_propTree.get_child( "sheets" ) )
//{
//std::string name = sheet.second.get< std::string >( "sheet" );
//nameTaken[name] = "1";
//}
BOOST_FOREACH(boost::property_tree::ptree::value_type &sheet, m_propTree.get_child("sheets")) BOOST_FOREACH( boost::property_tree::ptree::value_type &sheet, m_propTree.get_child( "sheets" ) )
{ {
std::string name = sheet.second.get<std::string>("sheet"); std::string name = sheet.second.get< std::string >( "sheet" );
forwards += "struct " + name +";\n";
structDefs += generateStruct( name ); structDefs += generateStruct( name );
dataDecl += generateDatAccessDecl( name ); dataDecl += generateDatAccessDecl( name );
getterDecl += generateDirectGetters( name ); getterDecl += generateDirectGetters( name );
@ -256,7 +283,8 @@ int main()
// for all sheets in the json i guess.... // for all sheets in the json i guess....
std::string result; std::string result;
result = std::regex_replace( exdH, std::regex( "\\STRUCTS" ), structDefs ); result = std::regex_replace( exdH, std::regex( "\\FORWARDS" ), forwards );
result = std::regex_replace( result, std::regex( "\\STRUCTS" ), structDefs );
result = std::regex_replace( result, std::regex( "\\DATACCESS" ), dataDecl ); result = std::regex_replace( result, std::regex( "\\DATACCESS" ), dataDecl );
result = std::regex_replace( result, std::regex( "\\DIRECTGETTERS" ), getterDecl ); result = std::regex_replace( result, std::regex( "\\DIRECTGETTERS" ), getterDecl );