Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial proof of concept db #383

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"postinstall": "yarn run electron-rebuild && yarn run link-modules"
},
"dependencies": {
"sqlite3": "^5.1.6",
"threads": "^1.6.5",
"typeorm": "^0.3.16",
"websocket": "^1.0.34"
},
"license": "GPL-3.0"
Expand Down
1,057 changes: 1,057 additions & 0 deletions release/app/yarn.lock

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DataSource } from "typeorm";

const dataSources: { [id: string]: DataSource } = {};

async function getDataSource(dbName: string) {
if (dbName in dataSources) {
return dataSources[dbName];
}

const AppDataSource = new DataSource({
type: "sqlite",
//database: settingsManager.get().settings.rootSlpPath + "/index.sqlite3",
//database: "/home/agiera/Slippi/index.sqlite3",
database: dbName,
synchronize: true,
logging: true,
entities: ["src/entity/*.ts"],
});

AppDataSource.initialize()
.then(() => {
console.log("Data Source has been initialized!");
})
.catch((err) => {
console.error("Error during Data Source initialization", err);
});

dataSources[dbName] = AppDataSource;

return AppDataSource;
}

export default getDataSource;
45 changes: 45 additions & 0 deletions src/entity/Replay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { EntitySchema } from "typeorm";

export const Replay = new EntitySchema({
name: "replay",
columns: {
id: {
type: Number,
primary: true,
generated: true,
},
fullPath: {
type: String,
unique: true,
},
startTime: {
type: String,
nullable: true,
},
lastFrame: {
type: Number,
nullable: true,
},
winnerIndices: {
type: "simple-json",
nullable: false,
},
},
relations: {
// Analogue to `GameStartType` in slippi-js
settings: {
type: "one-to-one",
target: "replayGameStart",
inverseSide: "replay",
cascade: ["insert", "update", "remove"],
},
// Analogue to `MetadataType` in slippi-js
metadata: {
type: "one-to-one",
target: "replayMetadata",
inverseSide: "replay",
cascade: ["insert", "update", "remove"],
nullable: true,
},
} as any,
});
97 changes: 97 additions & 0 deletions src/entity/ReplayGameStart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { GameMode, ItemSpawnType, Language, TimerType } from "@slippi/slippi-js";
import { EntitySchema } from "typeorm";

export const ReplayGameStart = new EntitySchema({
name: "replayGameStart",
columns: {
id: {
type: Number,
primary: true,
generated: true,
},
slpVersion: {
type: String,
nullable: true,
},
timerType: {
type: "simple-enum",
enum: TimerType,
nullable: true,
},
inGameMode: {
type: Number,
nullable: true,
},
friendlyFireEnabled: {
type: Boolean,
nullable: true,
},
isTeams: {
type: Boolean,
nullable: true,
},
stageId: {
type: Number,
nullable: true,
},
startingTimerSeconds: {
type: Number,
nullable: true,
},
itemSpawnBehavior: {
type: "simple-enum",
enum: ItemSpawnType,
nullable: true,
},
enabledItems: {
type: Number,
nullable: true,
},
scene: {
type: Number,
nullable: true,
},
gameMode: {
type: "simple-enum",
enum: GameMode,
nullable: true,
},
language: {
type: "simple-enum",
enum: Language,
nullable: true,
},
randomSeed: {
type: Number,
nullable: true,
},
isPAL: {
type: Boolean,
nullable: true,
},
isFrozenPS: {
type: Boolean,
nullable: true,
},
replayId: {
type: Number,
},
},
relations: {
replay: {
type: "one-to-one",
target: "replay",
invserSide: "settings",
joinColumn: {
name: "replayId",
},
orphanedRowAction: "delete",
},
players: {
type: "one-to-many",
target: "replayPlayer",
invserSide: "settings",
cascade: ["insert", "update", "remove"],
},
} as any,
});
38 changes: 38 additions & 0 deletions src/entity/ReplayMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { EntitySchema } from "typeorm";

export const ReplayMetadata = new EntitySchema({
name: "replayMetadata",
columns: {
id: {
type: Number,
primary: true,
generated: true,
},
startAt: {
type: String,
nullable: true,
},
playedOn: {
type: String,
nullable: true,
},
lastFrame: {
type: Number,
nullable: true,
},
replayId: {
type: Number,
},
},
relations: {
replay: {
type: "one-to-one",
target: "replay",
invserseSide: "metadata",
joinColumn: {
name: "replayId",
},
orphanedRowAction: "delete",
},
} as any,
});
125 changes: 125 additions & 0 deletions src/entity/ReplayPlayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { EntitySchema } from "typeorm";

export const ReplayPlayer = new EntitySchema({
name: "replayPlayer",
columns: {
id: {
type: Number,
primary: true,
generated: true,
},
playerIndex: {
type: Number,
},
port: {
type: Number,
unique: true,
},
characterId: {
type: Number,
nullable: true,
},
type: {
type: Number,
nullable: true,
},
startStocks: {
type: Number,
nullable: true,
},
characterColor: {
type: Number,
nullable: true,
},
teamShade: {
type: Number,
nullable: true,
},
handicap: {
type: Number,
nullable: true,
},
teamId: {
type: Number,
nullable: true,
},
staminaMode: {
type: Boolean,
nullable: true,
},
silentCharacter: {
type: Boolean,
nullable: true,
},
invisible: {
type: Boolean,
nullable: true,
},
lowGravity: {
type: Boolean,
nullable: true,
},
blackStockIcon: {
type: Boolean,
nullable: true,
},
metal: {
type: Boolean,
nullable: true,
},
startOnAngelPlatform: {
type: Boolean,
nullable: true,
},
rumbleEnabled: {
type: Boolean,
nullable: true,
},
cpuLevel: {
type: Number,
nullable: true,
},
offenseRatio: {
type: Number,
nullable: true,
},
defenseRatio: {
type: Number,
nullable: true,
},
modelScale: {
type: Number,
nullable: true,
},
controllerFix: {
type: String,
nullable: true,
},
nametag: {
type: String,
nullable: true,
},
displayName: {
type: String,
},
connectCode: {
type: String,
},
userId: {
type: String,
},
settingsId: {
type: Number,
},
},
relations: {
settings: {
type: "many-to-one",
target: "replayGameStart",
joinColumn: {
name: "settingsId",
},
orphanedRowAction: "delete",
},
} as any,
});
3 changes: 2 additions & 1 deletion src/main/installModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import setupMainIpc from "./setup";
export function installModules() {
const settingsManager = new SettingsManager();
const dolphinManager = new DolphinManager(settingsManager);
const dbName = settingsManager.get().settings.rootSlpPath + "/index.sqlite3";
setupDolphinIpc({ dolphinManager });
setupBroadcastIpc({ settingsManager, dolphinManager });
setupReplaysIpc();
setupReplaysIpc({ dbName });
setupSettingsIpc({ settingsManager, dolphinManager });
setupConsoleIpc({ dolphinManager });
setupMainIpc();
Expand Down
Loading