feat: add some funcs
This commit is contained in:
+15
-3
@@ -7,6 +7,8 @@ import { syncModpack } from './modpack'
|
||||
import { launchGame } from './launch'
|
||||
import { getSettings } from './settings'
|
||||
import { emit } from './events'
|
||||
import * as logger from './logger'
|
||||
import type { PlayOptions } from '../shared/ipc'
|
||||
|
||||
/** Process de jeu courant (un seul à la fois). */
|
||||
let gameProcess: ChildProcess | null = null
|
||||
@@ -20,7 +22,7 @@ let gameProcess: ChildProcess | null = null
|
||||
* idempotentes, donc à partir du 2e lancement seules les nouveautés du modpack
|
||||
* sont téléchargées.
|
||||
*/
|
||||
export async function play(): Promise<void> {
|
||||
export async function play(opts?: PlayOptions): Promise<void> {
|
||||
if (gameProcess) {
|
||||
throw new Error('Le jeu est déjà en cours.')
|
||||
}
|
||||
@@ -30,11 +32,14 @@ export async function play(): Promise<void> {
|
||||
throw new Error('Non connecté. Connecte-toi avec ton compte Microsoft d’abord.')
|
||||
}
|
||||
|
||||
const repair = opts?.repair ?? false
|
||||
logger.startSession()
|
||||
|
||||
try {
|
||||
const meta = await fetchPackMeta()
|
||||
const javaPath = await ensureJava()
|
||||
await installMinecraft(meta.minecraft)
|
||||
const versionId = await installNeoForge(meta.neoforge, meta.minecraft, javaPath)
|
||||
await installMinecraft(meta.minecraft, repair)
|
||||
const versionId = await installNeoForge(meta.neoforge, meta.minecraft, javaPath, repair)
|
||||
await syncModpack(javaPath)
|
||||
|
||||
const settings = await getSettings()
|
||||
@@ -48,3 +53,10 @@ export async function play(): Promise<void> {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/** Tue le process de jeu courant. Renvoie true si un process tournait. */
|
||||
export function stopGame(): boolean {
|
||||
if (!gameProcess) return false
|
||||
gameProcess.kill()
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user