only save once when checking/unchecking all visible markers

This commit is contained in:
Meduris 2025-08-04 22:50:28 +02:00
parent c195baf2ea
commit 78eebbd507
2 changed files with 13 additions and 2 deletions

View File

@ -52,6 +52,7 @@ public class Registry {
Map<UUID, Collectable> collectables = new LinkedHashMap<>(); Map<UUID, Collectable> collectables = new LinkedHashMap<>();
Set<UUID> completed = new HashSet<>(); Set<UUID> completed = new HashSet<>();
Object syncObj = new Object(); Object syncObj = new Object();
boolean bulkOperationActive = false;
public void load() { public void load() {
parseRegistry("/assets/data/medals.json", CollectableType.MEDAL); parseRegistry("/assets/data/medals.json", CollectableType.MEDAL);
@ -202,14 +203,22 @@ public class Registry {
public void markComplete(UUID id) { public void markComplete(UUID id) {
completed.add(id); completed.add(id);
save(); if (bulkOperationActive) save();
} }
public void unmarkComplete(UUID id) { public void unmarkComplete(UUID id) {
completed.remove(id); completed.remove(id);
save(); if (bulkOperationActive) save();
} }
public void setBulkOperation(boolean bulk) {
bulkOperationActive = bulk;
if (!bulk) {
save();
}
}
public boolean isCompleted(UUID id) { public boolean isCompleted(UUID id) {
return completed.contains(id); return completed.contains(id);
} }

View File

@ -345,7 +345,9 @@ public class MapPanel extends JPanel {
} }
public void setCompletionState(boolean value) { public void setCompletionState(boolean value) {
Registry.INSTANCE.setBulkOperation(true);
visibleMarkers.forEach(T -> T.setCompletion(value)); visibleMarkers.forEach(T -> T.setCompletion(value));
Registry.INSTANCE.setBulkOperation(false);
} }
@Override @Override