refactor: component test
This commit is contained in:
parent
77dcb7c5a1
commit
ac9e0b4134
|
@ -3,25 +3,21 @@ import {expect, test} from 'vitest';
|
|||
import Component from './component.js';
|
||||
import Ecs from './ecs.js';
|
||||
import System from './system.js';
|
||||
import {wrapComponents} from './test-helper.js';
|
||||
|
||||
function wrapProperties(name, properties) {
|
||||
return class WrappedComponent extends Component {
|
||||
static componentName = name;
|
||||
static properties = properties;
|
||||
};
|
||||
}
|
||||
const Components = wrapComponents([
|
||||
['Empty', {}],
|
||||
['Momentum', {x: {type: 'int32'}, y: {type: 'int32'}, z: {type: 'int32'}}],
|
||||
['Name', {name: {type: 'string'}}],
|
||||
['Position', {x: {type: 'int32', defaultValue: 32}, y: {type: 'int32'}, z: {type: 'int32'}}],
|
||||
]);
|
||||
|
||||
const Empty = wrapProperties('Empty', {});
|
||||
|
||||
const Name = wrapProperties('Name', {
|
||||
name: {type: 'string'},
|
||||
});
|
||||
|
||||
const Position = wrapProperties('Position', {
|
||||
x: {type: 'int32', defaultValue: 32},
|
||||
y: {type: 'int32'},
|
||||
z: {type: 'int32'},
|
||||
});
|
||||
const {
|
||||
Empty,
|
||||
Momentum,
|
||||
Position,
|
||||
Name,
|
||||
} = Components;
|
||||
|
||||
function asyncTimesTwo(x) {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -131,11 +127,6 @@ test('inserts components into entities', async () => {
|
|||
});
|
||||
|
||||
test('ticks systems', async () => {
|
||||
const Momentum = wrapProperties('Momentum', {
|
||||
x: {type: 'int32'},
|
||||
y: {type: 'int32'},
|
||||
z: {type: 'int32'},
|
||||
});
|
||||
const ecs = new Ecs({
|
||||
Components: {Momentum, Position},
|
||||
Systems: {
|
||||
|
|
|
@ -1,23 +1,14 @@
|
|||
import {expect, test} from 'vitest';
|
||||
|
||||
import Ecs from './ecs';
|
||||
import Component from './component.js';
|
||||
import Ecs from './ecs.js';
|
||||
import {wrapComponents} from './test-helper.js';
|
||||
import Query from './query.js';
|
||||
|
||||
const Components = [
|
||||
const Components = wrapComponents([
|
||||
['A', {a: {type: 'int32', defaultValue: 64}}],
|
||||
['B', {b: {type: 'int32', defaultValue: 32}}],
|
||||
['C', {c: {type: 'int32'}}],
|
||||
]
|
||||
.reduce((Components, [componentName, properties]) => {
|
||||
return {
|
||||
...Components,
|
||||
[componentName]: class extends Component {
|
||||
static componentName = componentName;
|
||||
static properties = properties;
|
||||
},
|
||||
};
|
||||
}, {})
|
||||
]);
|
||||
|
||||
const ecsTest = test.extend({
|
||||
ecs: async ({}, use) => {
|
||||
|
|
14
app/ecs/test-helper.js
Normal file
14
app/ecs/test-helper.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import Component from './component.js';
|
||||
|
||||
export function wrapComponents(Components) {
|
||||
return Components
|
||||
.reduce((Components, [componentName, properties]) => {
|
||||
return {
|
||||
...Components,
|
||||
[componentName]: class extends Component {
|
||||
static componentName = componentName;
|
||||
static properties = properties;
|
||||
},
|
||||
};
|
||||
}, {})
|
||||
}
|
Loading…
Reference in New Issue
Block a user