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

Fix turret anim frame calculation to match game #219

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/TSMapEditor/Models/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ public override int GetXDrawOffset()
(IsBuildingAnim ? BuildingAnimDrawConfig.X : 0);
}

// Turret anims have their facing frames reversed
// Turret anims also only have 32 facings
// Game uses lookup table containing frame indices (frame index 28 at array index 0,
// decrementing and wrapping around to 31 after 0) to determine the correct frame from
// direction normalized to range 0-31, the formula is replicated here without the LUT - Starkku
private int GetTurretAnimFrameIndex() => (28 - Facing / 8 + 32) % 32;

public override int GetFrameIndex(int frameCount)
{
if (IsTurretAnim)
{
// Turret anims have their facing frames reversed
// Turret anims also only have 32 facings
byte facing = (byte)(255 - Facing - 31);
return facing / (256 / 32);
}
return GetTurretAnimFrameIndex();

if (IsBuildingAnim && ParentBuilding != null)
{
Expand All @@ -60,6 +62,9 @@ public override int GetFrameIndex(int frameCount)

public override int GetShadowFrameIndex(int frameCount)
{
if (IsTurretAnim)
return GetTurretAnimFrameIndex() + frameCount / 2;

if (IsBuildingAnim && ParentBuilding != null)
{
if (ParentBuilding.HP < Constants.ConditionYellowHP)
Expand Down
8 changes: 0 additions & 8 deletions src/TSMapEditor/Rendering/ObjectRenderers/AnimRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,8 @@ public override void DrawShadow(Animation gameObject)

var drawParams = GetDrawParams(gameObject);
var drawPoint = GetDrawPoint(gameObject);

int shadowFrameIndex = gameObject.GetShadowFrameIndex(drawParams.ShapeImage.GetFrameCount());

if (gameObject.IsTurretAnim)
{
// Turret anims have their facing frames reversed
byte facing = (byte)(255 - gameObject.Facing - 31);
shadowFrameIndex += facing / (512 / drawParams.ShapeImage.GetFrameCount());
}

if (shadowFrameIndex > 0 && shadowFrameIndex < drawParams.ShapeImage.GetFrameCount())
{
var frame = drawParams.ShapeImage.GetFrame(shadowFrameIndex);
Expand Down
Loading