Skip to content

Commit e22b327

Browse files
committed
Replace IDebugCastEnv with IMixinCastingContext
1 parent 06f96ce commit e22b327

File tree

7 files changed

+117
-52
lines changed

7 files changed

+117
-52
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package gay.object.hexdebug.mixin;
2+
3+
import at.petrak.hexcasting.api.spell.Action;
4+
import at.petrak.hexcasting.api.spell.casting.CastingContext;
5+
import gay.object.hexdebug.casting.eval.IMixinCastingContext;
6+
import gay.object.hexdebug.debugger.DebugStepType;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.server.level.ServerPlayer;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Unique;
13+
14+
/*
15+
class DebugItemCastEnv(
16+
caster: ServerPlayer,
17+
castingHand: InteractionHand,
18+
) : PackagedItemCastEnv(caster, castingHand), IDebugCastEnv {
19+
override var lastEvaluatedAction: Action? = null
20+
override var lastDebugStepType: DebugStepType? = null
21+
22+
override fun printMessage(message: Component) {
23+
super.printMessage(message)
24+
printDebugMessage(caster, message)
25+
}
26+
27+
override fun sendMishapMsgToPlayer(mishap: OperatorSideEffect.DoMishap) {
28+
super.sendMishapMsgToPlayer(mishap)
29+
mishap.mishap.errorMessageWithName(this, mishap.errorCtx)?.also {
30+
printDebugMessage(caster, it, OutputEventArgumentsCategory.STDERR)
31+
}
32+
}
33+
}
34+
*/
35+
36+
@Mixin(CastingContext.class)
37+
public abstract class MixinCastingContext implements IMixinCastingContext {
38+
@Unique
39+
private boolean isDebugging$hexdebug = false;
40+
@Nullable
41+
@Unique
42+
private Action lastEvaluatedAction$hexdebug = null;
43+
@Nullable
44+
@Unique
45+
private DebugStepType lastDebugStepType$hexdebug = null;
46+
47+
@Override
48+
public boolean isDebugging$hexdebug() {
49+
return isDebugging$hexdebug;
50+
}
51+
52+
@Override
53+
public void setDebugging$hexdebug(boolean isDebugging) {
54+
isDebugging$hexdebug = isDebugging;
55+
}
56+
57+
@Nullable
58+
@Override
59+
public Action getLastEvaluatedAction$hexdebug() {
60+
return lastEvaluatedAction$hexdebug;
61+
}
62+
63+
@Override
64+
public void setLastEvaluatedAction$hexdebug(@Nullable Action lastEvaluatedAction) {
65+
lastEvaluatedAction$hexdebug = lastEvaluatedAction;
66+
}
67+
68+
@Nullable
69+
@Override
70+
public DebugStepType getLastDebugStepType$hexdebug() {
71+
return lastDebugStepType$hexdebug;
72+
}
73+
74+
@Override
75+
public void setLastDebugStepType$hexdebug(@Nullable DebugStepType lastDebugStepType) {
76+
lastDebugStepType$hexdebug = lastDebugStepType;
77+
}
78+
79+
// TODO: are these necessary?
80+
81+
@Override
82+
public void printDebugMessage$hexdebug(@NotNull ServerPlayer caster, @NotNull Component message, @NotNull String category, boolean withSource) {
83+
IMixinCastingContext.super.printDebugMessage$hexdebug(caster, message, category, withSource);
84+
}
85+
86+
@Override
87+
public void reset$hexdebug() {
88+
IMixinCastingContext.super.reset$hexdebug();
89+
}
90+
}
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package gay.`object`.hexdebug.casting.actions
22

3-
import at.petrak.hexcasting.api.casting.asActionResult
4-
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
5-
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
6-
import at.petrak.hexcasting.api.casting.iota.Iota
7-
import gay.`object`.hexdebug.casting.eval.IDebugCastEnv
3+
import at.petrak.hexcasting.api.spell.ConstMediaAction
4+
import at.petrak.hexcasting.api.spell.asActionResult
5+
import at.petrak.hexcasting.api.spell.casting.CastingContext
6+
import at.petrak.hexcasting.api.spell.iota.Iota
7+
import gay.`object`.hexdebug.casting.eval.IMixinCastingContext
88

99
object OpIsDebugging : ConstMediaAction {
1010
override val argc = 0
1111

12-
override fun execute(args: List<Iota>, env: CastingEnvironment) = when (env) {
13-
is IDebugCastEnv -> env.isDebugging
14-
else -> false
15-
}.asActionResult
12+
@Suppress("CAST_NEVER_SUCCEEDS")
13+
override fun execute(args: List<Iota>, ctx: CastingContext) =
14+
((ctx as? IMixinCastingContext)?.`isDebugging$hexdebug` ?: false).asActionResult
1615
}

Common/src/main/kotlin/gay/object/hexdebug/casting/eval/DebugItemCastEnv.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

Common/src/main/kotlin/gay/object/hexdebug/casting/eval/IDebugCastEnv.kt renamed to Common/src/main/kotlin/gay/object/hexdebug/casting/eval/IMixinCastingContext.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import net.minecraft.network.chat.Component
77
import net.minecraft.server.level.ServerPlayer
88
import org.eclipse.lsp4j.debug.OutputEventArgumentsCategory
99

10-
interface IDebugCastEnv {
11-
val isDebugging get() = true
10+
@Suppress("PropertyName", "FunctionName")
11+
interface IMixinCastingContext {
12+
var `isDebugging$hexdebug`: Boolean
1213

13-
var lastEvaluatedAction: Action?
14-
var lastDebugStepType: DebugStepType?
14+
var `lastEvaluatedAction$hexdebug`: Action?
15+
var `lastDebugStepType$hexdebug`: DebugStepType?
1516

16-
fun reset() {
17-
lastEvaluatedAction = null
18-
lastDebugStepType = null
17+
fun `reset$hexdebug`() {
18+
`lastEvaluatedAction$hexdebug` = null
19+
`lastDebugStepType$hexdebug` = null
1920
}
2021

21-
fun printDebugMessage(
22+
fun `printDebugMessage$hexdebug`(
2223
caster: ServerPlayer,
2324
message: Component,
2425
category: String = OutputEventArgumentsCategory.STDOUT,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package gay.`object`.hexdebug.debugger
22

3-
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
4-
import at.petrak.hexcasting.api.casting.iota.Iota
3+
import at.petrak.hexcasting.api.spell.casting.CastingContext
4+
import at.petrak.hexcasting.api.spell.iota.Iota
55
import net.minecraft.server.level.ServerLevel
66

77
data class CastArgs(
88
val iotas: List<Iota>,
9-
val env: CastingEnvironment,
9+
val env: CastingContext,
1010
val world: ServerLevel,
1111
val onExecute: ((Iota) -> Unit)? = null
12-
)
12+
)

Common/src/main/kotlin/gay/object/hexdebug/debugger/HexDebugger.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class HexDebugger(
4545
castArgs: CastArgs,
4646
) : this(initArgs, launchArgs, CastingHarness(castArgs.env), castArgs.world, castArgs.onExecute, castArgs.iotas)
4747

48-
val debugCastEnv = vm.ctx as IDebugCastEnv
48+
@Suppress("CAST_NEVER_SUCCEEDS")
49+
val debugCastEnv = vm.ctx as IMixinCastingContext
4950

5051
var lastEvaluatedMetadata: IotaMetadata? = null
5152
private set
@@ -401,7 +402,7 @@ class HexDebugger(
401402
val info = CastingHarness.TempControllerInfo(earlyExit = false)
402403
var sound = HexEvalSounds.NOTHING
403404
while (continuation is NotDone && !info.earlyExit) {
404-
debugCastEnv.reset()
405+
debugCastEnv.`reset$hexdebug`()
405406

406407
// Take the top of the continuation stack...
407408
val frame = continuation.frame
@@ -478,7 +479,7 @@ class HexDebugger(
478479
}
479480

480481
// insert a virtual FrameFinishEval if OpEval didn't (ie. if we did a TCO)
481-
if (launchArgs.showTailCallFrames && debugCastEnv.lastEvaluatedAction is OpEval) {
482+
if (launchArgs.showTailCallFrames && debugCastEnv.`lastEvaluatedAction$hexdebug` is OpEval) {
482483
val invokeMeta = iotaMetadata[cast]
483484
val nextInvokeMeta = frameInvocationMetadata[newContinuation.next]?.invoke()
484485
if (invokeMeta != null && invokeMeta != nextInvokeMeta) {
@@ -631,7 +632,7 @@ class HexDebugger(
631632
return DebugStepType.IN
632633
}
633634

634-
return debugCastEnv.lastDebugStepType
635+
return debugCastEnv.`lastDebugStepType$hexdebug`
635636
}
636637

637638
private fun setIotaOverrides(

Common/src/main/resources/hexdebug-common.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"MixinShiftScrollListener"
88
],
99
"mixins": [
10+
"MixinCastingContext",
1011
"MixinFrameEvaluate",
1112
"MixinMsgShiftScrollC2S",
1213
"MixinOpEval"

0 commit comments

Comments
 (0)