From 5bba19e4dcdcefc3e793f3d5790875feb4829d7e Mon Sep 17 00:00:00 2001 From: Edgar Quex Date: Sun, 27 Feb 2022 18:21:34 -0600 Subject: [PATCH] Added new features for reading animation evend data values. --- src/aces.json | 43 +++++++++++++++++++++++++++++++++++- src/c3runtime/conditions.js | 4 +++- src/c3runtime/expressions.js | 17 ++++++++++++++ src/c3runtime/instance.js | 34 ++++++++++++++++++++++++++-- src/lang/en-US.json | 33 ++++++++++++++++++++++++++- 5 files changed, 126 insertions(+), 5 deletions(-) diff --git a/src/aces.json b/src/aces.json index 488383b..a5e5e59 100644 --- a/src/aces.json +++ b/src/aces.json @@ -223,6 +223,18 @@ } ] }, + { + "id": "on-any-event", + "scriptName": "OnAnyEvent", + "isTrigger": true, + "params": [ + { + "id": "track-index", + "type": "number", + "initial-value": 0 + } + ] + }, { "id": "is-bone-control-property-active", "scriptName": "IsBoneControlPropertyActive", @@ -1130,7 +1142,36 @@ "highlight": false, "returnType": "number", "params": [] - } + }, + { + "id": "get-event-name", + "expressionName": "GetEventName", + "scriptName": "GetEventName", + "highlight": false, + "returnType": "string", + "params": [] + }, + { + "id": "get-event-track-index", + "expressionName": "GetEventTrackIndex", + "scriptName": "GetEventTrackIndex", + "highlight": false, + "returnType": "string", + "params": [] + }, + { + "id": "get-event-data", + "expressionName": "GetEventData", + "scriptName": "GetEventData", + "highlight": false, + "returnType": "any", + "params": [ + { + "id": "field", + "type": "string" + } + ] + } ] } } \ No newline at end of file diff --git a/src/c3runtime/conditions.js b/src/c3runtime/conditions.js index 8658a1b..46cfcf9 100644 --- a/src/c3runtime/conditions.js +++ b/src/c3runtime/conditions.js @@ -44,7 +44,9 @@ OnEvent(eventName, trackIndex) { return (this.completeEventName === eventName) && (this.completeEventTrackIndex === trackIndex); }, - + OnAnyEvent(trackIndex) { + return (this.completeEventTrackIndex === trackIndex); + }, IsBoneControlPropertyActive(bone, propertyIndex) { let properties=['x','y','rotation','scaleX','scaleY']; let property = properties[propertyIndex]; diff --git a/src/c3runtime/expressions.js b/src/c3runtime/expressions.js index e701074..9d41b5d 100644 --- a/src/c3runtime/expressions.js +++ b/src/c3runtime/expressions.js @@ -314,6 +314,23 @@ }, SkeletonScale(){ return this.skeletonScale; + }, + GetEventName() { + return this.completeEventName; + }, + GetEventTrackIndex() { + return this.completeEventTrackIndex; + }, + GetEventData(field) { + const fieldList = ["float", "int", "string", "balance", "volume", "audiopath", "event", "track"] + + if (!(fieldList.includes(field))) + return ""; + + if (!(field in this.completeEventData)) + return ""; + + return this.completeEventData[field]; } }; } \ No newline at end of file diff --git a/src/c3runtime/instance.js b/src/c3runtime/instance.js index 6ebc1a4..51635f7 100644 --- a/src/c3runtime/instance.js +++ b/src/c3runtime/instance.js @@ -87,6 +87,8 @@ this.completeEventName = "" this.textureWidth = 0; this.textureHeight = 0; + this.completeEventData = { } + // @ts-ignore const wi = this.GetWorldInfo(); @@ -290,6 +292,7 @@ stateData.defaultMix = this.defaultMix; // @ts-ignore var state = new spine.AnimationState(stateData); + state.setAnimation(0, animationName, true); // Record animation assigned for listener this.trackAnimations[0] = this.animationName; @@ -304,9 +307,22 @@ }, event: (trackEntry, event) => { this.completeEventName = event.data.name; - this.completeEventTrackIndex = trackEntry.trackIndex; + this.completeEventTrackIndex = trackEntry.trackIndex; + + this.completeEventData = { + 'float' : event.floatValue, + 'int' : event.intValue, + 'string' : event.stringValue, + 'balance' : event.balance, + 'volume' : event.volume, + 'audiopath' : event.data.audioPath, + 'event' : event.data.name, + 'track' : trackEntry.trackIndex + } + // @ts-ignore this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnEvent); + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnyEvent); } }; @@ -496,9 +512,22 @@ }, event: (trackEntry, event) => { this.completeEventName = event.data.name; - this.completeEventTrackIndex = trackEntry.trackIndex; + this.completeEventTrackIndex = trackEntry.trackIndex; + + this.completeEventData = { + 'float' : event.floatValue, + 'int' : event.intValue, + 'string' : event.stringValue, + 'balance' : event.balance, + 'volume' : event.volume, + 'audiopath' : event.data.audioPath, + 'event' : event.data.name, + 'track' : trackEntry.trackIndex + } + // @ts-ignore this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnEvent); + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnyEvent); } }; } @@ -648,6 +677,7 @@ this.spineError = null this.animationSpeed = null; this.completeEventName = null; + this.completeEventData = null; this.skeletonRenderQuality = null; this.textureWidth = null; this.textureHeight = null; diff --git a/src/lang/en-US.json b/src/lang/en-US.json index a898b75..2645992 100644 --- a/src/lang/en-US.json +++ b/src/lang/en-US.json @@ -192,6 +192,17 @@ } } }, + "on-any-event": { + "list-name": "On any animation event", + "display-text": "On any event on track {0}", + "description": "Triggered on any event on specified track.", + "params": { + "track-index": { + "name": "Track index", + "desc": "Track index" + } + } + }, "is-bone-control-property-active": { "list-name": "Is bone control property active", "display-text": "Is {0} {1} control active", @@ -1085,7 +1096,27 @@ "description": "Skeleton scale", "translated-name": "SkeletonScale", "params": {} - } + }, + "get-event-name": { + "description": "Get current event name on the current track", + "translated-name": "GetEventName", + "params": {} + }, + "get-event-track-index": { + "description": "Get track index of the current event", + "translated-name": "GetEventTrackIndex", + "params": {} + }, + "get-event-data": { + "description": "Get value field of the current event", + "translated-name": "GetEventData", + "params": { + "field": { + "name": "Field", + "desc": "The field of the event data to read (float,int,string,balance,volume,audiopath,event,track)" + } + } + } } } }