Readded auto-trace
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
D4rkr34lm 2024-03-01 23:48:53 +01:00
Ursprung 1094f4a979
Commit 0c37cfc3bb
2 geänderte Dateien mit 42 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -43,12 +43,12 @@ public class Recorder implements Listener {
public TraceManager manager;
/**
* Map for all traces beeing activly recorded
* Map for all traces being actively recorded
*/
private final Map<Region, Trace> activeTraces = new HashMap<>();
/**
* Map for all tnts being traced, by region
* Map for all TNTs being traced, by region
*/
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
@ -58,22 +58,39 @@ public class Recorder implements Listener {
private final Map<TNTPrimed, Region> tntSpawnRegion = new HashMap<>();
/**
* Maps a tracked tnt entity to the last record taken of it
* Maps a tracked tnt entity to its entire recording history
*/
private final Map<TNTPrimed, List<TNTRecord>> historyMap = new HashMap<>();
/**
* Regions where auto-trace is enabled
*/
private final Set<Region> autoTraceRegions = new HashSet<>();
public Recorder(){
BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1);
}
/** Toggles auto trace for the given region
*
* @param region
*/
public void toggleAutoTrace(Region region) {
if (autoTraceRegions.contains(region))
autoTraceRegions.remove(region);
else
autoTraceRegions.add(region);
}
/** Starts a recording at the given region
*
* @param region region to be recorded
* @
*/
public int startRecording(Region region){
public void startRecording(Region region){
if(activeTraces.containsKey(region)) return;
Trace trace = new Trace(region);
activeTraces.put(region, trace);
return manager.add(trace);
}
/** Stops the recording at the given region
@ -81,7 +98,8 @@ public class Recorder implements Listener {
* @param region region to stop recording
*/
public void stopRecording(Region region){
Trace trace = activeTraces.get(region);
Trace trace = activeTraces.getOrDefault(region, null);
if (trace == null) return;
trace.setRecords(Collections.unmodifiableList(trace.getRecords()));
activeTraces.remove(region);
@ -136,6 +154,10 @@ public class Recorder implements Listener {
if(!(event.getEntity() instanceof TNTPrimed)) return;
Region region = Region.getRegion(event.getLocation());
if(autoTraceRegions.contains(region) && !activeTraces.containsKey(region))
startRecording(region);
if(activeTraces.containsKey(region)){
//Check whether set for tracking already exists. Creating it if necessary
if(!trackedTNT.containsKey(region))

Datei anzeigen

@ -29,33 +29,24 @@ import java.util.stream.Collectors;
@Linked
public class TraceManager implements Listener {
/**
* Map of all current traces
* List of all current traces
*/
private final Map<Integer, Trace> traces = new HashMap<>();
/**
* Utility variable to keep track of the next open trace id
*/
private int currOpenId = 0;
private final List<Trace> traces = new ArrayList<>();
/** Adds a new trace to the global record
*
* @param trace Trace to be added
* @return id of the newly added trace
*/
protected int add(Trace trace){
int id = currOpenId;
traces.put(id, trace);
currOpenId++;
return id;
protected void add(Trace trace){
traces.add(trace);
}
/** Removes the trace with the given id
*
* @param id Id of the trace to be removed
* @param index index of the trace to be removed
*/
public void remove(int id){
traces.remove(id);
public void remove(int index){
traces.remove(index);
}
/** Clears all traces
@ -63,7 +54,6 @@ public class TraceManager implements Listener {
*/
public void clear(){
traces.clear();
currOpenId = 0;
}
/** Methode to get all traces in a certain region
@ -72,21 +62,19 @@ public class TraceManager implements Listener {
* @return All traces recorded in the given Region
*/
public Set<Trace> get(Region region){
return traces.values()
.stream()
return traces.stream()
.filter((Trace trace) -> trace.getRegion() == region)
.collect(Collectors.toSet());
}
/** Methode to get the trace with specific id
*
* @param id id of the trace
* @param index index of the trace
* @return the trace with given id or null if no trace with id is found
*/
public Optional<Trace> get(int id){
Trace ret = traces.get(id);
if(traces.containsKey(id))
return Optional.of(traces.get(id));
public Optional<Trace> get(int index){
if(index < traces.size())
return Optional.of(traces.get(index));
return Optional.empty();
}
@ -94,7 +82,7 @@ public class TraceManager implements Listener {
*
* @return fresh set of all current traces
*/
public Set<Trace> getAll(){
return new HashSet<>(traces.values());
public List<Trace> getAll(){
return new ArrayList<>(traces);
}
}