diff --git a/app/helpers/modtest.ts b/app/helpers/modtest.ts index 456b418..e50f2d7 100644 --- a/app/helpers/modtest.ts +++ b/app/helpers/modtest.ts @@ -23,10 +23,13 @@ process.on('exit', () => { }); export function testMod(sendToUI: SendToUI, modData: any) { - const { mod, openClient, map, settings } = modData; + const { mod, openClient, map, settings, databaseOverrideURL } = modData; // check mongodb install - if (!fs.existsSync(`${baseUrl}/resources/mongodb/bin/mongod.exe`)) { + if ( + !databaseOverrideURL && + !fs.existsSync(`${baseUrl}/resources/mongodb/bin/mongod.exe`) + ) { testLogger.log(`MongoDB is not installed.`); sendToUI('notify', { type: 'error', text: 'MongoDB is not installed.' }); return; @@ -76,11 +79,13 @@ export function testMod(sendToUI: SendToUI, modData: any) { fs.writeJSONSync(`${baseUrl}/resources/rair/content/mods/mod.rairmod`, mod); sendToUI('notify', { type: 'info', text: 'Copied mod file!' }); + const defaultDatabaseURL = `mongodb://localhost:35353/lotr2`; + // write .env fs.writeFileSync( `${baseUrl}/resources/rair/.env`, ` -DATABASE_URI=mongodb://localhost:35353/lotr2 +DATABASE_URI=${databaseOverrideURL || defaultDatabaseURL} TEST_MODE=1 TEST_USER_NAME=${username} TEST_USER_PASSWORD=${password} @@ -90,6 +95,10 @@ MODS_TO_LOAD=mod ); sendToUI('notify', { type: 'info', text: 'Wrote .env file!' }); + if (databaseOverrideURL) { + sendToUI('notify', { type: 'info', text: 'Using custom database!' }); + } + // run mongodb if not running (kill old install) if (mongoProcess) { try { @@ -101,27 +110,29 @@ MODS_TO_LOAD=mod } } - // run mongo if not running - testLogger.log(`Starting MongoDB...`); - sendToUI('notify', { type: 'info', text: 'Starting MongoDB...' }); - mongoProcess = childProcess.spawn( - `${baseUrl}/resources/mongodb/bin/mongod.exe`, - [ - '--quiet', - '--port', - '35353', - '--dbpath', - `${baseUrl}/resources/mongodb/data/db`, - ] - ); - - mongoProcess.stdout.on('data', (data: any) => { - testLogger.log(`mongo stdout: ${data}`); - }); + // run mongo if not running and no override specified + if (!databaseOverrideURL) { + testLogger.log(`Starting MongoDB...`); + sendToUI('notify', { type: 'info', text: 'Starting MongoDB...' }); + mongoProcess = childProcess.spawn( + `${baseUrl}/resources/mongodb/bin/mongod.exe`, + [ + '--quiet', + '--port', + '35353', + '--dbpath', + `${baseUrl}/resources/mongodb/data/db`, + ] + ); + + mongoProcess.stdout.on('data', (data: any) => { + testLogger.log(`mongo stdout: ${data}`); + }); - mongoProcess.stderr.on('data', (data) => { - testLogger.log(`mongo stderr: ${data}`); - }); + mongoProcess.stderr.on('data', (data) => { + testLogger.log(`mongo stderr: ${data}`); + }); + } // run lotr server if not running (kill old install) if (lotrProcess) { diff --git a/src/app/shared/components/test-view/test-view.component.html b/src/app/shared/components/test-view/test-view.component.html index ac89bad..944d737 100644 --- a/src/app/shared/components/test-view/test-view.component.html +++ b/src/app/shared/components/test-view/test-view.component.html @@ -6,27 +6,34 @@

Useful Character Settings

Character Level - +
Map - +
Map X - +
Map Y - + +
+ +
+ Database Override URL +
diff --git a/src/app/shared/components/test-view/test-view.component.ts b/src/app/shared/components/test-view/test-view.component.ts index a111ebd..a1c2ec0 100644 --- a/src/app/shared/components/test-view/test-view.component.ts +++ b/src/app/shared/components/test-view/test-view.component.ts @@ -22,6 +22,7 @@ export class TestViewComponent implements OnInit { x: 4, y: 4, openClient: true, + databaseOverride: '', otherProps: '{\n \n}', }; @@ -33,6 +34,7 @@ export class TestViewComponent implements OnInit { ngOnInit() { const settings = this.localStorage.retrieve('testsettings'); + console.log('old settings', settings); if (settings) { this.settings.level = settings.level; this.settings.map = settings.map; @@ -40,22 +42,28 @@ export class TestViewComponent implements OnInit { this.settings.y = settings.y; this.settings.openClient = settings.openClient; this.settings.otherProps = settings.otherProps; + this.settings.databaseOverride = settings.databaseOverride; this.dialogModel.value = settings.otherProps; } } + public saveSettings() { + this.localStorage.store('testsettings', this.settings); + } + public onSettingsChanged(newProps: string) { this.settings.otherProps = newProps; try { this.isValidJSON.set(!!JSON.parse(newProps)); + this.saveSettings(); } catch { this.isValidJSON.set(false); } } public testMod() { - this.localStorage.store('testsettings', this.settings); + this.saveSettings(); const settingsString = JSON.stringify({ map: this.settings.map, @@ -69,6 +77,7 @@ export class TestViewComponent implements OnInit { map: this.settings.map, settings: settingsString, openClient: this.settings.openClient, + databaseOverrideURL: this.settings.databaseOverride, }); }