Compare commits
No commits in common. "b5be558b5735e06505c29c5429cbdb0f8bbae4e4" and "721544e7b27015a62b238f4a157b52698da746a1" have entirely different histories.
b5be558b57
...
721544e7b2
|
|
@ -1,7 +0,0 @@
|
||||||
# type EncounterType = 'minion'|'elite'|'event'|'shop'|'camp'|'curio'
|
|
||||||
# type EnemyList = [name: string; hp: int; effects: [effect: string;stacks: int][]][]
|
|
||||||
|
|
||||||
id,type,name,description,enemies,dialogue
|
|
||||||
string,EncounterType,string,string,EnemyList,string
|
|
||||||
cactus_pair,minion,仙人掌怪,概念:防+强化。【尖刺X】:对攻击者造成X点伤害。,[仙人掌怪;12;[]];[仙人掌怪;12;[]],
|
|
||||||
snake_pair,minion,蛇,概念:攻+强化。给玩家塞入蛇毒牌(1费:打出时移除此牌。弃掉时受到3点伤害)。,[蛇;10;[[poison;2];[quick;1]]],
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { parseCsv } from "../loader";
|
import { parseCsv } from "../loader";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { fixturesDir, readFixture } from "../test-utils";
|
import { fixturesDir } from "../test-utils";
|
||||||
|
|
||||||
describe("parseCsv - references in combinatory schemas", () => {
|
describe("parseCsv - references in combinatory schemas", () => {
|
||||||
it("should resolve reference inside a tuple", () => {
|
it("should resolve reference inside a tuple", () => {
|
||||||
|
|
@ -161,50 +161,4 @@ describe("parseCsv - references in combinatory schemas", () => {
|
||||||
});
|
});
|
||||||
expect(details[1]).toBe(5);
|
expect(details[1]).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse encounter fixture with custom type aliases and nested tuples/arrays", () => {
|
|
||||||
const encounterCsv = readFixture("encounter.csv");
|
|
||||||
|
|
||||||
const result = parseCsv(encounterCsv, {
|
|
||||||
emitTypes: false,
|
|
||||||
currentFilePath: path.join(fixturesDir, "encounter.csv"),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.data).toHaveLength(2);
|
|
||||||
|
|
||||||
// First row: cactus_pair
|
|
||||||
expect(result.data[0]).toMatchObject({
|
|
||||||
id: "cactus_pair",
|
|
||||||
type: "minion",
|
|
||||||
name: "仙人掌怪",
|
|
||||||
description: "概念:防+强化。【尖刺X】:对攻击者造成X点伤害。",
|
|
||||||
dialogue: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
const cactusEnemies = result.data[0].enemies as unknown[];
|
|
||||||
expect(cactusEnemies).toHaveLength(2);
|
|
||||||
expect(cactusEnemies[0]).toEqual(["仙人掌怪", 12, []]);
|
|
||||||
expect(cactusEnemies[1]).toEqual(["仙人掌怪", 12, []]);
|
|
||||||
|
|
||||||
// Second row: snake_pair
|
|
||||||
expect(result.data[1]).toMatchObject({
|
|
||||||
id: "snake_pair",
|
|
||||||
type: "minion",
|
|
||||||
name: "蛇",
|
|
||||||
description:
|
|
||||||
"概念:攻+强化。给玩家塞入蛇毒牌(1费:打出时移除此牌。弃掉时受到3点伤害)。",
|
|
||||||
dialogue: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
const snakeEnemies = result.data[1].enemies as unknown[];
|
|
||||||
expect(snakeEnemies).toHaveLength(1);
|
|
||||||
expect(snakeEnemies[0]).toEqual([
|
|
||||||
"蛇",
|
|
||||||
10,
|
|
||||||
[
|
|
||||||
["poison", 2],
|
|
||||||
["quick", 1],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -304,23 +304,9 @@ class ValueParser {
|
||||||
if (!elementIsTupleOrArray) {
|
if (!elementIsTupleOrArray) {
|
||||||
this.consume();
|
this.consume();
|
||||||
hasOpenBracket = true;
|
hasOpenBracket = true;
|
||||||
} else {
|
} else if (this.input[this.pos + 1] === "[") {
|
||||||
// Element is tuple or array - need to disambiguate
|
|
||||||
// Save position to check if this is an empty array
|
|
||||||
const savedPos = this.pos;
|
|
||||||
this.consume();
|
this.consume();
|
||||||
this.skipWhitespace();
|
|
||||||
if (this.peek() === "]") {
|
|
||||||
// Empty array []
|
|
||||||
this.consume();
|
|
||||||
return [];
|
|
||||||
} else if (this.peek() === "[") {
|
|
||||||
// Nested brackets [[ - this is the array opener
|
|
||||||
hasOpenBracket = true;
|
hasOpenBracket = true;
|
||||||
} else {
|
|
||||||
// [ belongs to the first element, restore position
|
|
||||||
this.pos = savedPos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,8 +324,7 @@ class ValueParser {
|
||||||
const result: unknown[] = [];
|
const result: unknown[] = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
|
result.push(this.parseValue(schema.element, false));
|
||||||
result.push(this.parseValue(schema.element, elementIsTupleOrArray));
|
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
|
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue