diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7b0672..84356d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Many thanks to the following for contributing to this release: - Changed default role selection to be a dropdown menu rather than id [#664](https://github.com/clusterio/clusterio/pull/664). - Added credential option to config entries to allow writing sensitive data that can't be read back remotely. - Allow hidden and readonly graphical representations of config values. [#665](https://github.com/clusterio/clusterio/pull/665). +- Added locale exporting for all builtin mods, not just for the base mod. [#684](https://github.com/clusterio/clusterio/pull/684). ### Changes @@ -70,6 +71,8 @@ Many thanks to the following for contributing to this release: - Updated display name and description of `controller.external_address` to avoid confusion. [#674](https://github.com/clusterio/clusterio/pull/674) - Fixed invalid transient state during server start. [#676](https://github.com/clusterio/clusterio/issues/676) - Fixed host user sync to instances after reconnecting to the controller. [#678](https://github.com/clusterio/clusterio/pull/678) +- Fixed WebUI adding and displaying the wrong base mod version. [#684](https://github.com/clusterio/clusterio/pull/684). +- Fixed WebUI inconsistent pattern matching for factorio version. [#684](https://github.com/clusterio/clusterio/pull/684). ### Breaking Changes diff --git a/packages/host/src/Host.ts b/packages/host/src/Host.ts index 32c6ae4a..6690d304 100644 --- a/packages/host/src/Host.ts +++ b/packages/host/src/Host.ts @@ -620,11 +620,9 @@ export default class Host extends lib.Link { async fetchMods(mods: Iterable) { // This is better than the previous hard coded names // But it really shouldn't be a hard coded version either - const builtinModNames = lib.ModPack.getBuiltinMods("2.0").map(builtinMod => builtinMod.name); + const builtinModNames = lib.ModPack.getBuiltinModNames("2.0"); const modInfos: Promise[] = []; for (const mod of mods) { - // XXX These mods ship with Factorio, but the list of mods may - // change and should not be hardcoded here. if (builtinModNames.includes(mod.name)) { continue; } diff --git a/packages/host/src/export.ts b/packages/host/src/export.ts index c2f64099..32e94a04 100644 --- a/packages/host/src/export.ts +++ b/packages/host/src/export.ts @@ -103,8 +103,8 @@ async function loadFile(server: FactorioServer, modVersions: Map let [, mod, filePath] = match; - const builtinMods = lib.ModPack.getBuiltinMods(server.version!); - if (builtinMods.some(builtinMod => builtinMod.name === mod)) { + const builtinModNames = ["core", ...lib.ModPack.getBuiltinModNames(server.version!)]; + if (builtinModNames.includes(mod)) { try { return await fs.readFile(server.dataPath(mod, filePath)); } catch (err: any) { @@ -397,15 +397,18 @@ async function exportLocale( } } - const builtinMods = lib.ModPack.getBuiltinMods(server.version!); - for (const builtinMod of builtinMods) { - const localeFilePath = server.dataPath(builtinMod.name, "locale", languageCode, `${builtinMod.name}.cfg`); + const builtinModNames = [ + // Filter if on builtin mods so "core" does not need to be specified in modOrder + "core", ...lib.ModPack.getBuiltinModNames(server.version!).filter(mod => modOrder.includes(mod)), + ]; + for (const builtinModName of builtinModNames) { + const localeFilePath = server.dataPath(builtinModName, "locale", languageCode, `${builtinModName}.cfg`); mergeLocale(lib.parse(await fs.readFile(localeFilePath, "utf8"))); } - const builtinModNames = ["export", ...builtinMods.map(builtinMod => builtinMod.name)]; + const builtinModNamesExport = ["export", ...builtinModNames]; for (let mod of modOrder) { - if (builtinModNames.includes(mod)) { + if (builtinModNamesExport.includes(mod)) { continue; } diff --git a/packages/host/src/patch.ts b/packages/host/src/patch.ts index 1221224e..9b7f1fb9 100644 --- a/packages/host/src/patch.ts +++ b/packages/host/src/patch.ts @@ -346,9 +346,9 @@ function reorderDependencies(modules: SaveModule[]) { const knownScenarios: Record = { // First seen in 0.17.63 "4e866186ebe297f1038fd325b09df1a1f5e2fdd1": new lib.ModuleInfo("freeplay", "0.17.63", [], ["scenario"]), - // First seen in 1.2.0 (aka 2.0) TODO Uncomment once clusterio lib supports 2.0 + // First seen in 2.0 TODO Uncomment once clusterio lib supports 2.0 // The rest of the code has already been updated to support the new control.lua file for 2.0 - // "bcbdde18ce4ec16ebfd93bd694cd9b12ef969c9a": new lib.ModuleInfo("freeplay", "1.2.0", [], ["scenario"]), + // "bcbdde18ce4ec16ebfd93bd694cd9b12ef969c9a": new lib.ModuleInfo("freeplay", "2.0.0", [], ["scenario"]), }; /** diff --git a/packages/lib/src/data/ModPack.ts b/packages/lib/src/data/ModPack.ts index 094a9248..df140c8b 100644 --- a/packages/lib/src/data/ModPack.ts +++ b/packages/lib/src/data/ModPack.ts @@ -391,6 +391,7 @@ export default class ModPack { */ static getBuiltinMods(factorioVersion: string) { let defaultMods: ModRecord[] = [ + // "core" not included because core cannot be disabled { name: "base", enabled: true, version: factorioVersion }, ]; @@ -405,4 +406,8 @@ export default class ModPack { return defaultMods; } + + static getBuiltinModNames(factorioVersion: string) { + return this.getBuiltinMods(factorioVersion).map(builtinMod => builtinMod.name); + } } diff --git a/test/file/factorio/data/base/locale/en/base.cfg b/test/file/factorio/data/base/locale/en/base.cfg index db44f757..ae82115b 100644 --- a/test/file/factorio/data/base/locale/en/base.cfg +++ b/test/file/factorio/data/base/locale/en/base.cfg @@ -1,4 +1,4 @@ ; Test data for exportLocale [test] -key-a=1 -key-b=2 +base-a=1 +base-b=2 diff --git a/test/host/export.js b/test/host/export.js index b0de6a0a..c806c316 100644 --- a/test/host/export.js +++ b/test/host/export.js @@ -17,7 +17,16 @@ describe("host/src/export", function() { it("returns a flattened mapping with locale definitions", async function() { let locale = await _exportLocale(testServer, new Map(), ["base"], "en"); - assert.deepEqual(locale, new Map([["test.key-a", "1"], ["test.key-b", "2"]])); + assert.deepEqual(locale, new Map([ + ["test.core-a", "1"], ["test.core-b", "2"], + ["test.base-a", "1"], ["test.base-b", "2"], + ])); + }); + it("returns a filtered locale definitions based on mod order", async function() { + let locale = await _exportLocale(testServer, new Map(), [], "en"); + assert.deepEqual(locale, new Map([ + ["test.core-a", "1"], ["test.core-b", "2"], + ])); }); }); }); diff --git a/test/lib/data/ModPack.js b/test/lib/data/ModPack.js index d1fc713e..4cd8a5fd 100644 --- a/test/lib/data/ModPack.js +++ b/test/lib/data/ModPack.js @@ -378,5 +378,32 @@ describe("lib/data/ModPack", function() { /* eslint-enable indent */ }); }); + describe("getBuiltinMods()", function() { + it("should work with versions before 2.0", function() { + const builtinMods = ModPack.getBuiltinMods("1.1"); + assert.deepEqual(builtinMods, [ + { name: "base", enabled: true, version: "1.1" }, + ]); + }); + it("should work with versions after 2.0", function() { + const builtinMods = ModPack.getBuiltinMods("2.0"); + assert.deepEqual(builtinMods, [ + { name: "base", enabled: true, version: "2.0" }, + { name: "elevated-rails", enabled: false, version: "2.0" }, + { name: "quality", enabled: false, version: "2.0" }, + { name: "space-age", enabled: false, version: "2.0" }, + ]); + }); + }); + describe("getBuiltinModNames()", function() { + it("should work with versions before 2.0", function() { + const builtinModNames = ModPack.getBuiltinModNames("1.1"); + assert.deepEqual(builtinModNames, ["base"]); + }); + it("should work with versions after 2.0", function() { + const builtinModNames = ModPack.getBuiltinModNames("2.0"); + assert.deepEqual(builtinModNames, ["base", "elevated-rails", "quality", "space-age"]); + }); + }); }); });