2019-05-29 23:04:06 +08:00
|
|
|
import { CylinderBufferGeometry, MeshLambertMaterial, Object3D, Vector3 } from 'three';
|
2019-07-01 14:53:16 +08:00
|
|
|
import { DatNpc, DatObject } from '../data_formats/parsing/quest/dat';
|
2019-07-02 23:00:24 +08:00
|
|
|
import { NpcType, ObjectType, QuestNpc, QuestObject } from '../domain';
|
|
|
|
import { Vec3 } from "../data_formats/Vec3";
|
2019-06-28 00:50:22 +08:00
|
|
|
import { create_npc_mesh, create_object_mesh, NPC_COLOR, OBJECT_COLOR } from './entities';
|
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-07-01 14:53:16 +08:00
|
|
|
const object = new QuestObject(7, 13, new Vec3(17, 19, 23), new Vec3(0, 0, 0), ObjectType.PrincipalWarp, {} as DatObject);
|
2019-06-28 00:50:22 +08:00
|
|
|
const geometry = create_object_mesh(object, 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 23:04:06 +08:00
|
|
|
expect(geometry.position.x).toBe(17);
|
|
|
|
expect(geometry.position.y).toBe(19);
|
|
|
|
expect(geometry.position.z).toBe(23);
|
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-07-01 14:53:16 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(0, 0, 0), NpcType.Booma, {} as DatNpc);
|
2019-06-28 00:50:22 +08:00
|
|
|
const geometry = create_npc_mesh(npc, 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 23:04:06 +08:00
|
|
|
expect(geometry.position.x).toBe(17);
|
|
|
|
expect(geometry.position.y).toBe(19);
|
|
|
|
expect(geometry.position.z).toBe(23);
|
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-07-01 14:53:16 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(0, 0, 0), NpcType.Booma, {} as DatNpc);
|
2019-06-28 00:50:22 +08:00
|
|
|
const geometry = create_npc_mesh(npc, 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-07-01 14:53:16 +08:00
|
|
|
const npc = new QuestNpc(7, 13, new Vec3(17, 19, 23), new Vec3(0, 0, 0), NpcType.Booma, {} as DatNpc);
|
2019-06-28 00:50:22 +08:00
|
|
|
const geometry = create_npc_mesh(npc, 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));
|
|
|
|
});
|