[oden] Assets becomes async load in terms of IO/GFX
This commit is contained in:
parent
d2dfa7c401
commit
f3f9988314
3 changed files with 16 additions and 8 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import * as core from "asset-core";
|
||||
import * as io from "./io.ts";
|
||||
import * as gfx from "./graphics.ts";
|
||||
|
||||
export function load_texture(path: string): number {
|
||||
return core.load_texture(path);
|
||||
export async function load_texture(path: string): Promise<number> {
|
||||
const buffer = await io.load(path);
|
||||
return gfx.create_texture(buffer, path);
|
||||
}
|
||||
|
|
|
|||
14
src/main.ts
14
src/main.ts
|
|
@ -1,18 +1,22 @@
|
|||
import { cls, print, spr, use_texture } from "./graphics.ts";
|
||||
import { load_texture } from "./assets.ts";
|
||||
|
||||
let the_texture = 0;
|
||||
let the_texture: number | undefined = undefined;
|
||||
|
||||
export function init() {
|
||||
print("Hello world!");
|
||||
// TODO: Async IO
|
||||
the_texture = load_texture("./src/happy-tree.png");
|
||||
|
||||
// Start this load, but then...
|
||||
load_texture("./src/happy-tree.png").then((n) => (the_texture = n));
|
||||
}
|
||||
|
||||
export function update() {}
|
||||
|
||||
export function draw() {
|
||||
cls(0.1, 0.2, 0.3);
|
||||
use_texture(the_texture);
|
||||
spr((320 - 256) / 2, 0, 256, 240, 0, 0);
|
||||
if (the_texture != undefined) {
|
||||
// ...it gets resolved here?
|
||||
use_texture(the_texture);
|
||||
spr((320 - 256) / 2, 0, 256, 240, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
types/asset-core.d.ts
vendored
2
types/asset-core.d.ts
vendored
|
|
@ -1 +1,3 @@
|
|||
// These are the functions exposed by the native assets module.
|
||||
//
|
||||
export function load_texture(path: string): number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue