goofed the pattern for reverski, aaalmost add lastN

This commit is contained in:
Noobulus 2022-02-02 14:45:35 -06:00
parent b418bcfd9b
commit 7bece78121
2 changed files with 37 additions and 1 deletions

View file

@ -291,7 +291,7 @@ public class RegisterPatterns {
OpSingleton.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqaeaae", HexDir.NORTH_EAST), prefix("empty_list"),
OpEmptyList.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqaedae", HexDir.EAST), prefix("reverse_list"),
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqaede", HexDir.EAST), prefix("reverse_list"),
OpReverski.INSTANCE);
} catch (PatternRegistry.RegisterPatternException exn) {

View file

@ -0,0 +1,36 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.OperationResult
import at.petrak.hexcasting.api.Operator
import at.petrak.hexcasting.api.Operator.Companion.getChecked
import at.petrak.hexcasting.api.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.SpellDatum
import at.petrak.hexcasting.common.casting.CastException
import at.petrak.hexcasting.common.casting.CastingContext
import at.petrak.hexcasting.common.casting.OperatorSideEffect
object OpLastNToList : Operator {
val manaCost: Int
get() = 0
override fun operate(stack: MutableList<SpellDatum<*>>, ctx: CastingContext): OperationResult {
if (stack.isEmpty())
throw CastException(CastException.Reason.NOT_ENOUGH_ARGS, 1, stack.size)
val arg = stack.takeLast(1).getChecked<Double>(0)
stack.removeLast()
if (arg < 0) {
throw CastException(CastException.Reason.INVALID_VALUE, "integer greater than 0", arg)
}
val output = emptyList<SpellDatum<*>>()
output.toMutableList().addAll(stack.takeLast(arg.toInt()))
val endSize = stack.size - output.toList().size
while (stack.size != endSize) {
stack.removeLast()
}
stack.add(spellListOf(output))
val sideEffects = mutableListOf<OperatorSideEffect>(OperatorSideEffect.ConsumeMana(this.manaCost))
return OperationResult(stack, sideEffects)
}
}