2019-08-09 01:44:59 +00:00
|
|
|
package net.shadowfacts.asmr.program
|
|
|
|
|
|
|
|
import net.shadowfacts.asmr.program.blocks.StartBlock
|
2019-08-12 00:05:09 +00:00
|
|
|
import net.shadowfacts.asmr.program.execution.ExecutableBlock
|
2019-08-09 02:44:19 +00:00
|
|
|
import net.shadowfacts.cacao.geometry.Point
|
2019-08-09 01:44:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class Program {
|
|
|
|
|
2019-08-09 02:44:19 +00:00
|
|
|
var startBlock = StartBlock().apply {
|
|
|
|
position = Point.ORIGIN
|
|
|
|
}
|
2019-08-10 04:03:25 +00:00
|
|
|
val blocks = mutableListOf<ProgramBlock>(startBlock)
|
2019-08-09 01:44:59 +00:00
|
|
|
|
|
|
|
fun execute() {
|
2019-08-12 00:05:09 +00:00
|
|
|
var currentBlock: ExecutableBlock? = startBlock.next()
|
2019-08-09 01:44:59 +00:00
|
|
|
while (currentBlock != null) {
|
|
|
|
currentBlock.execute()
|
|
|
|
|
2019-08-12 00:05:09 +00:00
|
|
|
currentBlock = currentBlock.next()
|
2019-08-09 01:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 02:44:19 +00:00
|
|
|
fun <Block: ProgramBlock> addBlock(block: Block, init: (Block) -> Unit = {}): Block {
|
|
|
|
init(block)
|
|
|
|
blocks.add(block)
|
|
|
|
return block
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:44:59 +00:00
|
|
|
}
|