Add ModInfo.id getter

Provide a simple unique identifier for mods consisting of the name
followed by an underscore and then the version.
This commit is contained in:
Hornwitser committed 2023-12-12 00:08:25 +01:00
1 parent ddba58ca99
commit 867bb0c646
4 files changed
+13 -5

No files matched your search

+1 -1
View File
@@ -867,7 +867,7 @@ modPackCommands.add(new lib.Command({
}],
handler: async function(args: { modPack: string }, control: Control) {
let mods = new Map(
(await control.send(new lib.ModListRequest())).map(m => [`${m.name}_${m.version}`, m])
(await control.send(new lib.ModListRequest())).map(m => [m.id, m])
);
let modPack = await control.send(
new lib.ModPackGetRequest(await lib.resolveModPack(control, args.modPack))
+8
View File
@@ -16,6 +16,14 @@ import { integerModVersion, integerFactorioVersion, modVersionRegExp } from "./v
* details of the invidiual fields sourced from info.json.
*/
export default class ModInfo {
/**
* String containing {mod.name}_{mod.version}, uniquely identifies this
* mod.
*/
get id() {
return `${this.name}_${this.version}`;
}
/**
* Internal name of this mod.
* This is the name of the zip file as well as the name that appears in
@@ -261,7 +261,7 @@ function ModsTable(props: ModsTableProps) {
}
}
const modListMap = new Map(modList.map(mod => [`${mod.name}_${mod.version}`, mod]));
const modListMap = new Map(modList.map(mod => [mod.id, mod]));
const mods = [...props.modPack.mods.values(), ...deletedMods.values()].map(
(mod: lib.ModRecord|lib.ModInfo): lib.ModInfo|lib.ModRecord => {
const candidate = modListMap.get(`${mod.name}_${mod.version}`);
@@ -481,8 +481,8 @@ function SettingsTable(props: SettingsTableProps) {
const [modList] = useModList();
const modsInPack = new Set([...props.modPack.mods.values()].map(mod => `${mod.name}_${mod.version}`));
const modTitles = new Map(modList
.filter(mod => modsInPack.has(`${mod.name}_${mod.version}`))
.map(mod => [`${mod.name}`, mod.title])
.filter(mod => modsInPack.has(mod.id))
.map(mod => [mod.name, mod.title])
);
const types = ["bool-setting", "int-setting", "double-setting", "string-setting"];
+1 -1
View File
@@ -265,7 +265,7 @@ export default function ModsPage() {
}}
dataSource={modList}
pagination={false}
rowKey={mod => `${mod.name}_${mod.version}`}
rowKey={mod => mod.id}
/>
<PluginExtra component="ModsPage" />
</PageLayout>;