mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Added Builtin Mods
This commit is contained in:
4 files changed
+44
-8
No files matched your search
@@ -618,11 +618,14 @@ export default class Host extends lib.Link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchMods(mods: Iterable<lib.ModRecord>) {
|
async fetchMods(mods: Iterable<lib.ModRecord>) {
|
||||||
|
// 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 modInfos: Promise<lib.ModInfo>[] = [];
|
const modInfos: Promise<lib.ModInfo>[] = [];
|
||||||
for (const mod of mods) {
|
for (const mod of mods) {
|
||||||
// XXX These mods ship with Factorio, but the list of mods may
|
// XXX These mods ship with Factorio, but the list of mods may
|
||||||
// change and should not be hardcoded here.
|
// change and should not be hardcoded here.
|
||||||
if (["core", "base"].includes(mod.name)) {
|
if (builtinModNames.includes(mod.name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
modInfos.push(this.fetchMod(mod));
|
modInfos.push(this.fetchMod(mod));
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ async function loadFile(server: FactorioServer, modVersions: Map<string, string>
|
|||||||
|
|
||||||
let [, mod, filePath] = match;
|
let [, mod, filePath] = match;
|
||||||
|
|
||||||
if (["core", "base"].includes(mod)) {
|
const builtinMods = lib.ModPack.getBuiltinMods(server.version!);
|
||||||
|
if (builtinMods.some(builtinMod => builtinMod.name === mod)) {
|
||||||
try {
|
try {
|
||||||
return await fs.readFile(server.dataPath(mod, filePath));
|
return await fs.readFile(server.dataPath(mod, filePath));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -396,11 +397,15 @@ async function exportLocale(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let baseLocaleFilePath = server.dataPath("base", "locale", languageCode, "base.cfg");
|
const builtinMods = lib.ModPack.getBuiltinMods(server.version!);
|
||||||
mergeLocale(lib.parse(await fs.readFile(baseLocaleFilePath, "utf8")));
|
for (const builtinMod of builtinMods) {
|
||||||
|
const localeFilePath = server.dataPath(builtinMod.name, "locale", languageCode, `${builtinMod.name}.cfg`);
|
||||||
|
mergeLocale(lib.parse(await fs.readFile(localeFilePath, "utf8")));
|
||||||
|
}
|
||||||
|
|
||||||
|
const builtinModNames = ["export", ...builtinMods.map(builtinMod => builtinMod.name)];
|
||||||
for (let mod of modOrder) {
|
for (let mod of modOrder) {
|
||||||
if (["core", "base", "export"].includes(mod)) {
|
if (builtinModNames.includes(mod)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,8 +173,11 @@ export default class ModPack {
|
|||||||
if (json.updated_at_ms) { modPack.updatedAtMs = json.updated_at_ms; }
|
if (json.updated_at_ms) { modPack.updatedAtMs = json.updated_at_ms; }
|
||||||
if (json.is_deleted) { modPack.isDeleted = json.is_deleted; }
|
if (json.is_deleted) { modPack.isDeleted = json.is_deleted; }
|
||||||
|
|
||||||
if (!modPack.mods.has("base")) {
|
const builtinMods = ModPack.getBuiltinMods(modPack.factorioVersion);
|
||||||
modPack.mods.set("base", { name: "base", enabled: true, version: modPack.factorioVersion });
|
for (const builtinMod of builtinMods) {
|
||||||
|
if (!modPack.mods.has(builtinMod.name)) {
|
||||||
|
modPack.mods.set(builtinMod.name, builtinMod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return modPack;
|
return modPack;
|
||||||
@@ -379,4 +382,27 @@ export default class ModPack {
|
|||||||
this.settings[settingType].set(prototype.name, { value });
|
this.settings[settingType].set(prototype.name, { value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of ModInfo containing all mods included in factorio
|
||||||
|
*
|
||||||
|
* @param factorioVersion - Factorio version to get the default mods for
|
||||||
|
* @return Built in mods for the given version
|
||||||
|
*/
|
||||||
|
static getBuiltinMods(factorioVersion: string) {
|
||||||
|
let defaultMods: ModRecord[] = [
|
||||||
|
{ name: "base", enabled: true, version: factorioVersion },
|
||||||
|
];
|
||||||
|
|
||||||
|
const integerVersion = integerFactorioVersion(factorioVersion);
|
||||||
|
if (integerVersion > integerFactorioVersion("1.2")) {
|
||||||
|
defaultMods = defaultMods.concat([
|
||||||
|
{ name: "elevated-rails", enabled: false, version: factorioVersion },
|
||||||
|
{ name: "quality", enabled: false, version: factorioVersion },
|
||||||
|
{ name: "space-age", enabled: false, version: factorioVersion },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultMods;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -894,7 +894,9 @@ export default function ModPackViewPage() {
|
|||||||
changes={changes}
|
changes={changes}
|
||||||
onChange={pushChange}
|
onChange={pushChange}
|
||||||
onRevert={revertChange}
|
onRevert={revertChange}
|
||||||
builtInMods={["base", "core"]}
|
builtInMods={
|
||||||
|
lib.ModPack.getBuiltinMods(modPack.factorioVersion).map(builtinMod => builtinMod.name)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<SettingsTable
|
<SettingsTable
|
||||||
modPack={modifiedModPack}
|
modPack={modifiedModPack}
|
||||||
|
|||||||
Reference in new issue
Block a user