Skip to content

Instantly share code, notes, and snippets.

@ForsakenHarmony
Created May 17, 2017 23:19
Show Gist options
  • Save ForsakenHarmony/33ef7c4d7cba7a08d5fa2667b5b1b31e to your computer and use it in GitHub Desktop.
Save ForsakenHarmony/33ef7c4d7cba7a08d5fa2667b5b1b31e to your computer and use it in GitHub Desktop.
declare module 'gg-entities' {
type Component = any
type Id = number
type ComponentsMask = number
type Entity = { components: ComponentsMask }
enum SystemType {
Logic,
Render,
Init,
}
export class EntityManager {
constructor(capacity?: number)
increaseCapacity()
newEntity(components: ComponentsMask | Array<Id>): { id: Id, entity: Entity | null }
deleteEntity(id: Id)
getEntities(components?: ComponentsMask): Generator
registerConfiguration(): Id
registerComponent(name: string, component: any): Id
addComponent(entityId: Id, component)
removeComponent(entityId: Id, component)
registerSystem(type: SystemType, components: ComponentsMask | Array<Id>, callback: Function): Id
registerLogicSystem(components: ComponentsMask | Array<Id>, callback: Function): Id
registerRenderSystem(components: ComponentsMask | Array<Id>, callback: Function): Id
registerInitSystem(components: ComponentsMask | Array<Id>, callback: Function): Id
removeSystem(systemId: Id): boolean
onLogic(opts: any)
onRender(opts: any)
onInit(opts: any)
// Entity Factory
registerInitializer(component, initializer)
build()
withComponent(component, initializer)
create(count, configurationId)
// Event Handler
listen(event: string, callback: Function): number
stopListen(eventId: number): boolean
trigger(): Promise<any>
triggerDelayed(): Promise<any>
}
export class EntityFactory {
registerInitializer(id: number, initializer: Function)
build(): EntityFactory
withComponent(componentId: Id, initializer: Function): EntityFactory
createConfiguration(): Map<any, any>
create(entityManager: EntityManager, count?: number, configuration?: Map<any, any>)
}
export class ComponentManager {
newComponent(componentId: Id): Component
registerComponent(component: Component): Id
getComponents(): Map<Id, Component>
}
export class EventHandler {
listen(event: string, callback: Function): number
stopListen(eventId: number): boolean
trigger(): Promise<any>
triggerDelayed(): Promise<any>
}
export class SystemManager {
registerSystem(type: SystemType, components: ComponentsMask, callback: Function): Id
removeSystem(systemId: Id): boolean
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment