Skip to content

Commit

Permalink
Add option to disable default instance generation
Browse files Browse the repository at this point in the history
  • Loading branch information
IrishBruse committed Oct 9, 2024
1 parent e264931 commit e6a7b97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
39 changes: 21 additions & 18 deletions LDtk.Codegen/Generators/ClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,33 @@ void GenClass(string identifier, string folder, EntityDefinition entityDefinitio
void GenEntityFields(string identifier, EntityDefinition entityDefinition)
{
//generate the default data for fields.
Line($"public static {identifier} Default() => new()");
StartBlock();
if (Options.DefaultInstance)
{
Line($"Identifier = \"{identifier}\",");
Line($"Uid = {entityDefinition.Uid},");
Line($"Size = new Vector2({entityDefinition.Width}f, {entityDefinition.Height}f),");
Line($"Pivot = new Vector2({entityDefinition.PivotX}f, {entityDefinition.PivotY}f),");
if (entityDefinition.TileRect != null)
Line($"public static {identifier} Default() => new()");
StartBlock();
{
GenTilesetRectangle("Tile", entityDefinition.TileRect);
}
Line($"Identifier = \"{identifier}\",");
Line($"Uid = {entityDefinition.Uid},");
Line($"Size = new Vector2({entityDefinition.Width}f, {entityDefinition.Height}f),");
Line($"Pivot = new Vector2({entityDefinition.PivotX}f, {entityDefinition.PivotY}f),");
if (entityDefinition.TileRect != null)
{
GenTilesetRectangle("Tile", entityDefinition.TileRect);
}

byte r = entityDefinition.Color.R;
byte g = entityDefinition.Color.G;
byte b = entityDefinition.Color.B;
byte a = entityDefinition.Color.A;
byte r = entityDefinition.Color.R;
byte g = entityDefinition.Color.G;
byte b = entityDefinition.Color.B;
byte a = entityDefinition.Color.A;

Line($"SmartColor = new Color({r}, {g}, {b}, {a}),");
Line($"SmartColor = new Color({r}, {g}, {b}, {a}),");

//generate default data for custom fields
GenCustomFieldDefData(entityDefinition.FieldDefs);
//generate default data for custom fields
GenCustomFieldDefData(entityDefinition.FieldDefs);
}
EndCodeBlock();
Blank();
}
EndCodeBlock();
Blank();

//generate the rest of the class
Line("public string Identifier { get; set; }");
Expand Down
3 changes: 3 additions & 0 deletions LDtk.Codegen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ public class Options

[Option("EntityInterface", Required = false, Default = true, HelpText = "Use the ILDtkEntity interface")]
public bool EntityInterface { get; set; }

[Option("DefaultInstance", Required = false, Default = true, HelpText = "Generate an entity from its default values")]
public bool DefaultInstance { get; set; }
}

0 comments on commit e6a7b97

Please sign in to comment.