handle(data) { const client = this.client; const guild = client.guilds.cache.get(data.guild_id); if (guild) { for (const partialRole of data.roles) { const role = guild.roles.cache.get(partialRole.id); if (role) role.rawPosition = partialRole.position; } } return { guild }; }
const getSummaryPosition = function (items) { return items.map((item) => item.position) .reduce(concatPosition, { grow: 0, size: 0 }); }
/** * Returns the space where this unit is located. * * @returns {Space} The space this unit is located at. */ getSpace() { return this.position.getSpace(); }
test('returns immediate space at a given direction if number of spaces is omitted', () => { unit.position = { getRelativeSpace: jest.fn() }; unit.getSpaceAt(LEFT); expect(unit.position.getRelativeSpace).toHaveBeenCalledWith(LEFT, [1, 0]); });
function () { // This routine does not support objects with rotated and/or translated parent(s) var m1 = new THREE.Matrix4(); return function ( vector ) { m1.lookAt( vector, this.position, this.up ); this.quaternion.setFromRotationMatrix( m1 ); }; }()
/** * Returns the unit at a given location or null if there is none. * * @param {number[]} location The location as [x, y]. * * @returns {Unit} The unit at the location. */ getUnitAt(location) { return this.getUnits().find(unit => unit.position.isAt(location)); }
/** * Checks if the unit is alive. * * A unit is alive if it has a position. * * @returns {boolean} Whether the unit is alive or not. */ isAlive() { return this.position !== null; }
/** * Returns the space located at the direction and number of spaces. * * @param {string} direction The direction. * @param {number} forward The number of spaces forward. * @param {number} right The number of spaces to the right. * * @returns {Space} The space. */ getSpaceAt(direction, forward = 1, right = 0) { return this.position.getRelativeSpace(direction, [forward, right]); }
/** * Compares the positions of two roles. * @param {Role} role1 First role to compare * @param {Role} role2 Second role to compare * @returns {number} Negative number if the first role's position is lower (second role's is higher), * positive number if the first's is higher (second's is lower), 0 if equal */ static comparePositions(role1, role2) { if (role1.position === role2.position) return role2.id - role1.id; return role1.position - role2.position; }
/** * Rotates the unit in a given direction. * * @param {string} direction The direction in which to rotate. */ rotate(direction) { this.position.rotate(direction); }
/** * Moves the unit in the given direction and number of spaces. * * @param {string} direction The direction. * @param {number} forward The number of spaces forward. * @param {number} right The number of spaces to the right. */ move(direction, forward = 1, right = 0) { this.position.move(direction, [forward, right]); }
function () { // This routine does not support cameras with rotated and/or translated parent(s) var m1 = new THREE.Matrix4(); return function ( vector ) { m1.lookAt( this.position, vector, this.up ); this.quaternion.setFromRotationMatrix( m1 ); }; }()
test('returns space at a given direction and number of spaces', () => { unit.position = { getRelativeSpace: jest.fn() }; unit.getSpaceAt(RIGHT, 2, 1); expect(unit.position.getRelativeSpace).toHaveBeenCalledWith(RIGHT, [2, 1]); });