You've already forked AstralRinth
forked from didirus/AstralRinth
Fix and unify version selection when installing mods and filtering (#4252)
* Fix and unify version selection when installing mods * Update version list filters to match install version selection logic * Fix lint issues --------- Co-authored-by: Cal H. <contact@cal.engineer>
This commit is contained in:
committed by
GitHub
parent
0925abfd1c
commit
a2c07c92f8
@@ -22,7 +22,11 @@ import {
|
|||||||
get,
|
get,
|
||||||
list,
|
list,
|
||||||
} from '@/helpers/profile'
|
} from '@/helpers/profile'
|
||||||
import { installVersionDependencies } from '@/store/install.js'
|
import {
|
||||||
|
findPreferredVersion,
|
||||||
|
installVersionDependencies,
|
||||||
|
isVersionCompatible,
|
||||||
|
} from '@/store/install.js'
|
||||||
|
|
||||||
const { handleError } = injectNotificationManager()
|
const { handleError } = injectNotificationManager()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -49,14 +53,11 @@ const shownProfiles = computed(() =>
|
|||||||
return profile.name.toLowerCase().includes(searchFilter.value.toLowerCase())
|
return profile.name.toLowerCase().includes(searchFilter.value.toLowerCase())
|
||||||
})
|
})
|
||||||
.filter((profile) => {
|
.filter((profile) => {
|
||||||
const loaders = versions.value.flatMap((v) => v.loaders)
|
const version = {
|
||||||
|
game_versions: versions.value.flatMap((v) => v.game_versions),
|
||||||
return (
|
loaders: versions.value.flatMap((v) => v.loaders),
|
||||||
versions.value.flatMap((v) => v.game_versions).includes(profile.game_version) &&
|
}
|
||||||
(project.value.project_type === 'mod'
|
return isVersionCompatible(version, project.value, profile)
|
||||||
? loaders.includes(profile.loader) || loaders.includes('minecraft')
|
|
||||||
: true)
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -94,14 +95,7 @@ defineExpose({
|
|||||||
|
|
||||||
async function install(instance) {
|
async function install(instance) {
|
||||||
instance.installing = true
|
instance.installing = true
|
||||||
const version = versions.value.find((v) => {
|
const version = findPreferredVersion(versions.value, project.value, instance)
|
||||||
return (
|
|
||||||
v.game_versions.includes(instance.game_version) &&
|
|
||||||
(project.value.project_type === 'mod'
|
|
||||||
? v.loaders.includes(instance.loader) || v.loaders.includes('minecraft')
|
|
||||||
: true)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
instance.installing = false
|
instance.installing = false
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
label: 'Versions',
|
label: 'Versions',
|
||||||
href: {
|
href: {
|
||||||
path: `/project/${$route.params.id}/versions`,
|
path: `/project/${$route.params.id}/versions`,
|
||||||
query: { l: instance?.loader, g: instance?.game_version },
|
query: instanceFilters,
|
||||||
},
|
},
|
||||||
subpages: ['version'],
|
subpages: ['version'],
|
||||||
},
|
},
|
||||||
@@ -154,7 +154,7 @@ import {
|
|||||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||||
import { ref, shallowRef, watch } from 'vue'
|
import { computed, ref, shallowRef, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||||
@@ -186,6 +186,24 @@ const instanceProjects = ref(null)
|
|||||||
const installed = ref(false)
|
const installed = ref(false)
|
||||||
const installedVersion = ref(null)
|
const installedVersion = ref(null)
|
||||||
|
|
||||||
|
const instanceFilters = computed(() => {
|
||||||
|
if (!instance.value) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loaders = []
|
||||||
|
if (data.value.project_type === 'mod') {
|
||||||
|
if (instance.value.loader !== 'vanilla') {
|
||||||
|
loaders.push(instance.value.loader)
|
||||||
|
}
|
||||||
|
if (instance.value.loader === 'vanilla' || data.value.loaders.includes('datapack')) {
|
||||||
|
loaders.push('datapack')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { l: loaders, g: instance.value.game_version }
|
||||||
|
})
|
||||||
|
|
||||||
const [allLoaders, allGameVersions] = await Promise.all([
|
const [allLoaders, allGameVersions] = await Promise.all([
|
||||||
get_loaders().catch(handleError).then(ref),
|
get_loaders().catch(handleError).then(ref),
|
||||||
get_game_versions().catch(handleError).then(ref),
|
get_game_versions().catch(handleError).then(ref),
|
||||||
|
|||||||
@@ -41,6 +41,31 @@ export const useInstall = defineStore('installStore', {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const findPreferredVersion = (versions, project, instance) => {
|
||||||
|
// If we can find a version using strictly the instance loader then prefer that
|
||||||
|
let version = versions.find(
|
||||||
|
(v) =>
|
||||||
|
v.game_versions.includes(instance.game_version) &&
|
||||||
|
(project.project_type === 'mod' ? v.loaders.includes(instance.loader) : true),
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!version) {
|
||||||
|
// Otherwise use first compatible version (in addition to versions with the instance loader this includes datapacks)
|
||||||
|
version = versions.find((v) => isVersionCompatible(v, project, instance))
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isVersionCompatible = (version, project, instance) => {
|
||||||
|
return (
|
||||||
|
version.game_versions.includes(instance.game_version) &&
|
||||||
|
(project.project_type === 'mod'
|
||||||
|
? version.loaders.includes(instance.loader) || version.loaders.includes('datapack')
|
||||||
|
: true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const install = async (
|
export const install = async (
|
||||||
projectId,
|
projectId,
|
||||||
versionId,
|
versionId,
|
||||||
@@ -90,27 +115,16 @@ export const install = async (
|
|||||||
|
|
||||||
let version
|
let version
|
||||||
if (versionId) {
|
if (versionId) {
|
||||||
version = projectVersions.find((x) => x.id === versionId)
|
version = projectVersions.find((v) => v.id === versionId)
|
||||||
} else {
|
} else {
|
||||||
version = projectVersions.find(
|
version = findPreferredVersion(projectVersions, project, instance)
|
||||||
(v) =>
|
|
||||||
v.game_versions.includes(instance.game_version) &&
|
|
||||||
(project.project_type === 'mod'
|
|
||||||
? v.loaders.includes(instance.loader) || v.loaders.includes('minecraft')
|
|
||||||
: true),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
version = projectVersions[0]
|
version = projectVersions[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (isVersionCompatible(version, project, instance, true)) {
|
||||||
version.game_versions.includes(instance.game_version) &&
|
|
||||||
(project.project_type === 'mod'
|
|
||||||
? version.loaders.includes(instance.loader) || version.loaders.includes('minecraft')
|
|
||||||
: true)
|
|
||||||
) {
|
|
||||||
for (const [path, file] of Object.entries(instanceProjects)) {
|
for (const [path, file] of Object.entries(instanceProjects)) {
|
||||||
if (file.metadata && file.metadata.project_id === project.id) {
|
if (file.metadata && file.metadata.project_id === project.id) {
|
||||||
await remove_project(instance.path, path)
|
await remove_project(instance.path, path)
|
||||||
@@ -142,10 +156,14 @@ export const install = async (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const versions = (await get_version_many(project.versions)).sort(
|
let versions = (await get_version_many(project.versions)).sort(
|
||||||
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (versionId) {
|
||||||
|
versions = versions.filter((v) => v.id === versionId)
|
||||||
|
}
|
||||||
|
|
||||||
const install = useInstall()
|
const install = useInstall()
|
||||||
install.showModInstallModal(project, versions, callback)
|
install.showModInstallModal(project, versions, callback)
|
||||||
}
|
}
|
||||||
@@ -162,7 +180,7 @@ export const install = async (
|
|||||||
// - If no version is selected, we look check the instance for versions to select based on the versions
|
// - If no version is selected, we look check the instance for versions to select based on the versions
|
||||||
// - If there are no versions, we show the incompat modal
|
// - If there are no versions, we show the incompat modal
|
||||||
// - If a version is selected, and the version is incompatible, we show the incompat modal
|
// - If a version is selected, and the version is incompatible, we show the incompat modal
|
||||||
// - Version is inarlled, as well as version dependencies
|
// - Version is installed, as well as version dependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
export const installVersionDependencies = async (profile, version) => {
|
export const installVersionDependencies = async (profile, version) => {
|
||||||
@@ -182,9 +200,7 @@ export const installVersionDependencies = async (profile, version) => {
|
|||||||
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
||||||
)
|
)
|
||||||
|
|
||||||
const latest = depVersions.find(
|
const latest = findPreferredVersion(depVersions, dep, profile)
|
||||||
(v) => v.game_versions.includes(profile.game_version) && v.loaders.includes(profile.loader),
|
|
||||||
)
|
|
||||||
if (latest) {
|
if (latest) {
|
||||||
await add_project_from_version(profile.path, latest.id)
|
await add_project_from_version(profile.path, latest.id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user