diff --git a/src/components/App.tsx b/src/components/App.tsx index 36628ec..57d53f4 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -16,7 +16,7 @@ import { Launcher } from './Launcher' import { PieRayHelper } from './PieRayHelper' function App() { - const [selectedTab, setSelectedTab] = React.useState(1) + const [selectedTab, setSelectedTab] = React.useState(2) return ( (x: X | undefined | null, name?: string): X { if (!x) throw new Error(`missing ${name}`) @@ -127,8 +133,9 @@ export function NewGameInstall(props: { ) const updateNewInstallVersionManifest = (version: string) => { - const newVersionManifest = versionManifests.data?.versions?.find( - (x) => x.id === version + const newVersionManifest = findVersionManifest( + versionManifests.data, + version ) if (!newVersionManifest) return setNewInstall((prev) => ({ @@ -148,7 +155,15 @@ export function NewGameInstall(props: { useEffect(() => { if (!newInstall.versionManifest?.id && versionManifests.isSuccess) { - updateNewInstallVersionManifest(versionManifests.data.latest.release) + const defaultVersionManifest = findVersionManifest( + versionManifests.data, + defaultVersion + ) + updateNewInstallVersionManifest( + defaultVersionManifest + ? defaultVersion + : versionManifests.data.latest.release + ) } }, [ newInstall.versionManifest?.id, @@ -221,6 +236,30 @@ export function NewGameInstall(props: { ))} + {newInstall.fabricLoaderVersion && ( + + {Object.entries( + mods[`${newInstall?.versionManifest?.id}-fabric`] || {} + ).map(([name, url]) => ( + + + setNewInstall((prev) => + toggleGameInstallModeUrl( + prev, + url, + !!e.target.checked + ) + ) + } + > + {name} + + + ))} + + )} )} diff --git a/src/constants.ts b/src/constants.ts index d03fe84..155f6d9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -119,6 +119,7 @@ export const gameInstall = z.object({ uuid: z.string(), versionManifest: mojangVersionManifest, fabricLoaderVersion: z.optional(z.string()), + mods: z.optional(z.array(z.string())), }) export type MojangLibrary = z.infer @@ -161,6 +162,11 @@ export const CHANNELS = { export const LAUNCH_CHANNEL = (uuid: string) => `launch-game-install-${uuid}` +export const findVersionManifest = ( + versionManifests: MojangVersionManifests | undefined, + version: string +) => versionManifests?.versions?.find((x) => x.id === version) + export const getGameInstalModLoaderName = ( gameInstall: Partial ): ModLoaderName => { @@ -180,6 +186,19 @@ export const setGameInstallModLoaderName = ( } } +export const toggleGameInstallModeUrl = ( + gameInstall: Partial, + url: string, + includeUrl?: boolean +): Partial => ({ + ...gameInstall, + mods: ( + includeUrl !== undefined ? includeUrl : gameInstall.mods?.includes(url) + ) + ? [...(gameInstall.mods ?? []), url] + : (gameInstall.mods ?? []).filter((x) => x !== url), +}) + export const parseLibraryName = (libraryName: string) => { const [jarOrg, jarName, jarVersion] = libraryName.split(':') return { diff --git a/src/store.ts b/src/store.ts index 27c82d1..9edd76a 100644 --- a/src/store.ts +++ b/src/store.ts @@ -11,7 +11,18 @@ export const schema: Schema = { name: { type: 'string' }, path: { type: 'string' }, uuid: { type: 'string' }, - version: { type: 'string' }, + versionManifest: { + type: 'object', + properties: { + id: { type: 'string' }, + type: { type: 'string' }, + url: { type: 'string' }, + time: { type: 'string' }, + releaseTime: { type: 'string' }, + }, + }, + fabricLoaderVersion: { type: 'string', default: '' }, + mods: { type: 'array', items: { type: 'string' }, default: [] }, }, }, default: [], diff --git a/src/utils/launcher.ts b/src/utils/launcher.ts index f02df75..5a14f01 100644 --- a/src/utils/launcher.ts +++ b/src/utils/launcher.ts @@ -145,6 +145,17 @@ export async function updateInstall(install: GameInstall) { versionDetails.mainClass = fabricDetails.mainClass } + const modsPath = path.join(install.path, 'mods') + for (const mod of install.mods ?? []) { + const url = new URL(mod) + downloadLibraries.push(() => + downloadIfMissing( + mod, + path.join(modsPath, path.basename(url.pathname)) + ) + ) + } + await pSettle(downloadLibraries, { concurrency: 8 }) return versionDetails } diff --git a/src/utils/mods.ts b/src/utils/mods.ts new file mode 100644 index 0000000..b460a96 --- /dev/null +++ b/src/utils/mods.ts @@ -0,0 +1,14 @@ +export const mods: Record> = { + '1.20.6-fabric': { + baritone: + 'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/baritone/baritone-1.20.6-SNAPSHOT.jar?raw=true', + litematica: + 'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/litematica/litematica-fabric-1.20.6-0.18.0.jar?raw=true', + malilib: + 'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/malilib/malilib-fabric-1.20.6-0.19.0.jar?raw=true', + 'meteor-client': + 'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/meteor-client/meteor-client-0.5.7.jar?raw=true', + replaymod: + 'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/replaymod/replaymod-1.20.6-2.6.20.jar?raw=true', + }, +}