flow: testing

This commit is contained in:
cha0s 2021-01-03 16:37:03 -06:00
parent f0ecc1f093
commit d0ca3ff0e2
14 changed files with 149 additions and 38 deletions

View File

@ -61,7 +61,6 @@ export default class Existent extends decorate(Trait) {
constructor(...args) {
super(...args);
this._isDestroying = false;
this._isTicking = this.params.isTicking;
}
methods() {

View File

@ -41,9 +41,6 @@ export default class Listed extends Trait {
if (!list) {
return;
}
if (!this.entity.is('visible')) {
return;
}
const aabb = this.entity.visibleAabb;
if (Rectangle.isNull(aabb)) {
return;

View File

@ -108,27 +108,27 @@ describe(name, () => {
it('generates and accepts life packets', async () => {
entity.life = 80;
entity.maxLife = 90;
const packets = entity.traitInstance('Alive').packets();
const packets = normalize(latus, entity.traitInstance('Alive').packets());
expect(packets).to.have.lengthOf(1);
expect(packets[0][0]).to.equal('TraitUpdateAlive');
expect(packets[0][1]).to.deep.equal({life: 80, maxLife: 90});
entity2.traitInstance('Alive').acceptPacket(normalize(latus, packets[0]).pop());
expect(packets[0].constructor.type).to.equal('TraitUpdateAlive');
expect(packets[0].data).to.deep.equal({life: 80, maxLife: 90});
entity2.traitInstance('Alive').acceptPacket(packets[0]);
expect(entity2.life).to.equal(80);
expect(entity2.maxLife).to.equal(90);
});
it('generates and accepts death packets', async () => {
entity.life = 0;
entity.tick();
const packets = entity.traitInstance('Alive').packets();
const packets = normalize(latus, entity.traitInstance('Alive').packets());
expect(packets).to.have.lengthOf(2);
expect(packets[0][0]).to.equal('TraitUpdateAlive');
expect(packets[0][1]).to.deep.equal({life: 0, maxLife: 100});
expect(packets[1][0]).to.equal('Died');
expect(packets[0].constructor.type).to.equal('TraitUpdateAlive');
expect(packets[0].data).to.deep.equal({life: 0, maxLife: 100});
expect(packets[1].constructor.type).to.equal('Died');
expect(entity2.isDying).to.equal(false);
const promise = new Promise((resolve) => {
entity2.on('isDyingChanged', resolve);
});
entity2.traitInstance('Alive').acceptPacket(normalize(latus, packets[1]).pop());
entity2.traitInstance('Alive').acceptPacket(packets[1]);
return promise;
});
});

View File

@ -1,4 +1,5 @@
import {resource} from '@avocado/resource';
import {normalize} from '@avocado/s13n';
import {Latus} from '@latus/core';
import {expect} from 'chai';
@ -12,19 +13,52 @@ describe(name, () => {
['@avocado/entity', `${__dirname}/../src`],
'@avocado/resource',
'@avocado/traits',
'@latus/socket',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
});
describe('Traits', () => {
describe('Directional', () => {
it('is Directional', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Directional: {
params: {
directionCount: 4,
},
},
},
});
});
it('exists', async () => {
expect(entity.is('Directional')).to.equal(true);
});
it('tracks movement', async () => {
entity.emit('movementRequest', [1, 0]);
expect(entity.direction).to.equal(1);
entity.emit('movementRequest', [0, 1]);
expect(entity.direction).to.equal(2);
entity.emit('movementRequest', [-1, 0]);
expect(entity.direction).to.equal(3);
entity.emit('movementRequest', [0, -1]);
expect(entity.direction).to.equal(0);
});
it('generates and accepts direction packets', async () => {
entity.direction = 2;
const packets = normalize(latus, entity.traitInstance('Directional').packets());
expect(packets).to.have.lengthOf(1);
expect(packets[0].constructor.type).to.equal('TraitUpdateDirectionalDirection');
expect(packets[0].data).to.equal(2);
const entity2 = await Entity.load({
traits: {
Directional: {},
},
});
expect(entity.is('Directional')).to.equal(true);
expect(entity2.direction).to.equal(0);
entity2.traitInstance('Directional').acceptPacket(packets[0]);
expect(entity2.direction).to.equal(2);
});
});
});

View File

@ -18,14 +18,44 @@ describe(name, () => {
});
describe('Traits', () => {
describe('Existent', () => {
it('is Existent', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Existent: {},
},
});
});
it('exists', async () => {
expect(entity.is('Existent')).to.equal(true);
});
it('can transition', async () => {
entity.foobar = 10;
const tickingPromise = entity.transition(
{foobar: 30},
200,
'linear',
);
tickingPromise.tick(100);
expect(entity.foobar).to.equal(20);
tickingPromise.tick(100);
expect(entity.foobar).to.equal(30);
return tickingPromise;
});
it('can be destroyed', async () => {
expect(entity.isTicking).to.equal(true);
const promise = Promise.all([
new Promise((resolve) => {
entity.on('destroy', resolve);
}),
new Promise((resolve) => {
entity.on('destroyed', resolve);
}),
]);
entity.destroy();
expect(entity.allTraitInstances()).to.deep.equal({});
return promise;
});
});
});
});

View File

@ -7,6 +7,7 @@ const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
@ -14,18 +15,36 @@ describe(name, () => {
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Traits', () => {
describe('Listed', () => {
it('is Listed', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Listed: {},
},
});
});
it('exists', async () => {
expect(entity.is('Listed')).to.equal(true);
});
it('can be added to list quadtree', async () => {
entity.isVisible = true;
entity.visibleAabb = [0, 0, 16, 16];
const list = new EntityList();
entity.attachToList(list);
expect(list.visibleEntities([-16, -16, 32, 32])).to.have.lengthOf(1);
});
it('will be removed from quadtree on destroy', async () => {
entity.isVisible = true;
entity.visibleAabb = [0, 0, 16, 16];
const list = new EntityList();
entity.attachToList(list);
entity.emit('destroyed');
expect(list.visibleEntities([-16, -16, 32, 32])).to.have.lengthOf(0);
});
});
});
});

View File

@ -7,6 +7,7 @@ const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
@ -14,18 +15,29 @@ describe(name, () => {
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Traits', () => {
describe('Mobile', () => {
it('is Mobile', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Mobile: {},
},
});
});
it('exists', async () => {
expect(entity.is('Mobile')).to.equal(true);
});
it('can request movement', async () => {
});
it('can apply movement', async () => {
});
it('can force movement', async () => {
});
it('can move for a time', async () => {
});
});
});
});

View File

@ -7,6 +7,7 @@ const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
@ -14,18 +15,23 @@ describe(name, () => {
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Traits', () => {
describe('Perishable', () => {
it('is Perishable', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Perishable: {},
},
});
});
it('exists', async () => {
expect(entity.is('Perishable')).to.equal(true);
});
it('expires', async () => {
});
});
});
});

View File

@ -7,6 +7,7 @@ const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
@ -14,18 +15,23 @@ describe(name, () => {
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Traits', () => {
describe('Positioned', () => {
it('is Positioned', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Positioned: {},
},
});
});
it('exists', async () => {
expect(entity.is('Positioned')).to.equal(true);
});
it('generates and accepts movement packets', async () => {
});
});
});
});

View File

@ -7,6 +7,7 @@ const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
@ -14,18 +15,27 @@ describe(name, () => {
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity}} = resource(latus));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Traits', () => {
describe('Spawner', () => {
it('is Spawner', async () => {
const entity = await Entity.load({
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Spawner: {},
},
});
});
it('exists', async () => {
expect(entity.is('Spawner')).to.equal(true);
});
it('can spawn from list', async () => {
});
it('can spawn from arbitrary JSON', async () => {
});
it('can kill all children', async () => {
});
});
});
});

View File

@ -56,8 +56,8 @@
"@avocado/math@2.0.0":
version "2.0.0"
resolved "https://npm.i12e.cha0s.io/@avocado%2fmath/-/math-2.0.0.tgz#6de3d9b4ae9118c3d2e8580534cd834efd96350d"
integrity sha512-uBQs/xEyQ7X9NR40PFO2vwsAguLwSmORYxGM3/LZH0DzmcEiWouxIYCzuk2neNL38Fiz+vBMQXdLDSEp9gIgYw==
resolved "https://npm.i12e.cha0s.io/@avocado%2fmath/-/math-2.0.0.tgz#0b46612f7b1dca75e0d3d94937d0680ffdb84544"
integrity sha512-S8iPJduKeURqrVc/co2SGkJkDgxwdH85lsoi9TaKfWkJIWvkAtLREZNLS+Tgu0CrrTahzszN4Anng8mV53+ZVQ==
dependencies:
"@avocado/core" "2.0.0"
"@latus/core" "^2.0.0"

View File

@ -5,7 +5,6 @@ import * as Rectangle from './rectangle';
export default class QuadTree {
constructor() {
this._visitNodes = [];
this._queryRectangle = [0, 0, 0, 0];
this.quadTree = quadtree();
this.onVisit = this.onVisit.bind(this);

View File

@ -2,7 +2,6 @@ import {
SQRT_2_2,
EIGHTH_PI,
QUARTER_PI,
HALF_PI,
TWO_PI,
} from '../math';

View File

@ -15,7 +15,7 @@ export function translate(vertice, origin, rotation = 0, scale = 1) {
return Vector.scale(Vector.add(
origin,
Vector.scale(
Vector.fromAngle(Vector.toAngle(Vector.sub(vertice, origin))),
Vector.fromRadians(Vector.toRadians(Vector.sub(vertice, origin))),
Vector.magnitude(vertice, origin),
),
), scale);