diff --git a/src/api/comms.ts b/src/api/comms.ts index b0a52d51..3d7a0644 100644 --- a/src/api/comms.ts +++ b/src/api/comms.ts @@ -3,7 +3,7 @@ import { arrayToMap, assign } from "jaz-ts-utils"; import { battleSchema, myUserSchema, TachyonClient } from "tachyon-client"; import { reactive } from "vue"; -import { SpadsBattle } from "@/model/battle/tachyon-spads-battle"; +import { SpadsBattle } from "@/model/battle/spads-battle"; import { tachyonLog } from "@/utils/tachyon-log"; export class CommsAPI extends TachyonClient { constructor(config: ConstructorParameters[0]) { diff --git a/src/api/content/game-content.ts b/src/api/content/game-content.ts index a24481fb..546dd6d6 100644 --- a/src/api/content/game-content.ts +++ b/src/api/content/game-content.ts @@ -1,5 +1,5 @@ import axios from "axios"; -import { spawn } from "child_process"; +import { ChildProcess, spawn } from "child_process"; import * as fs from "fs"; import * as glob from "glob-promise"; import { BufferStream, lastInArray, removeFromArray } from "jaz-ts-utils"; @@ -36,6 +36,7 @@ export class GameContentAPI extends AbstractContentAPI { /** Latest version is last item */ public installedVersions: string[] = reactive([]); + protected prdProcess: ChildProcess | null = null; protected prBinaryPath!: string; protected ocotokit = new Octokit(); protected md5ToRapidVersionMap: Record = {}; @@ -56,14 +57,19 @@ export class GameContentAPI extends AbstractContentAPI { */ public async downloadGame(gameVersion = `${contentSources.rapid.game}:test`) { return new Promise((resolve) => { - const prDownloaderProcess = spawn(`${this.prBinaryPath}`, ["--filesystem-writepath", api.info.contentPath, "--download-game", gameVersion]); + if (this.prdProcess) { + console.warn("Could not spawn new prd instance until existing instance has finished"); + return; + } + + this.prdProcess = spawn(`${this.prBinaryPath}`, ["--filesystem-writepath", api.info.contentPath, "--download-game", gameVersion]); - console.debug(prDownloaderProcess.spawnargs); + console.debug(this.prdProcess.spawnargs); let downloadType: DownloadType = DownloadType.Metadata; let downloadInfo: DownloadInfo | undefined; - prDownloaderProcess.stdout.on("data", (stdout: Buffer) => { + this.prdProcess.stdout?.on("data", (stdout: Buffer) => { const lines = stdout.toString().trim().split(os.EOL).filter(Boolean); console.debug(lines.join("\n")); const messages = lines.map((line) => this.processPrDownloaderLine(line)).filter(Boolean) as Message[]; @@ -87,11 +93,11 @@ export class GameContentAPI extends AbstractContentAPI { } }); - prDownloaderProcess.stderr.on("data", (data: Buffer) => { + this.prdProcess.stderr?.on("data", (data: Buffer) => { console.error(data.toString()); }); - prDownloaderProcess.on("exit", async () => { + this.prdProcess.on("exit", async () => { if (downloadInfo) { if (!this.installedVersions.includes(downloadInfo.name)) { this.installedVersions.push(downloadInfo.name); @@ -100,6 +106,9 @@ export class GameContentAPI extends AbstractContentAPI { removeFromArray(this.currentDownloads, downloadInfo); this.onDownloadComplete.dispatch(downloadInfo); } + + this.prdProcess = null; + resolve(); }); }); diff --git a/src/api/content/map-content.ts b/src/api/content/map-content.ts index 7c96d504..57c2c45d 100644 --- a/src/api/content/map-content.ts +++ b/src/api/content/map-content.ts @@ -83,6 +83,8 @@ export class MapContentAPI extends AbstractContentAPI { // currently reliant on springfiles for scriptname lookup public async installMapByScriptName(scriptName: string, host = contentSources.maps.http[0]!) { if (this.getMapByScriptName(scriptName)) { + console.debug(`${scriptName} already installed`); + // TODO: validate if map is cached return; } @@ -106,6 +108,7 @@ export class MapContentAPI extends AbstractContentAPI { } public async installMapByFilename(filename: string, scriptName: string, host = contentSources.maps.http[0]!): Promise { + // TODO: tidy up this logic to avoid downloading/caching the same maps multiple times, or incorrectly assuming maps are downloaded/cached when they're not if (this.getMapByFileName(filename)) { return; } diff --git a/src/api/session.ts b/src/api/session.ts index a33031fa..1dfead57 100644 --- a/src/api/session.ts +++ b/src/api/session.ts @@ -5,7 +5,7 @@ import { reactive, Ref, ref, shallowReactive, shallowRef, toRaw } from "vue"; import { BattleChatMessage } from "@/model/battle/battle-chat"; import { OfflineBattle } from "@/model/battle/offline-battle"; -import { SpadsBattle } from "@/model/battle/tachyon-spads-battle"; +import { SpadsBattle } from "@/model/battle/spads-battle"; import { CurrentUser, User } from "@/model/user"; export class SessionAPI { diff --git a/src/model/battle/tachyon-spads-battle.ts b/src/model/battle/spads-battle.ts similarity index 100% rename from src/model/battle/tachyon-spads-battle.ts rename to src/model/battle/spads-battle.ts diff --git a/src/utils/start-script-converter.ts b/src/utils/start-script-converter.ts index 584e05ff..7362be4b 100644 --- a/src/utils/start-script-converter.ts +++ b/src/utils/start-script-converter.ts @@ -3,7 +3,7 @@ import { assign } from "jaz-ts-utils"; import { AbstractBattle } from "@/model/battle/abstract-battle"; import { OfflineBattle } from "@/model/battle/offline-battle"; -import { SpadsBattle } from "@/model/battle/tachyon-spads-battle"; +import { SpadsBattle } from "@/model/battle/spads-battle"; import { StartPosType } from "@/model/battle/types"; import type { StartScriptTypes } from "@/model/start-script"; diff --git a/src/views/multiplayer/custom.vue b/src/views/multiplayer/custom.vue index eab23990..7bb576ee 100644 --- a/src/views/multiplayer/custom.vue +++ b/src/views/multiplayer/custom.vue @@ -37,7 +37,7 @@ import BattlePreview from "@/components/battle/BattlePreview.vue"; import HostBattle from "@/components/battle/HostBattle.vue"; import Button from "@/components/inputs/Button.vue"; import Checkbox from "@/components/inputs/Checkbox.vue"; -import { SpadsBattle } from "@/model/battle/tachyon-spads-battle"; +import { SpadsBattle } from "@/model/battle/spads-battle"; const hostBattleOpen = ref(false); const hidePvE = ref(false);