rayjs/examples/ts_game/src/entity.ts

45 lines
848 B
TypeScript
Raw Normal View History

2023-05-27 09:35:08 +00:00
export interface HasIdentity {
id: number
}
export interface Drawable<T> {
draw: (entity: T) => void
}
export interface Updatable<T> {
update: (entity: T) => void
}
export interface HasResources<T> {
load: (entity: T) => void
unload: (entity: T) => void
}
export interface HasPosition {
position: Vector2
}
export interface HasColor {
color: Color
}
export type EntityOf<T> = HasIdentity & Partial<HasResources<T>> & Partial<Updatable<T>> & Partial<Drawable<T>> & T
let ID = 0
export const makeEntity = () => ({
id: ID++
})
export const makePosition = (x = 0, y = 0) => ({
position: new Vector2(x,y)
})
export const makeColorRgb = (r = 255, g = 255, b = 255, a = 255) => ({
color: new Color(r,g,b,a)
})
export const makeColorClone = (c = WHITE) => ({
color: new Color(c.r,c.g,c.b,c.a)
})