christopher-buss / christopher-buss/flux

Export named constants for InputPlatform values

Open Beginner friendly
#263 0 comments 0 reactions 0 assignees View on GitHub
core enhancement
Dominant language
TypeScript
Stars
10
Forks
1
Avg merge
11h 36m
Merged PRs (30d)
29

Description

## Motivation

`getInputPlatform()` (#130) returns a bare string union, so every consumer switch reads as string literals:

```ts
switch (getInputPlatform()) {
case "gamepad": { ... }
case "keyboard": { ... }
case "touch": { ... }
}
```

Before #130 the same switch read `Enum.PreferredInput.Gamepad`, which named itself. The literals type-check exactly as well, but they lose the "where does this vocabulary come from" signal at the call site, and they read as magic strings to anyone who has not met `InputPlatform`.

## Proposal

Export a frozen const record next to `INPUT_PLATFORMS`:

```ts
export const InputPlatforms = table.freeze({
Gamepad: "gamepad",
Keyboard: "keyboard",
Touch: "touch",
}) satisfies Record;
```

Consumers then write `case InputPlatforms.Gamepad:` and keep exhaustiveness checking, because the values are still the literal union.

## Not proposed: compatibility with `Enum.PreferredInput`

Worth writing down so it stops being re-asked. It cannot be done:

- `Enum` items are engine userdata. A Luau library cannot construct one, so no exported value can be `===` to `Enum.PreferredInput.Gamepad`.
- The member sets do not line up anyway. `InputPlatform` has `"keyboard"`; `Enum.PreferredInput` has `KeyboardAndMouse`. The mapping is 1:1 today by coincidence of member count, not by name.

A named const record is the closest available shape, and it is what the engine `Enum` was providing at the call site in the first place.

## Notes

- Related: #130 (introduced `getInputPlatform`), #199 (platform classification).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the exported INPUT_PLATFORMS record and getInputPlatform implementation, then inspect nearby tests or consumers for the existing InputPlatform values. Add the named frozen record with Gamepad, Keyboard, and Touch values while preserving the literal union and exhaustiveness behavior; done means consumers can reference the named values without changing their accepted strings.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
game-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.