Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/components/views/LocalModList/LocalModCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,30 @@ const canBeDisabled = computed(() => !store.getters['isModLoader'](props.mod.get
const isDeprecated = computed(() => store.state.tsMods.deprecated.get(props.mod.getName()) || false);
const isLatestVersion = computed(() => store.getters['tsMods/isLatestVersion'](props.mod));
const localModList = computed(() => store.state.profile.modList);
const modMap = computed((): Map<string, ManifestV2> => store.getters['profile/modMap']);
const tsMod = computed(() => store.getters['tsMods/tsMod'](props.mod));

async function updateDependencies() {
function updateDependencies() {
if (props.mod.getDependencies().length === 0) {
return;
}

const dependencies = props.mod.getDependencies();
const dependencyNames = dependencies.map(dependencyStringToModName);
const foundDependencies: ManifestV2[] = [];

for (const mod of localModList.value) {
if (foundDependencies.length === dependencyNames.length) {
break;
}

if (dependencyNames.includes(mod.getName())) {
for (const depString of dependencies) {
const depName = dependencyStringToModName(depString);
const mod = modMap.value.get(depName);
if (mod !== undefined) {
foundDependencies.push(mod);
}
}

const foundNames = foundDependencies.map((mod) => mod.getName());
const foundNames = new Set(foundDependencies.map((mod) => mod.getName()));

disabledDependencies.value = foundDependencies.filter((d) => !d.isEnabled());
missingDependencies.value = dependencies.filter(
(d) => !foundNames.includes(dependencyStringToModName(d))
(d) => !foundNames.has(dependencyStringToModName(d))
);
}

Expand Down
82 changes: 52 additions & 30 deletions src/r2mm/mods/Dependants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,64 @@ import ManifestV2 from '../../model/ManifestV2';

export default class Dependants {

public static getDependantList(manifestMod: ManifestV2, modList: ManifestV2[], dependantSet?: Set<ManifestV2>): Set<ManifestV2> {
private static buildDependantIndex(modList: ManifestV2[]): Map<string, ManifestV2[]> {
const index = new Map<string, ManifestV2[]>();
for (const mod of modList) {
for (const dep of mod.getDependencies()) {
const depName = dep.substring(0, dep.lastIndexOf('-'));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same outcome but you have changed the logic here. I'd probably say to revert so that it's a bit easier to read and doesn't rely on knowing the format as much.

if (!index.has(depName)) {
index.set(depName, []);
}
index.get(depName)!.push(mod);
}
}
return index;
}

private static buildModMap(modList: ManifestV2[]): Map<string, ManifestV2> {
const map = new Map<string, ManifestV2>();
for (const mod of modList) {
map.set(mod.getName(), mod);
}
return map;
}

public static getDependantList(
manifestMod: ManifestV2,
modList: ManifestV2[],
dependantSet?: Set<ManifestV2>,
dependantIndex?: Map<string, ManifestV2[]>
): Set<ManifestV2> {
const dependants = dependantSet || new Set<ManifestV2>();
const index = dependantIndex || this.buildDependantIndex(modList);

// For all mods
modList.forEach(mod => {
// Get mod dependencies
mod.getDependencies().forEach(dependency => {
// If mod name equals mod trying to get dependants
if (dependency.startsWith(manifestMod.getName() + "-")) {
if (!dependants.has(mod)) {
dependants.add(mod);
// Get dependants of new mod
this.getDependantList(mod, modList, dependants).forEach(recursive => {
dependants.add(recursive);
})
}
}
})
})
const directDependants = index.get(manifestMod.getName()) || [];
for (const mod of directDependants) {
if (!dependants.has(mod)) {
dependants.add(mod);
this.getDependantList(mod, modList, dependants, index);
}
}
return dependants;
}

public static getDependencyList(manifestMod: ManifestV2, modList: ManifestV2[], dependencySet?: Set<ManifestV2>): Set<ManifestV2> {
public static getDependencyList(
manifestMod: ManifestV2,
modList: ManifestV2[],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be replacing modList entirely with modMap otherwise we're having double the memory consumption

dependencySet?: Set<ManifestV2>,
modMap?: Map<string, ManifestV2>
): Set<ManifestV2> {
const dependencies = dependencySet || new Set<ManifestV2>();
manifestMod.getDependencies().forEach(dependant => {
modList.forEach(mod => {
if (dependant.startsWith(mod.getName() + "-")) {
if (!dependencies.has(mod)) {
dependencies.add(mod);
this.getDependencyList(mod, modList, dependencies).forEach(recursive => {
dependencies.add(recursive);
})
}
}
})
})
const map = modMap || this.buildModMap(modList);

for (const depString of manifestMod.getDependencies()) {
const depName = depString.substring(0, depString.lastIndexOf('-'));
const mod = map.get(depName);
if (mod !== undefined && !dependencies.has(mod)) {
dependencies.add(mod);
this.getDependencyList(mod, modList, dependencies, map);
}
}
return dependencies;
}

Expand Down
8 changes: 8 additions & 0 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ export default {
return state.modList;
},

modMap(state): Map<string, ManifestV2> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not rebuilding the map every time this getter is called?

const map = new Map<string, ManifestV2>();
for (const mod of state.modList) {
map.set(mod.getName(), mod);
}
return map;
},

// Swap the ManifestV2s to ThunderstoreMods as the latter knows the version number
// of the latest version, which we need when showing how mods will be updated.
modsWithUpdates(state, _getters, _rootState, rootGetters): ThunderstoreMod[] {
Expand Down