swap characters in front/behind positions on speech

This commit is contained in:
2022-01-06 14:21:55 -07:00
parent 7611a6ba47
commit 4c715be44d
3 changed files with 40 additions and 8 deletions

View File

@@ -44,11 +44,13 @@
(- (case character.stagePosition (- (case character.stagePosition
(Left (Left
(set currentState.actorOnLeft character.actor) (set currentState.actorOnLeft character.actor)
(set currentState.characterOnLeft character)
STAGE_LEFT_X) STAGE_LEFT_X)
(LeftBehind (LeftBehind
STAGE_LEFT_X) STAGE_LEFT_X)
(Right (Right
(set currentState.actorOnRight character.actor) (set currentState.actorOnRight character.actor)
(set currentState.characterOnRight character)
STAGE_RIGHT_X) STAGE_RIGHT_X)
(RightBehind (RightBehind
STAGE_RIGHT_X) STAGE_RIGHT_X)
@@ -75,16 +77,29 @@
(method :Void hideCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> character :Continuation cc] (method :Void hideCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> character :Continuation cc]
(when (= currentState.actorOnLeft character.actor) (when (= currentState.actorOnLeft character.actor)
(set currentState.actorOnLeft null)) (set currentState.actorOnLeft null)
(set currentState.characterOnLeft null))
(when (= currentState.actorOnRight character.actor) (when (= currentState.actorOnRight character.actor)
(set currentState.actorOnRight null)) (set currentState.actorOnRight null)
(set currentState.characterOnRight null))
(currentState.remove character.actor) (currentState.remove character.actor)
(cc)) (cc))
(method :Void moveCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> character fromPos fromFacing toPos toFacing :Continuation cc] (method :Void moveCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> 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 (hideCharacter character
->:Void (showCharacter character ReAppearance cc))) ->:Void (showCharacter character ReAppearance cc)))
(method :Void swapCharacters [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> a :Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> 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<Continuation> nextCC) (prop &mut :Null<Continuation> nextCC)
(method onContinue [:FlxActionDigital continueAction] (method onContinue [:FlxActionDigital continueAction]
(whenLet [cc nextCC] (whenLet [cc nextCC]
@@ -135,18 +150,32 @@
// TODO handle text messages, wrylies, off-screen, from-phone, etc. via (case type) // TODO handle text messages, wrylies, off-screen, from-phone, etc. via (case type)
// TODO attribute on-screen dialogue to the character's stageposition // 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 // TODO allow sounds for wrylies, like the dispatch click
(localVar &mut nameOnRight false) (localVar &mut nameOnRight false)
(doFor =>actorName character currentState.characters (case type
(when (= actorName speakerName) ((OnScreen character)
(case character.stagePosition (case character.stagePosition
((or Right RightBehind) (set nameOnRight true)) ((or Right RightBehind) (set nameOnRight true))
(otherwise)) (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)] (let [actor (the ActorFlxSprite character.actor)]
(if wryly (if wryly
(actor.playAnimation 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 // Make a dialog box
(unless dialogBox (unless dialogBox

View File

@@ -2,6 +2,7 @@ package hollywoo_flixel;
import kiss.Prelude; import kiss.Prelude;
import kiss.List; import kiss.List;
import kiss.FuzzyMap;
import flixel.FlxSubState; import flixel.FlxSubState;
import flixel.FlxState; import flixel.FlxState;
import flixel.FlxSprite; import flixel.FlxSprite;

View File

@@ -1,11 +1,13 @@
// Track which actors are in FRONT of the stage so actors can appear behind them // Track which actors are in FRONT of the stage so actors can appear behind them
(prop &mut :ActorFlxSprite actorOnLeft null) (prop &mut :ActorFlxSprite actorOnLeft null)
(prop &mut :Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> characterOnLeft null)
(prop &mut :ActorFlxSprite actorOnRight null) (prop &mut :ActorFlxSprite actorOnRight null)
(prop &mut :Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> characterOnRight null)
(defNew [&prop :FlxSprite setSprite &prop :SceneTime time &prop :ScenePerspective perspective] (defNew [&prop :FlxSprite setSprite &prop :SceneTime time &prop :ScenePerspective perspective]
[ [
&mut :FlxState parent null &mut :FlxState parent null
:Map<String,Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite>> characters (new Map) :FuzzyMap<Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite>> characters (new FuzzyMap<Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite>>)
:Map<FlxSprite,FlxScreenPosition> propsOnScreen (new Map) :Map<FlxSprite,FlxScreenPosition> propsOnScreen (new Map)
] ]
(super) (super)