ASMR/src/main/kotlin/net/shadowfacts/asmr/program/Program.kt

31 lines
645 B
Kotlin

package net.shadowfacts.asmr.program
import net.shadowfacts.asmr.program.blocks.StartBlock
import net.shadowfacts.cacao.geometry.Point
/**
* @author shadowfacts
*/
class Program {
var startBlock = StartBlock().apply {
position = Point.ORIGIN
}
val blocks = mutableListOf<ProgramBlock>()
fun execute() {
var currentBlock: ExecutableBlock? = startBlock.nextExecutableBlock
while (currentBlock != null) {
currentBlock.execute()
currentBlock = currentBlock.nextExecutableBlock
}
}
fun <Block: ProgramBlock> addBlock(block: Block, init: (Block) -> Unit = {}): Block {
init(block)
blocks.add(block)
return block
}
}