run and crawl buttons, no styling

This commit is contained in:
2018-11-16 16:43:05 -05:00
parent e91ddb068f
commit 1eb850bd70
4 changed files with 107 additions and 21 deletions

View File

@@ -6,7 +6,7 @@ import befide.befunge.state.*
class B93Funge : Funge {
override val width = 80
override val height = 25
private var cars = Array(height) { Array(width) {' '.toLong()}}
private var cars = Array(height) { Array(width) { ' '.toLong() } }
override fun get(vec: Vec): Value {
return Value(cars[vec.y][vec.x])
@@ -32,17 +32,17 @@ class B93Funge : Funge {
y += height
}
return Vec(x,y)
return Vec(x, y)
}
override fun setString(data: String) {
val strings = data.split('\n')
for (i in strings.size until height) {
cars[i] = Array(width) {' '.toLong()}
cars[i] = Array(width) { ' '.toLong() }
}
strings.map {
it.toList().map{it.toLong()}
}
it.toList().map { it.toLong() }
}
.forEachIndexed { index, list ->
if (index > height) {
return
@@ -50,13 +50,17 @@ class B93Funge : Funge {
cars[index] = (
list.toList() + List(
if (list.size <= width) width - list.size else 0
){
' '.toLong()
}
) {
' '.toLong()
}
)
.subList(0, width)
.toTypedArray()
}
}
override fun toString(): String {
return cars.map { it.map { Value(it).asChar ?: '?' }.joinToString("") }.joinToString("\n")
}
}

View File

@@ -17,6 +17,9 @@
</compilerArguments>
</configuration>
</facet>
<facet type="TornadoFX" name="TornadoFX">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />

View File

@@ -0,0 +1,87 @@
package befide.ide
import befide.befunge.b93.B93Interpreter
import befide.befunge.core.Interpreter
import befide.befunge.state.Vec
import javafx.animation.Animation
import javafx.animation.Timeline
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import javafx.util.Duration
import tornadofx.*
class EditorView : View("Befide") {
private var interp: Interpreter = B93Interpreter()
private val textProperty = SimpleStringProperty("")
private var text by textProperty
private val posProperty = SimpleObjectProperty<Vec>(Vec(0, 0))
private var pos by posProperty
private var runTimeline: Timeline = timeline(false) {
keyframe(Duration.seconds(0.0)) {
setOnFinished {
if (!interp.step())
this@timeline.stop()
}
}
keyframe(Duration.seconds(1.0)) {}
cycleCount = Animation.INDEFINITE
}
init {
interp.fungeChanged += { text = interp.funge.toString() }
textProperty.addListener { _, _, newValue -> interp.funge.setString(newValue) }
interp.ipChanged += { pos = it.to.pos }
}
override val root = vbox {
label {
bind(posProperty.stringBinding { if (it != null) "${it.x} ${it.y}" else "-" })
}
hbox {
button("step") {
setOnAction { interp.step() }
}
button("reset") {
setOnAction { interp.reset() }
}
button("run") {
setOnAction {
runTimeline.rate = 1000.0
runTimeline.playFromStart()
}
}
button("crawl") {
setOnAction {
runTimeline.rate = 2.0
runTimeline.playFromStart()
}
}
button("stop") {
setOnAction {
runTimeline.stop()
}
}
}
textarea(textProperty)
}
init {
text = """64+"!dlroW ,olleH">:#,_@"""
}
}
class MainApp : App(EditorView::class) {
init {
importStylesheet(resources["style.css"])
}
}

View File

@@ -1,16 +1,8 @@
.lbl {
-fx-text-fill: maroon;
* {
-fx-font-size: 14;
-fx-font-fill: black;
}
.val {
-fx-font-weight: bold;
}
#heightLabel {
-fx-font-style: italic;
}
GridPane {
-fx-font-size: 20px;
-fx-font-family: Consolas, monospace;
.text-area {
-fx-font-family: monospace;
}