31 lines
1.3 KiB
Kotlin
31 lines
1.3 KiB
Kotlin
package at.petrak.hexcasting.common.casting.actions.eval
|
|
|
|
import at.petrak.hexcasting.api.casting.castables.Action
|
|
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
|
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
|
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
|
import at.petrak.hexcasting.api.casting.eval.vm.FrameForEach
|
|
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
|
import at.petrak.hexcasting.api.casting.getList
|
|
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
|
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
|
|
|
|
object OpForEach : Action {
|
|
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
|
val stack = image.stack.toMutableList()
|
|
|
|
if (stack.size < 2)
|
|
throw MishapNotEnoughArgs(2, stack.size)
|
|
|
|
val instrs = stack.getList(stack.lastIndex - 1)
|
|
val datums = stack.getList(stack.lastIndex)
|
|
stack.removeLastOrNull()
|
|
stack.removeLastOrNull()
|
|
|
|
val frame = FrameForEach(datums, instrs, null, mutableListOf())
|
|
val image2 = image.withUsedOp().copy(stack = stack)
|
|
|
|
return OperationResult(image2, listOf(), continuation.pushFrame(frame), HexEvalSounds.THOTH)
|
|
}
|
|
}
|