import {resource} from '@avocado/resource'; import {normalize} from '@avocado/s13n'; import {Latus} from '@latus/core'; import {expect} from 'chai'; const {name} = require('../package.json'); describe(name, () => { let latus; let Entity; let EntityList; beforeEach(async () => { latus = Latus.mock([ ['@avocado/entity', `${__dirname}/../src`], '@avocado/resource', '@avocado/traits', '@latus/socket', ]); await Promise.all(latus.invokeFlat('@latus/core/starting')); ({fromResourceType: {Entity, EntityList}} = resource(latus)); }); describe('Traits', () => { describe('Positioned', () => { let entity; beforeEach(async () => { entity = await Entity.load({ traits: { Positioned: {}, }, }); }); it('exists', async () => { expect(entity.is('Positioned')).to.be.true; }); it('generates and accepts movement packets', async () => { entity.setPosition([1, 1]); const packets = normalize(latus, entity.trait('Positioned').packets()); expect(packets).to.have.lengthOf(1); expect(packets[0].constructor.type).to.equal('TraitUpdatePositionedPosition'); expect(packets[0].data).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(packets[0]); expect(trait.serverPosition).to.deep.equal([1, 1]); }); }); }); });