49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import {Latus} from '@latus/core';
|
|
import {normalize} from '@latus/socket';
|
|
import {expect} from 'chai';
|
|
|
|
let latus;
|
|
let Entity;
|
|
let EntityList;
|
|
beforeEach(async () => {
|
|
latus = Latus.mock({
|
|
'@avocado/entity': require('../src'),
|
|
'@avocado/resource': require('@avocado/resource'),
|
|
'@avocado/traits': require('@avocado/traits'),
|
|
'@latus/socket': require('@latus/socket'),
|
|
});
|
|
await Promise.all(latus.invokeFlat('@latus/core/starting'));
|
|
({Entity, EntityList} = latus.get('%resources'));
|
|
});
|
|
describe('Positioned', () => {
|
|
let entity;
|
|
beforeEach(async () => {
|
|
entity = await Entity.load({
|
|
traits: {
|
|
Positioned: {},
|
|
},
|
|
});
|
|
});
|
|
it('exists', async () => {
|
|
expect(entity.is('Positioned')).to.be.true;
|
|
});
|
|
if ('client' !== process.env.SIDE) {
|
|
it('generates and accepts movement packets', async () => {
|
|
entity.setPosition([1, 1]);
|
|
const packets = entity.trait('Positioned').packetsFor();
|
|
expect(packets).to.have.lengthOf(1);
|
|
expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition');
|
|
expect(packets[0][1]).to.deep.equal([1, 1]);
|
|
const entity2 = await Entity.load({
|
|
traits: {
|
|
Positioned: {},
|
|
},
|
|
});
|
|
expect(entity2.position).to.deep.equal([0, 0]);
|
|
const trait = entity2.trait('Positioned');
|
|
trait.acceptPacket(normalize(latus, packets[0]));
|
|
expect(trait.serverPosition).to.deep.equal([1, 1]);
|
|
});
|
|
}
|
|
});
|