Skip to content

Commit

Permalink
Merge pull request #1204 from ebkr/mod-typing
Browse files Browse the repository at this point in the history
Remove any-types and Mod class
  • Loading branch information
anttimaki authored Feb 15, 2024
2 parents 9c2b206 + bbd7ea6 commit a2a11b1
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 187 deletions.
58 changes: 23 additions & 35 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ 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 Mod from '../../model/Mod';
import DependencyListDisplayType from '../../model/enums/DependencyListDisplayType';
import Dependants from '../../r2mm/mods/Dependants';
import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileInstallerProvider';
Expand Down Expand Up @@ -142,8 +141,7 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
}
}
getMissingDependencies(vueMod: any): string[] {
const mod: Mod = new Mod().fromReactive(vueMod);
getMissingDependencies(mod: ManifestV2): string[] {
return mod.getDependencies().filter((dependency: string) => {
// Include in filter if mod isn't found.
return this.$store.state.localModList.find(
Expand All @@ -152,9 +150,8 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
});
}
getDisabledDependencies(vueMod: any): ManifestV2[] {
const dependencies = new Mod()
.fromReactive(vueMod)
getDisabledDependencies(mod: ManifestV2): ManifestV2[] {
const dependencies = mod
.getDependencies()
.map((x) => x.toLowerCase().substring(0, x.lastIndexOf('-') + 1));
Expand Down Expand Up @@ -192,13 +189,11 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
return modList;
}
async disableModWithDependents(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
async disableModWithDependents(mod: ManifestV2) {
await this.disableMods([...this.getDependantList(mod), mod]);
}
async disableModExcludeDependents(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
async disableModExcludeDependents(mod: ManifestV2) {
await this.disableMods([mod]);
}
Expand Down Expand Up @@ -247,13 +242,11 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
await this.updateModListAfterChange(updatedList);
}
async uninstallModWithDependents(vueMod: any) {
let mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
async uninstallModWithDependents(mod: ManifestV2) {
await this.uninstallMods([...this.getDependantList(mod), mod]);
}
async uninstallModExcludeDependents(vueMod: any) {
let mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
async uninstallModExcludeDependents(mod: ManifestV2) {
await this.uninstallMods([mod]);
}
Expand Down Expand Up @@ -291,23 +284,21 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
await this.updateModListAfterChange(result);
}
showDependencyList(vueMod: any, displayType: string) {
this.selectedManifestMod = new ManifestV2().fromReactive(vueMod);
showDependencyList(mod: ManifestV2, displayType: string) {
this.selectedManifestMod = mod;
this.dependencyListDisplayType = displayType;
this.showingDependencyList = true;
}
uninstallModRequireConfirmation(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
uninstallModRequireConfirmation(mod: ManifestV2) {
if (this.getDependantList(mod).size === 0) {
this.performUninstallMod(mod);
} else {
this.showDependencyList(mod, DependencyListDisplayType.UNINSTALL);
}
}
disableModRequireConfirmation(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
disableModRequireConfirmation(mod: ManifestV2) {
for (const value of this.getDependantList(mod)) {
if (value.isEnabled()) {
this.showDependencyList(mod, DependencyListDisplayType.DISABLE);
Expand All @@ -317,13 +308,11 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
this.performDisable([mod]);
}
viewDependencyList(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
viewDependencyList(mod: ManifestV2) {
this.showDependencyList(mod, DependencyListDisplayType.VIEW);
}
async enableMod(vueMod: any) {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
async enableMod(mod: ManifestV2) {
try {
const result = await this.performEnable([...this.getDependencyList(mod), mod]);
if (result instanceof R2Error) {
Expand Down Expand Up @@ -359,23 +348,22 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
await this.updateModListAfterChange(updatedList);
}
updateMod(vueMod: any) {
this.selectedManifestMod = new ManifestV2().fromReactive(vueMod);
const mod = ModBridge.getCachedThunderstoreModFromMod(
this.selectedManifestMod
);
if (mod instanceof ThunderstoreMod) {
this.$store.commit("openDownloadModModal", mod);
updateMod(mod: ManifestV2) {
this.selectedManifestMod = mod;
const tsMod = ModBridge.getCachedThunderstoreModFromMod(mod);
if (tsMod instanceof ThunderstoreMod) {
this.$store.commit("openDownloadModModal", tsMod);
} else {
this.$store.commit("closeDownloadModModal");
}
}
downloadDependency(missingDependency: string) {
const mod: ThunderstoreMod | undefined = this.thunderstorePackages.find(
(tsMod: ThunderstoreMod) => missingDependency.toLowerCase().startsWith(tsMod.getFullName().toLowerCase() + "-")
const tsMod: ThunderstoreMod | undefined = this.thunderstorePackages.find(
(m: ThunderstoreMod) => missingDependency.toLowerCase().startsWith(m.getFullName().toLowerCase() + "-")
);
if (mod === undefined) {
if (tsMod === undefined) {
this.$store.commit("closeDownloadModModal");
const error = new R2Error(
`${missingDependency} could not be found`,
Expand All @@ -385,7 +373,7 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
this.$emit('error', error);
return;
}
this.$store.commit("openDownloadModModal", mod);
this.$store.commit("openDownloadModModal", tsMod);
}
async created() {
Expand Down
90 changes: 0 additions & 90 deletions src/model/Mod.ts

This file was deleted.

78 changes: 75 additions & 3 deletions src/model/ThunderstoreVersion.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Mod from './Mod';
import VersionNumber from './VersionNumber';
import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
import CdnProvider from '../providers/generic/connection/CdnProvider';

export default class ThunderstoreVersion extends Mod implements ReactiveObjectConverterInterface {
export default class ThunderstoreVersion implements ReactiveObjectConverterInterface {

private name: string = '';
private versionNumber: VersionNumber = new VersionNumber('0.0.0');
private dependencies: string[] = [];
private fullName: string = '';
private description: string = ''
private icon: string = ''
private enabled: boolean = true;
private downloads: number = 0;
private downloadUrl: string = '';

Expand All @@ -21,12 +27,78 @@ export default class ThunderstoreVersion extends Mod implements ReactiveObjectCo
}

public fromReactive(reactive: any): ThunderstoreVersion {
super.fromReactive(reactive);
this.setName(reactive.name);
this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber));
this.setDependencies(reactive.dependencies);
this.setFullName(reactive.fullName);
this.setDescription(reactive.description);
this.setIcon(reactive.icon);
this.enabled = reactive.enabled;
this.setDownloadCount(reactive.downloadCount);
this.setDownloadUrl(reactive.downloadUrl);
return this;
}

public getName(): string {
return this.name;
}

public setName(name: string) {
this.name = name;
}

public getVersionNumber(): VersionNumber {
return this.versionNumber;
}

public setVersionNumber(versionNumber: VersionNumber) {
this.versionNumber = versionNumber;
}

public getDependencies(): string[] {
return this.dependencies;
}

public setDependencies(dependencies: string[]) {
this.dependencies = dependencies;
}

public getFullName(): string {
return this.fullName;
}

public setFullName(name: string) {
this.fullName = name;
}

public getDescription(): string {
return this.description;
}

public setDescription(description: string) {
this.description = description;
}

public getIcon(): string {
return this.icon;
}

public setIcon(icon: string) {
this.icon = icon;
}

public isEnabled(): boolean {
return this.enabled;
}

public enable() {
this.enabled = true;
}

public disable() {
this.enabled = false;
}

public getDownloadCount(): number {
return this.downloads;
}
Expand Down
59 changes: 0 additions & 59 deletions src/r2mm/mods/ModFromManifest.ts

This file was deleted.

0 comments on commit a2a11b1

Please sign in to comment.