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