2019-05-29 00:40:29 +08:00
|
|
|
import * as fs from 'fs';
|
2019-06-26 23:21:05 +08:00
|
|
|
import { BufferCursor } from '../../BufferCursor';
|
2019-06-22 02:06:55 +08:00
|
|
|
import { parseQuest, writeQuestQst } from '.';
|
|
|
|
import { ObjectType, Quest } from '../../../domain';
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
test('parse Towards the Future', () => {
|
|
|
|
const buffer = fs.readFileSync('test/resources/quest118_e.qst').buffer;
|
2019-06-26 23:21:05 +08:00
|
|
|
const cursor = new BufferCursor(buffer, true);
|
2019-05-29 07:37:00 +08:00
|
|
|
const quest = parseQuest(cursor)!;
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
expect(quest.name).toBe('Towards the Future');
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(quest.shortDescription).toBe('Challenge the\nnew simulator.');
|
|
|
|
expect(quest.longDescription).toBe('Client: Principal\nQuest: Wishes to have\nhunters challenge the\nnew simulator\nReward: ??? Meseta');
|
2019-05-29 00:40:29 +08:00
|
|
|
expect(quest.episode).toBe(1);
|
|
|
|
expect(quest.objects.length).toBe(277);
|
|
|
|
expect(quest.objects[0].type).toBe(ObjectType.MenuActivation);
|
|
|
|
expect(quest.objects[4].type).toBe(ObjectType.PlayerSet);
|
|
|
|
expect(quest.npcs.length).toBe(216);
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(testableAreaVariants(quest)).toEqual([
|
|
|
|
[0, 0], [2, 0], [11, 0], [5, 4], [12, 0], [7, 4], [13, 0], [8, 4], [10, 4], [14, 0]
|
|
|
|
]);
|
2019-05-29 00:40:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a QST file, write the resulting Quest object to QST again, then parse that again.
|
|
|
|
* Then check whether the two Quest objects are equal.
|
|
|
|
*/
|
2019-05-29 07:37:00 +08:00
|
|
|
test('parseQuest and writeQuestQst', () => {
|
2019-05-29 00:40:29 +08:00
|
|
|
const buffer = fs.readFileSync('test/resources/tethealla_v0.143_quests/solo/ep1/02.qst').buffer;
|
2019-06-26 23:21:05 +08:00
|
|
|
const cursor = new BufferCursor(buffer, true);
|
2019-05-29 07:37:00 +08:00
|
|
|
const origQuest = parseQuest(cursor)!;
|
|
|
|
const testQuest = parseQuest(writeQuestQst(origQuest, '02.qst'))!;
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-05-29 07:37:00 +08:00
|
|
|
expect(testQuest.name).toBe(origQuest.name);
|
|
|
|
expect(testQuest.shortDescription).toBe(origQuest.shortDescription);
|
|
|
|
expect(testQuest.longDescription).toBe(origQuest.longDescription);
|
|
|
|
expect(testQuest.episode).toBe(origQuest.episode);
|
|
|
|
expect(testableObjects(testQuest))
|
|
|
|
.toEqual(testableObjects(origQuest));
|
|
|
|
expect(testableNpcs(testQuest))
|
|
|
|
.toEqual(testableNpcs(origQuest));
|
|
|
|
expect(testableAreaVariants(testQuest))
|
|
|
|
.toEqual(testableAreaVariants(origQuest));
|
2019-05-29 00:40:29 +08:00
|
|
|
});
|
|
|
|
|
2019-05-29 07:37:00 +08:00
|
|
|
function testableObjects(quest: Quest) {
|
2019-05-29 00:40:29 +08:00
|
|
|
return quest.objects.map(object => [
|
2019-05-29 07:37:00 +08:00
|
|
|
object.areaId,
|
|
|
|
object.sectionId,
|
2019-05-29 00:40:29 +08:00
|
|
|
object.position,
|
|
|
|
object.type
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-05-29 07:37:00 +08:00
|
|
|
function testableNpcs(quest: Quest) {
|
2019-05-29 00:40:29 +08:00
|
|
|
return quest.npcs.map(npc => [
|
2019-05-29 07:37:00 +08:00
|
|
|
npc.areaId,
|
|
|
|
npc.sectionId,
|
2019-05-29 00:40:29 +08:00
|
|
|
npc.position,
|
|
|
|
npc.type
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-05-29 07:37:00 +08:00
|
|
|
function testableAreaVariants(quest: Quest) {
|
|
|
|
return quest.areaVariants.map(av => [av.area.id, av.id]);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|