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