feat: component shorthand
This commit is contained in:
parent
6429ae6e80
commit
22568bd999
|
@ -18,3 +18,14 @@ export default function ComponentRouter() {
|
|||
}
|
||||
return new RealClass(schema);
|
||||
}
|
||||
|
||||
ComponentRouter.normalize = (ComponentLike) => {
|
||||
if (ComponentLike.prototype instanceof ComponentRouter) {
|
||||
return ComponentLike;
|
||||
}
|
||||
return class AdhocComponent extends ComponentRouter {
|
||||
|
||||
static schema = ComponentLike;
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable guard-for-in, max-classes-per-file, no-continue, no-restricted-syntax */
|
||||
import Component from './component';
|
||||
|
||||
export default class Ecs {
|
||||
|
||||
|
@ -16,7 +17,7 @@ export default class Ecs {
|
|||
|
||||
constructor(Components) {
|
||||
for (const i in Components) {
|
||||
this.Components[i] = this.trackDirtyEntities(Components[i]);
|
||||
this.Components[i] = this.trackDirtyEntities(Component.normalize(Components[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
/* eslint-disable react/prefer-stateless-function */
|
||||
import {expect} from 'chai';
|
||||
|
||||
import Component from '../src/component';
|
||||
import Ecs from '../src/ecs';
|
||||
import System from '../src/system';
|
||||
|
||||
class Empty extends Component {}
|
||||
const Empty = {};
|
||||
|
||||
class Position extends Component {
|
||||
|
||||
static schema = {
|
||||
x: {type: 'int32', defaultValue: 32},
|
||||
y: 'int32',
|
||||
z: 'int32',
|
||||
};
|
||||
|
||||
}
|
||||
const Position = {
|
||||
x: {type: 'int32', defaultValue: 32},
|
||||
y: 'int32',
|
||||
z: 'int32',
|
||||
};
|
||||
|
||||
it('can create entities with components', () => {
|
||||
const ecs = new Ecs({Empty, Position});
|
||||
|
@ -25,15 +20,11 @@ it('can create entities with components', () => {
|
|||
});
|
||||
|
||||
it('can tick systems', () => {
|
||||
class Momentum extends Component {
|
||||
|
||||
static schema = {
|
||||
x: 'int32',
|
||||
y: 'int32',
|
||||
z: 'int32',
|
||||
};
|
||||
|
||||
}
|
||||
const Momentum = {
|
||||
x: 'int32',
|
||||
y: 'int32',
|
||||
z: 'int32',
|
||||
};
|
||||
const ecs = new Ecs({Momentum, Position});
|
||||
class Physics extends System {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user