Skip to content

Commit

Permalink
allow database override uri
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Oct 25, 2024
1 parent 20ab4eb commit d6bcd77
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
57 changes: 34 additions & 23 deletions app/helpers/modtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
17 changes: 12 additions & 5 deletions src/app/shared/components/test-view/test-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@ <h2 class="text-xl font-bold mb-2">Useful Character Settings</h2>

<div class="form-row">
<app-input-floating-label>Character Level</app-input-floating-label>
<input [(ngModel)]="settings.level" min="1" type="number" class="form-input" />
<input [(ngModel)]="settings.level" min="1" type="number" class="form-input" (change)="saveSettings()" />
</div>

<div class="form-row">
<app-input-floating-label>Map</app-input-floating-label>
<app-input-map [(map)]="settings.map" [defaultValue]="''"></app-input-map>
<app-input-map [(map)]="settings.map" [defaultValue]="''" (mapChange)="saveSettings()"></app-input-map>
</div>

<div class="form-row">
<app-input-floating-label>Map X</app-input-floating-label>
<input [(ngModel)]="settings.x" min="0" type="number" class="form-input" />
<input [(ngModel)]="settings.x" min="0" type="number" class="form-input" (change)="saveSettings()" />
</div>

<div class="form-row">
<app-input-floating-label>Map Y</app-input-floating-label>
<input [(ngModel)]="settings.y" min="0" type="number" class="form-input" />
<input [(ngModel)]="settings.y" min="0" type="number" class="form-input" (change)="saveSettings()" />
</div>

<div class="form-row">
<app-input-floating-label>Database Override URL</app-input-floating-label>
<input [(ngModel)]="settings.databaseOverride" type="text"
placeholder="If unspecified, will start the MongoDB installed with ModKit" class="form-input"
(change)="saveSettings()" />
</div>

<div class="form-row pl-1">
<label class="label cursor-pointer" floatUi="Whether or not to open the game client.">
<input type="checkbox" [(ngModel)]="settings.openClient" class="checkbox" />
<input type="checkbox" [(ngModel)]="settings.openClient" class="checkbox" (change)="saveSettings()" />
<span class="label-text">Open Client?</span>
</label>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/app/shared/components/test-view/test-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class TestViewComponent implements OnInit {
x: 4,
y: 4,
openClient: true,
databaseOverride: '',
otherProps: '{\n \n}',
};

Expand All @@ -33,29 +34,36 @@ 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;
this.settings.x = settings.x;
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,
Expand All @@ -69,6 +77,7 @@ export class TestViewComponent implements OnInit {
map: this.settings.map,
settings: settingsString,
openClient: this.settings.openClient,
databaseOverrideURL: this.settings.databaseOverride,
});
}

Expand Down

0 comments on commit d6bcd77

Please sign in to comment.