Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript support #7

Open
eranimo opened this issue Jan 30, 2018 · 2 comments
Open

Typescript support #7

eranimo opened this issue Jan 30, 2018 · 2 comments

Comments

@eranimo
Copy link

eranimo commented Jan 30, 2018

Would be great.

Also, would it be possible to define a component as a Typescript interface?

@eranimo eranimo changed the title Typescript definitions Typescript support Jan 30, 2018
@bencoveney
Copy link

I have some rough typings. Feel free to use them or I can tidy up them up and make a PR if the author wants them?

@bencoveney
Copy link

bencoveney commented May 22, 2019

That link is dead now - here's the typings:

// entity-component-system.d.ts
declare module "entity-component-system" {
	export class EntityComponentSystem {
		constructor();
		add(system: System): void;
		addEach(system: System, search: string): void;
		run(entityPool: EntityPool, elapsedTime: number): void;
		runs(): number;
		timings(): { [key: string]: number };
		resetTimings(): void;
	}

	export class EntityPool {
		constructor();
		create(): number;
		destroy(id: number): void;
		registerComponent<Component>(
			component: string,
			factory: () => Component,
			reset?: (component: Component) => void,
			size?: number,
		): void;
		addComponent<Component>(
			id: number,
			component: string,
		): Component;
		getComponent<Component>(
			id: number,
			component: string,
		): Component;
		setComponent<Component>(
			id: number,
			component: string,
			value: Component
		): void;
		onAddComponent<Component>(
			component: string,
			callback: Callback<Component>
		): void;
		onRemoveComponent<Component>(
			component: string,
			callback: Callback<Component>
		): void;
		registerSearch(
			search: string,
			components: string[]
		): void;
		find(
			search: string,
		): number[];
		load(entities: EntityJson[]): void;
		save(): EntityJson[];
	}

	export interface System {
		(entityPool: EntityPool, elapsedTime: number): void
	}

	export interface Callback<Component> {
		(id: number, component: string, value: Component): void;
	}

	export interface EntityJson {
		id: number,
		[componentName: string]: any
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants