mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-15 22:02:28 +03:00
Extract WriteEnum
This commit is contained in:
parent
2c54889462
commit
1e99eec50a
@ -25,10 +25,10 @@ namespace Generator
|
|||||||
if ( name[0] == 'E' )
|
if ( name[0] == 'E' )
|
||||||
name = name.Substring( 1 );
|
name = name.Substring( 1 );
|
||||||
|
|
||||||
name = Cleanup.ConvertType( name );
|
name = Cleanup.ConvertType( name );
|
||||||
|
|
||||||
if ( !Cleanup.ShouldCreate( name ) )
|
if ( !Cleanup.ShouldCreate( name ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var lowest = o.Values.Min( x => long.Parse( x.Value ) );
|
var lowest = o.Values.Min( x => long.Parse( x.Value ) );
|
||||||
var highest = o.Values.Max( x => long.Parse( x.Value ) );
|
var highest = o.Values.Max( x => long.Parse( x.Value ) );
|
||||||
@ -38,58 +38,62 @@ namespace Generator
|
|||||||
if ( highest > int.MaxValue )
|
if ( highest > int.MaxValue )
|
||||||
t = "uint";
|
t = "uint";
|
||||||
|
|
||||||
|
WriteEnum( o, name, t );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StartBlock( $"{Cleanup.Expose( name )} enum {name} : {t}" );
|
private void WriteEnum( SteamApiDefinition.EnumDef o, string name, string t = "int" )
|
||||||
|
{
|
||||||
|
StartBlock( $"{Cleanup.Expose( name )} enum {name} : {t}" );
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// If all the enum values start with the same
|
||||||
|
// string, remove it. This converts
|
||||||
|
// "k_EUserHasLicenseResultHasLicense" to "HasLicense" etc
|
||||||
|
//
|
||||||
|
int iFinished = int.MaxValue;
|
||||||
|
for ( int i = 0; i < 4096; i++ )
|
||||||
{
|
{
|
||||||
//
|
var c = o.Values.First().Name[i];
|
||||||
// If all the enum values start with the same
|
|
||||||
// string, remove it. This converts
|
|
||||||
// "k_EUserHasLicenseResultHasLicense" to "HasLicense" etc
|
|
||||||
//
|
|
||||||
int iFinished = int.MaxValue;
|
|
||||||
for ( int i = 0; i < 4096; i++ )
|
|
||||||
{
|
|
||||||
var c = o.Values.First().Name[i];
|
|
||||||
foreach ( var entry in o.Values )
|
|
||||||
{
|
|
||||||
if ( entry.Name[i] != c )
|
|
||||||
{
|
|
||||||
iFinished = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( iFinished != int.MaxValue )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( var entry in o.Values )
|
foreach ( var entry in o.Values )
|
||||||
{
|
{
|
||||||
var ename = entry.Name;
|
if ( entry.Name[i] != c )
|
||||||
|
|
||||||
if ( iFinished != int.MaxValue )
|
|
||||||
ename = ename.Substring( iFinished );
|
|
||||||
|
|
||||||
//
|
|
||||||
// Names aren't allowed to start with a number
|
|
||||||
// So just stick the enum name on the front
|
|
||||||
//
|
|
||||||
if ( char.IsNumber( ename[0] ) )
|
|
||||||
{
|
{
|
||||||
var p = name;
|
iFinished = i;
|
||||||
|
break;
|
||||||
if ( p == "HTTPStatusCode" ) p = "Code";
|
|
||||||
if ( p == "SteamIPType" ) p = "Type";
|
|
||||||
|
|
||||||
ename = p + ename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLine( $"{ename} = {entry.Value}," );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( iFinished != int.MaxValue )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( var entry in o.Values )
|
||||||
|
{
|
||||||
|
var ename = entry.Name;
|
||||||
|
|
||||||
|
if ( iFinished != int.MaxValue )
|
||||||
|
ename = ename.Substring( iFinished );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Names aren't allowed to start with a number
|
||||||
|
// So just stick the enum name on the front
|
||||||
|
//
|
||||||
|
if ( char.IsNumber( ename[0] ) )
|
||||||
|
{
|
||||||
|
var p = name;
|
||||||
|
|
||||||
|
if ( p == "HTTPStatusCode" ) p = "Code";
|
||||||
|
if ( p == "SteamIPType" ) p = "Type";
|
||||||
|
|
||||||
|
ename = p + ename;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteLine( $"{ename} = {entry.Value}," );
|
||||||
}
|
}
|
||||||
EndBlock();
|
|
||||||
WriteLine();
|
|
||||||
}
|
}
|
||||||
|
EndBlock();
|
||||||
|
WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user