Export named constants for InputPlatform values

Open Beginner friendly
#263 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

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.

Description

core enhancement

Motivation

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

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:

export const InputPlatforms = table.freeze({
	Gamepad: "gamepad",
	Keyboard: "keyboard",
	Touch: "touch",
}) satisfies Record<string, InputPlatform>;

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).
Dominant language
TypeScript
Stars
11
Forks
1
Avg merge
11h 36m
Merged PRs (30d)
29

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from christopher-buss/flux

All issues in christopher-buss/flux

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.