[feat-75] support import for maps exported by BSM

This commit is contained in:
silentrald
2024-09-29 18:32:23 +08:00
parent 9d4acea654
commit eb119a31f0
13 changed files with 211 additions and 148 deletions
@@ -121,23 +121,7 @@ export function MapsPlaylistsPanel({ version, isActive }: Props) {
return;
}
const importCount = await mapsManager.importMaps(paths, version);
if (importCount === 0) {
return;
}
if (importCount < paths.length) {
notifications.notifySuccess({
title: "notifications.maps.import-map.titles.success",
desc: "notifications.maps.import-map.msgs.some-success",
});
return;
}
notifications.notifySuccess({
title: "notifications.maps.import-map.titles.success",
desc: "notifications.maps.import-map.msgs.success",
});
await mapsManager.importMaps(paths, version);
}
const dropDownItems = ((): DropDownItem[] => {
@@ -123,20 +123,24 @@ export const LocalMapsListPanel = forwardRef<LocalMapsListPanelRef, Props>(({ ve
}, [isActiveOnce, version])
const importListener = (importMap: BsmLocalMap, targetVersion?: BSVersion) => {
const importListener = (importMaps: BsmLocalMap[], targetVersion?: BSVersion) => {
if (!equal(targetVersion, version)) {
return;
}
const mapsCopy = maps ? [ ...maps ] : [];
// importMap can collide with existing map
const index = maps.findIndex(map => map.songDetails?.name === importMap.songDetails.name);
if (index > -1) {
mapsCopy.splice(index, 1);
for (const importMap of importMaps) {
if (importMap.songDetails) {
// importMap can collide with existing map
const index = maps.findIndex(map => map.songDetails?.name === importMap.songDetails.name);
if (index > -1) {
mapsCopy.splice(index, 1);
}
}
}
setMaps([importMap, ...mapsCopy]);
setMaps([...importMaps, ...mapsCopy]);
};
const loadMaps = () => {