Skip to content

Commit 3d27d42

Browse files
committed
Unignore env directory
1 parent 05ae2a6 commit 3d27d42

File tree

4 files changed

+248
-2
lines changed

4 files changed

+248
-2
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ celerybeat.pid
156156
# Environments
157157
.env
158158
.venv
159-
env/
160159
venv/
161-
ENV/
162160
env.bak/
163161
venv.bak/
164162

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package gay.object.hexdebug.core.api.debugging.env;
2+
3+
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
4+
import net.minecraft.server.level.ServerPlayer;
5+
import org.jetbrains.annotations.ApiStatus;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
@ApiStatus.NonExtendable
10+
public abstract class BaseCircleDebugEnv extends DebugEnvironment {
11+
@Nullable
12+
private CastingImage newImage;
13+
14+
protected BaseCircleDebugEnv(@NotNull ServerPlayer caster) {
15+
super(caster);
16+
}
17+
18+
@Nullable
19+
public CastingImage getNewImage() {
20+
return newImage;
21+
}
22+
23+
public void setNewImage(@Nullable CastingImage newImage) {
24+
this.newImage = newImage;
25+
}
26+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package gay.object.hexdebug.core.api.debugging.env;
2+
3+
import at.petrak.hexcasting.api.casting.castables.Action;
4+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
5+
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType;
6+
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect;
7+
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
8+
import gay.object.hexdebug.core.api.HexDebugCoreAPI;
9+
import gay.object.hexdebug.core.api.debugging.DebugOutputCategory;
10+
import gay.object.hexdebug.core.api.debugging.DebugStepType;
11+
import net.minecraft.network.chat.Component;
12+
import net.minecraft.server.level.ServerPlayer;
13+
import org.jetbrains.annotations.ApiStatus;
14+
import org.jetbrains.annotations.Contract;
15+
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
import java.util.UUID;
19+
20+
/**
21+
* Like {@link CastingEnvironment}, but for debugging.
22+
*/
23+
public abstract class DebugEnvironment {
24+
@NotNull
25+
private final ServerPlayer caster;
26+
@NotNull
27+
private final UUID sessionId = UUID.randomUUID();
28+
@Nullable
29+
private DebugStepType lastDebugStepType = null;
30+
@Nullable
31+
private Action lastEvaluatedAction = null;
32+
33+
protected DebugEnvironment(@NotNull ServerPlayer caster) {
34+
this.caster = caster;
35+
}
36+
37+
/**
38+
* Attempts to resume execution of the debuggee. This is called by the debugger after the
39+
* current continuation is successfully evaluated to completion.
40+
* @return true if the debug session can continue, or false if the debuggee should be terminated
41+
*/
42+
public abstract boolean resume(
43+
@NotNull CastingEnvironment env,
44+
@NotNull CastingImage image,
45+
@NotNull ResolvedPatternType resolutionType
46+
);
47+
48+
/**
49+
* Attempts to restart the debuggee on the given debug thread. This is called by the debugger
50+
* when requested by the user.
51+
* <br>
52+
* The previous debug thread is removed before this method is called, so the implementation may
53+
* use {@link HexDebugCoreAPI#createDebugThread} and {@link HexDebugCoreAPI#startDebuggingIotas}.
54+
* However, note that {@link DebugEnvironment} is <strong>not</strong> called before this
55+
* method, so it's up to the implementation whether they need to call that or not.
56+
*/
57+
public abstract void restart(int threadId);
58+
59+
/**
60+
* Terminates the debuggee. This is called by the debugger after {@link DebugEnvironment#resume}
61+
* returns {@code false}, during {@link HexDebugCoreAPI#terminateDebugThread}, or when requested
62+
* by the user.
63+
*/
64+
public abstract void terminate();
65+
66+
/**
67+
* For in-world debugees, returns whether the caster is close enough to the debuggee to allow
68+
* debug-related actions to be performed (eg. pause, step, restart).
69+
*/
70+
@Contract(pure = true)
71+
public abstract boolean isCasterInRange();
72+
73+
/**
74+
* Returns a display name for this debug session.
75+
* <br>
76+
* For example, debugger items return the name of the item, and spell circles return the name of
77+
* the impetus.
78+
*/
79+
@Contract(pure = true)
80+
@NotNull
81+
public abstract Component getName();
82+
83+
public void printDebugMessage(@NotNull Component message) {
84+
printDebugMessage(message, DebugOutputCategory.STDOUT, true);
85+
}
86+
87+
public void printDebugMessage(
88+
@NotNull Component message,
89+
@NotNull DebugOutputCategory category
90+
) {
91+
printDebugMessage(message, category, true);
92+
}
93+
94+
public void printDebugMessage(
95+
@NotNull Component message,
96+
@NotNull DebugOutputCategory category,
97+
boolean withSource
98+
) {
99+
HexDebugCoreAPI.INSTANCE.printDebugMessage(caster, sessionId, message, category, withSource);
100+
}
101+
102+
public void printDebugMishap(
103+
@NotNull CastingEnvironment env,
104+
@NotNull OperatorSideEffect.DoMishap sideEffect
105+
) {
106+
var message = sideEffect.getMishap().errorMessageWithName(env, sideEffect.getErrorCtx());
107+
if (message != null) {
108+
printDebugMessage(message, DebugOutputCategory.STDERR);
109+
}
110+
}
111+
112+
@Contract(pure = true)
113+
public boolean isDebugging() {
114+
return HexDebugCoreAPI.INSTANCE.isSessionDebugging(this);
115+
}
116+
117+
@NotNull
118+
public ServerPlayer getCaster() {
119+
return caster;
120+
}
121+
122+
@NotNull
123+
public UUID getSessionId() {
124+
return sessionId;
125+
}
126+
127+
@ApiStatus.Internal
128+
@Nullable
129+
public DebugStepType getLastDebugStepType() {
130+
return lastDebugStepType;
131+
}
132+
133+
@ApiStatus.Internal
134+
public void setLastDebugStepType(@Nullable DebugStepType lastDebugStepType) {
135+
this.lastDebugStepType = lastDebugStepType;
136+
}
137+
138+
@ApiStatus.Internal
139+
@Nullable
140+
public Action getLastEvaluatedAction() {
141+
return lastEvaluatedAction;
142+
}
143+
144+
@ApiStatus.Internal
145+
public void setLastEvaluatedAction(@Nullable Action lastEvaluatedAction) {
146+
this.lastEvaluatedAction = lastEvaluatedAction;
147+
}
148+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package gay.object.hexdebug.core.api.debugging.env;
2+
3+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
4+
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType;
5+
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
6+
import at.petrak.hexcasting.api.casting.iota.Iota;
7+
import gay.object.hexdebug.core.api.HexDebugCoreAPI;
8+
import gay.object.hexdebug.core.api.exceptions.DebugException;
9+
import gay.object.hexdebug.core.api.exceptions.IllegalDebugSessionException;
10+
import gay.object.hexdebug.core.api.exceptions.IllegalDebugThreadException;
11+
import net.minecraft.network.chat.Component;
12+
import net.minecraft.server.level.ServerPlayer;
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
import java.util.List;
17+
18+
public class SimplePlayerBasedDebugEnv extends DebugEnvironment {
19+
@NotNull
20+
private final CastingEnvironment env;
21+
@NotNull
22+
private final List<Iota> iotas;
23+
@NotNull
24+
private final Component name;
25+
26+
public SimplePlayerBasedDebugEnv(
27+
@NotNull ServerPlayer caster,
28+
@NotNull CastingEnvironment env,
29+
@NotNull List<Iota> iotas,
30+
@NotNull Component name
31+
) {
32+
super(caster);
33+
this.env = env;
34+
this.iotas = iotas;
35+
this.name = name;
36+
}
37+
38+
@Override
39+
public boolean resume(
40+
@NotNull CastingEnvironment env,
41+
@NotNull CastingImage image,
42+
@NotNull ResolvedPatternType resolutionType
43+
) {
44+
return false;
45+
}
46+
47+
@Override
48+
public void restart(int threadId) {
49+
try {
50+
start(threadId);
51+
} catch (DebugException ignored) {}
52+
}
53+
54+
@Override
55+
public void terminate() {}
56+
57+
@Override
58+
public boolean isCasterInRange() {
59+
return true;
60+
}
61+
62+
@Override
63+
@NotNull
64+
public Component getName() {
65+
return name;
66+
}
67+
68+
public void start(@Nullable Integer threadId)
69+
throws IllegalDebugSessionException, IllegalDebugThreadException
70+
{
71+
HexDebugCoreAPI.INSTANCE.createDebugThread(this, threadId);
72+
HexDebugCoreAPI.INSTANCE.startDebuggingIotas(this, env, iotas, null);
73+
}
74+
}

0 commit comments

Comments
 (0)