rpgmaker-mz-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +425 -0
- package/dist/events/commandBuilders.d.ts +405 -0
- package/dist/events/commandBuilders.d.ts.map +1 -0
- package/dist/events/commandBuilders.js +554 -0
- package/dist/events/commandBuilders.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +81 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +49 -0
- package/dist/registry.js.map +1 -0
- package/dist/tiles/autotile.d.ts +65 -0
- package/dist/tiles/autotile.d.ts.map +1 -0
- package/dist/tiles/autotile.js +201 -0
- package/dist/tiles/autotile.js.map +1 -0
- package/dist/tiles/catalog/dungeon.d.ts +16 -0
- package/dist/tiles/catalog/dungeon.d.ts.map +1 -0
- package/dist/tiles/catalog/dungeon.js +765 -0
- package/dist/tiles/catalog/dungeon.js.map +1 -0
- package/dist/tiles/catalog/index.d.ts +78 -0
- package/dist/tiles/catalog/index.d.ts.map +1 -0
- package/dist/tiles/catalog/index.js +115 -0
- package/dist/tiles/catalog/index.js.map +1 -0
- package/dist/tiles/catalog/inside.d.ts +16 -0
- package/dist/tiles/catalog/inside.d.ts.map +1 -0
- package/dist/tiles/catalog/inside.js +765 -0
- package/dist/tiles/catalog/inside.js.map +1 -0
- package/dist/tiles/catalog/outside.d.ts +16 -0
- package/dist/tiles/catalog/outside.d.ts.map +1 -0
- package/dist/tiles/catalog/outside.js +799 -0
- package/dist/tiles/catalog/outside.js.map +1 -0
- package/dist/tiles/catalog/overworld.d.ts +16 -0
- package/dist/tiles/catalog/overworld.d.ts.map +1 -0
- package/dist/tiles/catalog/overworld.js +585 -0
- package/dist/tiles/catalog/overworld.js.map +1 -0
- package/dist/tiles/catalog/sf.d.ts +16 -0
- package/dist/tiles/catalog/sf.d.ts.map +1 -0
- package/dist/tiles/catalog/sf.js +1313 -0
- package/dist/tiles/catalog/sf.js.map +1 -0
- package/dist/tiles/paint.d.ts +20 -0
- package/dist/tiles/paint.d.ts.map +1 -0
- package/dist/tiles/paint.js +65 -0
- package/dist/tiles/paint.js.map +1 -0
- package/dist/tiles/png.d.ts +11 -0
- package/dist/tiles/png.d.ts.map +1 -0
- package/dist/tiles/png.js +180 -0
- package/dist/tiles/png.js.map +1 -0
- package/dist/tiles/tileCodec.d.ts +95 -0
- package/dist/tiles/tileCodec.d.ts.map +1 -0
- package/dist/tiles/tileCodec.js +186 -0
- package/dist/tiles/tileCodec.js.map +1 -0
- package/dist/tiles/tileFlags.d.ts +98 -0
- package/dist/tiles/tileFlags.d.ts.map +1 -0
- package/dist/tiles/tileFlags.js +129 -0
- package/dist/tiles/tileFlags.js.map +1 -0
- package/dist/tiles/tilegeom.d.ts +29 -0
- package/dist/tiles/tilegeom.d.ts.map +1 -0
- package/dist/tiles/tilegeom.js +111 -0
- package/dist/tiles/tilegeom.js.map +1 -0
- package/dist/tiles/transparency.d.ts +22 -0
- package/dist/tiles/transparency.d.ts.map +1 -0
- package/dist/tiles/transparency.js +59 -0
- package/dist/tiles/transparency.js.map +1 -0
- package/dist/tools/actorTools.d.ts +48 -0
- package/dist/tools/actorTools.d.ts.map +1 -0
- package/dist/tools/actorTools.js +154 -0
- package/dist/tools/actorTools.js.map +1 -0
- package/dist/tools/allTools.d.ts +8 -0
- package/dist/tools/allTools.d.ts.map +1 -0
- package/dist/tools/allTools.js +56 -0
- package/dist/tools/allTools.js.map +1 -0
- package/dist/tools/assetTools.d.ts +113 -0
- package/dist/tools/assetTools.d.ts.map +1 -0
- package/dist/tools/assetTools.js +97 -0
- package/dist/tools/assetTools.js.map +1 -0
- package/dist/tools/batchTools.d.ts +3 -0
- package/dist/tools/batchTools.d.ts.map +1 -0
- package/dist/tools/batchTools.js +138 -0
- package/dist/tools/batchTools.js.map +1 -0
- package/dist/tools/battleTools.d.ts +72 -0
- package/dist/tools/battleTools.d.ts.map +1 -0
- package/dist/tools/battleTools.js +322 -0
- package/dist/tools/battleTools.js.map +1 -0
- package/dist/tools/catalogTools.d.ts +3 -0
- package/dist/tools/catalogTools.d.ts.map +1 -0
- package/dist/tools/catalogTools.js +134 -0
- package/dist/tools/catalogTools.js.map +1 -0
- package/dist/tools/classTools.d.ts +85 -0
- package/dist/tools/classTools.d.ts.map +1 -0
- package/dist/tools/classTools.js +279 -0
- package/dist/tools/classTools.js.map +1 -0
- package/dist/tools/commonEventTools.d.ts +32 -0
- package/dist/tools/commonEventTools.d.ts.map +1 -0
- package/dist/tools/commonEventTools.js +150 -0
- package/dist/tools/commonEventTools.js.map +1 -0
- package/dist/tools/eventCommandTools.d.ts +37 -0
- package/dist/tools/eventCommandTools.d.ts.map +1 -0
- package/dist/tools/eventCommandTools.js +893 -0
- package/dist/tools/eventCommandTools.js.map +1 -0
- package/dist/tools/eventPageTools.d.ts +112 -0
- package/dist/tools/eventPageTools.d.ts.map +1 -0
- package/dist/tools/eventPageTools.js +597 -0
- package/dist/tools/eventPageTools.js.map +1 -0
- package/dist/tools/itemTools.d.ts +82 -0
- package/dist/tools/itemTools.d.ts.map +1 -0
- package/dist/tools/itemTools.js +380 -0
- package/dist/tools/itemTools.js.map +1 -0
- package/dist/tools/listTools.d.ts +58 -0
- package/dist/tools/listTools.d.ts.map +1 -0
- package/dist/tools/listTools.js +99 -0
- package/dist/tools/listTools.js.map +1 -0
- package/dist/tools/mapTools.d.ts +270 -0
- package/dist/tools/mapTools.d.ts.map +1 -0
- package/dist/tools/mapTools.js +1066 -0
- package/dist/tools/mapTools.js.map +1 -0
- package/dist/tools/moveTools.d.ts +43 -0
- package/dist/tools/moveTools.d.ts.map +1 -0
- package/dist/tools/moveTools.js +240 -0
- package/dist/tools/moveTools.js.map +1 -0
- package/dist/tools/objectTools.d.ts +12 -0
- package/dist/tools/objectTools.d.ts.map +1 -0
- package/dist/tools/objectTools.js +221 -0
- package/dist/tools/objectTools.js.map +1 -0
- package/dist/tools/paintTools.d.ts +3 -0
- package/dist/tools/paintTools.d.ts.map +1 -0
- package/dist/tools/paintTools.js +134 -0
- package/dist/tools/paintTools.js.map +1 -0
- package/dist/tools/pluginScanTools.d.ts +22 -0
- package/dist/tools/pluginScanTools.d.ts.map +1 -0
- package/dist/tools/pluginScanTools.js +119 -0
- package/dist/tools/pluginScanTools.js.map +1 -0
- package/dist/tools/pluginTools.d.ts +11 -0
- package/dist/tools/pluginTools.d.ts.map +1 -0
- package/dist/tools/pluginTools.js +63 -0
- package/dist/tools/pluginTools.js.map +1 -0
- package/dist/tools/projectTools.d.ts +11 -0
- package/dist/tools/projectTools.d.ts.map +1 -0
- package/dist/tools/projectTools.js +74 -0
- package/dist/tools/projectTools.js.map +1 -0
- package/dist/tools/skillTools.d.ts +83 -0
- package/dist/tools/skillTools.d.ts.map +1 -0
- package/dist/tools/skillTools.js +369 -0
- package/dist/tools/skillTools.js.map +1 -0
- package/dist/tools/stateTools.d.ts +28 -0
- package/dist/tools/stateTools.d.ts.map +1 -0
- package/dist/tools/stateTools.js +161 -0
- package/dist/tools/stateTools.js.map +1 -0
- package/dist/tools/systemTools.d.ts +86 -0
- package/dist/tools/systemTools.d.ts.map +1 -0
- package/dist/tools/systemTools.js +342 -0
- package/dist/tools/systemTools.js.map +1 -0
- package/dist/tools/tileTools.d.ts +9 -0
- package/dist/tools/tileTools.d.ts.map +1 -0
- package/dist/tools/tileTools.js +34 -0
- package/dist/tools/tileTools.js.map +1 -0
- package/dist/tools/tileTransparency.d.ts +40 -0
- package/dist/tools/tileTransparency.d.ts.map +1 -0
- package/dist/tools/tileTransparency.js +156 -0
- package/dist/tools/tileTransparency.js.map +1 -0
- package/dist/tools/tilesetTools.d.ts +23 -0
- package/dist/tools/tilesetTools.d.ts.map +1 -0
- package/dist/tools/tilesetTools.js +209 -0
- package/dist/tools/tilesetTools.js.map +1 -0
- package/dist/tools/validationTools.d.ts +50 -0
- package/dist/tools/validationTools.d.ts.map +1 -0
- package/dist/tools/validationTools.js +229 -0
- package/dist/tools/validationTools.js.map +1 -0
- package/dist/utils/commit.d.ts +62 -0
- package/dist/utils/commit.d.ts.map +1 -0
- package/dist/utils/commit.js +119 -0
- package/dist/utils/commit.js.map +1 -0
- package/dist/utils/fileHandler.d.ts +49 -0
- package/dist/utils/fileHandler.d.ts.map +1 -0
- package/dist/utils/fileHandler.js +137 -0
- package/dist/utils/fileHandler.js.map +1 -0
- package/dist/utils/records.d.ts +8 -0
- package/dist/utils/records.d.ts.map +1 -0
- package/dist/utils/records.js +10 -0
- package/dist/utils/records.js.map +1 -0
- package/dist/utils/types.d.ts +465 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +5 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/validation/assets.d.ts +53 -0
- package/dist/validation/assets.d.ts.map +1 -0
- package/dist/validation/assets.js +198 -0
- package/dist/validation/assets.js.map +1 -0
- package/dist/validation/createRefs.d.ts +37 -0
- package/dist/validation/createRefs.d.ts.map +1 -0
- package/dist/validation/createRefs.js +89 -0
- package/dist/validation/createRefs.js.map +1 -0
- package/dist/validation/eventCommands.d.ts +70 -0
- package/dist/validation/eventCommands.d.ts.map +1 -0
- package/dist/validation/eventCommands.js +273 -0
- package/dist/validation/eventCommands.js.map +1 -0
- package/dist/validation/gate.d.ts +56 -0
- package/dist/validation/gate.d.ts.map +1 -0
- package/dist/validation/gate.js +50 -0
- package/dist/validation/gate.js.map +1 -0
- package/dist/validation/moveCommands.d.ts +31 -0
- package/dist/validation/moveCommands.d.ts.map +1 -0
- package/dist/validation/moveCommands.js +123 -0
- package/dist/validation/moveCommands.js.map +1 -0
- package/dist/validation/pluginCommands.d.ts +83 -0
- package/dist/validation/pluginCommands.d.ts.map +1 -0
- package/dist/validation/pluginCommands.js +134 -0
- package/dist/validation/pluginCommands.js.map +1 -0
- package/dist/validation/pluginManifest.d.ts +67 -0
- package/dist/validation/pluginManifest.d.ts.map +1 -0
- package/dist/validation/pluginManifest.js +199 -0
- package/dist/validation/pluginManifest.js.map +1 -0
- package/dist/validation/references.d.ts +57 -0
- package/dist/validation/references.d.ts.map +1 -0
- package/dist/validation/references.js +314 -0
- package/dist/validation/references.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GameClass, Learning, Skill } from '../utils/types.js';
|
|
2
|
+
import { ToolDefinition } from '../registry.js';
|
|
3
|
+
import { ValidationWarning } from '../validation/eventCommands.js';
|
|
4
|
+
/** Human-readable labels for the 8 base parameters, indexed 0-7. */
|
|
5
|
+
export declare const PARAM_NAMES: readonly ["maxHP", "maxMP", "atk", "def", "mat", "mdf", "agi", "luk"];
|
|
6
|
+
/**
|
|
7
|
+
* Build the 8×(maxLevel+1) parameter matrix for a new class: one linear curve per
|
|
8
|
+
* param. Index 0 mirrors the level-1 value (the engine never reads level 0).
|
|
9
|
+
*/
|
|
10
|
+
export declare function defaultClassParams(maxLevel?: number): number[][];
|
|
11
|
+
/**
|
|
12
|
+
* A blank class mirroring what the RPG Maker MZ editor writes for a freshly-created
|
|
13
|
+
* class: the default EXP curve, no traits or learnings, and a default linear param
|
|
14
|
+
* curve. Pure so the template shape can be unit-tested. Field order mirrors the
|
|
15
|
+
* editor's on-disk shape.
|
|
16
|
+
*/
|
|
17
|
+
export declare function defaultClass(maxLevel?: number): Omit<GameClass, 'id'>;
|
|
18
|
+
/** Get all classes from the project (`data/Classes.json`). */
|
|
19
|
+
export declare function getClasses(projectPath: string): Promise<(GameClass | null)[]>;
|
|
20
|
+
/** The caller-supplied class shape accepted by both `create_class` and `batch_create`. */
|
|
21
|
+
export type ClassInput = {
|
|
22
|
+
name: string;
|
|
23
|
+
maxLevel?: number;
|
|
24
|
+
} & Partial<Omit<GameClass, 'id' | 'name'>>;
|
|
25
|
+
/**
|
|
26
|
+
* Build one new class record against the current array — the shared per-record
|
|
27
|
+
* source of truth for both `create_class` and `batch_create`. Pure: `maxLevel`
|
|
28
|
+
* sizes the generated param curves via {@link defaultClass}, then the caller's
|
|
29
|
+
* defined fields merge over it with the computed id last so it always wins.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildClassRecord(existing: (GameClass | null)[], input: ClassInput): GameClass;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new class. Only `name` is required; any omitted field falls back to the
|
|
34
|
+
* editor's new-class default (see {@link defaultClass}). Allocates the next unused
|
|
35
|
+
* id (max existing + 1) and writes through the commit choke point.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createClass(projectPath: string, options: ClassInput): Promise<GameClass>;
|
|
38
|
+
/** Update an existing class's properties (shallow merge; id re-pinned). */
|
|
39
|
+
export declare function updateClass(projectPath: string, classId: number, updates: Partial<GameClass>): Promise<GameClass>;
|
|
40
|
+
/**
|
|
41
|
+
* Add a "learn skill at level" entry to a class — the first-class replacement for
|
|
42
|
+
* the hack of attaching skills directly to an actor via an Add-Skill trait. The
|
|
43
|
+
* `skillId` is validated to reference an existing skill (throws otherwise) and the
|
|
44
|
+
* resulting `learnings` list is kept sorted by level.
|
|
45
|
+
*/
|
|
46
|
+
export declare function addClassLearning(projectPath: string, classId: number, skillId: number, level: number, note?: string): Promise<GameClass>;
|
|
47
|
+
/**
|
|
48
|
+
* Replace one of a class's 8 parameter growth curves. `paramId` is 0-7
|
|
49
|
+
* ([maxHP, maxMP, atk, def, mat, mdf, agi, luk]) and `values` must match the
|
|
50
|
+
* existing curve's length (so the matrix stays rectangular / same max level).
|
|
51
|
+
*/
|
|
52
|
+
export declare function setClassParamCurve(projectPath: string, classId: number, paramId: number, values: number[]): Promise<GameClass>;
|
|
53
|
+
/**
|
|
54
|
+
* A compact response view of a class for mutation tools. The on-disk record keeps
|
|
55
|
+
* its full 8×(maxLevel+1) `params` matrix, but echoing 800+ numbers back on every
|
|
56
|
+
* edit (e.g. adding one skill learning) is pure token waste — so the tool response
|
|
57
|
+
* replaces `params` with `maxLevel` plus a per-param first/last-level preview. A
|
|
58
|
+
* caller that needs the whole curve can still `get_database('classes')`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function summarizeClass(c: GameClass): {
|
|
61
|
+
maxLevel: number;
|
|
62
|
+
paramCurves: {
|
|
63
|
+
param: "def" | "maxHP" | "maxMP" | "atk" | "mat" | "mdf" | "agi" | "luk";
|
|
64
|
+
atLevel1: number;
|
|
65
|
+
atMaxLevel: number;
|
|
66
|
+
}[];
|
|
67
|
+
id: number;
|
|
68
|
+
name: string;
|
|
69
|
+
expParams: number[];
|
|
70
|
+
learnings: Learning[];
|
|
71
|
+
traits: import("../utils/types.js").Trait[];
|
|
72
|
+
note: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Warn (never throw) when a class learns skills whose skill type is not covered by
|
|
76
|
+
* an Add Skill Type trait ({ code: 41, dataId: stypeId }). Learnings only *teach*
|
|
77
|
+
* the skill — without the trait the skill-type command never appears in battle or
|
|
78
|
+
* the menu, so the actor silently "has no skills" even though the learnings are
|
|
79
|
+
* correct. One aggregated warning per uncovered stypeId. Skills with stypeId 0
|
|
80
|
+
* (no type) and learnings pointing at unknown skills are skipped (the latter is
|
|
81
|
+
* add_class_learning's throw, not this check's job). Pure so it's unit-testable.
|
|
82
|
+
*/
|
|
83
|
+
export declare function skillTypeTraitWarnings(gameClass: GameClass, skills: (Skill | null)[]): ValidationWarning[];
|
|
84
|
+
export declare const classToolDefinitions: ToolDefinition[];
|
|
85
|
+
//# sourceMappingURL=classTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classTools.d.ts","sourceRoot":"","sources":["../../src/tools/classTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,oEAAoE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AM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,SAAS,CAAC,CAmBpB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS;;;;;;;;;;;;;EAS1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GACvB,iBAAiB,EAAE,CAmBrB;AAmBD,eAAO,MAAM,oBAAoB,EAAE,cAAc,EAmGhD,CAAC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { readJsonFile, getDataPath } from '../utils/fileHandler.js';
|
|
3
|
+
import { commitChange } from '../utils/commit.js';
|
|
4
|
+
import { definedOnly } from '../utils/records.js';
|
|
5
|
+
/** Human-readable labels for the 8 base parameters, indexed 0-7. */
|
|
6
|
+
export const PARAM_NAMES = ['maxHP', 'maxMP', 'atk', 'def', 'mat', 'mdf', 'agi', 'luk'];
|
|
7
|
+
/**
|
|
8
|
+
* Per-param [level-1 base, growth-per-level] for the default new-class curve.
|
|
9
|
+
* RPG Maker MZ's sample curves are effectively linear, so a fresh class gets a
|
|
10
|
+
* clean linear growth the user can then reshape with `set_class_param_curve`.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_PARAM_CURVE = [
|
|
13
|
+
[500, 50], // maxHP
|
|
14
|
+
[50, 8], // maxMP
|
|
15
|
+
[15, 2], // atk
|
|
16
|
+
[15, 2], // def
|
|
17
|
+
[15, 2], // mat
|
|
18
|
+
[15, 2], // mdf
|
|
19
|
+
[15, 2], // agi
|
|
20
|
+
[15, 2], // luk
|
|
21
|
+
];
|
|
22
|
+
const DEFAULT_MAX_LEVEL = 99;
|
|
23
|
+
/**
|
|
24
|
+
* Build the 8×(maxLevel+1) parameter matrix for a new class: one linear curve per
|
|
25
|
+
* param. Index 0 mirrors the level-1 value (the engine never reads level 0).
|
|
26
|
+
*/
|
|
27
|
+
export function defaultClassParams(maxLevel = DEFAULT_MAX_LEVEL) {
|
|
28
|
+
return DEFAULT_PARAM_CURVE.map(([base, growth]) => {
|
|
29
|
+
const row = [];
|
|
30
|
+
for (let level = 0; level <= maxLevel; level++) {
|
|
31
|
+
row.push(base + growth * Math.max(level - 1, 0));
|
|
32
|
+
}
|
|
33
|
+
return row;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A blank class mirroring what the RPG Maker MZ editor writes for a freshly-created
|
|
38
|
+
* class: the default EXP curve, no traits or learnings, and a default linear param
|
|
39
|
+
* curve. Pure so the template shape can be unit-tested. Field order mirrors the
|
|
40
|
+
* editor's on-disk shape.
|
|
41
|
+
*/
|
|
42
|
+
export function defaultClass(maxLevel = DEFAULT_MAX_LEVEL) {
|
|
43
|
+
return {
|
|
44
|
+
name: '',
|
|
45
|
+
expParams: [30, 20, 30, 30],
|
|
46
|
+
traits: [],
|
|
47
|
+
learnings: [],
|
|
48
|
+
note: '',
|
|
49
|
+
params: defaultClassParams(maxLevel),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Get all classes from the project (`data/Classes.json`). */
|
|
53
|
+
export async function getClasses(projectPath) {
|
|
54
|
+
return await readJsonFile(getDataPath(projectPath, 'Classes.json'));
|
|
55
|
+
}
|
|
56
|
+
/** Load a class by id or throw a "not found" error. Returns [classes, index]. */
|
|
57
|
+
async function findClassIndex(projectPath, classId) {
|
|
58
|
+
const classes = await getClasses(projectPath);
|
|
59
|
+
const index = classes.findIndex((c) => c && c.id === classId);
|
|
60
|
+
if (index === -1) {
|
|
61
|
+
throw new Error(`Class with ID ${classId} not found`);
|
|
62
|
+
}
|
|
63
|
+
return [classes, index];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build one new class record against the current array — the shared per-record
|
|
67
|
+
* source of truth for both `create_class` and `batch_create`. Pure: `maxLevel`
|
|
68
|
+
* sizes the generated param curves via {@link defaultClass}, then the caller's
|
|
69
|
+
* defined fields merge over it with the computed id last so it always wins.
|
|
70
|
+
*/
|
|
71
|
+
export function buildClassRecord(existing, input) {
|
|
72
|
+
const { maxLevel, ...overrides } = input;
|
|
73
|
+
const maxId = existing.reduce((max, c) => (c && c.id > max ? c.id : max), 0);
|
|
74
|
+
return {
|
|
75
|
+
...defaultClass(maxLevel),
|
|
76
|
+
...definedOnly(overrides),
|
|
77
|
+
id: maxId + 1,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new class. Only `name` is required; any omitted field falls back to the
|
|
82
|
+
* editor's new-class default (see {@link defaultClass}). Allocates the next unused
|
|
83
|
+
* id (max existing + 1) and writes through the commit choke point.
|
|
84
|
+
*/
|
|
85
|
+
export async function createClass(projectPath, options) {
|
|
86
|
+
const classes = await getClasses(projectPath);
|
|
87
|
+
const gameClass = buildClassRecord(classes, options);
|
|
88
|
+
classes.push(gameClass);
|
|
89
|
+
await commitChange(getDataPath(projectPath, 'Classes.json'), classes);
|
|
90
|
+
return gameClass;
|
|
91
|
+
}
|
|
92
|
+
/** Update an existing class's properties (shallow merge; id re-pinned). */
|
|
93
|
+
export async function updateClass(projectPath, classId, updates) {
|
|
94
|
+
const [classes, index] = await findClassIndex(projectPath, classId);
|
|
95
|
+
classes[index] = { ...classes[index], ...updates, id: classId };
|
|
96
|
+
await commitChange(getDataPath(projectPath, 'Classes.json'), classes);
|
|
97
|
+
return classes[index];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Add a "learn skill at level" entry to a class — the first-class replacement for
|
|
101
|
+
* the hack of attaching skills directly to an actor via an Add-Skill trait. The
|
|
102
|
+
* `skillId` is validated to reference an existing skill (throws otherwise) and the
|
|
103
|
+
* resulting `learnings` list is kept sorted by level.
|
|
104
|
+
*/
|
|
105
|
+
export async function addClassLearning(projectPath, classId, skillId, level, note = '') {
|
|
106
|
+
const skills = await readJsonFile(getDataPath(projectPath, 'Skills.json'));
|
|
107
|
+
if (!skills.some((s) => s && s.id === skillId)) {
|
|
108
|
+
throw new Error(`Learning references skillId ${skillId}, which does not exist`);
|
|
109
|
+
}
|
|
110
|
+
const [classes, index] = await findClassIndex(projectPath, classId);
|
|
111
|
+
const gameClass = classes[index];
|
|
112
|
+
const learning = { level, note, skillId };
|
|
113
|
+
const learnings = [...(gameClass.learnings ?? []), learning].sort((a, b) => a.level - b.level);
|
|
114
|
+
classes[index] = { ...gameClass, learnings };
|
|
115
|
+
await commitChange(getDataPath(projectPath, 'Classes.json'), classes);
|
|
116
|
+
return classes[index];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Replace one of a class's 8 parameter growth curves. `paramId` is 0-7
|
|
120
|
+
* ([maxHP, maxMP, atk, def, mat, mdf, agi, luk]) and `values` must match the
|
|
121
|
+
* existing curve's length (so the matrix stays rectangular / same max level).
|
|
122
|
+
*/
|
|
123
|
+
export async function setClassParamCurve(projectPath, classId, paramId, values) {
|
|
124
|
+
if (paramId < 0 || paramId > 7) {
|
|
125
|
+
throw new Error(`paramId must be 0-7 (got ${paramId})`);
|
|
126
|
+
}
|
|
127
|
+
const [classes, index] = await findClassIndex(projectPath, classId);
|
|
128
|
+
const gameClass = classes[index];
|
|
129
|
+
const expectedLength = gameClass.params[paramId]?.length ?? values.length;
|
|
130
|
+
if (values.length !== expectedLength) {
|
|
131
|
+
throw new Error(`Param curve for ${PARAM_NAMES[paramId]} must have ${expectedLength} entries (got ${values.length})`);
|
|
132
|
+
}
|
|
133
|
+
const params = gameClass.params.map((row, i) => (i === paramId ? values : row));
|
|
134
|
+
classes[index] = { ...gameClass, params };
|
|
135
|
+
await commitChange(getDataPath(projectPath, 'Classes.json'), classes);
|
|
136
|
+
return classes[index];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A compact response view of a class for mutation tools. The on-disk record keeps
|
|
140
|
+
* its full 8×(maxLevel+1) `params` matrix, but echoing 800+ numbers back on every
|
|
141
|
+
* edit (e.g. adding one skill learning) is pure token waste — so the tool response
|
|
142
|
+
* replaces `params` with `maxLevel` plus a per-param first/last-level preview. A
|
|
143
|
+
* caller that needs the whole curve can still `get_database('classes')`.
|
|
144
|
+
*/
|
|
145
|
+
export function summarizeClass(c) {
|
|
146
|
+
const { params, ...rest } = c;
|
|
147
|
+
const maxLevel = (params?.[0]?.length ?? 1) - 1;
|
|
148
|
+
const paramCurves = params?.map((row, i) => ({
|
|
149
|
+
param: PARAM_NAMES[i],
|
|
150
|
+
atLevel1: row[1],
|
|
151
|
+
atMaxLevel: row[maxLevel],
|
|
152
|
+
}));
|
|
153
|
+
return { ...rest, maxLevel, paramCurves };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Warn (never throw) when a class learns skills whose skill type is not covered by
|
|
157
|
+
* an Add Skill Type trait ({ code: 41, dataId: stypeId }). Learnings only *teach*
|
|
158
|
+
* the skill — without the trait the skill-type command never appears in battle or
|
|
159
|
+
* the menu, so the actor silently "has no skills" even though the learnings are
|
|
160
|
+
* correct. One aggregated warning per uncovered stypeId. Skills with stypeId 0
|
|
161
|
+
* (no type) and learnings pointing at unknown skills are skipped (the latter is
|
|
162
|
+
* add_class_learning's throw, not this check's job). Pure so it's unit-testable.
|
|
163
|
+
*/
|
|
164
|
+
export function skillTypeTraitWarnings(gameClass, skills) {
|
|
165
|
+
const covered = new Set((gameClass.traits ?? []).filter((t) => t.code === 41).map((t) => t.dataId));
|
|
166
|
+
const missing = new Map();
|
|
167
|
+
for (const learning of gameClass.learnings ?? []) {
|
|
168
|
+
const skill = skills.find((s) => s && s.id === learning.skillId);
|
|
169
|
+
if (!skill || !skill.stypeId || covered.has(skill.stypeId))
|
|
170
|
+
continue;
|
|
171
|
+
const names = missing.get(skill.stypeId) ?? [];
|
|
172
|
+
names.push(skill.name || `#${skill.id}`);
|
|
173
|
+
missing.set(skill.stypeId, names);
|
|
174
|
+
}
|
|
175
|
+
return [...missing].map(([stypeId, names]) => ({
|
|
176
|
+
path: 'learnings',
|
|
177
|
+
message: `class "${gameClass.name}" learns ${names.join(', ')} (skill type ${stypeId}) but has no ` +
|
|
178
|
+
`Add Skill Type trait { code: 41, dataId: ${stypeId}, value: 1 } — without it the ` +
|
|
179
|
+
`skill-type command never appears, so actors can never use these skills`,
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Attach warn-by-default skill-type coverage to a class-write response (on the
|
|
184
|
+
* compact summary the handlers return). Fails soft when Skills.json is missing
|
|
185
|
+
* (nothing to check against — e.g. a bare fixture).
|
|
186
|
+
*/
|
|
187
|
+
async function withSkillTypeWarnings(projectPath, gameClass) {
|
|
188
|
+
const summary = summarizeClass(gameClass);
|
|
189
|
+
let skills;
|
|
190
|
+
try {
|
|
191
|
+
skills = await readJsonFile(getDataPath(projectPath, 'Skills.json'));
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return summary;
|
|
195
|
+
}
|
|
196
|
+
const warnings = skillTypeTraitWarnings(gameClass, skills);
|
|
197
|
+
return warnings.length > 0 ? { ...summary, warnings } : summary;
|
|
198
|
+
}
|
|
199
|
+
export const classToolDefinitions = [
|
|
200
|
+
{
|
|
201
|
+
name: 'create_class',
|
|
202
|
+
mutates: true,
|
|
203
|
+
description: "Create a new character class in data/Classes.json. Only `name` is required; omitted fields use the editor's new-class defaults (EXP curve [30,20,30,30], no traits/learnings, a linear param curve to maxLevel). Allocates and returns the next unused class id. NOTE: a class with no Hit Rate trait (xparam id 0: trait { code: 22, dataId: 0, value: 0.95 }) makes its actors always miss physical actions — pass one in `traits` for a combat-ready class. Likewise every learned skill's stypeId needs an Add Skill Type trait ({ code: 41, dataId: stypeId, value: 1 }) or the skill-type command never appears (warned, never blocked).",
|
|
204
|
+
inputSchema: {
|
|
205
|
+
name: z.string().describe('Class name shown in the database'),
|
|
206
|
+
maxLevel: z
|
|
207
|
+
.number()
|
|
208
|
+
.int()
|
|
209
|
+
.optional()
|
|
210
|
+
.describe('Highest level the param curve covers (default 99); sizes the params matrix'),
|
|
211
|
+
expParams: z
|
|
212
|
+
.array(z.number())
|
|
213
|
+
.length(4)
|
|
214
|
+
.optional()
|
|
215
|
+
.describe('EXP curve: [basis, extra, accelerationA, accelerationB]'),
|
|
216
|
+
params: z
|
|
217
|
+
.array(z.array(z.number()))
|
|
218
|
+
.optional()
|
|
219
|
+
.describe('8 param growth curves, each maxLevel+1 long: [maxHP,maxMP,atk,def,mat,mdf,agi,luk]'),
|
|
220
|
+
learnings: z
|
|
221
|
+
.array(z.unknown())
|
|
222
|
+
.optional()
|
|
223
|
+
.describe('Learned-skill entries { level, skillId, note }'),
|
|
224
|
+
traits: z.array(z.unknown()).optional().describe('Trait objects { code, dataId, value }'),
|
|
225
|
+
note: z.string().optional().describe('Note field'),
|
|
226
|
+
},
|
|
227
|
+
handler: async (ctx, args) => {
|
|
228
|
+
const { dryRun: _dryRun, name, ...rest } = args;
|
|
229
|
+
return withSkillTypeWarnings(ctx.projectPath, await createClass(ctx.projectPath, { name, ...rest }));
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'update_class',
|
|
234
|
+
mutates: true,
|
|
235
|
+
description: "Update a class's properties (shallow merge into the existing record). Use for name, expParams, traits, or to replace the whole learnings/params arrays; for targeted edits prefer add_class_learning / set_class_param_curve. Warns when a learned skill's stypeId has no Add Skill Type trait ({ code: 41 }).",
|
|
236
|
+
inputSchema: {
|
|
237
|
+
classId: z.number().int().positive().describe('The ID of the class to update'),
|
|
238
|
+
updates: z
|
|
239
|
+
.record(z.string(), z.unknown())
|
|
240
|
+
.describe('Object containing class properties to update'),
|
|
241
|
+
},
|
|
242
|
+
handler: async (ctx, args) => withSkillTypeWarnings(ctx.projectPath, await updateClass(ctx.projectPath, args.classId, args.updates)),
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'add_class_learning',
|
|
246
|
+
mutates: true,
|
|
247
|
+
description: 'Add a "learn skill at level" entry to a class (replaces the hack of attaching skills to an actor via an Add-Skill trait). Validates the skillId exists and keeps the learnings sorted by level. Warns (never blocks) when the skill\'s stypeId is not covered by an Add Skill Type trait ({ code: 41, dataId: stypeId, value: 1 }) on the class — without it the skill-type command never appears and actors cannot use the skill.',
|
|
248
|
+
inputSchema: {
|
|
249
|
+
classId: z.number().int().positive().describe('The ID of the class to add the learning to'),
|
|
250
|
+
skillId: z
|
|
251
|
+
.number()
|
|
252
|
+
.int()
|
|
253
|
+
.positive()
|
|
254
|
+
.describe('The skill learned (must exist in data/Skills.json)'),
|
|
255
|
+
level: z.number().int().describe('Level at which the skill is learned'),
|
|
256
|
+
note: z.string().optional().describe('Optional note for the learning entry'),
|
|
257
|
+
},
|
|
258
|
+
handler: async (ctx, args) => withSkillTypeWarnings(ctx.projectPath, await addClassLearning(ctx.projectPath, args.classId, args.skillId, args.level, args.note)),
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'set_class_param_curve',
|
|
262
|
+
mutates: true,
|
|
263
|
+
description: "Replace one of a class's 8 parameter growth curves. paramId is 0-7 ([maxHP,maxMP,atk,def,mat,mdf,agi,luk]); values must match the existing curve length (same max level).",
|
|
264
|
+
inputSchema: {
|
|
265
|
+
classId: z.number().int().positive().describe('The ID of the class to edit'),
|
|
266
|
+
paramId: z
|
|
267
|
+
.number()
|
|
268
|
+
.int()
|
|
269
|
+
.min(0)
|
|
270
|
+
.max(7)
|
|
271
|
+
.describe('Which param: 0 maxHP,1 maxMP,2 atk,3 def,4 mat,5 mdf,6 agi,7 luk'),
|
|
272
|
+
values: z
|
|
273
|
+
.array(z.number())
|
|
274
|
+
.describe('New curve, indexed by level; must match the existing curve length'),
|
|
275
|
+
},
|
|
276
|
+
handler: async (ctx, args) => summarizeClass(await setClassParamCurve(ctx.projectPath, args.classId, args.paramId, args.values)),
|
|
277
|
+
},
|
|
278
|
+
];
|
|
279
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AC,6BAA6B,CAAC;YAC5E,OAAO,EAAE,CAAC;iBACP,MAAM,EAAE;iBACR,GAAG,EAAE;iBACL,GAAG,CAAC,CAAC,CAAC;iBACN,GAAG,CAAC,CAAC,CAAC;iBACN,QAAQ,CAAC,kEAAkE,CAAC;YAC/E,MAAM,EAAE,CAAC;iBACN,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;iBACjB,QAAQ,CAAC,mEAAmE,CAAC;SACjF;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAC3B,cAAc,CACZ,MAAM,kBAAkB,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CACnF;KACJ;CACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CommonEvent, EventCommand } from '../utils/types.js';
|
|
2
|
+
import { ToolDefinition } from '../registry.js';
|
|
3
|
+
import { PreCommit } from '../validation/gate.js';
|
|
4
|
+
/**
|
|
5
|
+
* A blank common event mirroring what the RPG Maker MZ editor writes for a fresh
|
|
6
|
+
* slot: no trigger (call-only), switch 1, and an empty (just the code-0 end
|
|
7
|
+
* marker) command list. Pure so the template shape can be unit-tested. Field
|
|
8
|
+
* order mirrors the editor's on-disk shape.
|
|
9
|
+
*/
|
|
10
|
+
export declare function defaultCommonEvent(): Omit<CommonEvent, 'id'>;
|
|
11
|
+
/** Get all common events from the project (`data/CommonEvents.json`). */
|
|
12
|
+
export declare function getCommonEvents(projectPath: string): Promise<(CommonEvent | null)[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new common event. Only `name` is required; any omitted field falls
|
|
15
|
+
* back to the editor's new-slot default (see {@link defaultCommonEvent}).
|
|
16
|
+
* Allocates the next unused id (max existing + 1) and writes through the commit
|
|
17
|
+
* choke point.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createCommonEvent(projectPath: string, overrides: {
|
|
20
|
+
name: string;
|
|
21
|
+
} & Partial<Omit<CommonEvent, 'id' | 'name'>>, precommit?: PreCommit<CommonEvent>): Promise<CommonEvent>;
|
|
22
|
+
/** Update an existing common event's properties (shallow merge; id re-pinned). */
|
|
23
|
+
export declare function updateCommonEvent(projectPath: string, commonEventId: number, updates: Partial<CommonEvent>, precommit?: PreCommit<CommonEvent>): Promise<CommonEvent>;
|
|
24
|
+
/**
|
|
25
|
+
* Build a "Common Event" event command (code 117) that calls the given common
|
|
26
|
+
* event — the helper for wiring shared logic into a map/battle event page via
|
|
27
|
+
* `add_event_command`. Validates that the referenced common event exists (throws
|
|
28
|
+
* otherwise, mirroring create_map's parent check).
|
|
29
|
+
*/
|
|
30
|
+
export declare function callCommonEvent(projectPath: string, commonEventId: number, indent?: number): Promise<EventCommand>;
|
|
31
|
+
export declare const commonEventToolDefinitions: ToolDefinition[];
|
|
32
|
+
//# sourceMappingURL=commonEventTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonEventTools.d.ts","sourceRoot":"","sources":["../../src/tools/commonEventTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAa,MAAM,uBAAuB,CAAC;AAK7D;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAO5D;AAgBD,yEAAyE;AACzE,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,CAE1F;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,EACvE,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC,CAiBtB;AAED,kFAAkF;AAClF,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,EAC7B,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC,CAatB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,MAAM,SAAI,GACT,OAAO,CAAC,YAAY,CAAC,CAMvB;AAED,eAAO,MAAM,0BAA0B,EAAE,cAAc,EAkFtD,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { readJsonFile, getDataPath } from '../utils/fileHandler.js';
|
|
3
|
+
import { commitChange } from '../utils/commit.js';
|
|
4
|
+
import { definedOnly } from '../utils/records.js';
|
|
5
|
+
import { validateCommandList } from '../validation/eventCommands.js';
|
|
6
|
+
import { writeGate } from '../validation/gate.js';
|
|
7
|
+
/** Command code for "Common Event" (call a common event from an event page). */
|
|
8
|
+
const CALL_COMMON_EVENT_CODE = 117;
|
|
9
|
+
/**
|
|
10
|
+
* A blank common event mirroring what the RPG Maker MZ editor writes for a fresh
|
|
11
|
+
* slot: no trigger (call-only), switch 1, and an empty (just the code-0 end
|
|
12
|
+
* marker) command list. Pure so the template shape can be unit-tested. Field
|
|
13
|
+
* order mirrors the editor's on-disk shape.
|
|
14
|
+
*/
|
|
15
|
+
export function defaultCommonEvent() {
|
|
16
|
+
return {
|
|
17
|
+
list: [{ code: 0, indent: 0, parameters: [] }],
|
|
18
|
+
name: '',
|
|
19
|
+
switchId: 1,
|
|
20
|
+
trigger: 0,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The pre-commit gate the common-event-writing tools install. A common event's
|
|
25
|
+
* `list` reuses the event-command format, so the same command validator applies
|
|
26
|
+
* — and a structurally invalid list is refused before the write rather than
|
|
27
|
+
* saved and warned about.
|
|
28
|
+
*/
|
|
29
|
+
function commonEventWriteGate(force) {
|
|
30
|
+
return writeGate(force, 'common event', (commonEvent) => validateCommandList(commonEvent.list, `common event ${commonEvent.id}`));
|
|
31
|
+
}
|
|
32
|
+
/** Get all common events from the project (`data/CommonEvents.json`). */
|
|
33
|
+
export async function getCommonEvents(projectPath) {
|
|
34
|
+
return await readJsonFile(getDataPath(projectPath, 'CommonEvents.json'));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a new common event. Only `name` is required; any omitted field falls
|
|
38
|
+
* back to the editor's new-slot default (see {@link defaultCommonEvent}).
|
|
39
|
+
* Allocates the next unused id (max existing + 1) and writes through the commit
|
|
40
|
+
* choke point.
|
|
41
|
+
*/
|
|
42
|
+
export async function createCommonEvent(projectPath, overrides, precommit) {
|
|
43
|
+
const commonEvents = await getCommonEvents(projectPath);
|
|
44
|
+
const maxId = commonEvents.reduce((max, ce) => (ce && ce.id > max ? ce.id : max), 0);
|
|
45
|
+
// Template first, caller's defined fields next, computed id last so it always wins.
|
|
46
|
+
const commonEvent = {
|
|
47
|
+
...defaultCommonEvent(),
|
|
48
|
+
...definedOnly(overrides),
|
|
49
|
+
id: maxId + 1,
|
|
50
|
+
};
|
|
51
|
+
commonEvents.push(commonEvent);
|
|
52
|
+
await precommit?.(commonEvent);
|
|
53
|
+
await commitChange(getDataPath(projectPath, 'CommonEvents.json'), commonEvents);
|
|
54
|
+
return commonEvent;
|
|
55
|
+
}
|
|
56
|
+
/** Update an existing common event's properties (shallow merge; id re-pinned). */
|
|
57
|
+
export async function updateCommonEvent(projectPath, commonEventId, updates, precommit) {
|
|
58
|
+
const commonEvents = await getCommonEvents(projectPath);
|
|
59
|
+
const index = commonEvents.findIndex((ce) => ce && ce.id === commonEventId);
|
|
60
|
+
if (index === -1) {
|
|
61
|
+
throw new Error(`Common event with ID ${commonEventId} not found`);
|
|
62
|
+
}
|
|
63
|
+
commonEvents[index] = { ...commonEvents[index], ...updates, id: commonEventId };
|
|
64
|
+
await precommit?.(commonEvents[index]);
|
|
65
|
+
await commitChange(getDataPath(projectPath, 'CommonEvents.json'), commonEvents);
|
|
66
|
+
return commonEvents[index];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build a "Common Event" event command (code 117) that calls the given common
|
|
70
|
+
* event — the helper for wiring shared logic into a map/battle event page via
|
|
71
|
+
* `add_event_command`. Validates that the referenced common event exists (throws
|
|
72
|
+
* otherwise, mirroring create_map's parent check).
|
|
73
|
+
*/
|
|
74
|
+
export async function callCommonEvent(projectPath, commonEventId, indent = 0) {
|
|
75
|
+
const commonEvents = await getCommonEvents(projectPath);
|
|
76
|
+
if (!commonEvents.some((ce) => ce && ce.id === commonEventId)) {
|
|
77
|
+
throw new Error(`Common event with ID ${commonEventId} does not exist`);
|
|
78
|
+
}
|
|
79
|
+
return { code: CALL_COMMON_EVENT_CODE, indent, parameters: [commonEventId] };
|
|
80
|
+
}
|
|
81
|
+
export const commonEventToolDefinitions = [
|
|
82
|
+
{
|
|
83
|
+
name: 'create_common_event',
|
|
84
|
+
mutates: true,
|
|
85
|
+
forceable: true,
|
|
86
|
+
description: "Create a new common event (reusable event-command list) in data/CommonEvents.json. Only `name` is required; omitted fields use the editor's new-slot defaults (empty command list, trigger 0 = call-only, switchId 1). Allocates and returns the next unused id. A structurally invalid command list refuses the write (nothing is saved) — pass force: true to override.",
|
|
87
|
+
inputSchema: {
|
|
88
|
+
name: z.string().describe('Common event name shown in the database'),
|
|
89
|
+
trigger: z
|
|
90
|
+
.number()
|
|
91
|
+
.int()
|
|
92
|
+
.optional()
|
|
93
|
+
.describe('How it runs on its own: 0 None (call-only), 1 Autorun, 2 Parallel'),
|
|
94
|
+
switchId: z
|
|
95
|
+
.number()
|
|
96
|
+
.int()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe('Switch that gates an Autorun/Parallel trigger (ignored when trigger is 0)'),
|
|
99
|
+
list: z
|
|
100
|
+
.array(z.unknown())
|
|
101
|
+
.optional()
|
|
102
|
+
.describe('Event-command list { code, indent, parameters }; must end with code 0'),
|
|
103
|
+
},
|
|
104
|
+
handler: async (ctx, args) => {
|
|
105
|
+
// dryRun/force are dispatcher arguments, not common-event fields — strip
|
|
106
|
+
// them so they can't leak into the record via the spread below.
|
|
107
|
+
const { dryRun: _dryRun, force, ...overrides } = args;
|
|
108
|
+
const gate = commonEventWriteGate(force);
|
|
109
|
+
const commonEvent = await createCommonEvent(ctx.projectPath, overrides, gate.precommit);
|
|
110
|
+
return gate.respond({ commonEvent });
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'update_common_event',
|
|
115
|
+
mutates: true,
|
|
116
|
+
forceable: true,
|
|
117
|
+
description: "Update a common event's properties (shallow merge into the existing record). Use for name, trigger, switchId, or to replace the whole command list. A structurally invalid command list refuses the write (nothing is saved) — pass force: true to override.",
|
|
118
|
+
inputSchema: {
|
|
119
|
+
commonEventId: z.number().int().positive().describe('The ID of the common event to update'),
|
|
120
|
+
updates: z
|
|
121
|
+
.record(z.string(), z.unknown())
|
|
122
|
+
.describe('Object containing common event properties to update (name, trigger, switchId, list)'),
|
|
123
|
+
},
|
|
124
|
+
handler: async (ctx, args) => {
|
|
125
|
+
const gate = commonEventWriteGate(args.force);
|
|
126
|
+
const commonEvent = await updateCommonEvent(ctx.projectPath, args.commonEventId, args.updates, gate.precommit);
|
|
127
|
+
return gate.respond({ commonEvent });
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'call_common_event',
|
|
132
|
+
description: 'Build a "Common Event" event command (code 117) that calls the given common event, for insertion into an event page via insert_event_commands. Validates the common event exists. Read-only: returns `{ command }` (matching the build_* tools, so it composes into a thenBranch/commands array); writes nothing.',
|
|
133
|
+
inputSchema: {
|
|
134
|
+
commonEventId: z
|
|
135
|
+
.number()
|
|
136
|
+
.int()
|
|
137
|
+
.positive()
|
|
138
|
+
.describe('The ID of the common event to call (must exist)'),
|
|
139
|
+
indent: z
|
|
140
|
+
.number()
|
|
141
|
+
.int()
|
|
142
|
+
.optional()
|
|
143
|
+
.describe('Indentation level in the target list (default 0)'),
|
|
144
|
+
},
|
|
145
|
+
handler: async (ctx, args) => ({
|
|
146
|
+
command: await callCommonEvent(ctx.projectPath, args.commonEventId, args.indent),
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
//# sourceMappingURL=commonEventTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonEventTools.js","sourceRoot":"","sources":["../../src/tools/commonEventTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE7D,gFAAgF;AAChF,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;QAC9C,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;KACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAC3B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AAC;iBAC/B,QAAQ,CACP,qFAAqF,CACtF;SACJ;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC3B,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9C,MAAM,WAAW,GAAG,MAAM,iBAAiB,CACzC,GAAG,CAAC,WAAW,EACf,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,SAAS,CACf,CAAC;YACF,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QACvC,CAAC;KACF;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,mTAAmT;QACrT,WAAW,EAAE;YACX,aAAa,EAAE,CAAC;iBACb,MAAM,EAAE;iBACR,GAAG,EAAE;iBACL,QAAQ,EAAE;iBACV,QAAQ,CAAC,iDAAiD,CAAC;YAC9D,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,GAAG,EAAE;iBACL,QAAQ,EAAE;iBACV,QAAQ,CAAC,kDAAkD,CAAC;SAChE;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7B,OAAO,EAAE,MAAM,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC;SACjF,CAAC;KACH;CACF,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventCommand } from '../utils/types.js';
|
|
2
|
+
import { ToolDefinition } from '../registry.js';
|
|
3
|
+
import { ValidationWarning } from '../validation/eventCommands.js';
|
|
4
|
+
/** The three homes an EventCommand list can have in an MZ project. */
|
|
5
|
+
export type CommandListTarget = 'map_event' | 'common_event' | 'troop_page';
|
|
6
|
+
export interface InsertEventCommandsOptions {
|
|
7
|
+
mapId?: number;
|
|
8
|
+
eventId?: number;
|
|
9
|
+
commonEventId?: number;
|
|
10
|
+
troopId?: number;
|
|
11
|
+
pageIndex?: number;
|
|
12
|
+
commands: EventCommand[];
|
|
13
|
+
position?: number;
|
|
14
|
+
force?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface InsertEventCommandsResult {
|
|
17
|
+
target: CommandListTarget;
|
|
18
|
+
id: number;
|
|
19
|
+
list: EventCommand[];
|
|
20
|
+
warnings?: ValidationWarning[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Insert a pre-built command sequence into any of the three command lists an MZ
|
|
24
|
+
* project has — a map event page, a common event body, or a troop battle-event
|
|
25
|
+
* page — the mutating companion to the read-only builders below. This is how a
|
|
26
|
+
* Show Text / Show Choices / Conditional Branch block built by the builders
|
|
27
|
+
* actually lands in the game.
|
|
28
|
+
*
|
|
29
|
+
* All three lists share the EventCommand format, so there is one splice path:
|
|
30
|
+
* resolve the list, splice before its code-0 end marker (or at `position`),
|
|
31
|
+
* gate, commit. The resulting list is validated **before** the commit — a
|
|
32
|
+
* structurally invalid result is refused and nothing is written (unless
|
|
33
|
+
* `opts.force`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function insertEventCommands(projectPath: string, target: CommandListTarget, opts: InsertEventCommandsOptions): Promise<InsertEventCommandsResult>;
|
|
36
|
+
export declare const eventCommandToolDefinitions: ToolDefinition[];
|
|
37
|
+
//# sourceMappingURL=eventCommandTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventCommandTools.d.ts","sourceRoot":"","sources":["../../src/tools/eventCommandTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAGL,iBAAiB,EAClB,MAAM,gCAAgC,CAAC;AA0FxC,sEAAsE;AACtE,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,cAAc,GAAG,YAAY,CAAC;AAE5E,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAuGD;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,0BAA0B,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAMpC;AAqKD,eAAO,MAAM,2BAA2B,EAAE,cAAc,EAypBvD,CAAC"}
|