mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-03 09:10:41 +03:00
Enum cleanip
This commit is contained in:
parent
5da0690c5c
commit
48cb001fb3
@ -1,74 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Generator
|
|
||||||
{
|
|
||||||
public partial class CodeWriter
|
|
||||||
{
|
|
||||||
private void Enums()
|
|
||||||
{
|
|
||||||
//StartBlock( "namespace Enum" );
|
|
||||||
|
|
||||||
foreach ( var o in def.enums )
|
|
||||||
{
|
|
||||||
|
|
||||||
WriteLine( $"//" );
|
|
||||||
WriteLine( $"// {o.Name}" );
|
|
||||||
WriteLine( $"//" );
|
|
||||||
var name = o.Name;
|
|
||||||
|
|
||||||
if ( name.Contains( "::" ) )
|
|
||||||
name = o.Name.Substring( o.Name.LastIndexOf( ":" ) + 1 );
|
|
||||||
|
|
||||||
// Skip the E
|
|
||||||
if ( name[0] == 'E' )
|
|
||||||
name = name.Substring( 1 );
|
|
||||||
|
|
||||||
StartBlock( $"public enum {name} : int" );
|
|
||||||
|
|
||||||
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 )
|
|
||||||
{
|
|
||||||
var ename = entry.Name;
|
|
||||||
|
|
||||||
if ( iFinished != int.MaxValue )
|
|
||||||
ename = ename.Substring( iFinished );
|
|
||||||
|
|
||||||
if ( char.IsNumber( ename[0] ) )
|
|
||||||
ename = name + ename;
|
|
||||||
|
|
||||||
// while ( char.IsNumber( ename [0] ) )
|
|
||||||
// {
|
|
||||||
// ename = ename.Substring( 1 );
|
|
||||||
// }
|
|
||||||
|
|
||||||
WriteLine( $"{ename} = {entry.Value}," );
|
|
||||||
}
|
|
||||||
|
|
||||||
EndBlock();
|
|
||||||
WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
// EndBlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
74
Generator/CodeWriter/Enums.cs
Normal file
74
Generator/CodeWriter/Enums.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
public partial class CodeWriter
|
||||||
|
{
|
||||||
|
private void Enums()
|
||||||
|
{
|
||||||
|
foreach ( var o in def.enums )
|
||||||
|
{
|
||||||
|
WriteLine( $"//" );
|
||||||
|
WriteLine( $"// {o.Name}" );
|
||||||
|
WriteLine( $"//" );
|
||||||
|
var name = o.Name;
|
||||||
|
|
||||||
|
// We're not interested in namespacing
|
||||||
|
if ( name.Contains( "::" ) )
|
||||||
|
name = o.Name.Substring( o.Name.LastIndexOf( ":" ) + 1 );
|
||||||
|
|
||||||
|
// Skip the E
|
||||||
|
if ( name[0] == 'E' )
|
||||||
|
name = name.Substring( 1 );
|
||||||
|
|
||||||
|
StartBlock( $"public enum {name} : int" );
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// 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 )
|
||||||
|
{
|
||||||
|
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] ) )
|
||||||
|
ename = name + ename;
|
||||||
|
|
||||||
|
WriteLine( $"{ename} = {entry.Value}," );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EndBlock();
|
||||||
|
WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,7 +50,7 @@
|
|||||||
<Compile Include="Argument.cs" />
|
<Compile Include="Argument.cs" />
|
||||||
<Compile Include="CodeWriter\Class.cs" />
|
<Compile Include="CodeWriter\Class.cs" />
|
||||||
<Compile Include="CodeWriter.cs" />
|
<Compile Include="CodeWriter.cs" />
|
||||||
<Compile Include="CodeWriter.Enum.cs" />
|
<Compile Include="CodeWriter\Enums.cs" />
|
||||||
<Compile Include="CodeWriter.Struct.cs" />
|
<Compile Include="CodeWriter.Struct.cs" />
|
||||||
<Compile Include="CodeWriter.Types.cs" />
|
<Compile Include="CodeWriter.Types.cs" />
|
||||||
<Compile Include="CodeWriter\Utility.cs" />
|
<Compile Include="CodeWriter\Utility.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user