import { DIALOG_BUGREPORT , DIALOG_OPEN_TIME_MS , DIALOG_PROGRESS } from '@lib/constants' ; import { EventBus } from '@lib/event-bus' ; import { SaveGame } from 'satisfactory-json' ; import { reportError } from './errorReporting' ; export interface SaveFileWriter { writeFile ( saveGame , filepath , asJson , progressCallback , errorCallback , successCallback ) : void ; } export class SaveGameSaving { constructor ( private vue , private fileWriter ) { } saveSaveGame ( saveGame , filepath , asJson ) { this . vue . $store . dispatch ( 'setProgress' , 0 ) ; this . vue . $store . dispatch ( 'setProgressText' , { title : this . vue . $t ( 'savePage.savSubtitle' ) , currentStep : this . vue . $t ( 'savePage.processingFile' ) , showCloseButton : false } ) ; EventBus . $emit ( DIALOG_PROGRESS , true ) ; setTimeout ( ( ) => { console . time ( 'saveFile' ) ; this . fileWriter . writeFile ( window . data , filepath , asJson , progress => { this . vue . $store . dispatch ( 'setProgress' , progress ) ; } , error => { reportError ( error ) ; EventBus . $emit ( DIALOG_BUGREPORT , error . message ) ; } , ( ) => { console . timeEnd ( 'saveFile' ) ; this . vue . $store . dispatch ( 'setProgress' , 100 ) ; this . vue . $store . dispatch ( 'setProgressText' , { currentStep : this . vue . $t ( 'savePage.saveFinished' ) , showCloseButton : true } ) ; } ) ; } , DIALOG_OPEN_TIME_MS ) ; } }