SteamWar/BauSystem2.0
Archiviert
12
0

Merge pull request 'Trace now closes on being deleted' (#238) from trace/trace-clear-not-stopping-trace-fix into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #238
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
YoyoNow 2024-04-22 20:20:09 +02:00
Commit 18769a6931
2 geänderte Dateien mit 22 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -132,6 +132,11 @@ public class TraceManager implements Listener {
* @param trace the trace to be removed * @param trace the trace to be removed
*/ */
public boolean remove(Trace trace) { public boolean remove(Trace trace) {
Optional<Trace> activeTrace = TraceRecorder.instance.getActiveTraceForRegion(trace.getRegion());
if (activeTrace.isPresent() && activeTrace.get() == trace) {
TraceRecorder.instance.stopRecording(trace.getRegion());
}
Map<Integer, Trace> traces = tracesByRegion.getOrDefault(trace.getRegion(), Collections.emptyMap()); Map<Integer, Trace> traces = tracesByRegion.getOrDefault(trace.getRegion(), Collections.emptyMap());
Integer traceId = traces.entrySet().stream() Integer traceId = traces.entrySet().stream()
.filter(entry -> entry.getValue() == trace) .filter(entry -> entry.getValue() == trace)
@ -148,6 +153,7 @@ public class TraceManager implements Listener {
* Clears all traces * Clears all traces
*/ */
public void clear(Region region) { public void clear(Region region) {
TraceRecorder.instance.stopRecording(region);
showDataPerRegionPerPlayer.getOrDefault(region, new HashMap<>()) showDataPerRegionPerPlayer.getOrDefault(region, new HashMap<>())
.keySet() .keySet()
.forEach(player -> { .forEach(player -> {

Datei anzeigen

@ -185,6 +185,22 @@ public class TraceRecorder implements Listener {
return activeTraces.containsKey(region); return activeTraces.containsKey(region);
} }
/**
* Get the trace that is currently recorded in the given region
*
* @param region the region to get the trace for
* @return the trace recorded in region or empty if no trace is recorded in region
*/
public Optional<Trace> getActiveTraceForRegion(Region region) {
TraceRecordingWrapper traceWrapper = activeTraces.get(region);
if (traceWrapper == null) {
return Optional.empty();
} else {
return Optional.of(traceWrapper.getTrace());
}
}
public long getStartTimeOfTraceInRegion(Region region) { public long getStartTimeOfTraceInRegion(Region region) {
TraceRecordingWrapper wrapper = activeTraces.get(region); TraceRecordingWrapper wrapper = activeTraces.get(region);
if (wrapper == null) return 0; if (wrapper == null) return 0;