Skip to content

Commit

Permalink
Diver's Gambit
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Feb 21, 2024
1 parent eedd256 commit 3796c40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,51 @@ package miyucomics.hexical.casting.patterns.operators.eval

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.eval.FrameEvaluate
import at.petrak.hexcasting.api.spell.casting.eval.SpellContinuation
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.ListIota
import at.petrak.hexcasting.api.spell.iota.PatternIota
import at.petrak.hexcasting.api.spell.math.HexDir
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs

object OpDiver : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, ravenmind: Iota?, ctx: CastingContext): OperationResult {
if (stack.size < 2)
throw MishapNotEnoughArgs(2, stack.size)

// WHY IS THE STACK INDEXED LKE THIS?
// IT'S A STACK
// YOU KNOW, WHEN YOU STACK TWO THINGS ON TOP OF EACH OTHER
// 0 should be the fucking top!
// This cost me two hours of debugging
val instructions = stack.getList(stack.lastIndex - 1)
val diveAmount = stack.getPositiveIntUnderInclusive(0, stack.size - 1)
val diveAmount = stack.getPositiveInt(stack.lastIndex)
stack.removeLastOrNull()
stack.removeLastOrNull()

val output = mutableListOf<Iota>()
output.addAll(stack.takeLast(diveAmount))
for (i in 0 until diveAmount)
stack.removeLast()

// cast pattern list??
val constructedList = mutableListOf<Iota>();
constructedList.add(PatternIota(HexPattern.fromAngles("qqqaw", HexDir.WEST)))
constructedList.add(ListIota(stack.popStack(diveAmount)))
constructedList.add(PatternIota(HexPattern.fromAngles("qwaeawq", HexDir.WEST)))

output.reverse()
for (iota in output)
stack.add(iota)
return OperationResult(
continuation
.pushFrame(FrameEvaluate(SpellList.LList(0, constructedList), true))
.pushFrame(FrameEvaluate(instructions, true)),
stack,
ravenmind,
listOf()
)
}

return OperationResult(continuation, stack, ravenmind, listOf())
private fun MutableList<Iota>.popStack(argc: Int): List<Iota> {
val stackSize = this.size
if (stackSize < argc)
throw MishapNotEnoughArgs(argc, stackSize)
val args = this.subList(stackSize - argc, stackSize).toList()
repeat(argc) { this.removeLast() }
return args
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object HexicalPatterns {
var CHORUS_BLINK: HexPattern = register(HexPattern.fromAngles("aawqqqq", HexDir.SOUTH_EAST), "chorus_blink", OpChorusBlink())
var CONJURE_BOUNCY_BLOCK: HexPattern = register(HexPattern.fromAngles("dee", HexDir.NORTH_WEST), "conjure_bouncy_block", OpConjureBouncyBlock())
var PROGRAM_LAMP: HexPattern = register(HexPattern.fromAngles("wwqqqqq", HexDir.EAST), "program_lamp", OpProgramLamp())
var PING_SPELL: HexPattern = register(HexPattern.fromAngles("eweeewedqdeqqqqqwaeeee", HexDir.NORTH_EAST), "ping", OpPing())
var PING: HexPattern = register(HexPattern.fromAngles("eweeewedqdeqqqqqwaeeee", HexDir.NORTH_EAST), "ping", OpPing())

@JvmStatic
fun init() {
Expand Down

0 comments on commit 3796c40

Please sign in to comment.