implements PLN-0053
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
declare host LowComposer {
|
||||
[Host(module = "composer", name = "emit_sprite", version = 1)]
|
||||
[Capability(name = "gfx")]
|
||||
fn emit_sprite(
|
||||
glyph_id: int,
|
||||
palette_id: int,
|
||||
x: int,
|
||||
y: int,
|
||||
layer: int,
|
||||
bank_id: int,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int;
|
||||
}
|
||||
|
||||
declare service Composer
|
||||
{
|
||||
fn emit_sprite(
|
||||
glyph_id: int,
|
||||
palette_id: int,
|
||||
x: int,
|
||||
y: int,
|
||||
layer: int,
|
||||
bank_id: int,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int
|
||||
{
|
||||
return LowComposer.emit_sprite(glyph_id, palette_id, x, y, layer, bank_id, flip_x, flip_y, priority);
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
mod host LowComposer;
|
||||
pub service Composer;
|
||||
-31
@@ -25,21 +25,6 @@ declare host LowGfx {
|
||||
[Capability(name = "gfx")]
|
||||
fn draw_square(x: int, y: int, w: int, h: int, border_color: Color, fill_color: Color) -> void;
|
||||
|
||||
[Host(module = "gfx", name = "set_sprite", version = 1)]
|
||||
[Capability(name = "gfx")]
|
||||
fn set_sprite(
|
||||
bank_id: int,
|
||||
index: int,
|
||||
x: int,
|
||||
y: int,
|
||||
tile_id: int,
|
||||
palette_id: int,
|
||||
active: bool,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int;
|
||||
|
||||
[Host(module = "gfx", name = "draw_text", version = 1)]
|
||||
[Capability(name = "gfx")]
|
||||
fn draw_text(x: int, y: int, message: str, color: Color) -> void;
|
||||
@@ -81,22 +66,6 @@ declare service Gfx
|
||||
LowGfx.draw_square(x, y, w, h, border_color, fill_color);
|
||||
}
|
||||
|
||||
fn set_sprite(
|
||||
bank_id: int,
|
||||
index: int,
|
||||
x: int,
|
||||
y: int,
|
||||
tile_id: int,
|
||||
palette_id: int,
|
||||
active: bool,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int
|
||||
{
|
||||
return LowGfx.set_sprite(bank_id, index, x, y, tile_id, palette_id, active, flip_x, flip_y, priority);
|
||||
}
|
||||
|
||||
fn draw_text(x: int, y: int, message: str, color: Color) -> void
|
||||
{
|
||||
LowGfx.draw_text(x, y, message, color);
|
||||
|
||||
+67
@@ -84,4 +84,71 @@ class InterfaceModuleLoaderTest {
|
||||
"pub host LowAssets;",
|
||||
fileTable.get(module.barrelFiles().getFirst().fileId()).readUtf8().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLoadComposerStdlibModuleWithPublicServiceBarrel() {
|
||||
final var projectTable = new ProjectTable();
|
||||
final var projectId = projectTable.register(ProjectDescriptor.builder()
|
||||
.name("app")
|
||||
.version("1.0.0")
|
||||
.rootPath(Path.of("/tmp/app"))
|
||||
.sourceRoots(ReadOnlyList.wrap(java.util.List.of(Path.of("/tmp/app/src"))))
|
||||
.build());
|
||||
final var fileTable = new FileTable(1);
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
final var moduleSource = new StdlibModuleSource(
|
||||
"sdk",
|
||||
ReadOnlyList.wrap(java.util.List.of("composer")),
|
||||
ReadOnlyList.wrap(java.util.List.of(new StdlibModuleSource.SourceFile(
|
||||
"main.pbs",
|
||||
"""
|
||||
declare host LowComposer {
|
||||
[Host(module = "composer", name = "emit_sprite", version = 1)]
|
||||
[Capability(name = "gfx")]
|
||||
fn emit_sprite(
|
||||
glyph_id: int,
|
||||
palette_id: int,
|
||||
x: int,
|
||||
y: int,
|
||||
layer: int,
|
||||
bank_id: int,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int;
|
||||
}
|
||||
|
||||
declare service Composer {
|
||||
fn emit_sprite(
|
||||
glyph_id: int,
|
||||
palette_id: int,
|
||||
x: int,
|
||||
y: int,
|
||||
layer: int,
|
||||
bank_id: int,
|
||||
flip_x: bool,
|
||||
flip_y: bool,
|
||||
priority: int
|
||||
) -> int {
|
||||
return LowComposer.emit_sprite(glyph_id, palette_id, x, y, layer, bank_id, flip_x, flip_y, priority);
|
||||
}
|
||||
}
|
||||
"""))),
|
||||
"""
|
||||
mod host LowComposer;
|
||||
pub service Composer;
|
||||
""");
|
||||
|
||||
final var module = new InterfaceModuleLoader().load(moduleSource, projectId, fileTable, diagnostics);
|
||||
|
||||
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
|
||||
assertEquals(1, module.sourceFiles().size());
|
||||
assertEquals(1, module.barrelFiles().size());
|
||||
assertEquals(
|
||||
"""
|
||||
mod host LowComposer;
|
||||
pub service Composer;
|
||||
""".strip(),
|
||||
fileTable.get(module.barrelFiles().getFirst().fileId()).readUtf8().orElseThrow().strip());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user