we can export all or specific maps

This commit is contained in:
MathieuG-P
2022-12-08 00:09:59 +01:00
parent 6df2c98955
commit 5bf674d782
11 changed files with 98 additions and 134 deletions
@@ -9,6 +9,8 @@ import { IpcService } from "./ipc.service";
import { ModalExitCode, ModalService } from "./modale.service";
import { DeleteMapsModal } from "renderer/components/modal/modal-types/delete-maps-modal.component";
import { ProgressBarService } from "./progress-bar.service";
import { OpenSaveDialogOption } from "shared/models/ipc";
import { NotificationService } from "./notification.service";
export class MapsManagerService {
@@ -23,6 +25,7 @@ export class MapsManagerService {
private readonly bsaver: BeatSaverService;
private readonly modal: ModalService;
private readonly progressBar: ProgressBarService;
private readonly notifications: NotificationService
private readonly lastLinkedVersion$: Subject<BSVersion> = new Subject();
private readonly lastUnlinkedVersion$: Subject<BSVersion> = new Subject();
@@ -32,6 +35,7 @@ export class MapsManagerService {
this.bsaver = BeatSaverService.getInstance();
this.modal = ModalService.getInsance();
this.progressBar = ProgressBarService.getInstance();
this.notifications = NotificationService.getInstance();
}
public getMaps(version?: BSVersion, withDetails = true): Observable<BsmLocalMap[]>{
@@ -130,6 +134,30 @@ export class MapsManagerService {
return res.success;
}
public async exportMaps(version: BSVersion, maps?: BsmLocalMap[]): Promise<void>{
if(!this.progressBar.require()){ return; }
const resFile = await this.ipcService.send<string, OpenSaveDialogOption>("save-file", {args: {
filename: `${version.BSVersion} Maps`,
filters: [{name: "zip", extensions: ["zip"]}]
}});
if(!resFile.success){ return; }
this.progressBar.showFake(.008);
const resExport = await this.ipcService.send<string, {version: BSVersion, maps: BsmLocalMap[], outPath: string}>("export-maps", {args: {version, maps, outPath: resFile.data}});
if(!resExport.success && resExport.error.title){
const {title, msg} = resExport.error;
this.notifications.notifyError({title, desc: msg});
}
else {
this.notifications.notifySuccess({title: "Export terminé 🎉", duration: 3000});
}
this.progressBar.complete();
this.progressBar.hide(true);
}
public get versionLinked$(): Observable<BSVersion>{
return this.lastLinkedVersion$.asObservable();
}
-51
View File
@@ -1,51 +0,0 @@
import { BSVersion } from "shared/bs-version.interface";
import { OpenSaveDialogOption } from "shared/models/ipc";
import { ExportVersionMapsOption } from "shared/models/maps/export-version-maps.model";
import { IpcService } from "./ipc.service";
import { NotificationService } from "./notification.service";
import { ProgressBarService } from "./progress-bar.service";
export class MapService {
private static instance: MapService;
private readonly ipcService: IpcService;
private readonly progressService: ProgressBarService;
private readonly notificationService: NotificationService;
public static getInstance(): MapService{
if(!MapService.instance){ MapService.instance = new MapService(); }
return MapService.instance;
}
private constructor(){
this.ipcService = IpcService.getInstance();
this.notificationService = NotificationService.getInstance();
this.progressService = ProgressBarService.getInstance();
}
public async exportVersionMaps(version: BSVersion): Promise<void>{
if(!this.progressService.require()){ return; }
const resFile = await this.ipcService.send<string, OpenSaveDialogOption>("save-file", {args: {
filename: `${version.BSVersion} Maps`,
filters: [{name: "zip", extensions: ["zip"]}]
}});
if(!resFile.success){ return; }
this.progressService.showFake(.008);
const resExport = await this.ipcService.send<string, ExportVersionMapsOption>("map.export-version", {args: {version, path: resFile.data}});
if(!resExport.success && resExport.error.title){
const {title, msg} = resExport.error;
this.notificationService.notifyError({title, desc: msg});
}
else {
this.notificationService.notifySuccess({title: "Export terminé 🎉", duration: 3000});
}
this.progressService.complete();
this.progressService.hide(true);
}
}