Skip to content

Commit 4067a0d

Browse files
committed
ADD IntGrid values abstract enum
1 parent 53209ea commit 4067a0d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: src/ldtk/macro/TypeBuilder.hx

+23
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,29 @@ class TypeBuilder {
606606
switch type {
607607
case IntGrid:
608608

609+
// Create IntGrid abstract enum from values
610+
var intType = macro : Int;
611+
var enumTypeDef : TypeDefinition = {
612+
name: l.identifier+"_IntGridValues",
613+
pack: modPack,
614+
doc: "IntGrid values from layer "+l.identifier+" available as an Abstract Enum of Int",
615+
kind: TDAbstract(intType, [AbEnum, AbTo(intType)], [intType], [intType]),
616+
pos: curPos,
617+
fields: [],
618+
}
619+
for(v in l.intGridValues) {
620+
var groupInf = l.intGridValuesGroups.filter( g->g.uid==v.groupUid )[0];
621+
var groupId = groupInf!=null ? "_"+groupInf.identifier+"_" : "_";
622+
var enumUid = l.identifier + groupId + ( v.identifier!=null ? v.identifier : Std.string(v.value) );
623+
enumTypeDef.fields.push({
624+
name: sanitizeIdentifier(enumUid),
625+
pos: curPos,
626+
kind: FVar(intType, macro $v{v.value}),
627+
});
628+
}
629+
registerTypeDefinitionModule(enumTypeDef, projectFilePath);
630+
631+
609632
if( l.tilesetDefUid==null ) {
610633
// IntGrid
611634
var parentTypePath : TypePath = { pack: [APP_PACKAGE], name:"Layer_IntGrid" }

0 commit comments

Comments
 (0)