Add stack views, both char and long

This commit is contained in:
Jacob
2018-11-22 19:22:53 -05:00
parent af2f0442bf
commit 03b067ee2c
3 changed files with 49 additions and 5 deletions

View File

@@ -3,5 +3,5 @@ package befide.befunge.state
data class Value(val value: Long) {
constructor(value: Char) : this(value.toLong())
val asChar: Char? = if (value in (32..126)) value.toChar() else null
val asChar: Char? = if (value in (32..127)) value.toChar() else null
}

View File

@@ -38,9 +38,16 @@ class ActionView(val interp: Interpreter, val ioView: IOView) : View() {
}
}
button("walk") {
setOnAction {
runTimeline.rate = 50.0
runTimeline.playFromStart()
}
}
button("crawl") {
setOnAction {
runTimeline.rate = 2.0
runTimeline.rate = 4.0
runTimeline.playFromStart()
}
}

View File

@@ -1,10 +1,47 @@
package befide.ide
import befide.befunge.b93.padEnd
import befide.befunge.core.Interpreter
import befide.befunge.state.Value
import javafx.beans.property.SimpleStringProperty
import tornadofx.*
import tornadofx.getValue
import tornadofx.setValue
class StackView(val interp: Interpreter) : View() {
override val root = textarea {
prefWidth = 100.0
val charOutProperty = SimpleStringProperty()
var charOut by charOutProperty
val longOutProperty = SimpleStringProperty()
var longOut by longOutProperty
override val root = hbox {
textarea(charOutProperty) {
maxWidth = 1.0
paddingHorizontal = 1
isEditable = false
}
textarea(longOutProperty) {
prefWidth = 90.0
isEditable = false
}
}
private fun <T> getStackStr(mapping: (Value) -> T): String {
return interp.stack.takeLast(interp.funge.height)
.map (mapping)
.padEnd(interp.funge.height, "")
.reversed()
.joinToString("\n")
}
init {
charOut = getStackStr { it.asChar ?: '*'}
longOut = getStackStr { it.value }
interp.stackChanged += {
charOut = getStackStr { it.asChar ?: '*'}
longOut = getStackStr { it.value }
}
}
}