Skip to content

Commit d5b04ea

Browse files
committed
Replaced flipx with mirror, and add flip, adapting to c3 names. Fix follower flip/mirror.
1 parent 758058e commit d5b04ea

File tree

7 files changed

+128
-38
lines changed

7 files changed

+128
-38
lines changed

spine-ts/spine-construct3/spine-construct3-lib/src/C3SkeletonRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class C3SkeletonRenderer<
129129
const bones = skeleton.bones;
130130
for (let i = 0, n = bones.length; i < n; i++) {
131131
const bone = bones[i];
132-
if (!bone.parent) continue;
132+
// if (!bone.parent) continue;
133133
const boneApplied = bone.applied;
134134
const { x: x1, y: y1 } = matrix.skeletonToGame(boneApplied.worldX, boneApplied.worldY);
135135
const endX = boneApplied.worldX + bone.data.length * boneApplied.a;

spine-ts/spine-construct3/src/aces.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@
3131
]
3232
},
3333
{
34-
"id": "is-flipped-x",
35-
"scriptName": "IsFlippedX",
34+
"id": "is-mirrored",
35+
"scriptName": "IsMirrored",
36+
"isTrigger": false
37+
},
38+
{
39+
"id": "is-flipped",
40+
"scriptName": "IsFlipped",
3641
"isTrigger": false
3742
},
3843
{
@@ -95,12 +100,23 @@
95100
]
96101
},
97102
{
98-
"id": "flip-x",
99-
"scriptName": "FlipX",
103+
"id": "mirror",
104+
"scriptName": "Mirror",
105+
"highlight": false,
106+
"params": [
107+
{
108+
"id": "is-mirrored",
109+
"type": "boolean"
110+
}
111+
]
112+
},
113+
{
114+
"id": "flip",
115+
"scriptName": "Flip",
100116
"highlight": false,
101117
"params": [
102118
{
103-
"id": "is-flipped-x",
119+
"id": "is-flipped",
104120
"type": "boolean"
105121
}
106122
]

spine-ts/spine-construct3/src/c3runtime/actions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts =
3737
this.setSkin(skinList.split(","));
3838
},
3939

40-
FlipX (this: SDKInstanceClass, isFlippedX: boolean) {
41-
this.flipX(isFlippedX);
40+
Mirror (this: SDKInstanceClass, isMirrored: boolean) {
41+
this.mirror(isMirrored);
42+
},
43+
44+
Flip (this: SDKInstanceClass, isFlipped: boolean) {
45+
this.flip(isFlipped);
4246
},
4347

4448
SetAnimation (this: SDKInstanceClass, track: number, animation: string, loop = false) {

spine-ts/spine-construct3/src/c3runtime/conditions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Cnds =
4242
const animationMatches = animation === "" || this.triggeredEventAnimation === animation;
4343
return eventMatches && trackMatches && animationMatches;
4444
},
45-
IsFlippedX (this: SpineC3Instance) {
46-
return this.isFlippedX;
45+
IsMirrored (this: SpineC3Instance) {
46+
return this.isMirrored;
47+
},
48+
IsFlipped (this: SpineC3Instance) {
49+
return this.isFlipped;
4750
},
4851
IsSkeletonLoaded (this: SpineC3Instance) {
4952
return this.skeletonLoaded;

spine-ts/spine-construct3/src/c3runtime/instance.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
5252
propBoundsProvider: SpineBoundsProviderType = "setup";
5353
propEnableCollision = false;
5454

55-
isFlippedX = false;
55+
isMirrored = false;
56+
isFlipped = false;
5657
collisionSpriteInstance?: IWorldInstance;
5758
collisionSpriteClassName = "";
5859
isPlaying = true;
@@ -166,7 +167,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
166167
this.y + this.propOffsetY,
167168
this.totalZ,
168169
this.angle + this.propOffsetAngle,
169-
this.width / this.spineBounds.width * this.propScaleX * (this.isFlippedX ? -1 : 1),
170+
this.width / this.spineBounds.width * this.propScaleX,
170171
this.height / this.spineBounds.height * this.propScaleY);
171172

172173
this.updateCollisionSprite();
@@ -848,6 +849,14 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
848849
this.boneFollowers.delete(boneName);
849850
}
850851

852+
private mirrorFollower (instance: IWorldInstance) {
853+
instance.setSize(-instance.width, instance.height);
854+
}
855+
856+
private flipFollower (instance: IWorldInstance) {
857+
instance.setSize(instance.width, -instance.height);
858+
}
859+
851860
private updateBoneFollowers (matrix: C3Matrix) {
852861
if (this.boneFollowers.size === 0) return;
853862

@@ -872,8 +881,8 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
872881
const rotatedOffsetX = follower.offsetX * cos - follower.offsetY * sin;
873882
const rotatedOffsetY = follower.offsetX * sin + follower.offsetY * cos;
874883

875-
instance.x = x + rotatedOffsetX;
876-
instance.y = y + rotatedOffsetY;
884+
instance.x = x + rotatedOffsetX * (this.isMirrored ? -1 : 1);
885+
instance.y = y + rotatedOffsetY * (this.isFlipped ? -1 : 1);
877886
instance.angleDegrees = boneRotation + follower.offsetAngle;
878887
}
879888
}
@@ -1101,8 +1110,34 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
11011110
* Skeleton
11021111
*/
11031112

1104-
public flipX (isFlippedX: boolean) {
1105-
this.isFlippedX = isFlippedX;
1113+
public mirror (isMirrored: boolean) {
1114+
if (isMirrored !== this.isMirrored) {
1115+
this.isMirrored = isMirrored;
1116+
this.width = -this.width
1117+
1118+
for (const [, followers] of this.boneFollowers) {
1119+
for (const follower of followers) {
1120+
const instance = this.runtime.getInstanceByUid(follower.uid) as IWorldInstance;
1121+
if (instance) this.mirrorFollower(instance);
1122+
}
1123+
}
1124+
1125+
}
1126+
}
1127+
1128+
public flip (isFlipped: boolean) {
1129+
if (isFlipped !== this.isFlipped) {
1130+
this.isFlipped = isFlipped;
1131+
this.height = -this.height;
1132+
1133+
for (const [, followers] of this.boneFollowers) {
1134+
for (const follower of followers) {
1135+
const instance = this.runtime.getInstanceByUid(follower.uid) as IWorldInstance;
1136+
if (instance) this.flipFollower(instance);
1137+
}
1138+
}
1139+
1140+
}
11061141
}
11071142

11081143
public setPhysicsMode (mode: 0 | 1 | 2 | 3) {

spine-ts/spine-construct3/src/lang/en-US.json

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@
118118
}
119119
}
120120
},
121-
"is-flipped-x": {
122-
"list-name": "Is flipped X",
123-
"display-text": "Is flipped X",
124-
"description": "Check if the skeleton is flipped horizontally"
121+
"is-mirrored": {
122+
"list-name": "Is mirrored",
123+
"display-text": "Is mirrored",
124+
"description": "Check if the skeleton is mirrored horizontally"
125+
},
126+
"is-flipped": {
127+
"list-name": "Is flipped",
128+
"display-text": "Is flipped",
129+
"description": "Check if the skeleton is flipped vertically"
125130
},
126131
"is-skeleton-loaded": {
127132
"list-name": "Is skeleton loaded",
@@ -180,14 +185,25 @@
180185
}
181186
}
182187
},
183-
"flip-x": {
184-
"list-name": "Flip X",
185-
"display-text": "Set flip X to {0}",
186-
"description": "Flip the skeleton horizontally",
188+
"mirror": {
189+
"list-name": "Mirror",
190+
"display-text": "Set mirrored to {0}",
191+
"description": "Mirror the skeleton horizontally",
192+
"params": {
193+
"is-mirrored": {
194+
"name": "Is mirrored",
195+
"desc": "True to mirror the skeleton horizontally, false to show normally."
196+
}
197+
}
198+
},
199+
"flip": {
200+
"list-name": "Flip",
201+
"display-text": "Set flipped to {0}",
202+
"description": "Flip the skeleton vertically",
187203
"params": {
188-
"is-flipped-x": {
189-
"name": "Is flipped X",
190-
"desc": "True to flip the skeleton horizontally, false to show normally."
204+
"is-flipped": {
205+
"name": "Is flipped",
206+
"desc": "True to flip the skeleton vertically, false to show normally."
191207
}
192208
}
193209
},

spine-ts/spine-construct3/src/lang/zh-CN.json

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@
118118
}
119119
}
120120
},
121-
"is-flipped-x": {
122-
"list-name": "是否水平翻转",
123-
"display-text": "是否水平翻转",
124-
"description": "检查骨架是否水平翻转"
121+
"is-mirrored": {
122+
"list-name": "是否镜像",
123+
"display-text": "是否镜像",
124+
"description": "检查骨架是否水平镜像"
125+
},
126+
"is-flipped": {
127+
"list-name": "是否翻转",
128+
"display-text": "是否翻转",
129+
"description": "检查骨架是否垂直翻转"
125130
},
126131
"is-skeleton-loaded": {
127132
"list-name": "骨架是否已加载",
@@ -180,14 +185,25 @@
180185
}
181186
}
182187
},
183-
"flip-x": {
184-
"list-name": "水平翻转",
185-
"display-text": "设置水平翻转为 {0}",
186-
"description": "水平翻转骨架",
188+
"mirror": {
189+
"list-name": "镜像",
190+
"display-text": "设置镜像为 {0}",
191+
"description": "水平镜像骨架",
192+
"params": {
193+
"is-mirrored": {
194+
"name": "是否镜像",
195+
"desc": "设为true时水平镜像骨架,设为false时正常显示。"
196+
}
197+
}
198+
},
199+
"flip": {
200+
"list-name": "翻转",
201+
"display-text": "设置翻转为 {0}",
202+
"description": "垂直翻转骨架",
187203
"params": {
188-
"is-flipped-x": {
189-
"name": "是否水平翻转",
190-
"desc": "设为true时水平翻转骨架,设为false时正常显示。"
204+
"is-flipped": {
205+
"name": "是否翻转",
206+
"desc": "设为true时垂直翻转骨架,设为false时正常显示。"
191207
}
192208
}
193209
},

0 commit comments

Comments
 (0)