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
@@ -32,7 +32,7 @@ export const LocalMapsListPanel = forwardRef(({version, className, filter, searc
mapsManager.deleteMaps(mapsToDelete).finally(loadMaps);
},
exportMaps(){
console.log("TODO EXPORT MAPS");
mapsManager.exportMaps(version, selectedMaps)
}
}), [selectedMaps, maps]);
@@ -11,7 +11,6 @@ import { ModalExitCode, ModalService } from '../services/modale.service';
import DefautVersionImage from "../../../assets/images/default-version-img.jpg";
import { BsDownloaderService } from 'renderer/services/bs-downloader.service';
import { IpcService } from 'renderer/services/ipc.service';
import { MapService } from 'renderer/services/maps.service';
import { LaunchSlide } from 'renderer/components/version-viewer/slides/launch/launch-slide.component';
import { ModsSlide } from 'renderer/components/version-viewer/slides/mods/mods-slide.component';
import { UninstallModal } from 'renderer/components/modal/modal-types/uninstall-modal.component';
@@ -24,7 +23,6 @@ export function VersionViewer() {
const modalService = ModalService.getInsance();
const bsDownloaderService = BsDownloaderService.getInstance();
const ipcService = IpcService.getInstance();
const mapService = MapService.getInstance();
const {state} = useLocation() as {state: BSVersion};
const navigate = useNavigate();
@@ -32,7 +30,6 @@ export function VersionViewer() {
const navigateToVersion = (version: BSVersion) => navigate(`/bs-version/${version.BSVersion}`, {state: version});
const openFolder = () => ipcService.sendLazy("bs-version.open-folder", {args: state});
const exportMaps = () => mapService.exportVersionMaps(state);
const verifyFiles = () => bsDownloaderService.download(state, true);
const uninstall = async () => {
@@ -71,7 +68,7 @@ export function VersionViewer() {
<div className='mt-2 w-full min-h-0 grow flex transition-transform duration-300' style={{transform: `translate(${-(currentTabIndex * 100)}%, 0)`}}>
<LaunchSlide version={state}/>
<div className="w-full shrink-0 px-3 pb-3 flex flex-col items-center">
<MapsPlaylistsPanel version={state} oneBlock/>
<MapsPlaylistsPanel version={state}/>
</div>
<ModsSlide version={state}/>
</div>
@@ -79,7 +76,6 @@ export function VersionViewer() {
<BsmDropdownButton className='absolute top-5 right-5 h-9 w-9 bg-light-main-color-2 dark:bg-main-color-2 rounded-md' items={[
{text: "pages.version-viewer.dropdown.open-folder", icon: "folder", onClick: openFolder},
((!state.steam && !state.oculus) && {text: "pages.version-viewer.dropdown.verify-files", icon: "task", onClick: verifyFiles}),
((!state.steam && !state.oculus) && {text: "Exporter les misc.maps", icon: "export", onClick: exportMaps}),
((!state.steam && !state.oculus) && {text: "pages.version-viewer.dropdown.edit", icon: "edit", onClick: edit}),
(!state.oculus && {text: "pages.version-viewer.dropdown.clone", icon: "copy", onClick: clone}),
((!state.steam && !state.oculus) && {text: "pages.version-viewer.dropdown.uninstall", icon:"trash", onClick: uninstall})
@@ -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);
}
}