Compare commits
2 Commits
721544e7b2
...
b5be558b57
| Author | SHA1 | Date |
|---|---|---|
|
|
b5be558b57 | |
|
|
585f33b856 |
|
|
@ -0,0 +1,7 @@
|
|||
# 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 { parseCsv } from "../loader";
|
||||
import * as path from "path";
|
||||
import { fixturesDir } from "../test-utils";
|
||||
import { fixturesDir, readFixture } from "../test-utils";
|
||||
|
||||
describe("parseCsv - references in combinatory schemas", () => {
|
||||
it("should resolve reference inside a tuple", () => {
|
||||
|
|
@ -161,4 +161,50 @@ describe("parseCsv - references in combinatory schemas", () => {
|
|||
});
|
||||
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,9 +304,23 @@ class ValueParser {
|
|||
if (!elementIsTupleOrArray) {
|
||||
this.consume();
|
||||
hasOpenBracket = true;
|
||||
} else if (this.input[this.pos + 1] === "[") {
|
||||
} else {
|
||||
// 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.skipWhitespace();
|
||||
if (this.peek() === "]") {
|
||||
// Empty array []
|
||||
this.consume();
|
||||
return [];
|
||||
} else if (this.peek() === "[") {
|
||||
// Nested brackets [[ - this is the array opener
|
||||
hasOpenBracket = true;
|
||||
} else {
|
||||
// [ belongs to the first element, restore position
|
||||
this.pos = savedPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +338,8 @@ class ValueParser {
|
|||
const result: unknown[] = [];
|
||||
while (true) {
|
||||
this.skipWhitespace();
|
||||
result.push(this.parseValue(schema.element, false));
|
||||
|
||||
result.push(this.parseValue(schema.element, elementIsTupleOrArray));
|
||||
this.skipWhitespace();
|
||||
|
||||
if (!this.consumeStr(";")) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue