From 6b82ea6e5011d181fde31e8a93140446a63d5c88 Mon Sep 17 00:00:00 2001 From: Jonko <69772986+jonko0493@users.noreply.github.com> Date: Tue, 11 Apr 2023 15:26:45 -0700 Subject: [PATCH] Make script preview more accurately handle sprite entrances/exits (#147) --- src/SerialLoops/Editors/ScriptEditor.cs | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/SerialLoops/Editors/ScriptEditor.cs b/src/SerialLoops/Editors/ScriptEditor.cs index ca584a3e..39a68e34 100644 --- a/src/SerialLoops/Editors/ScriptEditor.cs +++ b/src/SerialLoops/Editors/ScriptEditor.cs @@ -1676,6 +1676,7 @@ private void UpdatePreview() // Draw character sprites Dictionary sprites = new(); + Dictionary previousSprites = new(); ScriptItemCommand previousCommand = null; foreach (ScriptItemCommand command in commands) @@ -1683,7 +1684,7 @@ private void UpdatePreview() if (previousCommand?.Verb == CommandVerb.DIALOGUE) { SpriteExitScriptParameter spriteExitMoveParam = (SpriteExitScriptParameter)previousCommand?.Parameters[3]; // exits/moves happen _after_ dialogue is advanced, so we check these at this point - if ((spriteExitMoveParam.ExitTransition) != SpriteExitScriptParameter.SpriteExitTransition.NO_EXIT) + if (spriteExitMoveParam.ExitTransition != SpriteExitScriptParameter.SpriteExitTransition.NO_EXIT) { Speaker prevSpeaker = ((DialogueScriptParameter)previousCommand.Parameters[0]).Line.Speaker; SpriteScriptParameter previousSpriteParam = (SpriteScriptParameter)previousCommand.Parameters[1]; @@ -1696,7 +1697,11 @@ private void UpdatePreview() case SpriteExitScriptParameter.SpriteExitTransition.SLIDE_FROM_CENTER_TO_RIGHT_FADE_OUT: case SpriteExitScriptParameter.SpriteExitTransition.FADE_OUT_CENTER: case SpriteExitScriptParameter.SpriteExitTransition.FADE_OUT_LEFT: - sprites.Remove(prevSpeaker); + if (sprites[prevSpeaker].Sprite == previousSprites[prevSpeaker].Sprite || ((SpriteEntranceScriptParameter)previousCommand.Parameters[2]).EntranceTransition != SpriteEntranceScriptParameter.SpriteEntranceTransition.NO_TRANSITION) + { + sprites.Remove(prevSpeaker); + previousSprites.Remove(prevSpeaker); + } break; case SpriteExitScriptParameter.SpriteExitTransition.SLIDE_CENTER_TO_LEFT_AND_STAY: @@ -1732,9 +1737,14 @@ private void UpdatePreview() SpriteEntranceScriptParameter spriteEntranceParam = (SpriteEntranceScriptParameter)command.Parameters[2]; short layer = ((ShortScriptParameter)command.Parameters[9]).Value; - if (!sprites.ContainsKey(speaker)) + if (!sprites.ContainsKey(speaker) && spriteEntranceParam.EntranceTransition != SpriteEntranceScriptParameter.SpriteEntranceTransition.NO_TRANSITION) { sprites.Add(speaker, new()); + previousSprites.Add(speaker, new()); + } + if (sprites.ContainsKey(speaker)) + { + previousSprites[speaker] = sprites[speaker]; } if (spriteEntranceParam.EntranceTransition != SpriteEntranceScriptParameter.SpriteEntranceTransition.NO_TRANSITION) { @@ -1761,16 +1771,6 @@ private void UpdatePreview() break; } } - else - { - if (sprites[speaker].Positioning is null) - { - _log.LogWarning($"Sprite {sprites[speaker]} has null positioning data!"); - } - SpritePositioning.SpritePosition position = sprites[speaker].Positioning?.Position ?? SpritePositioning.SpritePosition.CENTER; - - sprites[speaker] = new() { Sprite = spriteParam.Sprite, Positioning = new() { Position = position, Layer = layer }, PalEffect = spritePaint }; - } } } else if (command.Verb == CommandVerb.INVEST_START)