GeWuYou 4ff5189da4 docs(config): 添加游戏内容配置系统完整文档与验证工具
- 新增游戏内容配置系统详细文档,涵盖 YAML 配置、JSON Schema 结构、目录组织等
- 添加 Schema 示例和 YAML 示例,展示怪物和物品配置的具体用法
- 提供推荐接入模板,包括目录结构、csproj 配置和启动代码模板
- 添加运行时读取模板和 Architecture 接入模板,简化集成流程
- 实现配置系统运行时校验行为说明,支持多种约束验证
- 添加开发期热重载功能说明和使用方法
- 提供 VS Code 工具支持,包括配置浏览、表单编辑等功能
- 新增配置验证工具实现,支持 JSON Schema 解析和 YAML 验证
- 添加批编辑功能,支持安全更新顶层标量字段和数组
- 提供完整的 API 参考和最佳实践指南
2026-04-10 18:22:40 +08:00

72 lines
3.2 KiB
JavaScript

const test = require("node:test");
const assert = require("node:assert/strict");
const {createLocalizer} = require("../src/localization");
const {ValidationMessageKeys} = require("../src/localizationKeys");
test("createLocalizer should default to English strings", () => {
const localizer = createLocalizer("en");
assert.equal(localizer.languageTag, "en");
assert.equal(localizer.isChinese, false);
assert.equal(localizer.t("webview.button.save"), "Save Form");
assert.equal(
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
"Batch updated 2 config file(s) in 'monster'.");
});
test("createLocalizer should switch to Simplified Chinese for zh languages", () => {
const localizer = createLocalizer("zh-cn");
assert.equal(localizer.languageTag, "zh-CN");
assert.equal(localizer.isChinese, true);
assert.equal(localizer.t("webview.button.save"), "保存表单");
assert.equal(
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
"已在“monster”中批量更新 2 个配置文件。");
});
test("createLocalizer should fall back to English for Traditional Chinese locales", () => {
const localizer = createLocalizer("zh-TW");
assert.equal(localizer.languageTag, "zh-tw");
assert.equal(localizer.isChinese, false);
assert.equal(localizer.t("webview.button.save"), "Save Form");
assert.equal(
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
"Batch updated 2 config file(s) in 'monster'.");
});
test("createLocalizer should expose object property-count validation keys in English", () => {
const localizer = createLocalizer("en");
assert.equal(
localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}),
"Property 'reward' must contain at least 2 properties.");
assert.equal(
localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}),
"Property 'reward' must contain at most 3 properties.");
});
test("createLocalizer should expose object property-count validation keys in Simplified Chinese", () => {
const localizer = createLocalizer("zh-cn");
assert.equal(
localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}),
"对象属性“reward”至少需要包含 2 个子属性。");
assert.equal(
localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}),
"对象属性“reward”最多只能包含 3 个子属性。");
});
test("createLocalizer should expose contains-count validation keys", () => {
const englishLocalizer = createLocalizer("en");
const chineseLocalizer = createLocalizer("zh-cn");
assert.equal(
englishLocalizer.t(ValidationMessageKeys.minContainsViolation, {displayPath: "dropRates", value: 2}),
"Property 'dropRates' must contain at least 2 items matching the 'contains' schema.");
assert.equal(
chineseLocalizer.t(ValidationMessageKeys.maxContainsViolation, {displayPath: "dropRates", value: 1}),
"属性“dropRates”最多只能包含 1 个匹配 contains 条件的元素。");
});