Skip to content

Commit

Permalink
Added props to systems v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru committed Apr 1, 2021
1 parent 29638aa commit bdd3c00
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "darker-engine",
"description": "ecs lightweight library",
"version": "1.0.2",
"version": "1.1.0",
"author": "darkaqua",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,8 +12,12 @@
"start": "./node_modules/.bin/ts-node ./src/index.ts",
"build": "yarn run build:js && yarn run build:dts",
"build:js": "esbuild src/index.ts --bundle --format=esm --outfile=build/index.js",
"build:dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir build"
"build:dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir build",
"prepublish": "yarn run build"
},
"files": [
"build/"
],
"keywords": [
"ecs",
"entity-component-system",
Expand Down
14 changes: 9 additions & 5 deletions src/game.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {entitiesFunction} from "./entities";
import {GameFunction, SystemType} from "./types";
import {GameFunction, SystemFunction, SystemType} from "./types";

export const game: GameFunction = <SystemEnum, ComponentEnum>() => {
let systems: SystemType<SystemEnum, ComponentEnum>[] = [];
Expand All @@ -8,11 +8,15 @@ export const game: GameFunction = <SystemEnum, ComponentEnum>() => {
// Contains which entities has every system
const systemEntitiesMap = new Map<SystemEnum, string[]>();

const setSystems = (..._systems: SystemType<SystemEnum, ComponentEnum>[]) => {
_systems.forEach(system => {
systemEntitiesMap.set(system.id, []);
const setSystems = (..._systems: SystemFunction<SystemEnum, ComponentEnum>[]) => {
const systemList = _systems.map(system => {
const _system = system({
game: this
});
systemEntitiesMap.set(_system.id, []);
return _system;
});
systems.push(..._systems);
systems.push(...systemList);
}

const entities = entitiesFunction<ComponentEnum>();
Expand Down
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export interface GameType<SystemEnum, ComponentEnum> {
entities: EntitiesType<ComponentEnum>;
onLoop: (delta: number) => any;
setSystems: (...systems: SystemType<SystemEnum, ComponentEnum>[]) => any;
setSystems: (...systems: SystemFunction<SystemEnum, ComponentEnum>[]) => any;
getSystemEntities?: (system: SystemEnum) => string[];
}

Expand All @@ -23,7 +23,12 @@ export interface SystemType<SystemEnum, ComponentEnum> {
getEntities?: () => string[];
}

export type SystemFunction<SystemEnum, ComponentEnum> = () => SystemType<SystemEnum, ComponentEnum>;
export type SystemFunctionProps<SystemEnum, ComponentEnum> = {
game: GameType<SystemEnum, ComponentEnum>
}

export type SystemFunction<SystemEnum, ComponentEnum> =
(props: SystemFunctionProps<SystemEnum, ComponentEnum>) => SystemType<SystemEnum, ComponentEnum>;

/**
* Entity
Expand Down

0 comments on commit bdd3c00

Please sign in to comment.