• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

project-slippi / slippi-js / 20256270422

16 Dec 2025 04:14AM UTC coverage: 80.856% (+0.04%) from 80.813%
20256270422

Pull #158

github

web-flow
Merge 5cafcc36a into 414f15082
Pull Request #158: refactor: prefer undefined over null

696 of 929 branches covered (74.92%)

Branch coverage included in aggregate %.

63 of 82 new or added lines in 20 files covered. (76.83%)

6 existing lines in 2 files now uncovered.

1855 of 2226 relevant lines covered (83.33%)

125846.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/src/common/utils/homeRunDistance.ts
1
import type { FrameEntryType, GameStartType } from "../types";
2
import { Language } from "../types";
12✔
3
import { exists } from "./exists";
12✔
4

5
const SANDBAG_INTERNAL_ID = 32;
12✔
6

7
const FEET_CONVERSION_FACTOR = 0.952462;
12✔
8
const METERS_CONVERSION_FACTOR = 1.04167;
12✔
9

10
type HomeRunDistanceUnits = "feet" | "meters";
11

12
export function positionToHomeRunDistance(distance: number, units: HomeRunDistanceUnits = "feet"): number {
12✔
13
  let score = 0;
3✔
14
  switch (units) {
3!
15
    case "feet":
16
      score = 10 * Math.floor(distance - 70 * FEET_CONVERSION_FACTOR);
2✔
17
      // convert to float32
18
      score = Math.fround(score);
2✔
19
      score = Math.floor((score / 30.4788) * 10) / 10;
2✔
20
      break;
2✔
21
    case "meters":
22
      score = 10 * Math.floor(distance - 70 * METERS_CONVERSION_FACTOR);
1✔
23
      // convert to float32
24
      score = Math.fround(score);
1✔
25
      score = Math.floor((score / 100) * 10) / 10;
1✔
26
      break;
1✔
27
    default:
28
      throw new Error(`Unsupported units: ${units}`);
×
29
  }
30

31
  // round to 1 decimal
32
  score = Math.round(score * 10) / 10;
3✔
33
  return Math.max(0, score);
3✔
34
}
35

36
export function extractDistanceInfoFromFrame(
12✔
37
  settings: Pick<GameStartType, "language">,
38
  lastFrame: Pick<FrameEntryType, "players">,
39
): { distance: number; units: HomeRunDistanceUnits } | undefined {
40
  const sandbagLastFrame = Object.values(lastFrame.players)
2✔
41
    .filter(exists)
42
    .find((playerFrame) => playerFrame.post.internalCharacterId === SANDBAG_INTERNAL_ID);
4✔
43

44
  if (!sandbagLastFrame) {
2!
NEW
45
    return undefined;
×
46
  }
47

48
  // Only return the distance in meters if it's a Japanese replay.
49
  // Technically we should check if the replay is PAL but we don't yet support
50
  // stadium replays in PAL.
51
  const units: HomeRunDistanceUnits = settings.language === Language.JAPANESE ? "meters" : "feet";
2✔
52
  const distance = positionToHomeRunDistance(sandbagLastFrame.post.positionX ?? 0, units);
2!
53
  return {
2✔
54
    distance,
55
    units,
56
  };
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc