Improve text rendering system
This commit is contained in:
parent
b1bceb9ffc
commit
e951317ddd
|
|
@ -27,6 +27,10 @@ export class Sprite extends Component<{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get image(): string {
|
||||||
|
return this.state.frames[this.state.currentFrame];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@component export class Hidden extends Component<{}> {
|
@component export class Hidden extends Component<{}> {
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,16 @@ export class TextDisplaySystem extends System {
|
||||||
const sprites = Array.from(world.query(Sprite, Position)).sort((a, b) => a[2].state.z - b[2].state.z);
|
const sprites = Array.from(world.query(Sprite, Position)).sort((a, b) => a[2].state.z - b[2].state.z);
|
||||||
for (const [e, sprite, pos] of sprites) {
|
for (const [e, sprite, pos] of sprites) {
|
||||||
if (e.has(Hidden)) continue;
|
if (e.has(Hidden)) continue;
|
||||||
const { frames, currentFrame } = sprite.state;
|
const image = sprite.image;
|
||||||
const { x, y } = pos.state;
|
const { x, y } = pos.state;
|
||||||
|
|
||||||
const data = Resources.get(TextRegion, frames[currentFrame]) ?? new TextRegion(frames[currentFrame]);
|
const data =
|
||||||
this.display.setRegion(x, y, data);
|
Resources.get(TextRegion, image)
|
||||||
|
?? Resources.get(String, image)
|
||||||
|
?? image;
|
||||||
|
|
||||||
|
const region = data instanceof TextRegion ? data : new TextRegion(data);
|
||||||
|
this.display.setRegion(x, y, region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,9 @@ export namespace Resources {
|
||||||
const resources = new Map<Function, Map<string, any>>();
|
const resources = new Map<Function, Map<string, any>>();
|
||||||
|
|
||||||
export function get<T>(id: string): T | undefined;
|
export function get<T>(id: string): T | undefined;
|
||||||
|
export function get(ctor: StringConstructor, id: string): string | undefined;
|
||||||
|
export function get(ctor: NumberConstructor, id: string): number | undefined;
|
||||||
|
export function get(ctor: BooleanConstructor, id: string): boolean | undefined;
|
||||||
export function get<T>(ctor: Class<T>, id: string): T | undefined;
|
export function get<T>(ctor: Class<T>, id: string): T | undefined;
|
||||||
export function get<T>(ctorOrId: Class<T> | string, id?: string): T | undefined {
|
export function get<T>(ctorOrId: Class<T> | string, id?: string): T | undefined {
|
||||||
const ctor = typeof ctorOrId === 'string' ? undefined : ctorOrId;
|
const ctor = typeof ctorOrId === 'string' ? undefined : ctorOrId;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue