Skip to content
Open
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
48 changes: 47 additions & 1 deletion GUI/electron/src/modules/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function promiseFromChildProcess(child) {
});
}

function _extractStringToken(output) {
// allow URL-safe base64 chars as well (-, _)
let m = output.match(/[A-Za-z0-9_-]+/g);
return (m && m[0]) ? m[0] : "";
}

function isMulti(args) {

if (("world_count" in args) && args["world_count"] > 1)
Expand Down Expand Up @@ -337,7 +343,7 @@ function parseSettings(pythonPath, randoPath) {
reject(output);
}
else {
resolve(output.match(/([a-zA-Z0-9])\w+/g)[0]);
resolve(_extractStringToken(output));
}

}).catch(err => {
Expand All @@ -347,6 +353,44 @@ function parseSettings(pythonPath, randoPath) {
});
}

function getVisualSettings(pythonPath, randoPath, visualSettingsString) {
return new Promise(function (resolve, reject) {
let output = "";
let error = false;
let args = ['--convert_visual_settings', '--visual_settings_string', visualSettingsString];
let settingsPY = spawn(pythonPath + ' ' + '"' + randoPath + '"', args, { shell: true })
.on('error', err => {
console.error("[getVisualSettings] Error spawning process:", err);
reject(err);
});
settingsPY.stdout.on('data', data => { output += data.toString(); error = false; });
settingsPY.stderr.on('data', data => { output += data.toString(); error = true; });
promiseFromChildProcess(settingsPY).then(function () {
if (error) reject(output);
else resolve(output.replace(/\r?\n|\r/g, "\r\n"));
}).catch(err => reject(err));
});
}

function parseVisualSettings(pythonPath, randoPath) {
return new Promise(function (resolve, reject) {
let output = "";
let error = false;
let args = ['--convert_visual_settings'];
let settingsPY = spawn(pythonPath + ' ' + '"' + randoPath + '"', args, { shell: true })
.on('error', err => {
console.error("[parseVisualSettings] Error spawning process:", err);
reject(err);
});
settingsPY.stdout.on('data', data => { output += data.toString(); error = false; });
settingsPY.stderr.on('data', data => { output += data.toString(); error = true; });
promiseFromChildProcess(settingsPY).then(() => {
if (error) reject(output);
else resolve(_extractStringToken(output));
}).catch(err => reject(err));
});
}

function getUpdatedDynamicSetting(pythonPath, scriptPath, settingName) {
return new Promise(function (resolve, reject) {

Expand Down Expand Up @@ -394,6 +438,8 @@ module.exports = new EventEmitter();

module.exports.getSettings = getSettings;
module.exports.parseSettings = parseSettings;
module.exports.getVisualSettings = getVisualSettings;
module.exports.parseVisualSettings = parseVisualSettings;
module.exports.romBuilding = romBuilding;
module.exports.cancelRomBuilding = cancelRomBuilding;
module.exports.testPythonPath = testPythonPath;
Expand Down
44 changes: 41 additions & 3 deletions GUI/electron/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ function dumpSettingsToFile(settingsObj) {
fs.writeFileSync(pythonSourcePath + "settings.sav", JSON.stringify(settingsObj, null, 4));
}

function dumpSettingsToFileForPython(settingsObj) {
// Avoid feeding UI-only string fields into python Settings
let obj = Object.assign({}, settingsObj);
delete obj["settings_string"];
delete obj["visual_settings_string"];
obj["check_version"] = true;
fs.writeFileSync(pythonSourcePath + "settings.sav", JSON.stringify(obj, null, 4));
}

function dumpPresetsToFile(presetsString: string) {
fs.writeFileSync(pythonSourcePath + "presets.sav", presetsString);
}
Expand Down Expand Up @@ -239,7 +248,7 @@ post.on('convertSettingsToString', function (event) {
return false;

//Write settings obj to settings.sav
dumpSettingsToFile(data);
dumpSettingsToFileForPython(data);

//console.log("generate string with settings obj", data);

Expand All @@ -259,6 +268,21 @@ post.on('convertSettingsToString', function (event) {
return true;
});

post.on('convertVisualSettingsToString', function (event) {
let data = event.data;
if (!data || typeof (data) != "object" || Object.keys(data).length < 1) return false;
dumpSettingsToFileForPython(data);
generator.parseVisualSettings(pythonPath, pythonGeneratorPath).then(res => {
post.send(window, 'convertVisualSettingsToStringSuccess', res);
}).catch((err) => {
if (typeof err === "string" && err.includes("ImportError: No module named tkinter")) {
displayPythonErrorAndExit(true);
}
post.send(window, 'convertVisualSettingsToStringError', err);
});
return true;
});

post.on('updateDynamicSetting', function (event) {
let data = event.data;

Expand Down Expand Up @@ -305,6 +329,20 @@ post.on('convertStringToSettings', function (event) {
return true;
});

post.on('convertStringToVisualSettings', function (event) {
let data = event.data;
if (!data || typeof (data) != "string" || data.length < 1) return false;
generator.getVisualSettings(pythonPath, pythonGeneratorPath, data).then(res => {
post.send(window, 'convertStringToVisualSettingsSuccess', res);
}).catch((err) => {
if (typeof err === "string" && err.includes("ImportError: No module named tkinter")) {
displayPythonErrorAndExit(true);
}
post.send(window, 'convertStringToVisualSettingsError', err);
});
return true;
});

post.on('saveCurrentPresetsToFile', function (event) {

let data = event.data;
Expand All @@ -331,8 +369,8 @@ post.on('generateSeed', function (event) {
return false;

//Write settings obj to settings.sav
dumpSettingsToFile(settingsFile);

dumpSettingsToFileForPython(settingsFile);
//console.log("generate seed with settings:", data);

generator.romBuilding(pythonPath, pythonGeneratorPath, data).then(res => {
Expand Down
2 changes: 1 addition & 1 deletion GUI/src/app/@theme/styles/theme.ootr-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $nb-themes: nb-register-theme(
header-text-font-size: 13.125px,
header-text-line-height: 17.5px,

footer-height: 203px,
footer-height: 253px,
footer-text-font-size: 13.125px,
footer-text-line-height: 17.5px,

Expand Down
2 changes: 1 addition & 1 deletion GUI/src/app/@theme/styles/theme.ootr-default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $nb-themes: nb-register-theme(
header-text-font-size: 13.125px,
header-text-line-height: 17.5px,

footer-height: 215px,
footer-height: 265px,
footer-text-font-size: 13.125px,
footer-text-line-height: 17.5px,

Expand Down
16 changes: 16 additions & 0 deletions GUI/src/app/pages/generator/generator.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ <h3>{{section.text}}</h3>
<button class="footerButton" nbButton status="info" size="small" (click)="importSettingsString()">Import</button>
<!--Padding-->
<div class="settingPadding"></div>
<p class="footerInputLabel">Visual Settings String</p>
<input class="footerInput" nbInput type="text" maxlength="2000" fieldSize="small" (focus)="inputFocusIn('visual_settings_string')" (focusout)="inputFocusOut('visual_settings_string', true)" [(ngModel)]="global.generator_settingsMap['visual_settings_string']">
<button class="footerButton" nbButton status="info" size="small" (click)="copyVisualSettingsString()">Copy</button>
<button class="footerButton" nbButton status="info" size="small" (click)="importVisualSettingsString()">Import</button>
<!--Padding-->
<div class="settingPadding"></div>
<p class="footerInputLabel">Seed</p>
<input class="footerInput" nbInput type="text" maxlength="260" fieldSize="small" [(ngModel)]="seedString">
<!--Padding-->
Expand All @@ -285,6 +291,16 @@ <h3>{{section.text}}</h3>
<button class="footerButton" nbButton status="info" size="small" (click)="importSettingsString()">Import</button>
<!--Padding-->
<div class="settingPadding"></div>
<p class="footerInputLabel">Visual Settings String</p>
<input class="footerInputShort" nbInput type="text" maxlength="2000" fieldSize="small"
(focus)="inputFocusIn('visual_settings_string')"
(focusout)="inputFocusOut('visual_settings_string', true)"
[(ngModel)]="global.generator_settingsMap['visual_settings_string']">
<button class="footerButton" nbButton status="info" size="small" (click)="copyVisualSettingsString()">Copy</button>
<button class="footerButton" nbButton status="info" size="small" (click)="settingsBusy = true; getVisualSettingsString()">Get</button>
<button class="footerButton" nbButton status="info" size="small" (click)="importVisualSettingsString()">Import</button>
<!--Padding-->
<div class="settingPadding"></div>
<p class="footerInputLabel">Seed</p>
<input class="footerInputShort" nbInput type="text" maxlength="260" fieldSize="small" [(ngModel)]="seedString">
<!--Padding-->
Expand Down
6 changes: 3 additions & 3 deletions GUI/src/app/pages/generator/generator.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
}

.settingsTabset {
height: calc(91vh - 260px);
height: calc(91vh - 310px);
min-height: 490px;
padding: 0 7px !important;

@media (max-width: 400px) {
height: calc(88vh - 260px);
height: calc(88vh - 310px);
min-height: 460px;
}

Expand All @@ -89,7 +89,7 @@
margin-top: 5px;

@media (max-width: 700px) {
height: 210px;
height: 310px;
}

nb-tab {
Expand Down
112 changes: 107 additions & 5 deletions GUI/src/app/pages/generator/generator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class GeneratorComponent implements OnInit {

//Electron only: Ensure settings string is up-to-date on app launch
if (this.global.getGlobalVar('electronAvailable'))
this.getSettingsString();
this.getSettingsStrings();
else //Web only: Check if we should auto import settings/presets from a prior version
this.checkAutoImportSettings();
}
Expand Down Expand Up @@ -432,10 +432,57 @@ export class GeneratorComponent implements OnInit {
});
}

private normalizeSettingsString(value: any): string {
if (typeof value !== "string") return "";
let s = value.trim().replace(/[^a-zA-Z0-9_-]/g, "");
if (s.length > 0 && s.length < 8) s = s.padEnd(8, "A");
return s;
}

copySettingsString() {
this.global.copyToClipboard(this.global.generator_settingsMap["settings_string"]);
}


copyVisualSettingsString() {
this.global.copyToClipboard(this.global.generator_settingsMap["visual_settings_string"]);
}

getSettingsStrings() {
this.settingsLocked = true;
this.global.convertSettingsToString()
.then(settingsStr => {
this.global.generator_settingsMap["settings_string"] = settingsStr;
return this.global.convertVisualSettingsToString();
})
.then(visualStr => {
this.global.generator_settingsMap["visual_settings_string"] = this.normalizeSettingsString(visualStr);
this.global.saveCurrentSettingsToFile();
this.settingsLocked = false;
if (this.settingsBusy) {
this.settingsBusy = false;
this.afterSettingChange(this.settingsBusySaveOnly);
this.settingsBusySaveOnly = true;
}
this.cd.markForCheck();
this.cd.detectChanges();
})
.catch(err => {
this.settingsLocked = false;
if (this.settingsBusy) {
this.settingsBusy = false;
this.afterSettingChange(this.settingsBusySaveOnly);
this.settingsBusySaveOnly = true;
}
this.cd.markForCheck();
this.cd.detectChanges();
this.dialogService.open(ErrorDetailsWindowComponent, {
autoFocus: true, closeOnBackdropClick: true, closeOnEsc: true,
hasBackdrop: true, hasScroll: false, context: { errorMessage: err }
});
});
}

getSettingsString() {

this.settingsLocked = true;
Expand Down Expand Up @@ -476,12 +523,43 @@ export class GeneratorComponent implements OnInit {
});
}


getVisualSettingsString() {
this.settingsLocked = true;
this.global.convertVisualSettingsToString().then(res => {
this.global.generator_settingsMap["visual_settings_string"] = this.normalizeSettingsString(res);
this.global.saveCurrentSettingsToFile();
this.settingsLocked = false;
if (this.settingsBusy) {
this.settingsBusy = false;
this.afterSettingChange(this.settingsBusySaveOnly);
this.settingsBusySaveOnly = true;
}
this.cd.markForCheck();
this.cd.detectChanges();
}).catch((err) => {
this.settingsLocked = false;
if (this.settingsBusy) {
this.settingsBusy = false;
this.afterSettingChange(this.settingsBusySaveOnly);
this.settingsBusySaveOnly = true;
}
this.cd.markForCheck();
this.cd.detectChanges();
this.dialogService.open(ErrorDetailsWindowComponent, {
autoFocus: true, closeOnBackdropClick: true, closeOnEsc: true,
hasBackdrop: true, hasScroll: false, context: { errorMessage: err }
});
});
}

importSettingsString() {

this.generatorBusy = true;

this.global.convertStringToSettings(this.global.generator_settingsMap["settings_string"]).then(res => {

const normalized = this.normalizeSettingsString(this.global.generator_settingsMap["settings_string"]);
this.global.generator_settingsMap["settings_string"] = normalized;
this.global.convertStringToSettings(normalized).then(res => {
//console.log(res);

this.global.applySettingsObject(res);
Expand All @@ -506,6 +584,30 @@ export class GeneratorComponent implements OnInit {
});
}


importVisualSettingsString() {
this.generatorBusy = true;
const normalized = this.normalizeSettingsString(this.global.generator_settingsMap["visual_settings_string"]);
this.global.generator_settingsMap["visual_settings_string"] = normalized;
this.global.convertStringToVisualSettings(normalized).then(res => {
this.global.applySettingsObject(res);
this.global.saveCurrentSettingsToFile();
this.recheckAllSettings("", false, true);
this.generatorBusy = false;
this.cd.markForCheck();
this.cd.detectChanges();
}).catch((_err) => {
this.generatorBusy = false;
this.cd.markForCheck();
this.cd.detectChanges();
this.dialogService.open(DialogWindowComponent, {
autoFocus: true, closeOnBackdropClick: true, closeOnEsc: true,
hasBackdrop: true, hasScroll: false,
context: { dialogHeader: "Error", dialogMessage: "The entered visual settings string seems to be invalid!" }
});
});
}

getPresetArray() {
if (typeof (this.global.generator_presets) == "object")
return Object.keys(this.global.generator_presets);
Expand Down Expand Up @@ -1463,7 +1565,7 @@ export class GeneratorComponent implements OnInit {
this.cd.detectChanges();
}
else {
this.getSettingsString();
this.getSettingsStrings();
}
}, 0);
}
Expand Down Expand Up @@ -1563,4 +1665,4 @@ export class GeneratorComponent implements OnInit {
}
}
}
}
}
Loading