Compare commits
2 Commits
1061e12c81
...
f101c12097
| Author | SHA1 | Date |
|---|---|---|
|
|
f101c12097 | |
|
|
f03226221d |
|
|
@ -0,0 +1,7 @@
|
||||||
|
# type IntentEffectTarget = 'user' | 'eachEnemy' | 'randomEnemy' | 'player'
|
||||||
|
# type IntentEffect = [IntentEffectTarget; string; number]
|
||||||
|
# type IntentEffects = IntentEffect[]
|
||||||
|
|
||||||
|
id,enemy,initialIntent,nextIntents,brokenIntent,effects
|
||||||
|
string,string,boolean,string[],string[],IntentEffects
|
||||||
|
仙人掌怪-boost,仙人掌怪,true,仙人掌怪-boost;仙人掌怪-defend,,[user;spike;1];[user;defend;4]
|
||||||
|
|
|
@ -207,4 +207,28 @@ describe("parseCsv - references in combinatory schemas", () => {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should parse enemy_intents fixture with tuple arrays and type aliases", () => {
|
||||||
|
const enemyIntentsCsv = readFixture("enemy_intents.csv");
|
||||||
|
|
||||||
|
const result = parseCsv(enemyIntentsCsv, {
|
||||||
|
emitTypes: false,
|
||||||
|
currentFilePath: path.join(fixturesDir, "enemy_intents.csv"),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.data).toHaveLength(1);
|
||||||
|
|
||||||
|
expect(result.data[0]).toMatchObject({
|
||||||
|
id: "仙人掌怪-boost",
|
||||||
|
enemy: "仙人掌怪",
|
||||||
|
initialIntent: true,
|
||||||
|
nextIntents: ["仙人掌怪-boost", "仙人掌怪-defend"],
|
||||||
|
brokenIntent: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const effects = result.data[0].effects as unknown[][];
|
||||||
|
expect(effects).toHaveLength(2);
|
||||||
|
expect(effects[0]).toEqual(["user", "spike", 1]);
|
||||||
|
expect(effects[1]).toEqual(["user", "defend", 4]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,14 @@ function expandSchemaInString(
|
||||||
return expanded;
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle array suffix: TypeName[] or [tuple][]
|
||||||
|
const trimmed = schemaString.trim();
|
||||||
|
if (trimmed.endsWith("[]")) {
|
||||||
|
const inner = trimmed.slice(0, -2);
|
||||||
|
const expandedInner = expandSchemaInString(inner, declaredTypes);
|
||||||
|
return `${expandedInner}[]`;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle union types (recursively expand each member)
|
// Handle union types (recursively expand each member)
|
||||||
if (schemaString.includes("|")) {
|
if (schemaString.includes("|")) {
|
||||||
// Split by | but respect quotes
|
// Split by | but respect quotes
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ export function generateTypeDefinition(
|
||||||
? typeDeclarations
|
? typeDeclarations
|
||||||
.map(
|
.map(
|
||||||
(decl) =>
|
(decl) =>
|
||||||
`type ${decl.name} = ${schemaToTypeString(decl.schema, resourceNames)};`,
|
`export type ${decl.name} = ${schemaToTypeString(decl.schema, resourceNames)};`,
|
||||||
)
|
)
|
||||||
.join("\n") + "\n\n"
|
.join("\n") + "\n\n"
|
||||||
: "";
|
: "";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue