From 86c7e543a650479747601b87a0c9828249e17e85 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Aug 2023 11:41:58 -0300 Subject: [PATCH 01/11] remove binary encoding option since it returns a string not buffer --- runtime/src/ceramic/Files.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/ceramic/Files.hx b/runtime/src/ceramic/Files.hx index 955dc5e15..1601b2d99 100644 --- a/runtime/src/ceramic/Files.hx +++ b/runtime/src/ceramic/Files.hx @@ -460,7 +460,7 @@ class Files { return null; } else { - var data:UInt8Array = fs.readFileSync(path, 'binary'); + var data:UInt8Array = fs.readFileSync(path); return data != null ? data.toBytes() : null; } From ef25f74ab11e613166dca40ae0bc34894d3f2ea4 Mon Sep 17 00:00:00 2001 From: goldenPiGames <48254127+goldenPiGames@users.noreply.github.com> Date: Sat, 19 Aug 2023 11:52:49 -0400 Subject: [PATCH 02/11] Spine.hx clipping attachments --- plugins/spine/runtime/src/ceramic/Spine.hx | 84 +++++++++++++--------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/plugins/spine/runtime/src/ceramic/Spine.hx b/plugins/spine/runtime/src/ceramic/Spine.hx index 9fbd4f8a6..8d0ecb668 100644 --- a/plugins/spine/runtime/src/ceramic/Spine.hx +++ b/plugins/spine/runtime/src/ceramic/Spine.hx @@ -17,6 +17,7 @@ import spine.*; import spine.AnimationState; import spine.attachments.*; import spine.support.graphics.TextureAtlas; +import spine.support.utils.FloatArray; import spine.utils.SkeletonClipping; using StringTools; @@ -70,7 +71,11 @@ class Spine extends Visual { var firstBoundingBoxSlotIndex:Int = -1; - //var clipper:SkeletonClipping = new SkeletonClipping(); + var clipper:SkeletonClipping = new SkeletonClipping(); + + var clipShape:Shape = null; + + var slotClips:IntMap = new IntMap(16, 0.5, true); var muteEvents:Bool = false; @@ -635,6 +640,7 @@ class Spine extends Visual { foundMeshes.push(mesh); mesh.indices = null; mesh.uvs = null; + mesh.clip = null; if (mesh.transform != null) { TransformPool.recycle(mesh.transform); mesh.transform = null; @@ -646,8 +652,22 @@ class Spine extends Visual { } } + keys = slotClips.iterableKeys; + for (i in 0...keys.length) { + var key = keys.unsafeGet(i); + var clip = slotClips.getInline(key); + if (clip != null) { + clip.points = null; + clip.destroy(); + if (!destroyed) { + slotClips.set(key, null); + } + } + } + if (destroyed) { slotMeshes = null; + slotClips = null; } } @@ -1153,8 +1173,7 @@ class Spine extends Visual { boundSlot = null; tintBlack = slot.data.darkColor != null || useTintBlack; - // /!\ TODO clipping - vertexSize = 2;//clipper != null && clipper.isClipping() ? 5 : 2; + vertexSize = 2; if (tintBlack) vertexSize += 4; // Emit event and allow to override drawing of this slot @@ -1418,26 +1437,12 @@ class Spine extends Visual { alphaColor = new AlphaColor(Color.fromRGBFloat(r, g, b), Math.round(a * 255)); if (mesh.colors == null) mesh.colors = [alphaColor]; else mesh.colors[0] = alphaColor; - - /*if (clipper.isClipping()) { - clipper.clipTriangles(mesh.vertices, verticesLength, mesh.indices, mesh.indices.length, mesh.uvs, alphaColor, 0, false); - var clippedVertices = clipper.getClippedVertices(); - var clippedTriangles = clipper.getClippedTriangles(); - var verticeItems = clippedVertices.items; - - for (i in 0...verticeItems.length) { - mesh.vertices[i] = verticeItems.unsafeGet(i); - } - if (mesh.vertices.length > verticeItems.length) { - #if cpp - untyped mesh.vertices.__SetSize(verticeItems.length); - #else - mesh.vertices.splice(verticeItems.length, mesh.vertices.length - verticeItems.length); - #end - } - - mesh.indices = clippedTriangles.items; - }*/ + + if (clipper.isClipping()) { + mesh.clip = clipShape; + } else { + mesh.clip = null; + } mesh.blending = isAdditive ? Blending.ADD : Blending.AUTO; mesh.depth = slotInfo.depth; @@ -1543,14 +1548,27 @@ class Spine extends Visual { } } } - } - // else if (Std.isOfType(slot.attachment, ClippingAttachment)) { - - // clipAttachment = cast slot.attachment; - // clipper.clipStart(slot, clipAttachment); - // continue; - - // } + } else if (Std.isOfType(slot.attachment, ClippingAttachment)) { + clipAttachment = cast slot.attachment; + clipper.clipStart(slot, clipAttachment); + + clipShape = slotClips.getInline(slot.data.index); + + if (clipShape == null) { + clipShape = new Shape(); + clipShape.visible = false; + add(clipShape); + slotClips.set(slot.data.index, clipShape); + } + + @:privateAccess var points:Array = cast clipper.clippingPolygon; + clipShape.points = points.slice(0); + clipShape.scaleX = skeletonScale; + clipShape.scaleY = -skeletonScale; + clipShape.computeContent(); + + continue; + } z++; } @@ -1636,10 +1654,10 @@ class Spine extends Visual { } } - //clipper.clipEndWithSlot(slot); + clipper.clipEndWithSlot(slot); } - //clipper.clipEnd(); + clipper.clipEnd(); this.firstBoundingBoxSlotIndex = firstBoundingBoxSlotIndex; From 880acc9c7e6b0383a5ac22caa737cce4bb9c0bdd Mon Sep 17 00:00:00 2001 From: goldenPiGames <48254127+goldenPiGames@users.noreply.github.com> Date: Sat, 19 Aug 2023 12:01:07 -0400 Subject: [PATCH 03/11] indentation with spaces for consistency (bleh) --- plugins/spine/runtime/src/ceramic/Spine.hx | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/plugins/spine/runtime/src/ceramic/Spine.hx b/plugins/spine/runtime/src/ceramic/Spine.hx index 8d0ecb668..363d1c6d4 100644 --- a/plugins/spine/runtime/src/ceramic/Spine.hx +++ b/plugins/spine/runtime/src/ceramic/Spine.hx @@ -73,7 +73,7 @@ class Spine extends Visual { var clipper:SkeletonClipping = new SkeletonClipping(); - var clipShape:Shape = null; + var clipShape:Shape = null; var slotClips:IntMap = new IntMap(16, 0.5, true); @@ -652,18 +652,18 @@ class Spine extends Visual { } } - keys = slotClips.iterableKeys; - for (i in 0...keys.length) { - var key = keys.unsafeGet(i); - var clip = slotClips.getInline(key); - if (clip != null) { - clip.points = null; - clip.destroy(); - if (!destroyed) { - slotClips.set(key, null); - } - } - } + keys = slotClips.iterableKeys; + for (i in 0...keys.length) { + var key = keys.unsafeGet(i); + var clip = slotClips.getInline(key); + if (clip != null) { + clip.points = null; + clip.destroy(); + if (!destroyed) { + slotClips.set(key, null); + } + } + } if (destroyed) { slotMeshes = null; @@ -1438,11 +1438,11 @@ class Spine extends Visual { if (mesh.colors == null) mesh.colors = [alphaColor]; else mesh.colors[0] = alphaColor; - if (clipper.isClipping()) { - mesh.clip = clipShape; + if (clipper.isClipping()) { + mesh.clip = clipShape; } else { - mesh.clip = null; - } + mesh.clip = null; + } mesh.blending = isAdditive ? Blending.ADD : Blending.AUTO; mesh.depth = slotInfo.depth; @@ -1552,20 +1552,20 @@ class Spine extends Visual { clipAttachment = cast slot.attachment; clipper.clipStart(slot, clipAttachment); - clipShape = slotClips.getInline(slot.data.index); - - if (clipShape == null) { - clipShape = new Shape(); - clipShape.visible = false; - add(clipShape); - slotClips.set(slot.data.index, clipShape); - } - - @:privateAccess var points:Array = cast clipper.clippingPolygon; - clipShape.points = points.slice(0); - clipShape.scaleX = skeletonScale; - clipShape.scaleY = -skeletonScale; - clipShape.computeContent(); + clipShape = slotClips.getInline(slot.data.index); + + if (clipShape == null) { + clipShape = new Shape(); + clipShape.visible = false; + add(clipShape); + slotClips.set(slot.data.index, clipShape); + } + + @:privateAccess var points:Array = cast clipper.clippingPolygon; + clipShape.points = points.slice(0); + clipShape.scaleX = skeletonScale; + clipShape.scaleY = -skeletonScale; + clipShape.computeContent(); continue; } From c748f2087f05c1dfa41369ae0522a056bec72860 Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Thu, 31 Aug 2023 14:23:23 +0200 Subject: [PATCH 04/11] [runtime] round translation when using bitmap font with NEAREST filter --- runtime/src/ceramic/Text.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/src/ceramic/Text.hx b/runtime/src/ceramic/Text.hx index c25d5372b..779d89b7e 100644 --- a/runtime/src/ceramic/Text.hx +++ b/runtime/src/ceramic/Text.hx @@ -476,6 +476,7 @@ class Text extends Visual { quad.posInLine = i - numCharsBeforeLine; quad.line = lineQuads.length - 1; quad.texture = usePrerenderedSize ? font.preRenderedPages.get(scaledPreRenderedSize).get(glyph.page) : font.pages.get(glyph.page); + quad.roundTranslation = quad.texture != null && quad.texture.filter == NEAREST ? 1 : 0; quad.shader = !usePrerenderedSize && font.pageShaders != null ? font.pageShaders.get(glyph.page) : null; quad.color = color; quad.depth = depth; From 82c435697403dff3c44acdfc1941257674dd4a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabrielius=20Mickevi=C4=8Dius?= Date: Fri, 8 Sep 2023 18:26:55 +0200 Subject: [PATCH 05/11] [ldtk] Set the def field in LdtkFieldInstance --- plugins/ldtk/runtime/src/ceramic/LdtkData.hx | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx index 84ff4436b..6ed66d0d6 100644 --- a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx +++ b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx @@ -939,6 +939,11 @@ class LdtkEntityDefinition { */ public var tags:Array; + /** + * An array of field definitions that belong to this entity definition + */ + public var fieldDefs:Array; + public function new(?defs:LdtkDefinitions, ?json:DynamicAccess) { this.defs = defs; @@ -961,6 +966,10 @@ class LdtkEntityDefinition { tileset = defs.ldtkData.findTilesetDef(Std.int(json.get('tilesetId'))); uid = Std.int(json.get('uid')); tags = LdtkDataHelpers.toStringArray(json.get('tags')); + var fieldDefsJson:Array = json.get('fieldDefs'); + fieldDefs = fieldDefsJson != null ? [for (i in 0...fieldDefsJson.length) { + new LdtkFieldDefinition(defs, fieldDefsJson[i]); + }] : []; } } @@ -1014,6 +1023,21 @@ class LdtkEntityDefinition { } + public function fieldDef(identifier:String):LdtkFieldDefinition { + + if (this.fieldDefs != null) { + for (i in 0...this.fieldDefs.length) { + var fieldDef = this.fieldDefs[i]; + if (fieldDef.identifier == identifier) { + return fieldDef; + } + } + } + + return null; + + } + } /** @@ -2792,7 +2816,9 @@ class LdtkFieldInstance { */ public var tile:LdtkTilesetRectangle; - public function new(?ldtkData:LdtkData, ?ldtkWorld:LdtkWorld, ?json:DynamicAccess) { + public function new(?ldtkData:LdtkData, ?ldtkWorld:LdtkWorld, ?json:DynamicAccess, ?def:LdtkFieldDefinition) { + + this.def = def; if (json != null) { var defUid:Int = Std.int(json.get('defUid')); @@ -3199,7 +3225,9 @@ class LdtkEntityInstance { var fieldInstancesJson:Array = json.get('fieldInstances'); fieldInstances = fieldInstancesJson != null ? [for (i in 0...fieldInstancesJson.length) { - new LdtkFieldInstance(ldtkData, ldtkWorld, fieldInstancesJson[i]); + var fieldInstanceJson:haxe.DynamicAccess = fieldInstancesJson[i]; + var identifier = fieldInstanceJson.get('__identifier'); + new LdtkFieldInstance(ldtkData, ldtkWorld, fieldInstanceJson, def.fieldDef(identifier)); }] : []; } From fde04d69ea967a25804771bb0e9c68a096f05750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabrielius=20Mickevi=C4=8Dius?= Date: Sun, 10 Sep 2023 15:42:47 +0200 Subject: [PATCH 06/11] [ldtk] parse array type values in LdtkFieldInstance --- plugins/ldtk/runtime/src/ceramic/LdtkData.hx | 58 +++++++++++--------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx index 6ed66d0d6..993528dc2 100644 --- a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx +++ b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx @@ -2837,36 +2837,44 @@ class LdtkFieldInstance { tile = json.get('tile') != null ? new LdtkTilesetRectangle(ldtkData, json.get('tile')) : null; var rawValue:Any = json.get('__value'); - if (rawValue != null) { - var type:String = json.get('__type'); - var isArray = type.startsWith('Array<'); - if (isArray) { - type = type.substring(1, type.length - 1); - } - switch type { - case 'Int' | 'Integer': - value = Std.int(rawValue); - case 'Float' | 'Bool' | 'Boolean' | 'String' | 'Text' | 'FilePath' | 'Multilines': - value = rawValue; - case 'Color': - value = Color.fromString(rawValue); - case 'Point': - value = new Point(Std.int(Reflect.field(rawValue, 'cx')), Std.int(Reflect.field(rawValue, 'cy'))); - case 'TilesetRect': - value = new LdtkTilesetRectangle(ldtkData, rawValue); - case 'EntityRef': - value = ldtkData != null ? ldtkData._resolveEntityInstance(rawValue, ldtkWorld) : null; - default: - value = rawValue; - } - } - else { - value = null; + var type:String = json.get('__type'); + var isArray = type.startsWith('Array<'); + + if (isArray) { + type = type.substring(6, type.length - 1); + value = rawValue is Array ? [for (v in cast (rawValue, Array)) { + rawValueToValue(ldtkData, ldtkWorld, v, type); + }] : null; + } else { + value = rawValueToValue(ldtkData, ldtkWorld, rawValue, type); } } } + static function rawValueToValue(?ldtkData:LdtkData, ?ldtkWorld:LdtkWorld, ?rawValue:Any, ?type:String):Any { + if (rawValue == null) { + return null; + } + + switch type { + case 'Int' | 'Integer': + return Std.int(rawValue); + case 'Float' | 'Bool' | 'Boolean' | 'String' | 'Text' | 'FilePath' | 'Multilines': + return rawValue; + case 'Color': + return Color.fromString(rawValue); + case 'Point': + return new Point(Std.int(Reflect.field(rawValue, 'cx')), Std.int(Reflect.field(rawValue, 'cy'))); + case 'TilesetRect': + return new LdtkTilesetRectangle(ldtkData, rawValue); + case 'EntityRef': + return ldtkData != null ? ldtkData._resolveEntityInstance(rawValue, ldtkWorld) : null; + default: + return rawValue; + } + } + public function toString() { if (LdtkDataHelpers.beginObjectToString(this)) { From 9a719e4f09e8b89c3f8fd1d50af4a1d607d86351 Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Thu, 31 Aug 2023 16:52:44 +0200 Subject: [PATCH 07/11] [runtime] Minor naming change --- plugins/sprite/runtime/src/ceramic/Sprite.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/sprite/runtime/src/ceramic/Sprite.hx b/plugins/sprite/runtime/src/ceramic/Sprite.hx index 4508d9093..bbb9ee4b4 100644 --- a/plugins/sprite/runtime/src/ceramic/Sprite.hx +++ b/plugins/sprite/runtime/src/ceramic/Sprite.hx @@ -58,9 +58,9 @@ class Sprite extends Visual { return frameOffsetY; } - public function frameOffset(anchorX:Float, anchorY:Float) { - this.frameOffsetX = anchorX; - this.frameOffsetY = anchorY; + public function frameOffset(frameOffsetX:Float, frameOffsetY:Float) { + this.frameOffsetX = frameOffsetX; + this.frameOffsetY = frameOffsetY; } public var sheet(default,set):SpriteSheet = null; From 930c6d44b5271445da194f7b179029045628f37c Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Tue, 19 Sep 2023 13:27:28 +0200 Subject: [PATCH 08/11] Cleanup --- .vscode/settings.json | 3 ++- plugins/sprite/runtime/src/ceramic/Sprite.hx | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d68cb1047..86f692cc5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "haxe.executable": "tools/haxe", - "haxelib.executable": "tools/haxelib" + "haxelib.executable": "tools/haxelib", + "dotnet.defaultSolution": "disable" } \ No newline at end of file diff --git a/plugins/sprite/runtime/src/ceramic/Sprite.hx b/plugins/sprite/runtime/src/ceramic/Sprite.hx index bbb9ee4b4..b6618729e 100644 --- a/plugins/sprite/runtime/src/ceramic/Sprite.hx +++ b/plugins/sprite/runtime/src/ceramic/Sprite.hx @@ -274,8 +274,6 @@ class Sprite extends Visual { if (region != null) { quad.active = true; quad.tile = region; - var frameW = region.originalWidth * region.frameWidth / region.width; - var frameH = region.originalHeight * region.frameHeight / region.height; var quadX:Float = frameOffsetX; var quadY:Float = frameOffsetY; quad.pos( From 8dc7873696aa0a31b7b36fec8f5549c6e1b1c72c Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Sun, 24 Sep 2023 11:18:42 +0200 Subject: [PATCH 09/11] [ldtk] Ensure tiles without alpha property are treated as opaque --- plugins/ldtk/runtime/src/ceramic/LdtkData.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx index 993528dc2..faf748f76 100644 --- a/plugins/ldtk/runtime/src/ceramic/LdtkData.hx +++ b/plugins/ldtk/runtime/src/ceramic/LdtkData.hx @@ -3082,7 +3082,7 @@ class LdtkLayerInstance { autoLayerTiles.push(Std.int(tile.px[1])); autoLayerTiles.push(Std.int(tile.src[0])); autoLayerTiles.push(Std.int(tile.src[1])); - autoLayerTiles.push(Math.round(tile.a * 4096)); + autoLayerTiles.push(Math.round((tile.a ?? 1.0) * 4096)); } } else { @@ -3100,7 +3100,7 @@ class LdtkLayerInstance { gridTiles.push(Std.int(tile.px[1])); gridTiles.push(Std.int(tile.src[0])); gridTiles.push(Std.int(tile.src[1])); - gridTiles.push(Math.round(tile.a * 4096)); + gridTiles.push(Math.round((tile.a ?? 1.0) * 4096)); } } else { From 4e1215cf72554f0b1b39136e37d6546a55d07119 Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Sun, 24 Sep 2023 11:37:18 +0200 Subject: [PATCH 10/11] [spine] Fix indentation not matching the rest of the file after PR --- plugins/spine/runtime/src/ceramic/Spine.hx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/spine/runtime/src/ceramic/Spine.hx b/plugins/spine/runtime/src/ceramic/Spine.hx index 363d1c6d4..7e8df7027 100644 --- a/plugins/spine/runtime/src/ceramic/Spine.hx +++ b/plugins/spine/runtime/src/ceramic/Spine.hx @@ -640,7 +640,7 @@ class Spine extends Visual { foundMeshes.push(mesh); mesh.indices = null; mesh.uvs = null; - mesh.clip = null; + mesh.clip = null; if (mesh.transform != null) { TransformPool.recycle(mesh.transform); mesh.transform = null; @@ -667,7 +667,7 @@ class Spine extends Visual { if (destroyed) { slotMeshes = null; - slotClips = null; + slotClips = null; } } @@ -1437,7 +1437,7 @@ class Spine extends Visual { alphaColor = new AlphaColor(Color.fromRGBFloat(r, g, b), Math.round(a * 255)); if (mesh.colors == null) mesh.colors = [alphaColor]; else mesh.colors[0] = alphaColor; - + if (clipper.isClipping()) { mesh.clip = clipShape; } else { @@ -1551,7 +1551,7 @@ class Spine extends Visual { } else if (Std.isOfType(slot.attachment, ClippingAttachment)) { clipAttachment = cast slot.attachment; clipper.clipStart(slot, clipAttachment); - + clipShape = slotClips.getInline(slot.data.index); if (clipShape == null) { @@ -1568,7 +1568,7 @@ class Spine extends Visual { clipShape.computeContent(); continue; - } + } z++; } From 92253cf6f26be6bf76d05202c603916fb7ad9f20 Mon Sep 17 00:00:00 2001 From: Jeremy Faivre Date: Wed, 1 Nov 2023 18:51:01 +0100 Subject: [PATCH 11/11] Prepare 1.3.1 release --- tools/package-lock.json | 2 +- tools/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/package-lock.json b/tools/package-lock.json index 75ea51c89..0e31d5f98 100644 --- a/tools/package-lock.json +++ b/tools/package-lock.json @@ -1,6 +1,6 @@ { "name": "ceramic-tools", - "version": "1.3.0", + "version": "1.3.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/tools/package.json b/tools/package.json index 0de08ed5b..429378212 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,6 +1,6 @@ { "name": "ceramic-tools", - "version": "1.3.0", + "version": "1.3.1", "description": "Cross-platform 2D framework written in Haxe", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"