From f2442ad618852d5145043e575ca1f40362ae4a84 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 31 Dec 2021 17:18:48 -0700 Subject: [PATCH] hollywooFlixel actor animations by wryly --- .../src/hollywoo_flixel/ActorFlxSprite.hx | 2 +- .../src/hollywoo_flixel/ActorFlxSprite.kiss | 16 ++++++++++++++-- .../src/hollywoo_flixel/FlxDirector.kiss | 9 +++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.hx b/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.hx index 47c80e85..bfbb37c6 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.hx +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.hx @@ -2,11 +2,11 @@ package hollywoo_flixel; import kiss.Prelude; import kiss.List; +import kiss.FuzzyMap; import flixel.FlxSprite; import hollywoo_flixel.FlxMovie; typedef AnimationArgs = { - name:String, frames:Array, ?frameRate:Float, // default 30 ?looped:Bool, // default true diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.kiss index 4fdf499d..4eed7acb 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/ActorFlxSprite.kiss @@ -1,6 +1,8 @@ (prop :FlxStageFacing defaultFacing) -(defNew [:String assetPath &opt frameWidth frameHeight :FlxStageFacing defaultFacing :Map animations] +(prop :FuzzyMap animationNames (new FuzzyMap)) + +(defNew [&prop :String assetPath &opt frameWidth frameHeight :FlxStageFacing defaultFacing :Map animations] (super) (set this.defaultFacing (or defaultFacing Right)) @@ -10,10 +12,20 @@ (loadGraphic assetPath)) (when animations (doFor =>name animationArgs animations + (dictSet animationNames name name) (animation.add name animationArgs.frames (or animationArgs.frameRate 30) (or animationArgs.looped true) ?animationArgs.flipX - ?animationArgs.flipY)))) \ No newline at end of file + ?animationArgs.flipY)))) + +(method :Void playAnimation [fuzzySearchKey] + (if (animationNames.exists fuzzySearchKey) + (animation.play (dictGet animationNames fuzzySearchKey) true) + (#when debug + (print "WARNING! No animation matches $fuzzySearchKey for actor with spritesheet $assetPath")))) + +(method :Void stopAnimation [] + (animation.stop)) \ No newline at end of file diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss index 7262f5c9..6a69efda 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss @@ -104,6 +104,15 @@ (method showDialog [:String speakerName :SpeechType type :String wryly :String text :Continuation cc] // TODO handle text messages, wrylies, off-screen, from-phone, etc. via (case type) // TODO attribute on-screen dialogue to the character's stageposition + + // When the actor is in the scene, check for an animation matching the wryly + (doFor =>actorName character currentState.characters + (when (= actorName speakerName) + (let [actor (the ActorFlxSprite character.actor)] + (if wryly + (actor.playAnimation wryly) + (actor.playAnimation "neutral"))))) + // Make a dialog box (unless dialogBox (set dialogBox (new FlxSprite DIALOG_X DIALOG_Y))