Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke Bomb causes player dialog/thought bubbles to render in wrong spot #236

Closed
dbjorge opened this issue Dec 16, 2019 · 0 comments
Closed

Comments

@dbjorge
Copy link

dbjorge commented Dec 16, 2019

Repro steps:

  • Start a game using any character based on CustomPlayer that does not override movePosition
  • Enter a fight
  • draw 6
  • Observe that the "My hand is full!" thought bubble appears by the character in the expected position
  • potion 0 SmokeBomb
  • Use smoke bomb to escape fight
  • Enter a second fight
  • draw 6
  • Observe that the "My hand is full!" thought bubble now appears off to the right of the screen, rather than on the character

smoke_bomb_text_bug

Root cause

I think the underlying issue is with BaseMod's implementation of CustomPlayer.movePosition. Notable parts:

public void movePosition(float x, float y)
{
    float dialogOffsetX = dialogX - drawX;
    float dialogOffsetY = dialogY - drawY;
    drawX = x;
    drawY = y;
    dialogX = drawX + dialogOffsetX;
    dialogY = drawY + dialogOffsetY;
}

The way this is updating dialogX/dialogY is presuming that the offset between drawX/drawY will appear stable to subsequent calls of movePosition, but in the smoke bomb case, updateEscapeAnimation updates drawX without making corresponding updates to dialogX.

Some options for patching this in a backwards compatible way:

  • patch AbstractPlayer.updateEscapeAnimation to update dialogX along with drawX (either directly or by replacing the mutation of drawX with calls to movePostition)
  • update CustomPlayer to calculate and persist the dialogOffsets in a field early during play (possibly "the first time movePosition is called) and have subsequent calls to movePosition use that rather than re-calculating

The latter would be more resilient to cases other mods might add that move drawX around; the former would be friendlier to mods that for some reason move dialogX/dialogY dynamically (maybe a character with a shapeshifting mechanic that changes size dynamically, etc). I'd probably go with the latter.

Workaround

Individual mods looking to work around the issue can override movePosition in each of their characters as follows:

// These should be the values you're probably using in your constructor,
// assuming you followed StS-TheDefaultMod's example
private static final float DIALOG_OFFSET_X = 0.0F * Settings.scale;
private static final float DIALOG_OFFSET_Y = 220.0F * Settings.scale;

@Override
public void movePostition(float x, float y) {
    super.movePosition(x, y);
    dialogX = x + DIALOG_OFFSET_X;
    dialogY = y + DIALOG_OFFSET_Y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant