diff --git a/src/input.ts b/src/input.ts index 6b5ff13b..a7469b4f 100644 --- a/src/input.ts +++ b/src/input.ts @@ -202,10 +202,10 @@ export const Key = { // NOTE: This must match the definition in input.rs. export const Button = { - Up: 0, - Down: 1, - Left: 2, - Right: 3, + Up: core.BUTTON_UP, + Down: core.BUTTON_DOWN, + Left: core.BUTTON_LEFT, + Right: core.BUTTON_RIGHT, } as const; type Button = (typeof Button)[keyof typeof Button]; diff --git a/src/script/input.rs b/src/script/input.rs index ed5fa013..cbb04675 100644 --- a/src/script/input.rs +++ b/src/script/input.rs @@ -122,6 +122,10 @@ impl InputAPI { ctx.new_fn(move |_ctx: &ContextRef, b: u32| input.btn(b))?, )?; } + builder.export("BUTTON_UP", ctx.new_u32(Button::Up)?)?; + builder.export("BUTTON_DOWN", ctx.new_u32(Button::Down)?)?; + builder.export("BUTTON_LEFT", ctx.new_u32(Button::Left)?)?; + builder.export("BUTTON_RIGHT", ctx.new_u32(Button::Right)?)?; builder.build("input-core")?; Ok(InputAPI { input }) } diff --git a/types/input-core.d.ts b/types/input-core.d.ts index 027ccf81..d6d0b905 100644 --- a/types/input-core.d.ts +++ b/types/input-core.d.ts @@ -1,3 +1,8 @@ // These are the functions exposed by the native input module. // +export const BUTTON_UP: number; +export const BUTTON_DOWN: number; +export const BUTTON_LEFT: number; +export const BUTTON_RIGHT: number; + export function btn(b: number): boolean;