From 4c715be44deb96034dd2074109d31761f4bd5628 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 6 Jan 2022 14:21:55 -0700 Subject: [PATCH] swap characters in front/behind positions on speech --- src/hollywoo_flixel/FlxDirector.kiss | 43 +++++++++++++++++++++----- src/hollywoo_flixel/SceneFlxState.hx | 1 + src/hollywoo_flixel/SceneFlxState.kiss | 4 ++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/hollywoo_flixel/FlxDirector.kiss b/src/hollywoo_flixel/FlxDirector.kiss index cdd5a96..17a5db5 100644 --- a/src/hollywoo_flixel/FlxDirector.kiss +++ b/src/hollywoo_flixel/FlxDirector.kiss @@ -44,11 +44,13 @@ (- (case character.stagePosition (Left (set currentState.actorOnLeft character.actor) + (set currentState.characterOnLeft character) STAGE_LEFT_X) (LeftBehind STAGE_LEFT_X) (Right (set currentState.actorOnRight character.actor) + (set currentState.characterOnRight character) STAGE_RIGHT_X) (RightBehind STAGE_RIGHT_X) @@ -75,16 +77,29 @@ (method :Void hideCharacter [:Character character :Continuation cc] (when (= currentState.actorOnLeft character.actor) - (set currentState.actorOnLeft null)) + (set currentState.actorOnLeft null) + (set currentState.characterOnLeft null)) (when (= currentState.actorOnRight character.actor) - (set currentState.actorOnRight null)) + (set currentState.actorOnRight null) + (set currentState.characterOnRight null)) (currentState.remove character.actor) (cc)) -(method :Void moveCharacter [:Character character fromPos fromFacing toPos toFacing :Continuation cc] +(method :Void moveCharacter [:Character character toPos toFacing :Continuation cc] + // Directors don't have to change the character, but FlxDirector does because that state determines + // where actors are drawn in showCharacter: + (set character.stagePosition toPos) + (set character.stageFacing toFacing) (hideCharacter character ->:Void (showCharacter character ReAppearance cc))) +(method :Void swapCharacters [:Character a :Character b :Continuation cc] + (let [noCC ->:Void {} + tempStagePos a.stagePosition + tempStageFacing a.stageFacing] + (moveCharacter a b.stagePosition b.stageFacing noCC) + (moveCharacter b tempStagePos tempStageFacing cc))) + (prop &mut :Null nextCC) (method onContinue [:FlxActionDigital continueAction] (whenLet [cc nextCC] @@ -135,18 +150,32 @@ // 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 + // When an actor is associated with the line, check for an animation matching the wryly // TODO allow sounds for wrylies, like the dispatch click (localVar &mut nameOnRight false) - (doFor =>actorName character currentState.characters - (when (= actorName speakerName) + (case type + ((OnScreen character) (case character.stagePosition ((or Right RightBehind) (set nameOnRight true)) (otherwise)) + // If the character is behind another character, swap them so the speaker is front + (case character.stagePosition + (LeftBehind + ~"swap left" + (swapCharacters ~character ~currentState.characterOnLeft ->:Void {})) + (RightBehind + ~"swap Right" + (swapCharacters ~character ~currentState.characterOnRight ->:Void {})) + (otherwise)) (let [actor (the ActorFlxSprite character.actor)] (if wryly (actor.playAnimation wryly) - (actor.playAnimation "neutral"))))) + (actor.playAnimation "neutral")))) + ((or (OffScreen actor) (VoiceOver actor) (TextMessage actor) (FromPhone actor) (Custom _ actor _)) + (if wryly + (actor.playAnimation wryly) + (actor.playAnimation "neutral"))) + (otherwise)) // Make a dialog box (unless dialogBox diff --git a/src/hollywoo_flixel/SceneFlxState.hx b/src/hollywoo_flixel/SceneFlxState.hx index d7e3e95..c18eb03 100644 --- a/src/hollywoo_flixel/SceneFlxState.hx +++ b/src/hollywoo_flixel/SceneFlxState.hx @@ -2,6 +2,7 @@ package hollywoo_flixel; import kiss.Prelude; import kiss.List; +import kiss.FuzzyMap; import flixel.FlxSubState; import flixel.FlxState; import flixel.FlxSprite; diff --git a/src/hollywoo_flixel/SceneFlxState.kiss b/src/hollywoo_flixel/SceneFlxState.kiss index b0b0026..c89bfc2 100644 --- a/src/hollywoo_flixel/SceneFlxState.kiss +++ b/src/hollywoo_flixel/SceneFlxState.kiss @@ -1,11 +1,13 @@ // Track which actors are in FRONT of the stage so actors can appear behind them (prop &mut :ActorFlxSprite actorOnLeft null) +(prop &mut :Character characterOnLeft null) (prop &mut :ActorFlxSprite actorOnRight null) +(prop &mut :Character characterOnRight null) (defNew [&prop :FlxSprite setSprite &prop :SceneTime time &prop :ScenePerspective perspective] [ &mut :FlxState parent null - :Map> characters (new Map) + :FuzzyMap> characters (new FuzzyMap>) :Map propsOnScreen (new Map) ] (super)