exportScriptEvents also exports a Mermaid class diagram

This commit is contained in:
Robert Beckebans 2025-03-21 16:33:16 +01:00
parent 1971da173d
commit d2137ec719

View file

@ -1157,37 +1157,46 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
{
EXPORTLANG_DOOMSCRIPT,
EXPORTLANG_DOOMSHARP,
EXPORTLANG_MERMAID,
NUM_EXPORTLANGS,
};
// go through the inheritence order
#if 1 //defined(USE_DOOMSHARP)
for( int exportLang = 0; exportLang < NUM_EXPORTLANGS; exportLang++ )
#else
int exportLang = 0;
#endif
{
bool threadClassFound = false;
bool firstEntityClassFound = false;
memset( set, 0, sizeof( bool ) * numEventDefs );
#if 1 //defined(USE_DOOMSHARP)
idFile* file = NULL;
if( exportLang == EXPORTLANG_DOOMSHARP )
{
file = fileSystem->OpenFileWrite( "script/doom_events.cs", "fs_basepath" );
}
else if( exportLang == EXPORTLANG_MERMAID )
{
file = fileSystem->OpenFileWrite( "script/doom_events_class_diagram.md", "fs_basepath" );
}
else
{
file = fileSystem->OpenFileWrite( "script/d3xp_events.script", "fs_basepath" );
file->Printf( "// empty so it overrides base/d3xp_events.script\n" );
fileSystem->CloseFile( file );
file = fileSystem->OpenFileWrite( "script/doom_events.script", "fs_basepath" );
}
#else
idFile* file = fileSystem->OpenFileWrite( "script/doom_events.script", "fs_basepath" );
#endif
file->Printf( "// generated by RBDOOM-3-BFG\n//\n\n" );
if( exportLang == EXPORTLANG_MERMAID )
{
//file->Printf( "::: mermaid\n" );
file->Printf( "---\ntitle: Script Events Class Diagram generated by %s\n---\n", ENGINE_VERSION );
file->Printf( "classDiagram\n" );
}
else
{
file->Printf( "// Script Events API generated by %s\n\n", ENGINE_VERSION );
}
if( exportLang == EXPORTLANG_DOOMSHARP )
{
@ -1198,6 +1207,14 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
for( const idTypeInfo* c = classHierarchy.GetNext(); c != NULL; c = c->node.GetNext() )
{
if( exportLang == EXPORTLANG_MERMAID )
{
//if( c->superclass && idStr::Cmp( c->superclass, "NULL" ) != 0 )
{
file->Printf( "%s <|-- %s\n", c->superclass, c->classname );
}
}
idEventFunc<idClass>* def = c->eventCallbacks;
if( !def || !def[ 0 ].event )
{
@ -1205,6 +1222,26 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
continue;
}
bool hasNewEvent = false;
for( int j = 0; def[ j ].event != NULL; j++ )
{
const idEventDef* ev = def[ j ].event;
int evNum = ev->GetEventNum();
if( set[ evNum ] )
{
//continue;
}
if( ev->GetName()[0] == '_' || ev->GetName()[0] == '<' )
{
// internal event
continue;
}
hasNewEvent = true;
}
if( exportLang == EXPORTLANG_DOOMSHARP )
{
@ -1237,6 +1274,13 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
firstEntityClassFound = true;
}
}
else if( exportLang == EXPORTLANG_MERMAID )
{
if( hasNewEvent )
{
file->Printf( "class %s{\n", c->classname );
}
}
else
{
file->Printf( "/*\n\n" );
@ -1244,7 +1288,6 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
file->Printf( "*/\n\n" );
}
// go through each entry until we hit the NULL terminator
for( int j = 0; def[ j ].event != NULL; j++ )
{
@ -1262,7 +1305,7 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
continue;
}
if( set[ evNum ] )
if( set[ evNum ] && exportLang != EXPORTLANG_MERMAID )
{
file->Printf( "// override " );
}
@ -1280,127 +1323,96 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
file->Printf( "\tpublic " );
}
}
else if( exportLang == EXPORTLANG_MERMAID )
{
file->Printf( "\t+%s(", ev->GetName() );
}
else
{
file->Printf( "scriptEvent " );
}
switch( ev->GetReturnType() )
if( exportLang == EXPORTLANG_MERMAID )
{
case D_EVENT_FLOAT :
file->Printf( "float " );
break;
case D_EVENT_INTEGER :
file->Printf( "float " );
break;
case D_EVENT_VECTOR :
file->Printf( "vector " );
break;
case D_EVENT_STRING :
file->Printf( "string " );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "entity " );
break;
case 0:
file->Printf( "void " );
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> " );
break;
}
file->Printf( "%s(", ev->GetName() );
if( ev->GetNumArgs() )
{
file->Printf( " " );
}
const char* formatspec = ev->GetArgFormat();
for( int arg = 0; arg < ev->GetNumArgs(); arg++ )
{
if( arg != 0 )
if( ev->GetNumArgs() )
{
file->Printf( ", " );
file->Printf( " " );
}
switch( formatspec[ arg ] )
const char* formatspec = ev->GetArgFormat();
for( int arg = 0; arg < ev->GetNumArgs(); arg++ )
{
case D_EVENT_FLOAT :
file->Printf( "float parm%d", arg );
break;
if( arg != 0 )
{
file->Printf( ", " );
}
case D_EVENT_INTEGER :
file->Printf( "float parm%d", arg );
break;
switch( formatspec[ arg ] )
{
case D_EVENT_FLOAT :
file->Printf( "parm%d: float", arg );
break;
case D_EVENT_VECTOR :
file->Printf( "vector parm%d", arg );
break;
case D_EVENT_INTEGER :
file->Printf( "parm%d: int", arg );
break;
case D_EVENT_STRING :
file->Printf( "string parm%d", arg );
break;
case D_EVENT_VECTOR :
file->Printf( "parm%d: vector", arg );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "entity parm%d", arg );
break;
case D_EVENT_STRING :
file->Printf( "parm%d: string", arg );
break;
case 0:
// void
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "parm%d: entity", arg );
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> parm%d", arg );
break;
case 0:
// void
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> parm%d", arg );
break;
}
}
}
if( ev->GetNumArgs() )
{
file->Printf( " " );
}
if( ev->GetNumArgs() )
{
file->Printf( " " );
}
if( exportLang == EXPORTLANG_DOOMSHARP )
{
file->Printf( ") " );
file->Printf( "): " );
switch( ev->GetReturnType() )
{
case D_EVENT_FLOAT :
file->Printf( "{ return 0; }\n\n" );
file->Printf( "float " );
break;
case D_EVENT_INTEGER :
file->Printf( "{ return 0; }\n\n" );
file->Printf( "float " );
break;
case D_EVENT_VECTOR :
file->Printf( "{ return new vector( 0, 0, 0 ); }\n\n" );
file->Printf( "vector " );
break;
case D_EVENT_STRING :
file->Printf( "{ return \"\"; }\n\n" );
file->Printf( "string " );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "{ return null; }\n\n" );
file->Printf( "entity " );
break;
case 0:
file->Printf( "{ }\n\n" );
file->Printf( "void " );
break;
default:
@ -1408,19 +1420,156 @@ void idClass::ExportScriptEvents_f( const idCmdArgs& args )
file->Printf( "<unsupported> " );
break;
}
file->Printf( "\n" );
}
else
{
file->Printf( ");\n\n" );
switch( ev->GetReturnType() )
{
case D_EVENT_FLOAT :
file->Printf( "float " );
break;
case D_EVENT_INTEGER :
file->Printf( "float " );
break;
case D_EVENT_VECTOR :
file->Printf( "vector " );
break;
case D_EVENT_STRING :
file->Printf( "string " );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "entity " );
break;
case 0:
file->Printf( "void " );
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> " );
break;
}
file->Printf( "%s(", ev->GetName() );
if( ev->GetNumArgs() )
{
file->Printf( " " );
}
const char* formatspec = ev->GetArgFormat();
for( int arg = 0; arg < ev->GetNumArgs(); arg++ )
{
if( arg != 0 )
{
file->Printf( ", " );
}
switch( formatspec[ arg ] )
{
case D_EVENT_FLOAT :
file->Printf( "float parm%d", arg );
break;
case D_EVENT_INTEGER :
file->Printf( "float parm%d", arg );
break;
case D_EVENT_VECTOR :
file->Printf( "vector parm%d", arg );
break;
case D_EVENT_STRING :
file->Printf( "string parm%d", arg );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "entity parm%d", arg );
break;
case 0:
// void
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> parm%d", arg );
break;
}
}
if( ev->GetNumArgs() )
{
file->Printf( " " );
}
if( exportLang == EXPORTLANG_DOOMSHARP )
{
file->Printf( ") " );
switch( ev->GetReturnType() )
{
case D_EVENT_FLOAT :
file->Printf( "{ return 0; }\n\n" );
break;
case D_EVENT_INTEGER :
file->Printf( "{ return 0; }\n\n" );
break;
case D_EVENT_VECTOR :
file->Printf( "{ return new vector( 0, 0, 0 ); }\n\n" );
break;
case D_EVENT_STRING :
file->Printf( "{ return \"\"; }\n\n" );
break;
case D_EVENT_ENTITY :
case D_EVENT_ENTITY_NULL :
file->Printf( "{ return null; }\n\n" );
break;
case 0:
file->Printf( "{ }\n\n" );
break;
default:
case D_EVENT_TRACE :
file->Printf( "<unsupported> " );
break;
}
}
else
{
file->Printf( ");\n\n" );
}
}
}
if( exportLang == EXPORTLANG_MERMAID && hasNewEvent )
{
file->Printf( "\n}\n\n" );
}
}
if( exportLang == EXPORTLANG_DOOMSHARP )
{
file->Printf( "\n}\n\n" );
//file->Printf( "#endif // CSHARP\n\n" );
}
//else if( exportLang == EXPORTLANG_MERMAID )
//{
// file->Printf( ":::\n" );
//}
fileSystem->CloseFile( file );
}