implements input on stdlib
This commit is contained in:
parent
a26237cb87
commit
5bfb70979f
@ -0,0 +1,77 @@
|
||||
[BuiltinType(name = "input", version = 1)]
|
||||
declare builtin type Input() {
|
||||
[IntrinsicCall(name = "pad", version = 1)]
|
||||
fn pad() -> InputPad;
|
||||
|
||||
[IntrinsicCall(name = "touch", version = 1)]
|
||||
fn touch() -> InputTouch;
|
||||
}
|
||||
|
||||
[BuiltinType(name = "input.pad", version = 1)]
|
||||
declare builtin type InputPad() {
|
||||
[IntrinsicCall(name = "up", version = 1)]
|
||||
fn up() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "down", version = 1)]
|
||||
fn down() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "left", version = 1)]
|
||||
fn left() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "right", version = 1)]
|
||||
fn right() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "a", version = 1)]
|
||||
fn a() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "b", version = 1)]
|
||||
fn b() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "x", version = 1)]
|
||||
fn x() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "y", version = 1)]
|
||||
fn y() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "l", version = 1)]
|
||||
fn l() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "r", version = 1)]
|
||||
fn r() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "start", version = 1)]
|
||||
fn start() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "select", version = 1)]
|
||||
fn select() -> InputButton;
|
||||
}
|
||||
|
||||
[BuiltinType(name = "input.touch", version = 1)]
|
||||
declare builtin type InputTouch() {
|
||||
[IntrinsicCall(name = "button", version = 1)]
|
||||
fn button() -> InputButton;
|
||||
|
||||
[IntrinsicCall(name = "x", version = 1)]
|
||||
fn x() -> int;
|
||||
|
||||
[IntrinsicCall(name = "y", version = 1)]
|
||||
fn y() -> int;
|
||||
}
|
||||
|
||||
[BuiltinType(name = "input.button", version = 1)]
|
||||
declare builtin type InputButton() {
|
||||
[IntrinsicCall(name = "pressed", version = 1)]
|
||||
fn pressed() -> bool;
|
||||
|
||||
[IntrinsicCall(name = "released", version = 1)]
|
||||
fn released() -> bool;
|
||||
|
||||
[IntrinsicCall(name = "down", version = 1)]
|
||||
fn down() -> bool;
|
||||
|
||||
[IntrinsicCall(name = "hold", version = 1)]
|
||||
fn hold() -> int;
|
||||
}
|
||||
|
||||
[BuiltinConst(target = "input", name = "global", version = 1)]
|
||||
declare const Input: Input;
|
||||
@ -0,0 +1,5 @@
|
||||
pub struct Input;
|
||||
pub struct InputPad;
|
||||
pub struct InputTouch;
|
||||
pub struct InputButton;
|
||||
pub const Input;
|
||||
@ -94,9 +94,10 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
"""
|
||||
import { Color } from @core:color;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
import { Input, InputPad, InputButton } from @sdk:input;
|
||||
|
||||
declare contract Renderer {
|
||||
fn render(gfx: Gfx, color: Color) -> void;
|
||||
fn render(gfx: Gfx, color: Color, input: Input, pad: InputPad, button: InputButton) -> void;
|
||||
}
|
||||
""",
|
||||
"pub contract Renderer;",
|
||||
@ -108,6 +109,11 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
d.getCode().equals(PbsLinkErrors.E_LINK_IMPORT_SYMBOL_UNRESOLVED.name())));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("Color")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("Input") && t.canonicalTypeName().equals("input")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("InputButton")
|
||||
&& t.intrinsics().stream().anyMatch(i -> i.canonicalName().equals("hold"))));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().hostMethodBindings().stream()
|
||||
.anyMatch(h -> h.ownerName().equals("Gfx")));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user