Skip to content

Commit

Permalink
ok, added inavid_operator_args and associated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kineticneticat committed Jul 12, 2024
1 parent e73025f commit a2db04c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class OperationAction(val pattern: HexPattern) : Action {
return try {
HexArithmetics.getEngine().run(pattern, env, image, continuation)
} catch (e: NoOperatorCandidatesException) {
throw MishapInvalidOperatorArgs(e.args, e.pattern)
throw MishapInvalidOperatorArgs(e.args)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package at.petrak.hexcasting.api.casting.mishaps

import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.ComponentContents
import net.minecraft.network.chat.MutableComponent
import net.minecraft.world.item.DyeColor

/**
* The value failed some kind of predicate.
*/
class MishapInvalidOperatorArgs(
private val perpetrators: List<Iota>
) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
for (i in perpetrators.indices) {
stack[stack.size - 1 - i] = GarbageIota()
}
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component {
return if (perpetrators.size == 1) {
error(
"invalid_operator_args.single",
0,
perpetrators[0].display()
)
} else {
error(
"invalid_operator_args.plural",
perpetrators.size,
0,
perpetrators.lastIndex,
collateIotas(perpetrators)
)
}
}
private fun collateIotas(iotas: List<Iota>): MutableComponent {
val out = MutableComponent.create(ComponentContents.EMPTY)
for (i in iotas.indices) {
out.append(iotas[i].display())
if (i < iotas.size-1) {
out.append(", ")
}
}
return out
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,11 @@
cos: "the cosine of %s",
},

invalid_operator_args: {
single: "Got an unexpected iota at index %d of the stack: %s",
plural: "Got %d unexpected iotas at indices %d-%d of the stack: %s",
},

no_akashic_record: "No Akashic Record at %s",
disallowed: "has been disallowed by the server admins",
disallowed_circle: "has been disallowed in spell circles by the server admins",
Expand Down

0 comments on commit a2db04c

Please sign in to comment.