2019-05-29 00:40:29 +08:00
|
|
|
import {
|
2019-05-29 07:37:00 +08:00
|
|
|
createObjectMesh,
|
|
|
|
createNpcMesh,
|
2019-05-29 00:40:29 +08:00
|
|
|
OBJECT_COLOR,
|
|
|
|
NPC_COLOR
|
|
|
|
} from './entities';
|
2019-05-29 04:24:28 +08:00
|
|
|
import { Object3D, Vector3, MeshLambertMaterial, CylinderBufferGeometry } from 'three';
|
2019-05-29 00:40:29 +08:00
|
|
|
import { Vec3, QuestNpc, QuestObject, Section, NpcType, ObjectType } from '../domain';
|
2019-05-29 07:37:00 +08:00
|
|
|
import { DatObject, DatNpc } from '../data/parsing/dat';
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-05-29 04:24:28 +08:00
|
|
|
const cylinder = new CylinderBufferGeometry(3, 3, 20).translate(0, 10, 0);
|
|
|
|
|
2019-05-29 00:40:29 +08:00
|
|
|
test('create geometry for quest objects', () => {
|
2019-05-29 07:37:00 +08:00
|
|
|
const object = new QuestObject(7, 13, new Vec3(17, 19, 23), new Vec3(), ObjectType.PrincipalWarp, {} as DatObject);
|
|
|
|
const sectRot = 0.6;
|
|
|
|
const sectRotSin = Math.sin(sectRot);
|
|
|
|
const sectRotCos = Math.cos(sectRot);
|
|
|
|
const geometry = createObjectMesh(
|
|
|
|
object, [new Section(13, new Vec3(29, 31, 37), sectRot)], cylinder);
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
expect(geometry).toBeInstanceOf(Object3D);
|
|
|
|
expect(geometry.name).toBe('Object');
|
|
|
|
expect(geometry.userData.entity).toBe(object);
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(geometry.position.x).toBe(sectRotCos * 17 + sectRotSin * 23 + 29);
|
2019-05-29 00:40:29 +08:00
|
|
|
expect(geometry.position.y).toBe(19 + 31);
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(geometry.position.z).toBe(-sectRotSin * 17 + sectRotCos * 23 + 37);
|
2019-05-29 04:24:28 +08:00
|
|
|
expect((geometry.material as MeshLambertMaterial).color.getHex()).toBe(OBJECT_COLOR);
|
2019-05-29 00:40:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('create geometry for quest NPCs', () => {
|
2019-05-29 07:37:00 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(), NpcType.Booma, {} as DatNpc);
|
|
|
|
const sectRot = 0.6;
|
|
|
|
const sectRotSin = Math.sin(sectRot);
|
|
|
|
const sectRotCos = Math.cos(sectRot);
|
|
|
|
const geometry = createNpcMesh(
|
|
|
|
npc, [new Section(13, new Vec3(29, 31, 37), sectRot)], cylinder);
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
expect(geometry).toBeInstanceOf(Object3D);
|
|
|
|
expect(geometry.name).toBe('NPC');
|
|
|
|
expect(geometry.userData.entity).toBe(npc);
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(geometry.position.x).toBe(sectRotCos * 17 + sectRotSin * 23 + 29);
|
2019-05-29 00:40:29 +08:00
|
|
|
expect(geometry.position.y).toBe(19 + 31);
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(geometry.position.z).toBe(-sectRotSin * 17 + sectRotCos * 23 + 37);
|
2019-05-29 04:24:28 +08:00
|
|
|
expect((geometry.material as MeshLambertMaterial).color.getHex()).toBe(NPC_COLOR);
|
2019-05-29 00:40:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('geometry position changes when entity position changes element-wise', () => {
|
2019-05-29 07:37:00 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(), NpcType.Booma, {} as DatNpc);
|
|
|
|
const geometry = createNpcMesh(
|
2019-05-29 04:24:28 +08:00
|
|
|
npc, [new Section(13, new Vec3(0, 0, 0), 0)], cylinder);
|
2019-05-29 00:40:29 +08:00
|
|
|
npc.position = new Vec3(2, 3, 5).add(npc.position);
|
|
|
|
|
|
|
|
expect(geometry.position).toEqual(new Vector3(19, 22, 28));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('geometry position changes when entire entity position changes', () => {
|
2019-05-29 07:37:00 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(), NpcType.Booma, {} as DatNpc);
|
|
|
|
const geometry = createNpcMesh(
|
2019-05-29 04:24:28 +08:00
|
|
|
npc, [new Section(13, new Vec3(0, 0, 0), 0)], cylinder);
|
2019-05-29 00:40:29 +08:00
|
|
|
npc.position = new Vec3(2, 3, 5);
|
|
|
|
|
|
|
|
expect(geometry.position).toEqual(new Vector3(2, 3, 5));
|
|
|
|
});
|