Skip to content

Commit

Permalink
Continue refactoring mod downloading, added a few todo comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VilppeRiskidev committed Nov 27, 2024
1 parent 92d1e8b commit 0c52511
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
22 changes: 10 additions & 12 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<div>
<div id='downloadProgressModal' :class="['modal', {'is-active':activeDownloadModName}]" v-if="activeDownloadModName">
<div id='downloadProgressModal' :class="['modal', {'is-active':activeDownload}]" v-if="activeDownload">
<div class="modal-background" @click="closeModal();"></div>
<div class='modal-content'>
<div class='notification is-info'>
<h3 class='title'>Downloading {{activeDownloadModName}}</h3>
<p>{{Math.floor(activeDownloadProgress)}}% complete</p>
<h3 class='title'>Downloading {{activeDownload.modName}}</h3>
<p>{{Math.floor(activeDownload.downloadProgress)}}% complete</p>
<Progress
:max='100'
:value='activeDownloadProgress'
:value='activeDownload.downloadProgress'
:className="['is-dark']"
/>
</div>
Expand Down Expand Up @@ -137,12 +137,8 @@ let assignId = 0;
static allVersions: [number, DownloadProgress][] = [];
get activeDownloadProgress(): number {
return this.$store.getters['modDownload/activeDownloadProgress'];
}
get activeDownloadModName() {
return this.$store.getters['modDownload/activeDownloadModName'];
get activeDownload() {
return this.$store.getters['modDownload/activeDownload'];
}
get activeGame(): Game {
Expand Down Expand Up @@ -268,7 +264,6 @@ let assignId = 0;
closeModal() {
this.$store.commit("closeDownloadModModal");
this.$store.commit("modDownload/reset");
}
async downloadThunderstoreMod() {
Expand Down Expand Up @@ -340,10 +335,13 @@ let assignId = 0;
this.closeModal();
this.downloadingMod = true;
let tsCombo: ThunderstoreCombo = new ThunderstoreCombo();
let tsCombo = new ThunderstoreCombo();
tsCombo.setMod(tsMod);
tsCombo.setVersion(tsVersion);
//TODO: Remove the completedCallback and await instead
//TODO: Once the above is done, close the modal when the downloading and installation are completed.
await this.$store.dispatch(
'modDownload/downloadAndInstallMod',
{ profile: this.profile.asImmutableProfile(), mod: tsCombo }
Expand Down
46 changes: 13 additions & 33 deletions src/store/modules/ModDownloadModule.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {ActionTree, GetterTree} from 'vuex';

import StatusEnum from '../../model/enums/StatusEnum';
import {ImmutableProfile} from '../../model/Profile';
import ThunderstoreCombo from '../../model/ThunderstoreCombo';
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import {State as RootState} from '../index';
import R2Error from "../../model/errors/R2Error";

// TODO: Replace the "enum" in '../../model/enums/StatusEnum' with a proper enum like this one.
enum StatusEnum {
FAILURE = 0,
PENDING = 1,
SUCCESS = 2,
}

interface ProgressItem {
modName: string;
installProgress: number;
Expand All @@ -17,7 +23,6 @@ interface ProgressItem {

interface State {
downloads: ProgressItem[];
dependencyDownloads: ProgressItem[];
}

/**
Expand All @@ -28,36 +33,16 @@ export default {

state: (): State => ({
downloads: [],
dependencyDownloads: [],
}),

getters: <GetterTree<State, RootState>>{
allDownloads(state): ProgressItem[] {
return state.downloads;
},
activeDownload(state): ProgressItem {
activeDownload(state): ProgressItem | undefined {
return state.downloads.slice(-1)[0]; // Last element of the array
},
activeDownloadProgress(state): number | undefined {
if (state.downloads.length > 0) {
return state.downloads.slice(-1)[0].downloadProgress; // Last element of the array
}
},
activeDownloadModName(state): string | undefined {
if (state.downloads.length > 0) {
return state.downloads.slice(-1)[0].modName; // Last element of the array
}
},
activeDownloadProgressItem(state): ProgressItem | undefined {
if (state.downloads.length > 0) {
return state.downloads.slice(-1)[0]; // Last element of the array
}
},
},
mutations: {
reset(state: State) {
state.downloads = [];
state.dependencyDownloads = [];
},
addDownload(state: State, modName: string) {
state.downloads.push({
Expand All @@ -71,21 +56,16 @@ export default {
updateDownloadProgress(state: State, params: { progress: number, modName: string, status: number, err: R2Error | null }) {
let downloadMod = state.downloads.find((progressItem) => progressItem.modName === params.modName);

if (!downloadMod) {
state.dependencyDownloads.push({
modName: params.modName,
installProgress: 0,
downloadProgress: 0,
status: StatusEnum.PENDING,
error: null
});
downloadMod = state.dependencyDownloads.find((progressItem) => progressItem.modName === params.modName);
}
// Doesn't do anything when the downloaded mod is not found in the array (which means it is a dependency).
// TODO: figure out if/how/where to track/display these dependencies' progresses.
// Might be affected by removing the completedCallback as one way to do it is to have it return
// a list of all of the downloaded mods (including the dependencies).

if (downloadMod) {
downloadMod.downloadProgress = params.progress;
downloadMod.status = params.status;
if (params.status === StatusEnum.FAILURE && params.err) {
// TODO: do something with these failed downloads, i.e. display the error(s) to the user.
downloadMod.error = params.err;
}
}
Expand Down

0 comments on commit 0c52511

Please sign in to comment.