Skip to content

Commit

Permalink
Make script preview more accurately handle sprite entrances/exits (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Apr 11, 2023
1 parent c1cb8fb commit 6b82ea6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/SerialLoops/Editors/ScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,14 +1676,15 @@ private void UpdatePreview()

// Draw character sprites
Dictionary<Speaker, PositionedSprite> sprites = new();
Dictionary<Speaker, PositionedSprite> previousSprites = new();

ScriptItemCommand previousCommand = null;
foreach (ScriptItemCommand command in commands)
{
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];
Expand All @@ -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:
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 6b82ea6

Please sign in to comment.