Skip to content

Commit

Permalink
Merge pull request #1266 from ebkr/ts-mods-module
Browse files Browse the repository at this point in the history
Add TsModsModule for Vuex
  • Loading branch information
anttimaki authored Apr 15, 2024
2 parents 0652d70 + 9f67eb2 commit 1941370
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/mixins/SplashMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class SplashMixin extends Vue {
if (response) {
ThunderstorePackages.handlePackageApiResponse(response);
await this.$store.dispatch('updateThunderstoreModList', ThunderstorePackages.PACKAGES);
await this.$store.dispatch('tsMods/updateMods', ThunderstorePackages.PACKAGES);
await this.moveToNextScreen();
} else {
this.heroTitle = 'Failed to get mods from Thunderstore and cache';
Expand Down
2 changes: 1 addition & 1 deletion src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class UtilityMixin extends Vue {
const response = await ThunderstorePackages.update(this.$store.state.activeGame);
await ApiCacheUtils.storeLastRequest(response.data);
await this.$store.dispatch("updateThunderstoreModList", ThunderstorePackages.PACKAGES);
await this.$store.dispatch("tsMods/updateMods", ThunderstorePackages.PACKAGES);
await this.$store.dispatch("profile/tryLoadModListFromDisk");
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/NavigationMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class NavigationMenu extends Vue {
private LaunchMode = LaunchMode;
get thunderstoreModCount() {
let mods: ThunderstoreMod[] = this.$store.state.thunderstoreModList || [];
let mods: ThunderstoreMod[] = this.$store.state.tsMods.mods;
return this.$store.state.modFilters.showDeprecatedPackages
? mods.length
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ let assignId = 0;
}
get thunderstorePackages(): ThunderstoreMod[] {
return this.$store.state.thunderstoreModList || [];
return this.$store.state.tsMods.mods;
}
@Watch('$store.state.modals.downloadModModalMod')
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/OnlineModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class OnlineModList extends Vue {
}
get deprecationMap(): Map<string, boolean> {
return this.$store.state.deprecatedMods;
return this.$store.state.tsMods.deprecated;
}
isModDeprecated(key: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/OnlineModView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class OnlineModView extends Vue {
}
get thunderstoreModList(): ThunderstoreMod[] {
return this.$store.state.thunderstoreModList;
return this.$store.state.tsMods.mods;
}
getPaginationSize() {
Expand Down Expand Up @@ -174,7 +174,7 @@ export default class OnlineModView extends Vue {
@Watch("sortingDirectionModel")
@Watch("sortingStyleModel")
@Watch("thunderstoreModList")
@Watch("tsMods.mods")
sortThunderstoreModList() {
const sortDescending = this.sortingDirectionModel == SortingDirection.STANDARD;
const sortedList = [...this.thunderstoreModList];
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
private contextProfile: Profile | null = null;
get thunderstoreModList(): ThunderstoreMod[] {
return this.$store.state.thunderstoreModList || [];
return this.$store.state.tsMods.mods;
}
get localModList(): ManifestV2[] {
Expand Down
3 changes: 3 additions & 0 deletions src/r2mm/data/ThunderstorePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default class ThunderstorePackages {
}

/**
* TODO: This doesn't really do what the dosctring below says:
* deprecated dependencies do NOT mark the dependant deprecated.
*
* "Smart" package deprecation determination by keeping track of previously determine dependencies.
* This ensures that we hit as few iterations as possible to speed up calculation time.
*
Expand Down
18 changes: 2 additions & 16 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ import ErrorModule from './modules/ErrorModule';
import ModalsModule from './modules/ModalsModule';
import ModFilterModule from './modules/ModFilterModule';
import ProfileModule from './modules/ProfileModule';
import { TsModsModule } from './modules/TsModsModule';
import { FolderMigration } from '../migrations/FolderMigration';
import Game from '../model/game/Game';
import GameManager from '../model/game/GameManager';
import R2Error from '../model/errors/R2Error';
import ThunderstoreMod from '../model/ThunderstoreMod';
import ThunderstorePackages from '../r2mm/data/ThunderstorePackages';
import ManagerSettings from '../r2mm/manager/ManagerSettings';

Vue.use(Vuex);

export interface State {
activeGame: Game;
apiConnectionError: string;
deprecatedMods: Map<string, boolean>;
dismissedUpdateAll: boolean;
isMigrationChecked: boolean;
thunderstoreModList: ThunderstoreMod[];
_settings: ManagerSettings | null;
}

Expand All @@ -35,20 +32,14 @@ type Context = ActionContext<State, State>;
export const store = {
state: {
activeGame: GameManager.defaultGame,
thunderstoreModList: [],
dismissedUpdateAll: false,
isMigrationChecked: false,
apiConnectionError: "",
deprecatedMods: new Map<string, boolean>(),

// Access through getters to ensure the settings are loaded.
_settings: null,
},
actions: {
updateThunderstoreModList({ commit }: Context, modList: ThunderstoreMod[]) {
commit('setThunderstoreModList', modList);
commit('setDeprecatedMods', modList);
},
dismissUpdateAll({commit}: Context) {
commit('dismissUpdateAll');
},
Expand Down Expand Up @@ -87,9 +78,6 @@ export const store = {
setActiveGame(state: State, game: Game) {
state.activeGame = game;
},
setThunderstoreModList(state: State, list: ThunderstoreMod[]) {
state.thunderstoreModList = list;
},
dismissUpdateAll(state: State) {
state.dismissedUpdateAll = true;
},
Expand All @@ -99,9 +87,6 @@ export const store = {
setApiConnectionError(state: State, err: string) {
state.apiConnectionError = err;
},
setDeprecatedMods(state: State) {
state.deprecatedMods = ThunderstorePackages.getDeprecatedPackageMap();
},
setSettings(state: State, settings: ManagerSettings) {
state._settings = settings;
}
Expand Down Expand Up @@ -130,6 +115,7 @@ export const store = {
modals: ModalsModule,
modFilters: ModFilterModule,
profile: ProfileModule,
tsMods: TsModsModule,
},

// enable strict mode (adds overhead!)
Expand Down
16 changes: 2 additions & 14 deletions src/store/modules/ModFilterModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,8 @@ export default {
}),

getters: <GetterTree<State, RootState>>{
allCategories (_state, _getters, rootState) {
const categories = Array.from(
new Set(
rootState.thunderstoreModList
.map((mod) => mod.getCategories())
.flat()
)
);
categories.sort();
return categories;
},

unselectedCategories (state, getters) {
const categories: string[] = getters.allCategories;
unselectedCategories (state, _getters, _rootState, rootGetters) {
const categories: string[] = rootGetters['tsMods/categories'];
return categories.filter((c: string) => !state.selectedCategories.includes(c));
}
},
Expand Down
8 changes: 2 additions & 6 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { SortLocalDisabledMods } from '../../model/real_enums/sort/SortLocalDisa
import { SortNaming } from '../../model/real_enums/sort/SortNaming';
import ThunderstoreCombo from '../../model/ThunderstoreCombo';
import ConflictManagementProvider from '../../providers/generic/installing/ConflictManagementProvider';
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileInstallerProvider';
import ManagerSettings from '../../r2mm/manager/ManagerSettings';
import ModListSort from '../../r2mm/mods/ModListSort';
Expand Down Expand Up @@ -77,11 +76,8 @@ export default {
return getters.activeProfile.getProfileName();
},

modsWithUpdates(state, _getters, rootState): ThunderstoreCombo[] {
return ThunderstoreDownloaderProvider.instance.getLatestOfAllToUpdate(
state.modList,
rootState.thunderstoreModList
);
modsWithUpdates(state, _getters, _rootState, rootGetters): ThunderstoreCombo[] {
return rootGetters['tsMods/modsWithUpdates'](state.modList);
},

visibleModList(state, _getters, rootState): ManifestV2[] {
Expand Down
66 changes: 66 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ActionTree, GetterTree, MutationTree } from 'vuex';

import { State as RootState } from '../index';
import ManifestV2 from '../../model/ManifestV2';
import ThunderstoreMod from '../../model/ThunderstoreMod';
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import ThunderstorePackages from '../../r2mm/data/ThunderstorePackages';


interface State {
deprecated: Map<string, boolean>;
mods: ThunderstoreMod[];
}

/**
* For dealing with mods listed in communities, i.e. available through
* the Thunderstore API. Mods received from the API are stored in
* IndexedDB (via Dexie). For performance they're also stored in memory
* by this Vuex store module.
*/
export const TsModsModule = {
namespaced: true,

state: (): State => ({
deprecated: new Map<string, boolean>(),
/*** All mods available through API for the current active game */
mods: [],
}),

getters: <GetterTree<State, RootState>>{
/*** Categories used by any mod listed in the community */
categories(state) {
const categories = Array.from(
new Set(
state.mods.map((mod) => mod.getCategories()).flat()
)
);
categories.sort();
return categories;
},

/*** Which locally installed mods have updates in Thunderstore? */
modsWithUpdates: (state) => (profileMods: ManifestV2[]) => {
return ThunderstoreDownloaderProvider.instance.getLatestOfAllToUpdate(
profileMods,
state.mods
);
}
},

mutations: <MutationTree<State>>{
setMods(state, payload: ThunderstoreMod[]) {
state.mods = payload;
},
updateDeprecated(state) {
state.deprecated = ThunderstorePackages.getDeprecatedPackageMap();
}
},

actions: <ActionTree<State, RootState>>{
updateMods({commit}, modList: ThunderstoreMod[]) {
commit('setMods', modList);
commit('updateDeprecated');
}
}
}

0 comments on commit 1941370

Please sign in to comment.