Skip to content

Commit

Permalink
add custom game version to dropdown, add custom script launch debug p…
Browse files Browse the repository at this point in the history
…age, prevent redownloading installed game versions, fixed bug with trying dl engine via prd
  • Loading branch information
Jazcash committed Mar 6, 2023
1 parent 6b5bc3e commit 49b4aa9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/renderer/api/content/ai-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class AiContentAPI extends AbstractContentAPI {

const aiInfoFile = await fs.promises.readFile(aiInfoPath);
const aiInfoFields = parseLuaTable(aiInfoFile);
console.log(aiInfoFields);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const aiInfo: Record<string, any> = {};
for (const field of aiInfoFields) {
Expand Down
19 changes: 19 additions & 0 deletions src/renderer/api/content/game-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export class GameContentAPI extends PrDownloaderAPI {
* @param gameVersion e.g. "Beyond All Reason test-16289-b154c3d"
*/
public async downloadGame(gameVersion = `${contentSources.rapid.game}:test`) {
// skip download if already installed
if (this.installedVersions.has(gameVersion)) {
return;
}

return this.downloadContent("game", gameVersion);
}

Expand Down Expand Up @@ -92,6 +97,20 @@ export class GameContentAPI extends PrDownloaderAPI {

this.sortVersions();
}

const gamesDir = path.join(api.info.contentPath, "games");
if (fs.existsSync(gamesDir)) {
const dirs = await fs.promises.readdir(gamesDir);
for (const dir of dirs) {
try {
const modInfoLua = await fs.promises.readFile(path.join(gamesDir, dir, "modinfo.lua"));
const modInfo = parseLuaTable(modInfoLua);
this.installedVersions.add(`${modInfo.game} ${modInfo.version}`);
} catch (err) {
console.error(err);
}
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class GameAPI {

if (arg instanceof AbstractBattle) {
engineVersion = arg.battleOptions.engineVersion;
gameVersion = arg.battleOptions.engineVersion;
gameVersion = arg.battleOptions.gameVersion;
mapName = arg.battleOptions.map;
script = this.scriptConverter.generateScriptStr(arg);
} else if (typeof arg === "string") {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/controls/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</template>

<script lang="ts" setup>
// https://primevue.org/textarea
import Textarea from "primevue/textarea";
import Control from "@/components/controls/Control.vue";
Expand Down
1 change: 1 addition & 0 deletions src/renderer/typed-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare module 'vue-router/auto/routes' {
'/debug/b': RouteRecordInfo<'/debug/b', '/debug/b', Record<never, never>, Record<never, never>>,
'/debug/controls': RouteRecordInfo<'/debug/controls', '/debug/controls', Record<never, never>, Record<never, never>>,
'/debug/playground': RouteRecordInfo<'/debug/playground', '/debug/playground', Record<never, never>, Record<never, never>>,
'/debug/script-launcher': RouteRecordInfo<'/debug/script-launcher', '/debug/script-launcher', Record<never, never>, Record<never, never>>,
'/debug/test': RouteRecordInfo<'/debug/test', '/debug/test', Record<never, never>, Record<never, never>>,
'/development/': RouteRecordInfo<'/development/', '/development', Record<never, never>, Record<never, never>>,
'/development/game-dev': RouteRecordInfo<'/development/game-dev', '/development/game-dev', Record<never, never>, Record<never, never>>,
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/utils/parse-lua-table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { LocalStatement, TableConstructorExpression } from "luaparse";
import type { LocalStatement, ReturnStatement, TableConstructorExpression } from "luaparse";
import luaparse from "luaparse";

type ParseLuaTableOptions = {
Expand All @@ -21,7 +21,12 @@ export function parseLuaTable(luaFile: Buffer, options?: ParseLuaTableOptions):
}
} else {
const localStatement = parsedLua.body.find((body) => body.type === "LocalStatement") as LocalStatement | undefined;
tableConstructorExpression = localStatement?.init.find((obj) => obj.type === "TableConstructorExpression") as TableConstructorExpression | undefined;
if (localStatement) {
tableConstructorExpression = localStatement?.init.find((obj) => obj.type === "TableConstructorExpression") as TableConstructorExpression | undefined;
} else {
const returnStatement = parsedLua.body.find((body) => body.type === "ReturnStatement") as ReturnStatement | undefined;
tableConstructorExpression = returnStatement?.arguments.find((obj) => obj.type === "TableConstructorExpression") as TableConstructorExpression | undefined;
}
}

if (!tableConstructorExpression) {
Expand Down
48 changes: 48 additions & 0 deletions src/renderer/views/debug/script-launcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<route lang="json5">
{ meta: { title: "Script Launcher", order: 5 } }
</route>

<template>
<div class="flex-col gap-md fullheight">
<Textarea v-model="script" spellcheck="false" />
<Button class="green" @click="launch">Launch</Button>
</div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import Button from "@/components/controls/Button.vue";
import Textarea from "@/components/controls/Textarea.vue";
import { defaultGameVersion } from "@/config/default-versions";
const script = ref(`[game] {
[ais] {
}
[allyteam0] {
numallies=0;
}
[team0] {
teamleader=0;
allyteam=0;
}
[player0] {
team=0;
name=player;
}
mapname=Red Comet Remake 1.8;
myplayername=player;
ishost=1;
gametype=${defaultGameVersion};
}`);
function launch() {
api.game.launch(script.value);
}
</script>

<style lang="scss" scoped>
.textarea {
height: 100%;
}
</style>

0 comments on commit 49b4aa9

Please sign in to comment.