better mishap messages for bitwise ops
This commit is contained in:
parent
554e293f17
commit
8878dc4048
5 changed files with 29 additions and 18 deletions
|
@ -17,4 +17,15 @@ object MathOpUtils {
|
|||
TranslatableComponent("hexcasting.mishap.invalid_value.numvec")
|
||||
)
|
||||
}
|
||||
|
||||
fun GetNumOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, List<SpellDatum<*>>> =
|
||||
when (datum.payload) {
|
||||
is Double -> Either.left(datum.payload)
|
||||
is List<*> -> Either.right(datum.payload.filterIsInstance<SpellDatum<*>>())
|
||||
else -> throw MishapInvalidIota(
|
||||
datum,
|
||||
reverseIdx,
|
||||
TranslatableComponent("hexcasting.mishap.invalid_value.numlist")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.bit
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.DatumType
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpAnd : ConstManaOperator {
|
||||
override val argc = 2
|
||||
|
||||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
|
||||
val type = args[0].getType()
|
||||
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
|
||||
|
||||
if (type == DatumType.LIST) {
|
||||
val list1 = args.getChecked<List<SpellDatum<*>>>(0)
|
||||
if (firstParam.right().isPresent) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<List<SpellDatum<*>>>(1)
|
||||
return spellListOf(list1.filter { it in list2 })
|
||||
}
|
||||
|
||||
val num1 = args.getChecked<Double>(0).roundToInt()
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1).roundToInt()
|
||||
return spellListOf((num1 and num2).toDouble())
|
||||
}
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.bit
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.DatumType
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpOr : ConstManaOperator {
|
||||
override val argc = 2
|
||||
|
||||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
|
||||
val type = args[0].getType()
|
||||
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
|
||||
|
||||
if (type == DatumType.LIST) {
|
||||
val list1 = args.getChecked<List<SpellDatum<*>>>(0)
|
||||
if (firstParam.right().isPresent) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<List<SpellDatum<*>>>(1)
|
||||
return spellListOf(list1 + list2.filter { it !in list1 })
|
||||
}
|
||||
|
||||
val num1 = args.getChecked<Double>(0).roundToInt()
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1).roundToInt()
|
||||
return spellListOf((num1 or num2).toDouble())
|
||||
}
|
||||
|
|
|
@ -1,27 +1,26 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.bit
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.DatumType
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
|
||||
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpXor : ConstManaOperator {
|
||||
override val argc = 2
|
||||
|
||||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
|
||||
val type = args[0].getType()
|
||||
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
|
||||
|
||||
if (type == DatumType.LIST) {
|
||||
val list1 = args.getChecked<List<SpellDatum<*>>>(0)
|
||||
if (firstParam.right().isPresent) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<List<SpellDatum<*>>>(1)
|
||||
return spellListOf(list1.filter { it !in list2 } + list2.filter { it !in list1 })
|
||||
}
|
||||
|
||||
val num1 = args.getChecked<Double>(0).roundToInt()
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1).roundToInt()
|
||||
return spellListOf((num1 xor num2).toDouble())
|
||||
}
|
||||
|
|
|
@ -346,6 +346,7 @@
|
|||
"hexcasting.mishap.invalid_value.class.entity": "an entity",
|
||||
"hexcasting.mishap.invalid_value.class.unknown": "(unknown, uh-oh, this is a bug)",
|
||||
"hexcasting.mishap.invalid_value.numvec": "a number or vector",
|
||||
"hexcasting.mishap.invalid_value.numlist": "a number or list",
|
||||
"hexcasting.mishap.invalid_value.list.pattern": "a list of patterns",
|
||||
"hexcasting.mishap.invalid_value.int": "an integer",
|
||||
"hexcasting.mishap.invalid_value.double.between": "a number between %d and %d",
|
||||
|
|
Loading…
Reference in a new issue