package net.sonickat.sklib.common; import java.time.Instant; import java.util.ArrayList; import java.util.List; public class DebugQueueEvent { private final String message; private final String timestamp; private final CRef affectedBlock; private final List callStack; // Tracks full chain of triggers public DebugQueueEvent(String message, CRef affectedBlock, List callStack) { this.timestamp = Instant.now().toString(); this.message = message; this.affectedBlock = affectedBlock; // Copy call stack + add this block this.callStack = new ArrayList<>(callStack); this.callStack.add(affectedBlock); } public String getMessage() { return message; } public String getTimestamp() { return timestamp; } public CRef getAffectedBlock() { return affectedBlock; } public List getCallStack() { return callStack; } /** * Formats the call stack for console output, limiting excessive length. */ private String formatCallStack() { int size = callStack.size(); int maxLength = DebugQueue.MAX_CONSOLE_CHAIN_LENGTH; // Controlled by DebugQueue if (size <= maxLength) { return callStack.toString(); // Show full list if small } // Show first, '...', last few elements (e.g., [..., B, C, D]) List reducedStack = new ArrayList<>(); reducedStack.add(callStack.get(0)); // Always include the origin reducedStack.add(new CRef(0, 0, 0)); // Placeholder for "..." reducedStack.addAll(callStack.subList(size - (maxLength - 1), size)); return reducedStack.toString().replace(new CRef(0, 0, 0).toString(), "..."); } @Override public String toString() { return "[" + timestamp + "] (" + affectedBlock + ") <- " + formatCallStack() + " " + message; } }