first commit

This commit is contained in:
lucasdpt
2026-06-14 12:32:29 +02:00
commit cc4f90e840
32 changed files with 9729 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import type { ChildProcess } from 'child_process'
import { getCurrent } from './auth'
import { fetchPackMeta } from './modpack'
import { ensureJava } from './java'
import { installMinecraft, installNeoForge } from './install'
import { syncModpack } from './modpack'
import { launchGame } from './launch'
import { getSettings } from './settings'
import { emit } from './events'
/** Process de jeu courant (un seul à la fois). */
let gameProcess: ChildProcess | null = null
/**
* Séquence complète "Jouer" :
* auth (déjà fait) -> pack.toml -> Java 21 -> Minecraft -> NeoForge ->
* sync modpack (delta) -> lancement.
*
* Chaque étape émet sa progression vers le renderer. Les étapes d'install sont
* idempotentes, donc à partir du 2e lancement seules les nouveautés du modpack
* sont téléchargées.
*/
export async function play(): Promise<void> {
if (gameProcess) {
throw new Error('Le jeu est déjà en cours.')
}
const auth = getCurrent()
if (!auth) {
throw new Error('Non connecté. Connecte-toi avec ton compte Microsoft dabord.')
}
try {
const meta = await fetchPackMeta()
const javaPath = await ensureJava()
await installMinecraft(meta.minecraft)
const versionId = await installNeoForge(meta.neoforge, meta.minecraft, javaPath)
await syncModpack(javaPath)
const settings = await getSettings()
const proc = await launchGame(versionId, auth, javaPath, settings)
gameProcess = proc
proc.on('close', () => {
gameProcess = null
})
} catch (e) {
emit.progress({ phase: 'error', message: (e as Error).message, progress: undefined })
throw e
}
}