import { DIALOG_BUGREPORT , DIALOG_OPEN_TIME_MS , DIALOG_PROGRESS } from '@lib/constants' ; import { reportContext , reportError } from '@lib/errorReporting' ; import { EventBus } from '@lib/event-bus' ; import { SaveGame } from 'satisfactory-json' ; import { v4 } from 'uuid' ; import Vue from 'vue' ; export interface SaveFileReader { readFile ( filepath , asJson , progressCallback , errorCallback , successCallback ) : void ; } export class SaveGameLoading { constructor ( private vue , private fileReader ) { } loadSaveGame ( filename , filepath , asJson ) { this . vue . $store . dispatch ( 'setLoading' ) ; this . vue . $store . dispatch ( 'setProgressText' , { title : this . vue . $t ( 'openPage.subtitleSav' ) , currentStep : this . vue . $t ( 'openPage.readingFile' ) , showCloseButton : false } ) ; this . vue . $store . dispatch ( 'setProgress' , 0 ) ; EventBus . $emit ( DIALOG_PROGRESS , true ) ; setTimeout ( ( ) => { const uuid = v4 ( ) ; this . vue . $store . dispatch ( 'setUUID' , uuid ) ; this . vue . $store . dispatch ( 'setFilename' , filename ) ; this . vue . $store . dispatch ( 'setFilepath' , filepath ) ; reportContext ( 'uuid' , uuid ) ; reportContext ( 'savename' , filename ) ; this . fileReader . readFile ( filepath , asJson , progress => { this . vue . $store . dispatch ( 'setProgress' , progress / 2 ) ; } , error => { reportError ( error ) ; EventBus . $emit ( DIALOG_BUGREPORT , error . message ) ; } , saveGame => { this . vue . $store . dispatch ( 'setLoadedData' , saveGame ) . then ( ( ) => { this . vue . $store . dispatch ( 'setShowSaveMenuEntries' , true ) ; this . vue . $router . push ( { name : 'loadEditor' } ) ; } ) ; } ) ; } , DIALOG_OPEN_TIME_MS ) ; } }