Skip to content

Commit

Permalink
feat: mod manager (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonpole committed Dec 31, 2024
1 parent 49a0712 commit edc1686
Show file tree
Hide file tree
Showing 15 changed files with 598 additions and 101 deletions.
14 changes: 14 additions & 0 deletions cli/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Firebase,
GitHub,
Plugins,
Mods,
} from '@liga/backend/lib';

/**
Expand Down Expand Up @@ -327,6 +328,16 @@ async function sandboxPluginManager() {
return Plugins.getPath();
}

/**
* Tests the plugin-manager module.
*
* @function
*/
async function sandboxModManager() {
const mods = new Mods.Manager('https://github.com/playliga/mods.git');
return mods.all();
}

/**
* Validates the provided sandbox type and runs it.
*
Expand All @@ -350,6 +361,7 @@ export async function handleSandboxType(type: string, args: typeof DEFAULT_ARGS)
'training',
'github',
'plugin-manager',
'mod-manager',
];
const sandboxFns: Record<
string,
Expand All @@ -362,6 +374,7 @@ export async function handleSandboxType(type: string, args: typeof DEFAULT_ARGS)
| typeof sandboxTraining
| typeof sandboxGithub
| typeof sandboxPluginManager
| typeof sandboxModManager
> = {
sandboxWorldgen,
sandboxScore,
Expand All @@ -372,6 +385,7 @@ export async function handleSandboxType(type: string, args: typeof DEFAULT_ARGS)
sandboxTraining,
sandboxGithub,
sandboxPluginManager,
sandboxModManager,
};

if (!acceptedSandboxTypes.includes(type)) {
Expand Down
1 change: 1 addition & 0 deletions src/backend/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as IPCProfileHandler } from './profile';
export { default as IPCTransferHandler } from './transfer';
export { default as IPCIssuesHandler } from './issues';
export { default as IPCPluginsHandler } from './plugins';
export { default as IPCModsHandler } from './mods';

/**
* Gets application information such as name and
Expand Down
43 changes: 43 additions & 0 deletions src/backend/handlers/mods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* IPC handlers for the mod manager.
*
* @module
*/
import { ipcMain } from 'electron';
import { Constants } from '@liga/shared';
import { Mods } from '@liga/backend/lib';

/** @constant */
const MODS_REPO_URL = 'https://github.com/playliga/mods.git';

/**
* Register the IPC event handlers.
*
* @function
*/
export default function () {
ipcMain.handle(Constants.IPCRoute.MODS_ALL, () => {
const mods = new Mods.Manager(MODS_REPO_URL);
return mods.all();
});
ipcMain.on(Constants.IPCRoute.MODS_DOWNLOAD, async (event, data: string) => {
// initialize the mod manager
const mods = new Mods.Manager(MODS_REPO_URL);

// register event handlers
mods.on(Mods.EventIdentifier.DOWNLOADING, () =>
event.reply(Constants.IPCRoute.MODS_DOWNLOADING),
);
mods.on(Mods.EventIdentifier.DOWNLOAD_PROGRESS, (percent) =>
event.reply(Constants.IPCRoute.MODS_DOWNLOAD_PROGRESS, percent),
);
mods.on(Mods.EventIdentifier.ERROR, () => event.reply(Constants.IPCRoute.MODS_ERROR));
mods.on(Mods.EventIdentifier.FINISHED, () => event.reply(Constants.IPCRoute.MODS_FINISHED));
mods.on(Mods.EventIdentifier.INSTALL, () => event.reply(Constants.IPCRoute.MODS_INSTALLING));

// start the download
await mods.download(data);
await mods.extract();
});
ipcMain.handle(Constants.IPCRoute.MODS_GET_INSTALLED, Mods.Manager.getInstalledModName);
}
4 changes: 2 additions & 2 deletions src/backend/lib/database-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @module
*/
import * as sqlite3 from 'sqlite3';
import * as ModManager from './mod-manager';
import * as Mods from './mods';
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
Expand Down Expand Up @@ -195,7 +195,7 @@ export default class DatabaseClient {

// bail early if we're using a modded save
try {
await ModManager.initModdedDatabase(newSavePath);
await Mods.Manager.initModdedDatabase(newSavePath);
return Promise.resolve(newSavePath);
} catch (error) {
this.log.info(error);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * as FileManager from './file-manager';
export * as Firebase from './firebase';
export * as Game from './game';
export * as GitHub from './github';
export * as ModManager from './mod-manager';
export * as Mods from './mods';
export * as Ping from './ping';
export * as Plugins from './plugins';
export * as RCON from './rcon';
Expand Down
92 changes: 0 additions & 92 deletions src/backend/lib/mod-manager.ts

This file was deleted.

Loading

0 comments on commit edc1686

Please sign in to comment.