Also reset texture-gallery on map-purge

This commit is contained in:
Lukas Rieger (Blue) 2022-11-28 20:38:34 +01:00
parent 0fc1424021
commit 1368f86d13
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
3 changed files with 18 additions and 3 deletions

View File

@ -29,6 +29,7 @@
import de.bluecolored.bluemap.core.storage.Storage;
import de.bluecolored.bluemap.core.storage.file.FileStorage;
import de.bluecolored.bluemap.core.util.DeletingPathVisitor;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.nio.file.Files;
@ -56,7 +57,7 @@ public static MapPurgeTask create(Path mapDirectory) throws IOException {
@DebugDump
private static class MapFilePurgeTask extends MapPurgeTask {
private final BmMap map;
@Nullable private final BmMap map;
private final Path directory;
private final int subFilesCount;
private final LinkedList<Path> subFiles;
@ -72,7 +73,7 @@ public MapFilePurgeTask(BmMap map, FileStorage fileStorage) throws IOException {
this(map, fileStorage.getFilePath(map.getId()));
}
private MapFilePurgeTask(BmMap map, Path directory) throws IOException {
private MapFilePurgeTask(@Nullable BmMap map, Path directory) throws IOException {
this.map = map;
this.directory = directory;
try (Stream<Path> pathStream = Files.walk(directory, 3)) {
@ -92,7 +93,7 @@ public void doWork() throws Exception {
try {
// save lowres-tile-manager to clear/flush any buffered data
this.map.getLowresTileManager().save();
if (this.map != null) this.map.getLowresTileManager().save();
// delete subFiles first to be able to track the progress and cancel
while (!subFiles.isEmpty()) {
@ -106,6 +107,10 @@ public void doWork() throws Exception {
if (Files.exists(directory)) {
Files.walkFileTree(directory, DeletingPathVisitor.INSTANCE);
}
// reset texture-gallery
if (this.map != null) this.map.resetTextureGallery();
} finally {
// reset map render state
if (this.map != null) {

View File

@ -181,6 +181,11 @@ private void saveTextureGallery() {
}
}
public synchronized void resetTextureGallery() {
this.textureGallery.clear();
this.textureGallery.put(this.resourcePack);
}
private void saveMapSettings() {
try (
OutputStream out = storage.writeMeta(id, MetaType.SETTINGS);

View File

@ -24,6 +24,11 @@ public TextureGallery() {
this.nextId = 0;
}
public void clear() {
this.ordinalMap.clear();
this.nextId = 0;
}
public int get(@Nullable ResourcePath<Texture> textureResourcePath) {
if (textureResourcePath == null) textureResourcePath = ResourcePack.MISSING_TEXTURE;
Integer ordinal = ordinalMap.get(textureResourcePath);