| 9 | /* global MA, DATA, bootstrap */ |
| 10 | |
| 11 | class stateManager { |
| 12 | collectDialog = null |
| 13 | deleteDialog = null |
| 14 | importDialog = null |
| 15 | restoreDialog = null |
| 16 | |
| 17 | uuidMap = {} |
| 18 | langCode = 'en' |
| 19 | |
| 20 | constructor() { |
| 21 | MA.byIdEventIfExists('compare_save_btn', () => { this.compare.go() }) |
| 22 | MA.byIdEventIfExists('delete_save_btn', () => { this.delete.go() }) |
| 23 | MA.byIdEventIfExists('import_save_btn', () => { this.import.go() }) |
| 24 | MA.byIdEventIfExists('import_save_load_btn', () => { this.import.load() }) |
| 25 | MA.byIdEventIfExists('importButton', () => { this.import.open() }) |
| 26 | MA.byIdEventIfExists('restore_save_btn', () => { this.restore.go() }) |
| 27 | |
| 28 | this.collectDialog = new bootstrap.Modal('#collect_savegame_modal', { backdrop : 'static', keyboard : false }) |
| 29 | this.deleteDialog = new bootstrap.Modal('#delete_savegame_modal', { backdrop : 'static', keyboard : false }) |
| 30 | this.importDialog = new bootstrap.Modal('#import_savegame_modal', { backdrop : 'static', keyboard : false }) |
| 31 | this.restoreDialog = new bootstrap.Modal('#restore_savegame_modal', { backdrop : 'static', keyboard : false }) |
| 32 | |
| 33 | this.collectDialog.hide() |
| 34 | this.deleteDialog.hide() |
| 35 | this.importDialog.hide() |
| 36 | this.restoreDialog.hide() |
| 37 | |
| 38 | window.savemanage_IPC.receive('savemanage:info', (modCollect) => { |
| 39 | this.processData(modCollect) |
| 40 | }) |
| 41 | window.savemanage_IPC.receive('savemanage:import', (savePath) => { |
| 42 | MA.byIdText('save_import_path', savePath) |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | async processData(data) { |
| 47 | await this.updateLang() |
| 48 | |
| 49 | this.uuidMap = {} |
| 50 | const theseSaves = data.opts.saveInfo |
| 51 | |
| 52 | const activeIDS = Object.keys(theseSaves).filter((x) => typeof theseSaves[x].active === 'object' && theseSaves[x].active?.errorList.length === 0) |
| 53 | const backIDS = Object.keys(theseSaves).filter((x) => Array.isArray(theseSaves[x].backups) && theseSaves[x].backups.length !== 0 ) |
| 54 | |
| 55 | const activeGameHTML = [] |
| 56 | const backGameHTML = [] |
| 57 | const compareHTML = [] |
| 58 | |
| 59 | for ( const collectKey of data.set_Collections ) { |
| 60 | if ( data.appSettings.game_version === data.collectionNotes[collectKey].notes_version ) { |
| 61 | compareHTML.push(DATA.optionFromArray([collectKey, data.collectionToFullName[collectKey]])) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | for ( const thisID of activeIDS ) { |
| 66 | this.uuidMap[theseSaves[thisID].active.uuid] = { |
| 67 | path : theseSaves[thisID].active.fullPath, |
| 68 | name : theseSaves[thisID].active.fullName, |