Skip to content

Commit 17d14bc

Browse files
committed
Variables and Operators Implementation
1 parent 5c16e9e commit 17d14bc

File tree

8 files changed

+840
-44
lines changed

8 files changed

+840
-44
lines changed

src/main/java/com/pathmind/PathmindClientMod.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.pathmind.screen.PathmindMainMenuIntegration;
77
import com.pathmind.screen.PathmindScreens;
88
import com.pathmind.ui.overlay.ActiveNodeOverlay;
9+
import com.pathmind.ui.overlay.VariablesOverlay;
910
import com.pathmind.util.BaritoneDependencyChecker;
1011
import net.fabricmc.api.ClientModInitializer;
1112
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
@@ -25,6 +26,7 @@
2526
public class PathmindClientMod implements ClientModInitializer {
2627
private static final Logger LOGGER = LoggerFactory.getLogger("Pathmind/Client");
2728
private ActiveNodeOverlay activeNodeOverlay;
29+
private VariablesOverlay variablesOverlay;
2830
private volatile boolean worldShutdownHandled;
2931
private boolean baritoneAvailable;
3032
private boolean missingWarningShown;
@@ -37,6 +39,7 @@ public void onInitializeClient() {
3739
baritoneAvailable = BaritoneDependencyChecker.isBaritoneApiPresent();
3840
if (baritoneAvailable) {
3941
this.activeNodeOverlay = new ActiveNodeOverlay();
42+
this.variablesOverlay = new VariablesOverlay();
4043
}
4144

4245
// Register keybindings
@@ -70,11 +73,16 @@ public void onInitializeClient() {
7073
});
7174

7275
// Register HUD render callback for the active node overlay
73-
if (activeNodeOverlay != null) {
76+
if (activeNodeOverlay != null || variablesOverlay != null) {
7477
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
7578
MinecraftClient client = MinecraftClient.getInstance();
7679
if (client.player != null && client.textRenderer != null) {
77-
activeNodeOverlay.render(drawContext, client.textRenderer, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
80+
if (activeNodeOverlay != null) {
81+
activeNodeOverlay.render(drawContext, client.textRenderer, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
82+
}
83+
if (variablesOverlay != null) {
84+
variablesOverlay.render(drawContext, client.textRenderer, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
85+
}
7886
}
7987
});
8088
}

src/main/java/com/pathmind/execution/ExecutionManager.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,54 @@ public class ExecutionManager {
6666
private static class ChainController {
6767
final Node startNode;
6868
volatile boolean cancelRequested;
69+
final Map<String, RuntimeVariable> runtimeVariables;
6970

7071
ChainController(Node startNode) {
7172
this.startNode = startNode;
7273
this.cancelRequested = false;
74+
this.runtimeVariables = new ConcurrentHashMap<>();
75+
}
76+
}
77+
78+
public static final class RuntimeVariable {
79+
private final NodeType type;
80+
private final Map<String, String> values;
81+
82+
public RuntimeVariable(NodeType type, Map<String, String> values) {
83+
this.type = type;
84+
this.values = values == null ? Collections.emptyMap() : new HashMap<>(values);
85+
}
86+
87+
public NodeType getType() {
88+
return type;
89+
}
90+
91+
public Map<String, String> getValues() {
92+
return Collections.unmodifiableMap(values);
93+
}
94+
}
95+
96+
public static final class RuntimeVariableEntry {
97+
private final String startNodeId;
98+
private final String name;
99+
private final RuntimeVariable variable;
100+
101+
public RuntimeVariableEntry(String startNodeId, String name, RuntimeVariable variable) {
102+
this.startNodeId = startNodeId;
103+
this.name = name;
104+
this.variable = variable;
105+
}
106+
107+
public String getStartNodeId() {
108+
return startNodeId;
109+
}
110+
111+
public String getName() {
112+
return name;
113+
}
114+
115+
public RuntimeVariable getVariable() {
116+
return variable;
73117
}
74118
}
75119

@@ -138,6 +182,49 @@ public static ExecutionManager getInstance() {
138182
return instance;
139183
}
140184

185+
public boolean setRuntimeVariable(Node startNode, String name, RuntimeVariable value) {
186+
if (startNode == null || name == null || name.trim().isEmpty() || value == null) {
187+
return false;
188+
}
189+
ChainController controller = activeChains.get(startNode);
190+
if (controller == null) {
191+
return false;
192+
}
193+
controller.runtimeVariables.put(name.trim(), value);
194+
return true;
195+
}
196+
197+
public RuntimeVariable getRuntimeVariable(Node startNode, String name) {
198+
if (startNode == null || name == null || name.trim().isEmpty()) {
199+
return null;
200+
}
201+
ChainController controller = activeChains.get(startNode);
202+
if (controller == null) {
203+
return null;
204+
}
205+
return controller.runtimeVariables.get(name.trim());
206+
}
207+
208+
public List<RuntimeVariableEntry> getRuntimeVariableEntries() {
209+
if (activeChains.isEmpty()) {
210+
return Collections.emptyList();
211+
}
212+
List<RuntimeVariableEntry> entries = new ArrayList<>();
213+
for (ChainController controller : activeChains.values()) {
214+
if (controller == null || controller.runtimeVariables.isEmpty()) {
215+
continue;
216+
}
217+
String startId = controller.startNode != null ? controller.startNode.getId() : "";
218+
for (Map.Entry<String, RuntimeVariable> entry : controller.runtimeVariables.entrySet()) {
219+
if (entry.getKey() == null || entry.getValue() == null) {
220+
continue;
221+
}
222+
entries.add(new RuntimeVariableEntry(startId, entry.getKey(), entry.getValue()));
223+
}
224+
}
225+
return entries;
226+
}
227+
141228
public void executeGraph(List<Node> nodes, List<NodeConnection> connections) {
142229
executeGraphInternal(nodes, connections, true);
143230
}

0 commit comments

Comments
 (0)