Skip to content

Commit

Permalink
WIP Yeet ModBridge & ThunderstorePackages.PACKAGES
Browse files Browse the repository at this point in the history
Also change ALL THE THINGS. TODO: split this to sane commits
  • Loading branch information
anttimaki committed Mar 12, 2024
1 parent ba95fab commit 30d4de1
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 161 deletions.
17 changes: 6 additions & 11 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import StatusEnum from '../../model/enums/StatusEnum';
import ThunderstoreCombo from '../../model/ThunderstoreCombo';
import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileInstallerProvider';
import ProfileModList from '../../r2mm/mods/ProfileModList';
import ModBridge from '../../r2mm/mods/ModBridge';
import Profile from '../../model/Profile';
import { Progress } from '../all';
import Game from '../../model/game/Game';
Expand Down Expand Up @@ -242,27 +241,23 @@ let assignId = 0;
this.downloadHandler(refSelectedThunderstoreMod, version);
}
// TODO: rethink how this method and provider's downloadLatestOfAll()
// access the active game, local mod list and TS mod list.
async downloadLatest() {
this.closeModal();
const localMods = await ProfileModList.getModList(this.contextProfile!);
if (localMods instanceof R2Error) {
this.downloadingMod = false;
this.$store.commit('error/handleError', localMods);
return;
}
const outdatedMods = localMods.filter(mod => !ModBridge.isCachedLatestVersion(mod));
const modsWithUpdates: ThunderstoreCombo[] = this.$store.getters['profile/modsWithUpdates'];
const currentAssignId = assignId++;
const progressObject = {
progress: 0,
initialMods: outdatedMods.map(value => `${value.getName()} (${value.getVersionNumber().toString()})`),
initialMods: modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().toString()})`),
modName: '',
assignId: currentAssignId,
failed: false,
};
this.downloadObject = progressObject;
DownloadModModal.allVersions.push([currentAssignId, this.downloadObject]);
this.downloadingMod = true;
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(this.activeGame, outdatedMods, this.thunderstorePackages, (progress: number, modName: string, status: number, err: R2Error | null) => {
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(this.activeGame, modsWithUpdates, this.thunderstorePackages, (progress: number, modName: string, status: number, err: R2Error | null) => {
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
if (status === StatusEnum.FAILURE) {
if (err !== null) {
Expand All @@ -277,7 +272,7 @@ let assignId = 0;
const obj = {
progress: progress,
modName: modName,
initialMods: outdatedMods.map(value => `${value.getName()} (${value.getVersionNumber().toString()})`),
initialMods: modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().getVersionNumber().toString()})`),
assignId: currentAssignId,
failed: false,
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import ManifestV2 from '../../model/ManifestV2';
import ProfileModList from '../../r2mm/mods/ProfileModList';
import R2Error from '../../model/errors/R2Error';
import ManagerSettings from '../../r2mm/manager/ManagerSettings';
import ModBridge from '../../r2mm/mods/ModBridge';
import DependencyListDisplayType from '../../model/enums/DependencyListDisplayType';
import Dependants from '../../r2mm/mods/Dependants';
import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileInstallerProvider';
Expand Down Expand Up @@ -255,7 +254,7 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
updateMod(mod: ManifestV2) {
this.selectedManifestMod = mod;
const tsMod = ModBridge.getCachedThunderstoreModFromMod(mod);
const tsMod = this.$store.getters.tsMod(mod);
if (tsMod instanceof ThunderstoreMod) {
this.$store.commit("openDownloadModModal", tsMod);
Expand Down
14 changes: 9 additions & 5 deletions src/components/views/LocalModList/LocalModCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ExpandableCard, Link } from '../../all';
import DonateButton from '../../buttons/DonateButton.vue';
import R2Error from '../../../model/errors/R2Error';
import ManifestV2 from '../../../model/ManifestV2';
import ThunderstoreMod from '../../../model/ThunderstoreMod';
import { LogSeverity } from '../../../providers/ror2/logging/LoggerProvider';
import Dependants from '../../../r2mm/mods/Dependants';
import ModBridge from '../../../r2mm/mods/ModBridge';
@Component({
components: {
Expand Down Expand Up @@ -36,16 +36,20 @@ export default class LocalModCard extends Vue {
return this.tsMod ? this.tsMod.getDonationLink() : undefined;
}
get isDeprecated() {
return this.tsMod ? this.tsMod.isDeprecated() : false;
}
get isLatestVersion() {
return ModBridge.isCachedLatestVersion(this.mod);
return this.$store.getters.isLatestVersion(this.mod);
}
get localModList(): ManifestV2[] {
return this.$store.state.profile.modList;
}
get tsMod() {
return ModBridge.getCachedThunderstoreModFromMod(this.mod);
get tsMod(): ThunderstoreMod | undefined {
return this.$store.getters.tsMod(this.mod);
}
@Watch("localModList")
Expand Down Expand Up @@ -141,7 +145,7 @@ function dependencyStringToModName(x: string) {

<template v-slot:title>
<span class="non-selectable">
<span v-if="mod.isDeprecated()"
<span v-if="isDeprecated"
class="tag is-danger margin-right margin-right--half-width"
v-tooltip.right="'This mod is deprecated and could be broken'">
Deprecated
Expand Down
7 changes: 0 additions & 7 deletions src/model/ManifestV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
import * as path from 'path';
import PathResolver from '../r2mm/manager/PathResolver';
import R2Error from './errors/R2Error';
import ModBridge from '../r2mm/mods/ModBridge';
import ThunderstorePackages from '../r2mm/data/ThunderstorePackages';

export default class ManifestV2 implements ReactiveObjectConverterInterface {

Expand Down Expand Up @@ -268,11 +266,6 @@ export default class ManifestV2 implements ReactiveObjectConverterInterface {
return this.enabled;
}

public isDeprecated(): boolean {
const tsMod = ModBridge.getCachedThunderstoreModFromMod(this);
return tsMod !== undefined ? tsMod.isDeprecated() : false;
}

public getIcon(): string {
return this.icon;
}
Expand Down
13 changes: 3 additions & 10 deletions src/providers/ror2/downloading/ThunderstoreDownloaderProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,16 @@ export default abstract class ThunderstoreDownloaderProvider {
*/
public abstract buildDependencySetUsingLatest(mod: ThunderstoreVersion, allMods: ThunderstoreMod[], builder: ThunderstoreCombo[]): ThunderstoreCombo[];

/**
* Allows a list of mods passed in to be converted to the latest version of their equivalent upload.
*
* @param mods
* @param allMods
*/
public abstract getLatestOfAllToUpdate(mods: ManifestV2[], allMods: ThunderstoreMod[]): ThunderstoreCombo[];

/**
* A top-level method to download the latest version of all mods passed in, including their dependencies.
*
* @param mods An array of ManifestV2 objects to be updated.
* @param game Currently selected game
* @param modsWithUpdate An array of ThunderstoreCombo objects to be updated.
* @param allMods An array of all mods available from the Thunderstore API.
* @param callback Callback to show the current state of the downloads.
* @param completedCallback Callback to perform final actions against. Only called if {@param callback} has not returned a failed status.
*/
public abstract downloadLatestOfAll(game: Game, mods: ManifestV2[], allMods: ThunderstoreMod[],
public abstract downloadLatestOfAll(game: Game, modsWithUpdate: ThunderstoreCombo[], allMods: ThunderstoreMod[],
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
completedCallback: (modList: ThunderstoreCombo[]) => void): void;

Expand Down
17 changes: 4 additions & 13 deletions src/r2mm/data/ThunderstorePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import ThunderstoreMod from '../../model/ThunderstoreMod';
import Game from '../../model/game/Game';
import ApiResponse from '../../model/api/ApiResponse';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import ModBridge from '../mods/ModBridge';
import * as PackageDb from '../manager/PackageDexieStore';

export default class ThunderstorePackages {

public static PACKAGES: ThunderstoreMod[] = [];
public static PACKAGES_MAP: Map<String, ThunderstoreMod> = new Map();
// TODO: would IndexedDB or Vuex be more suitable place for exclusions?
public static EXCLUSIONS: string[] = [];
Expand All @@ -33,23 +31,16 @@ export default class ThunderstorePackages {

// TODO: can this be hooked into the progress bar in Splash screen?
await PackageDb.updateFromApiResponse(gameName, packages);
}

// The stuff below would become obsolete...
ThunderstorePackages.PACKAGES = response.data
.map(ThunderstoreMod.parseFromThunderstoreData)
.filter((mod) => !ThunderstorePackages.EXCLUSIONS.includes(mod.getFullName()));

ModBridge.clearCache();

ThunderstorePackages.PACKAGES_MAP = ThunderstorePackages.PACKAGES.reduce((map, pkg) => {
public static getDeprecatedPackageMap(packages: ThunderstoreMod[]): Map<string, boolean> {
ThunderstorePackages.PACKAGES_MAP = packages.reduce((map, pkg) => {
map.set(pkg.getFullName(), pkg);
return map;
}, new Map<String, ThunderstoreMod>());
}

public static getDeprecatedPackageMap(): Map<string, boolean> {
const result = new Map<string, boolean>();
this.PACKAGES.forEach(pkg => {
packages.forEach(pkg => {
this.populateDeprecatedPackageMapForModChain(pkg, result);
});
return result;
Expand Down
22 changes: 3 additions & 19 deletions src/r2mm/downloading/BetterThunderstoreDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import Profile from '../../model/Profile';
import ExportMod from '../../model/exports/ExportMod';
import ManagerSettings from '../manager/ManagerSettings';
import * as PackageDb from '../manager/PackageDexieStore';
import ManifestV2 from '../../model/ManifestV2';
import ModBridge from '../mods/ModBridge';
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import ManagerInformation from '../../_managerinf/ManagerInformation';
import Game from '../../model/game/Game';
Expand Down Expand Up @@ -92,26 +90,12 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader
})
}

public getLatestOfAllToUpdate(mods: ManifestV2[], allMods: ThunderstoreMod[]): ThunderstoreCombo[] {
return mods.filter(mod => !ModBridge.isCachedLatestVersion(mod))
.map(mod => ModBridge.getCachedThunderstoreModFromMod(mod))
.filter(value => value != undefined)
.map(mod => {
const latestVersion = mod!.getVersions().sort((a, b) => a.getVersionNumber().compareToDescending(b.getVersionNumber()))[0];
const combo = new ThunderstoreCombo();
combo.setMod(mod!);
combo.setVersion(latestVersion);
return combo;
})
}

public async downloadLatestOfAll(game: Game, mods: ManifestV2[], allMods: ThunderstoreMod[],
public async downloadLatestOfAll(game: Game, modsWithUpdates: ThunderstoreCombo[], allMods: ThunderstoreMod[],
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
completedCallback: (modList: ThunderstoreCombo[]) => void) {

const dependenciesToUpdate: ThunderstoreCombo[] = this.getLatestOfAllToUpdate(mods, allMods);
const dependencies: ThunderstoreCombo[] = [...dependenciesToUpdate];
dependenciesToUpdate.forEach(value => {
const dependencies: ThunderstoreCombo[] = [...modsWithUpdates];
modsWithUpdates.forEach(value => {
this.buildDependencySetUsingLatest(value.getVersion(), allMods, dependencies);
});

Expand Down
82 changes: 0 additions & 82 deletions src/r2mm/mods/ModBridge.ts

This file was deleted.

Loading

0 comments on commit 30d4de1

Please sign in to comment.