vscode-behavior3 2.2.0 → 2.3.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/README.md +119 -138
- package/build.d.ts +5 -0
- package/dist/build-cli.js +73 -16
- package/dist/extension.js +355 -49
- package/dist/webview/assets/editor-466vlAsX.js +8 -0
- package/dist/webview/assets/editor-CTBBjkkm.css +1 -0
- package/dist/webview/assets/{vendor-BuywoAnb.js → vendor-Ctok02TG.js} +23 -23
- package/dist/webview/index.html +3 -3
- package/dist/webview/locales/en.json +5 -0
- package/dist/webview/locales/zh.json +5 -0
- package/package.json +30 -10
- package/package.nls.json +4 -2
- package/package.nls.zh-cn.json +4 -2
- package/webview/shared/b3build-model.d.ts +22 -2
- package/dist/webview/assets/editor-BxvY-Wyu.css +0 -1
- package/dist/webview/assets/editor-DaW6jFnb.js +0 -7
package/dist/extension.js
CHANGED
|
@@ -216464,14 +216464,15 @@ var readWorkspaceSettings = (path14) => {
|
|
|
216464
216464
|
const content = getFs().readFileSync(path14, "utf-8");
|
|
216465
216465
|
return parseWorkspaceModelContent(content).settings;
|
|
216466
216466
|
};
|
|
216467
|
-
var
|
|
216467
|
+
var hasBuildHookMethod = (obj) => {
|
|
216468
216468
|
if (!obj || typeof obj !== "object") {
|
|
216469
216469
|
return false;
|
|
216470
216470
|
}
|
|
216471
216471
|
const candidate = obj;
|
|
216472
|
-
return typeof candidate.
|
|
216472
|
+
return typeof candidate.onProcessTree === "function" || typeof candidate.onProcessNode === "function" || typeof candidate.onWriteFile === "function" || typeof candidate.onComplete === "function";
|
|
216473
216473
|
};
|
|
216474
216474
|
var BUILD_HOOK_MARKER = "__behavior3BuildHook";
|
|
216475
|
+
var BATCH_HOOK_MARKER = "__behavior3BatchHook";
|
|
216475
216476
|
var CHECK_HOOK_MARKER = "__behavior3CheckHook";
|
|
216476
216477
|
var CHECK_HOOK_NAME = "__behavior3CheckName";
|
|
216477
216478
|
var markBuildHook = (ctor) => {
|
|
@@ -216481,6 +216482,13 @@ var markBuildHook = (ctor) => {
|
|
|
216481
216482
|
});
|
|
216482
216483
|
return ctor;
|
|
216483
216484
|
};
|
|
216485
|
+
var markBatchHook = (ctor) => {
|
|
216486
|
+
Object.defineProperty(ctor, BATCH_HOOK_MARKER, {
|
|
216487
|
+
value: true,
|
|
216488
|
+
configurable: false
|
|
216489
|
+
});
|
|
216490
|
+
return ctor;
|
|
216491
|
+
};
|
|
216484
216492
|
var markCheckCtor = (ctor, explicitName) => {
|
|
216485
216493
|
const name = explicitName?.trim() || ctor.name;
|
|
216486
216494
|
Object.defineProperty(ctor, CHECK_HOOK_MARKER, {
|
|
@@ -216499,28 +216507,51 @@ var markCheckHook = (nameOrCtor, _context) => {
|
|
|
216499
216507
|
}
|
|
216500
216508
|
return (ctor) => markCheckCtor(ctor, nameOrCtor);
|
|
216501
216509
|
};
|
|
216502
|
-
var
|
|
216510
|
+
var isDecoratedBuildHookCtor = (value) => typeof value === "function" && value[BUILD_HOOK_MARKER] === true;
|
|
216511
|
+
var isDecoratedBatchHookCtor = (value) => typeof value === "function" && value[BATCH_HOOK_MARKER] === true;
|
|
216503
216512
|
var isDecoratedCheckCtor = (value) => typeof value === "function" && value[CHECK_HOOK_MARKER] === true;
|
|
216504
|
-
var
|
|
216505
|
-
const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(
|
|
216513
|
+
var findDecoratedBuildHookCtor = (moduleRecord) => {
|
|
216514
|
+
const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(
|
|
216515
|
+
isDecoratedBuildHookCtor
|
|
216516
|
+
);
|
|
216506
216517
|
if (decorated.length > 1) {
|
|
216507
216518
|
logger.error("build script must decorate exactly one exported class with @behavior3.build");
|
|
216508
216519
|
return void 0;
|
|
216509
216520
|
}
|
|
216510
216521
|
return decorated[0];
|
|
216511
216522
|
};
|
|
216523
|
+
var findDecoratedBatchHookCtor = (moduleRecord) => {
|
|
216524
|
+
const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(
|
|
216525
|
+
isDecoratedBatchHookCtor
|
|
216526
|
+
);
|
|
216527
|
+
if (decorated.length > 1) {
|
|
216528
|
+
logger.error("batch script must decorate exactly one exported class with @behavior3.batch");
|
|
216529
|
+
return void 0;
|
|
216530
|
+
}
|
|
216531
|
+
if (decorated.length === 1) {
|
|
216532
|
+
return decorated[0];
|
|
216533
|
+
}
|
|
216534
|
+
const legacyDecorated = Array.from(new Set(Object.values(moduleRecord))).filter(
|
|
216535
|
+
isDecoratedBuildHookCtor
|
|
216536
|
+
);
|
|
216537
|
+
if (legacyDecorated.length > 1) {
|
|
216538
|
+
logger.error("batch script must decorate exactly one exported class with @behavior3.batch");
|
|
216539
|
+
return void 0;
|
|
216540
|
+
}
|
|
216541
|
+
return legacyDecorated[0];
|
|
216542
|
+
};
|
|
216512
216543
|
var findDecoratedCheckCtors = (moduleRecord) => Array.from(new Set(Object.values(moduleRecord))).filter(isDecoratedCheckCtor);
|
|
216513
|
-
var
|
|
216544
|
+
var createBuildHooks = (moduleExports, env2, reportMissing = true) => {
|
|
216514
216545
|
if (!moduleExports || typeof moduleExports !== "object") {
|
|
216515
216546
|
return void 0;
|
|
216516
216547
|
}
|
|
216517
216548
|
const moduleRecord = moduleExports;
|
|
216518
|
-
const defaultExport = isDecoratedCheckCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
|
|
216519
|
-
const ctor = moduleRecord.Hook ??
|
|
216549
|
+
const defaultExport = isDecoratedCheckCtor(moduleRecord.default) || isDecoratedBatchHookCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
|
|
216550
|
+
const ctor = moduleRecord.BuildHook ?? moduleRecord.Hook ?? findDecoratedBuildHookCtor(moduleRecord) ?? defaultExport;
|
|
216520
216551
|
if (typeof ctor === "function") {
|
|
216521
216552
|
try {
|
|
216522
216553
|
const instance = new ctor(env2);
|
|
216523
|
-
if (
|
|
216554
|
+
if (hasBuildHookMethod(instance)) {
|
|
216524
216555
|
return instance;
|
|
216525
216556
|
}
|
|
216526
216557
|
logger.error("build hook class instance has no supported hook methods");
|
|
@@ -216530,7 +216561,32 @@ var createBatchHooks = (moduleExports, env2, reportMissing = true) => {
|
|
|
216530
216561
|
}
|
|
216531
216562
|
if (reportMissing) {
|
|
216532
216563
|
logger.error(
|
|
216533
|
-
"build script must export a Hook class, default class, or one @behavior3.build-decorated class"
|
|
216564
|
+
"build script must export a BuildHook class, Hook class, default class, or one @behavior3.build-decorated class"
|
|
216565
|
+
);
|
|
216566
|
+
}
|
|
216567
|
+
return void 0;
|
|
216568
|
+
};
|
|
216569
|
+
var createBatchHooks = (moduleExports, env2, reportMissing = true) => {
|
|
216570
|
+
if (!moduleExports || typeof moduleExports !== "object") {
|
|
216571
|
+
return void 0;
|
|
216572
|
+
}
|
|
216573
|
+
const moduleRecord = moduleExports;
|
|
216574
|
+
const defaultExport = isDecoratedCheckCtor(moduleRecord.default) || isDecoratedBuildHookCtor(moduleRecord.default) || isDecoratedBatchHookCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
|
|
216575
|
+
const ctor = moduleRecord.BatchHook ?? findDecoratedBatchHookCtor(moduleRecord) ?? moduleRecord.Hook ?? defaultExport;
|
|
216576
|
+
if (typeof ctor === "function") {
|
|
216577
|
+
try {
|
|
216578
|
+
const instance = new ctor(env2);
|
|
216579
|
+
if (hasBuildHookMethod(instance) || typeof instance.shouldUpgradeTree === "function") {
|
|
216580
|
+
return instance;
|
|
216581
|
+
}
|
|
216582
|
+
logger.error("batch hook class instance has no supported hook methods");
|
|
216583
|
+
} catch (error) {
|
|
216584
|
+
logger.error("failed to instantiate batch hook class", error);
|
|
216585
|
+
}
|
|
216586
|
+
}
|
|
216587
|
+
if (reportMissing) {
|
|
216588
|
+
logger.error(
|
|
216589
|
+
"batch script must export a BatchHook class, default class, or one @behavior3.batch-decorated class"
|
|
216534
216590
|
);
|
|
216535
216591
|
}
|
|
216536
216592
|
return void 0;
|
|
@@ -216579,13 +216635,13 @@ var createBuildScriptRuntime = (moduleExports, env2) => {
|
|
|
216579
216635
|
};
|
|
216580
216636
|
}
|
|
216581
216637
|
const moduleRecord = moduleExports;
|
|
216582
|
-
const hasBuildHookCandidate = typeof moduleRecord.Hook === "function" || Object.values(moduleRecord).some(
|
|
216583
|
-
const buildScript =
|
|
216638
|
+
const hasBuildHookCandidate = typeof moduleRecord.BuildHook === "function" || typeof moduleRecord.Hook === "function" || Object.values(moduleRecord).some(isDecoratedBuildHookCtor) || typeof moduleRecord.default === "function" && !isDecoratedCheckCtor(moduleRecord.default) && !isDecoratedBatchHookCtor(moduleRecord.default);
|
|
216639
|
+
const buildScript = createBuildHooks(moduleExports, env2, false);
|
|
216584
216640
|
const checkerResult = createNodeArgCheckers(moduleExports, env2);
|
|
216585
216641
|
const hasEntries = Boolean(buildScript) || checkerResult.hasCheckers;
|
|
216586
216642
|
if (!hasEntries) {
|
|
216587
216643
|
logger.error(
|
|
216588
|
-
"build script must export a Hook class, default build class, @behavior3.build class, or @behavior3.check class"
|
|
216644
|
+
"build script must export a BuildHook class, Hook class, default build class, @behavior3.build class, or @behavior3.check class"
|
|
216589
216645
|
);
|
|
216590
216646
|
}
|
|
216591
216647
|
return {
|
|
@@ -217006,6 +217062,7 @@ var applyBehavior3DecoratorGlobal = () => {
|
|
|
217006
217062
|
runtimeGlobal.behavior3 = {
|
|
217007
217063
|
...decoratorGlobalState.previousBehavior3 && typeof decoratorGlobalState.previousBehavior3 === "object" ? decoratorGlobalState.previousBehavior3 : {},
|
|
217008
217064
|
build: markBuildHook,
|
|
217065
|
+
batch: markBatchHook,
|
|
217009
217066
|
check: markCheckHook
|
|
217010
217067
|
};
|
|
217011
217068
|
};
|
|
@@ -217026,7 +217083,7 @@ var restoreBehavior3DecoratorGlobal = () => {
|
|
|
217026
217083
|
decoratorGlobalState.hadBehavior3 = false;
|
|
217027
217084
|
decoratorGlobalState.previousBehavior3 = void 0;
|
|
217028
217085
|
};
|
|
217029
|
-
var
|
|
217086
|
+
var withBehavior3ScriptDecoratorGlobal = async (loader) => {
|
|
217030
217087
|
applyBehavior3DecoratorGlobal();
|
|
217031
217088
|
try {
|
|
217032
217089
|
return await loader();
|
|
@@ -217165,7 +217222,7 @@ var loadRuntimeModule = async (modulePath, options) => {
|
|
|
217165
217222
|
}
|
|
217166
217223
|
}
|
|
217167
217224
|
if (getRuntimeProcess()?.type === "renderer") {
|
|
217168
|
-
return await
|
|
217225
|
+
return await withBehavior3ScriptDecoratorGlobal(
|
|
217169
217226
|
() => import(
|
|
217170
217227
|
/* @vite-ignore */
|
|
217171
217228
|
`${modulePath}?t=${Date.now()}`
|
|
@@ -217193,7 +217250,7 @@ var loadRuntimeModule = async (modulePath, options) => {
|
|
|
217193
217250
|
return null;
|
|
217194
217251
|
}
|
|
217195
217252
|
const normalizedModulePath = b3path_default.posixPath(tempModulePath);
|
|
217196
|
-
const result = await
|
|
217253
|
+
const result = await withBehavior3ScriptDecoratorGlobal(
|
|
217197
217254
|
() => import(
|
|
217198
217255
|
/* @vite-ignore */
|
|
217199
217256
|
`file:///${normalizedModulePath}?t=${Date.now()}`
|
|
@@ -218524,15 +218581,14 @@ async function runBatchProcess(context, resourceUri) {
|
|
|
218524
218581
|
await runBatchProcessWithScript(context, workspaceFile, settingPath, projectRoot, picked[0].fsPath);
|
|
218525
218582
|
}
|
|
218526
218583
|
async function runBatchProcessScript(context, resourceUri) {
|
|
218527
|
-
const
|
|
218584
|
+
const resourceIsFile = resourceUri?.scheme === "file";
|
|
218585
|
+
const resourcePath = resourceIsFile ? resourceUri.fsPath : void 0;
|
|
218586
|
+
const explicitScriptUri = resourcePath && isSupportedBatchScriptPath(resourcePath) ? resourceUri : void 0;
|
|
218587
|
+
const activeFileUri = getActiveFileUri();
|
|
218588
|
+
const activeScriptUri = activeFileUri && isSupportedBatchScriptPath(activeFileUri.fsPath) ? activeFileUri : void 0;
|
|
218589
|
+
const scriptUri = explicitScriptUri ?? (!resourceUri ? activeScriptUri : void 0);
|
|
218528
218590
|
if (!scriptUri) {
|
|
218529
|
-
|
|
218530
|
-
return;
|
|
218531
|
-
}
|
|
218532
|
-
if (!isSupportedBatchScriptPath(scriptUri.fsPath)) {
|
|
218533
|
-
void vscode2.window.showErrorMessage(
|
|
218534
|
-
"Batch script must be a .ts, .mts, .js, or .mjs file."
|
|
218535
|
-
);
|
|
218591
|
+
await runBatchProcess(context, resourceUri);
|
|
218536
218592
|
return;
|
|
218537
218593
|
}
|
|
218538
218594
|
const folder = vscode2.workspace.getWorkspaceFolder(scriptUri) ?? vscode2.workspace.workspaceFolders?.[0];
|
|
@@ -219928,6 +219984,15 @@ function buildInitMessage(params) {
|
|
|
219928
219984
|
};
|
|
219929
219985
|
}
|
|
219930
219986
|
|
|
219987
|
+
// webview/shared/node-overrides.ts
|
|
219988
|
+
var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
219989
|
+
var getNodeArgOverrideCompareValue = (args, arg) => {
|
|
219990
|
+
if (args && hasOwn(args, arg.name)) {
|
|
219991
|
+
return args[arg.name];
|
|
219992
|
+
}
|
|
219993
|
+
return arg.default;
|
|
219994
|
+
};
|
|
219995
|
+
|
|
219931
219996
|
// media/locales/en.json
|
|
219932
219997
|
var en_default = {
|
|
219933
219998
|
about: "About Behavior3",
|
|
@@ -220095,6 +220160,11 @@ var en_default = {
|
|
|
220095
220160
|
"editor.newerVersionEditDenied": "This file is created by a newer version of Behavior3({{version}}). Please upgrade to the latest version.",
|
|
220096
220161
|
"inspector.noActiveDocument": "Open a Behavior3 editor to inspect and edit the active tree.",
|
|
220097
220162
|
"inspector.embeddedModeNotice": "Inspector is configured to appear inside the Behavior3 editor.",
|
|
220163
|
+
"inspector.embeddedToolbar.build": "Build Behavior Tree",
|
|
220164
|
+
"inspector.embeddedToolbar.toggleEditorMode": "Toggle Editor Mode",
|
|
220165
|
+
"inspector.embeddedToolbar.toggleInspectorNodeJson": "Toggle Raw Node JSON",
|
|
220166
|
+
"inspector.embeddedToolbar.createProject": "Create Project",
|
|
220167
|
+
"inspector.embeddedToolbar.createTree": "Create Behavior Tree",
|
|
220098
220168
|
"mutation.invalidJsonPath": "Invalid JSON path: {{path}}",
|
|
220099
220169
|
"mutation.missingSelectedNode": "No selected node is available for this mutation.",
|
|
220100
220170
|
"mutation.selectedNodeMismatch": "The selected node changed before the mutation was applied.",
|
|
@@ -220298,6 +220368,11 @@ var zh_default = {
|
|
|
220298
220368
|
"editor.newerVersionEditDenied": "\u6B64\u6587\u4EF6\u7531\u65B0\u7248\u672C Behavior3({{version}}) \u521B\u5EFA\uFF0C\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u7248\u672C\u540E\u518D\u7F16\u8F91\u3002",
|
|
220299
220369
|
"inspector.noActiveDocument": "\u6253\u5F00\u4E00\u4E2A Behavior3 \u7F16\u8F91\u5668\u540E\uFF0C\u8FD9\u91CC\u4F1A\u663E\u793A\u5F53\u524D\u884C\u4E3A\u6811\u7684 Inspector\uFF0C\u5E76\u652F\u6301\u76F4\u63A5\u7F16\u8F91\u3002",
|
|
220300
220370
|
"inspector.embeddedModeNotice": "Inspector \u5F53\u524D\u914D\u7F6E\u4E3A\u5728 Behavior3 \u7F16\u8F91\u5668\u5185\u90E8\u663E\u793A\u3002",
|
|
220371
|
+
"inspector.embeddedToolbar.build": "\u6784\u5EFA\u884C\u4E3A\u6811",
|
|
220372
|
+
"inspector.embeddedToolbar.toggleEditorMode": "\u5207\u6362\u7F16\u8F91\u5668\u6A21\u5F0F",
|
|
220373
|
+
"inspector.embeddedToolbar.toggleInspectorNodeJson": "\u5207\u6362\u539F\u59CB\u8282\u70B9 JSON",
|
|
220374
|
+
"inspector.embeddedToolbar.createProject": "\u65B0\u5EFA\u9879\u76EE",
|
|
220375
|
+
"inspector.embeddedToolbar.createTree": "\u65B0\u5EFA\u884C\u4E3A\u6811",
|
|
220301
220376
|
"mutation.invalidJsonPath": "\u65E0\u6548\u7684 JSON \u8DEF\u5F84: {{path}}",
|
|
220302
220377
|
"mutation.missingSelectedNode": "\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u4E8E\u63D0\u4EA4\u6B64\u4FEE\u6539\u7684\u9009\u4E2D\u8282\u70B9\u3002",
|
|
220303
220378
|
"mutation.selectedNodeMismatch": "\u5F53\u524D\u9009\u4E2D\u8282\u70B9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u8BD5\u3002",
|
|
@@ -220448,8 +220523,8 @@ var computeNodeOverride = (original, edited, def) => {
|
|
|
220448
220523
|
if (def?.args?.length) {
|
|
220449
220524
|
const diffArgs = {};
|
|
220450
220525
|
for (const arg of def.args) {
|
|
220451
|
-
const originalValue = original.args
|
|
220452
|
-
const editedValue = edited.args
|
|
220526
|
+
const originalValue = getNodeArgOverrideCompareValue(original.args, arg);
|
|
220527
|
+
const editedValue = getNodeArgOverrideCompareValue(edited.args, arg);
|
|
220453
220528
|
if (!isJsonEqual(originalValue, editedValue)) {
|
|
220454
220529
|
diffArgs[arg.name] = editedValue;
|
|
220455
220530
|
}
|
|
@@ -221243,6 +221318,9 @@ function createSessionDispatcher({
|
|
|
221243
221318
|
buildScriptDebug: msg.buildScriptDebug
|
|
221244
221319
|
}).then(void 0, logAsyncRuntimeError("command:behavior3.build"));
|
|
221245
221320
|
return;
|
|
221321
|
+
case "runInspectorCommand":
|
|
221322
|
+
void vscode14.commands.executeCommand(msg.command).then(void 0, logAsyncRuntimeError(`command:${msg.command}`));
|
|
221323
|
+
return;
|
|
221246
221324
|
case "validateNodeChecks":
|
|
221247
221325
|
await handleValidateNodeChecksMessage(msg, reply);
|
|
221248
221326
|
return;
|
|
@@ -222954,11 +223032,154 @@ function createLogOutputChannelLogger(out) {
|
|
|
222954
223032
|
};
|
|
222955
223033
|
}
|
|
222956
223034
|
|
|
223035
|
+
// src/script-scaffold.ts
|
|
223036
|
+
var SCRIPT_FILE_EXTENSION_RE = /\.(ts|mts|js|mjs)$/i;
|
|
223037
|
+
var INVALID_FILE_NAME_RE = /[\/\\:*?"<>|]/;
|
|
223038
|
+
var DEFAULT_BASE_NAMES = {
|
|
223039
|
+
build: "build",
|
|
223040
|
+
batch: "batch",
|
|
223041
|
+
checker: "checker"
|
|
223042
|
+
};
|
|
223043
|
+
function getScriptScaffoldDefaultBaseName(kind) {
|
|
223044
|
+
return DEFAULT_BASE_NAMES[kind];
|
|
223045
|
+
}
|
|
223046
|
+
function normalizeScriptScaffoldBaseName(value) {
|
|
223047
|
+
return value.trim();
|
|
223048
|
+
}
|
|
223049
|
+
function validateScriptScaffoldBaseName(value) {
|
|
223050
|
+
const normalized = normalizeScriptScaffoldBaseName(value);
|
|
223051
|
+
if (!normalized) {
|
|
223052
|
+
return "Name cannot be empty";
|
|
223053
|
+
}
|
|
223054
|
+
if (INVALID_FILE_NAME_RE.test(normalized)) {
|
|
223055
|
+
return "Name contains invalid characters";
|
|
223056
|
+
}
|
|
223057
|
+
if (SCRIPT_FILE_EXTENSION_RE.test(normalized)) {
|
|
223058
|
+
return "Enter the name without an extension";
|
|
223059
|
+
}
|
|
223060
|
+
return null;
|
|
223061
|
+
}
|
|
223062
|
+
function createScriptScaffoldFileName(baseName) {
|
|
223063
|
+
return `${normalizeScriptScaffoldBaseName(baseName)}.ts`;
|
|
223064
|
+
}
|
|
223065
|
+
function createScriptScaffoldContent(kind, baseName) {
|
|
223066
|
+
switch (kind) {
|
|
223067
|
+
case "build":
|
|
223068
|
+
return createBuildScriptContent(baseName);
|
|
223069
|
+
case "batch":
|
|
223070
|
+
return createBatchScriptContent(baseName);
|
|
223071
|
+
case "checker":
|
|
223072
|
+
return createCheckerScriptContent(baseName);
|
|
223073
|
+
}
|
|
223074
|
+
}
|
|
223075
|
+
function createBuildScriptContent(baseName) {
|
|
223076
|
+
const className = ensureSuffix(toPascalIdentifier(baseName), "Script");
|
|
223077
|
+
return [
|
|
223078
|
+
'import type { BuildEnv, BuildScript, NodeData, TreeData } from "vscode-behavior3/build";',
|
|
223079
|
+
"",
|
|
223080
|
+
"@behavior3.build",
|
|
223081
|
+
`export class ${className} implements BuildScript {`,
|
|
223082
|
+
" constructor(private readonly env: BuildEnv) {}",
|
|
223083
|
+
"",
|
|
223084
|
+
" onProcessTree(tree: TreeData, _path: string, _errors: string[]) {",
|
|
223085
|
+
" return tree;",
|
|
223086
|
+
" }",
|
|
223087
|
+
"",
|
|
223088
|
+
" onProcessNode(node: NodeData, _errors: string[]) {",
|
|
223089
|
+
" return node;",
|
|
223090
|
+
" }",
|
|
223091
|
+
"",
|
|
223092
|
+
' onComplete(status: "success" | "failure") {',
|
|
223093
|
+
" this.env.logger.info(`build ${status}`);",
|
|
223094
|
+
" }",
|
|
223095
|
+
"}",
|
|
223096
|
+
""
|
|
223097
|
+
].join("\n");
|
|
223098
|
+
}
|
|
223099
|
+
function createBatchScriptContent(baseName) {
|
|
223100
|
+
const className = ensureSuffix(toPascalIdentifier(baseName), "Script");
|
|
223101
|
+
return [
|
|
223102
|
+
'import type { BatchScript, BuildEnv, NodeData, TreeData } from "vscode-behavior3/build";',
|
|
223103
|
+
"",
|
|
223104
|
+
"@behavior3.batch",
|
|
223105
|
+
`export class ${className} implements BatchScript {`,
|
|
223106
|
+
" constructor(private readonly env: BuildEnv) {}",
|
|
223107
|
+
"",
|
|
223108
|
+
" shouldUpgradeTree(_path: string, _tree: TreeData) {",
|
|
223109
|
+
" return false;",
|
|
223110
|
+
" }",
|
|
223111
|
+
"",
|
|
223112
|
+
" onProcessTree(tree: TreeData, _path: string, _errors: string[]) {",
|
|
223113
|
+
" return tree;",
|
|
223114
|
+
" }",
|
|
223115
|
+
"",
|
|
223116
|
+
" onProcessNode(node: NodeData, _errors: string[]) {",
|
|
223117
|
+
" return node;",
|
|
223118
|
+
" }",
|
|
223119
|
+
"",
|
|
223120
|
+
' onComplete(status: "success" | "failure") {',
|
|
223121
|
+
" this.env.logger.info(`batch ${status}`);",
|
|
223122
|
+
" }",
|
|
223123
|
+
"}",
|
|
223124
|
+
""
|
|
223125
|
+
].join("\n");
|
|
223126
|
+
}
|
|
223127
|
+
function createCheckerScriptContent(baseName) {
|
|
223128
|
+
const className = ensureSuffix(toPascalIdentifier(baseName), "Checker");
|
|
223129
|
+
const checkerName = toCheckerRegistrationName(baseName);
|
|
223130
|
+
return [
|
|
223131
|
+
'import type { NodeArgCheckContext } from "vscode-behavior3/build";',
|
|
223132
|
+
"",
|
|
223133
|
+
`@behavior3.check("${checkerName}")`,
|
|
223134
|
+
`export class ${className} {`,
|
|
223135
|
+
" validate(value: unknown, ctx: NodeArgCheckContext) {",
|
|
223136
|
+
' if (value === undefined || value === null || value === "") {',
|
|
223137
|
+
" return;",
|
|
223138
|
+
" }",
|
|
223139
|
+
' if (typeof value !== "number") {',
|
|
223140
|
+
" return `${ctx.argName} must be a number`;",
|
|
223141
|
+
" }",
|
|
223142
|
+
" if (value <= 0) {",
|
|
223143
|
+
" return `${ctx.argName} must be greater than 0`;",
|
|
223144
|
+
" }",
|
|
223145
|
+
" }",
|
|
223146
|
+
"}",
|
|
223147
|
+
""
|
|
223148
|
+
].join("\n");
|
|
223149
|
+
}
|
|
223150
|
+
function toPascalIdentifier(value) {
|
|
223151
|
+
const source = normalizeScriptScaffoldBaseName(value).replace(SCRIPT_FILE_EXTENSION_RE, "");
|
|
223152
|
+
const tokens = source.match(/[A-Za-z0-9]+/g) ?? [];
|
|
223153
|
+
const joined = tokens.map((token) => token.charAt(0).toUpperCase() + token.slice(1)).join("");
|
|
223154
|
+
if (!joined) {
|
|
223155
|
+
return "Generated";
|
|
223156
|
+
}
|
|
223157
|
+
if (/^[A-Za-z_$]/.test(joined)) {
|
|
223158
|
+
return joined;
|
|
223159
|
+
}
|
|
223160
|
+
return `Generated${joined}`;
|
|
223161
|
+
}
|
|
223162
|
+
function ensureSuffix(value, suffix) {
|
|
223163
|
+
return value.toLowerCase().endsWith(suffix.toLowerCase()) ? value : `${value}${suffix}`;
|
|
223164
|
+
}
|
|
223165
|
+
function toCheckerRegistrationName(value) {
|
|
223166
|
+
const normalized = normalizeScriptScaffoldBaseName(value).replace(SCRIPT_FILE_EXTENSION_RE, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
223167
|
+
return normalized || "checker";
|
|
223168
|
+
}
|
|
223169
|
+
|
|
222957
223170
|
// src/extension.ts
|
|
222958
223171
|
var getVSCodeTheme2 = () => {
|
|
222959
223172
|
const kind = vscode23.window.activeColorTheme.kind;
|
|
222960
223173
|
return kind === vscode23.ColorThemeKind.Light || kind === vscode23.ColorThemeKind.HighContrastLight ? "light" : "dark";
|
|
222961
223174
|
};
|
|
223175
|
+
var getActiveBehaviorTreeEditorUri = () => {
|
|
223176
|
+
const tab = vscode23.window.tabGroups.activeTabGroup.activeTab;
|
|
223177
|
+
const input = tab?.input;
|
|
223178
|
+
if (!(input instanceof vscode23.TabInputCustom) || input.viewType !== TreeEditorProvider.viewType) {
|
|
223179
|
+
return null;
|
|
223180
|
+
}
|
|
223181
|
+
return input.uri;
|
|
223182
|
+
};
|
|
222962
223183
|
function activate(context) {
|
|
222963
223184
|
const config = vscode23.workspace.getConfiguration("behavior3");
|
|
222964
223185
|
const inspectorMode = config.get("inspectorMode", "sidebar");
|
|
@@ -223006,27 +223227,35 @@ function activate(context) {
|
|
|
223006
223227
|
inspectorCoordinator.setActiveDocument(documentUri);
|
|
223007
223228
|
};
|
|
223008
223229
|
syncActiveInspectorDocument();
|
|
223009
|
-
context.subscriptions.push(
|
|
223010
|
-
|
|
223011
|
-
|
|
223012
|
-
|
|
223013
|
-
|
|
223014
|
-
|
|
223015
|
-
|
|
223016
|
-
|
|
223017
|
-
|
|
223018
|
-
|
|
223019
|
-
|
|
223020
|
-
|
|
223021
|
-
|
|
223022
|
-
|
|
223023
|
-
|
|
223024
|
-
|
|
223025
|
-
|
|
223026
|
-
"behavior3.
|
|
223027
|
-
|
|
223028
|
-
|
|
223029
|
-
|
|
223230
|
+
context.subscriptions.push(
|
|
223231
|
+
vscode23.window.tabGroups.onDidChangeTabs(() => {
|
|
223232
|
+
syncActiveInspectorDocument();
|
|
223233
|
+
})
|
|
223234
|
+
);
|
|
223235
|
+
context.subscriptions.push(
|
|
223236
|
+
vscode23.window.tabGroups.onDidChangeTabGroups(() => {
|
|
223237
|
+
syncActiveInspectorDocument();
|
|
223238
|
+
})
|
|
223239
|
+
);
|
|
223240
|
+
context.subscriptions.push(
|
|
223241
|
+
vscode23.window.onDidChangeActiveColorTheme(() => {
|
|
223242
|
+
inspectorCoordinator.setTheme(getVSCodeTheme2());
|
|
223243
|
+
})
|
|
223244
|
+
);
|
|
223245
|
+
context.subscriptions.push(
|
|
223246
|
+
vscode23.workspace.onDidChangeConfiguration((event) => {
|
|
223247
|
+
if (!event.affectsConfiguration("behavior3.inspectorMode")) {
|
|
223248
|
+
return;
|
|
223249
|
+
}
|
|
223250
|
+
const nextInspectorMode = vscode23.workspace.getConfiguration("behavior3").get("inspectorMode", "sidebar");
|
|
223251
|
+
inspectorCoordinator.setInspectorMode(nextInspectorMode);
|
|
223252
|
+
void vscode23.commands.executeCommand(
|
|
223253
|
+
"setContext",
|
|
223254
|
+
"behavior3.inspectorSidebarMode",
|
|
223255
|
+
nextInspectorMode === "sidebar"
|
|
223256
|
+
);
|
|
223257
|
+
})
|
|
223258
|
+
);
|
|
223030
223259
|
const autoCheckedJsonWhileOpen = /* @__PURE__ */ new Set();
|
|
223031
223260
|
const autoOpeningJsonUris = /* @__PURE__ */ new Set();
|
|
223032
223261
|
const skipNextAutoOpenUris = /* @__PURE__ */ new Set();
|
|
@@ -223070,14 +223299,35 @@ function activate(context) {
|
|
|
223070
223299
|
);
|
|
223071
223300
|
context.subscriptions.push(
|
|
223072
223301
|
vscode23.commands.registerCommand("behavior3.toggleInspectorNodeJson", async () => {
|
|
223302
|
+
const activeEditorUri = getActiveBehaviorTreeEditorUri();
|
|
223303
|
+
const activeInspectorMode = vscode23.workspace.getConfiguration("behavior3").get("inspectorMode", "sidebar");
|
|
223304
|
+
if (activeInspectorMode === "embedded" && activeEditorUri) {
|
|
223305
|
+
TreeEditorProvider.postMessageToDocument(activeEditorUri.toString(), {
|
|
223306
|
+
type: "toggleInspectorNodeJson"
|
|
223307
|
+
});
|
|
223308
|
+
return;
|
|
223309
|
+
}
|
|
223073
223310
|
inspectorCoordinator.toggleNodeJsonView();
|
|
223074
223311
|
})
|
|
223075
223312
|
);
|
|
223076
223313
|
context.subscriptions.push(
|
|
223077
|
-
vscode23.commands.registerCommand("behavior3.
|
|
223078
|
-
await
|
|
223314
|
+
vscode23.commands.registerCommand("behavior3.createBuildScript", async (uri) => {
|
|
223315
|
+
await createBehavior3Script("build", uri);
|
|
223316
|
+
})
|
|
223317
|
+
);
|
|
223318
|
+
context.subscriptions.push(
|
|
223319
|
+
vscode23.commands.registerCommand("behavior3.createBatchScript", async (uri) => {
|
|
223320
|
+
await createBehavior3Script("batch", uri);
|
|
223079
223321
|
})
|
|
223080
223322
|
);
|
|
223323
|
+
context.subscriptions.push(
|
|
223324
|
+
vscode23.commands.registerCommand(
|
|
223325
|
+
"behavior3.createCheckerScript",
|
|
223326
|
+
async (uri) => {
|
|
223327
|
+
await createBehavior3Script("checker", uri);
|
|
223328
|
+
}
|
|
223329
|
+
)
|
|
223330
|
+
);
|
|
223081
223331
|
context.subscriptions.push(
|
|
223082
223332
|
vscode23.commands.registerCommand(
|
|
223083
223333
|
"behavior3.runBatchProcessScript",
|
|
@@ -223292,6 +223542,62 @@ function activate(context) {
|
|
|
223292
223542
|
}
|
|
223293
223543
|
function deactivate() {
|
|
223294
223544
|
}
|
|
223545
|
+
async function createBehavior3Script(kind, uri) {
|
|
223546
|
+
const folderUri = await resolveFolderTargetUri(uri);
|
|
223547
|
+
if (!folderUri) {
|
|
223548
|
+
void vscode23.window.showErrorMessage("Please open a workspace folder first.");
|
|
223549
|
+
return;
|
|
223550
|
+
}
|
|
223551
|
+
const baseName = await vscode23.window.showInputBox({
|
|
223552
|
+
prompt: `Enter ${getScriptScaffoldPromptLabel(kind)} file name (without extension)`,
|
|
223553
|
+
placeHolder: getScriptScaffoldDefaultBaseName(kind),
|
|
223554
|
+
value: getScriptScaffoldDefaultBaseName(kind),
|
|
223555
|
+
validateInput: validateScriptScaffoldBaseName
|
|
223556
|
+
});
|
|
223557
|
+
if (!baseName) {
|
|
223558
|
+
return;
|
|
223559
|
+
}
|
|
223560
|
+
const normalizedBaseName = normalizeScriptScaffoldBaseName(baseName);
|
|
223561
|
+
const fileName = createScriptScaffoldFileName(normalizedBaseName);
|
|
223562
|
+
const fileUri = vscode23.Uri.file(path13.join(folderUri.fsPath, fileName));
|
|
223563
|
+
if (fs8.existsSync(fileUri.fsPath)) {
|
|
223564
|
+
void vscode23.window.showErrorMessage(`File already exists: ${fileName}`);
|
|
223565
|
+
return;
|
|
223566
|
+
}
|
|
223567
|
+
try {
|
|
223568
|
+
await fs8.promises.writeFile(
|
|
223569
|
+
fileUri.fsPath,
|
|
223570
|
+
createScriptScaffoldContent(kind, normalizedBaseName),
|
|
223571
|
+
"utf-8"
|
|
223572
|
+
);
|
|
223573
|
+
await vscode23.window.showTextDocument(fileUri);
|
|
223574
|
+
} catch (e) {
|
|
223575
|
+
void vscode23.window.showErrorMessage(
|
|
223576
|
+
`Failed to create file: ${e instanceof Error ? e.message : e}`
|
|
223577
|
+
);
|
|
223578
|
+
}
|
|
223579
|
+
}
|
|
223580
|
+
async function resolveFolderTargetUri(uri) {
|
|
223581
|
+
if (uri?.scheme === "file") {
|
|
223582
|
+
try {
|
|
223583
|
+
const stat = await vscode23.workspace.fs.stat(uri);
|
|
223584
|
+
return stat.type === vscode23.FileType.Directory ? uri : vscode23.Uri.file(path13.dirname(uri.fsPath));
|
|
223585
|
+
} catch {
|
|
223586
|
+
return void 0;
|
|
223587
|
+
}
|
|
223588
|
+
}
|
|
223589
|
+
return vscode23.workspace.workspaceFolders?.[0]?.uri;
|
|
223590
|
+
}
|
|
223591
|
+
function getScriptScaffoldPromptLabel(kind) {
|
|
223592
|
+
switch (kind) {
|
|
223593
|
+
case "build":
|
|
223594
|
+
return "build script";
|
|
223595
|
+
case "batch":
|
|
223596
|
+
return "batch script";
|
|
223597
|
+
case "checker":
|
|
223598
|
+
return "checker script";
|
|
223599
|
+
}
|
|
223600
|
+
}
|
|
223295
223601
|
async function tryAutoOpenBehaviorEditor(uri, autoCheckedJsonWhileOpen, autoOpeningJsonUris, skipNextAutoOpenUris) {
|
|
223296
223602
|
if (uri.scheme !== "file") {
|
|
223297
223603
|
return;
|