Skip to content

Commit

Permalink
Merge pull request #220 from 1-alex98/bugfix/#219-error-on-single-player
Browse files Browse the repository at this point in the history
Error on SinglePlayer page
  • Loading branch information
Jazcash authored Jun 19, 2023
2 parents 915558b + 1bf8a75 commit 6fb5adb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/renderer/api/cache-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class CacheDbAPI extends Kysely<CacheDatabase> {
}

public async init() {
await this.serializePlugin.setSchema(this);

await this.schema
.createTable("map")
.ifNotExists()
Expand Down Expand Up @@ -122,8 +120,12 @@ export class CacheDbAPI extends Kysely<CacheDatabase> {
.addColumn("fileName", "varchar", (col) => col.primaryKey())
.execute();

await this.serializePlugin.setSchema(this); //might be needed already for migration

await this.migrateToLatest();

await this.serializePlugin.setSchema(this); //again in case migration changed the database

return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/content/engine-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class EngineContentAPI extends AbstractContentAPI<EngineVersion> {
}

protected async parseAi(aiPath: string): Promise<EngineAI> {
const aiDefinitions = await glob.promise(`${aiPath}/**/{AIInfo.lua,AIOptions.lua}`);
const aiDefinitions = await glob.promise(`${aiPath}/**/{AIInfo.lua,AIOptions.lua}`, { windowsPathsNoEscape: true });
const aiInfoPath = aiDefinitions.find((filePath) => filePath.endsWith("AIInfo.lua"));
const aiOptionsPath = aiDefinitions.find((filePath) => filePath.endsWith("AIOptions.lua"));

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/content/game-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class GameContentAPI extends PrDownloaderAPI<GameVersion | CustomGameVers
if ("dir" in version) {
const sdpFiles: Array<SdpFileMeta & { data?: Buffer }> = [];
const customGameDir = path.join(api.info.contentPath, "games", version.dir);
const files = await glob.promise(path.join(customGameDir, filePattern));
const files = await glob.promise(path.join(customGameDir, filePattern), { windowsPathsNoEscape: true });

for (const file of files) {
const sdpData = {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/config/default-battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function defaultBattle(mapScriptName?: string) {
me.battleStatus.isSpectator = false;

const engine = api.content.engine.installedVersions.find((version) => version.id === defaultEngineVersion);
const barb = engine?.ais.find((ai) => ai.shortName === "BARb")!;
const barb = engine?.ais.find((ai) => ai.shortName === "BARb");

return new OfflineBattle({
battleOptions: {
Expand All @@ -31,6 +31,6 @@ export function defaultBattle(mapScriptName?: string) {
restrictions: [],
},
users: [me],
bots: [{ playerId: 1, teamId: 1, ownerUserId: me.userId, name: barb.name, aiShortName: barb.shortName, aiOptions: {} }],
bots: barb ? [{ playerId: 1, teamId: 1, ownerUserId: me.userId, name: barb.name, aiShortName: barb.shortName, aiOptions: {} }] : [],
});
}
1 change: 1 addition & 0 deletions src/renderer/utils/serialize-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SerializePlugin implements KyselyPlugin {
protected colTypes = new Map<string, "json" | "datetime" | "boolean">();

public async setSchema(db: Kysely<unknown>) {
this.colTypes.clear();
const tableMetadata = await db.introspection.getTables();
for (const table of tableMetadata) {
for (const col of table.columns) {
Expand Down

0 comments on commit 6fb5adb

Please sign in to comment.