Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization for hexcasting.mishap.invalid_operator_args and associated stuff #695

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading