From 1eb850bd705833cdfec88347748b05290e6cad38 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 16 Nov 2018 16:43:05 -0500 Subject: [PATCH] run and crawl buttons, no styling --- .../kotlin/befide/befunge/b93/B93Funge.kt | 20 +++-- ide/ide.iml | 3 + ide/src/main/kotlin/befide/ide/Main.kt | 87 +++++++++++++++++++ ide/src/main/resources/befide/ide/style.css | 18 ++-- 4 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 ide/src/main/kotlin/befide/ide/Main.kt diff --git a/befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt b/befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt index 5244407..7cfa20e 100644 --- a/befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt +++ b/befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt @@ -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") + } } diff --git a/ide/ide.iml b/ide/ide.iml index 86b45e9..bf8f97e 100644 --- a/ide/ide.iml +++ b/ide/ide.iml @@ -17,6 +17,9 @@ + + + diff --git a/ide/src/main/kotlin/befide/ide/Main.kt b/ide/src/main/kotlin/befide/ide/Main.kt new file mode 100644 index 0000000..11c0ce8 --- /dev/null +++ b/ide/src/main/kotlin/befide/ide/Main.kt @@ -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(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"]) + } +} diff --git a/ide/src/main/resources/befide/ide/style.css b/ide/src/main/resources/befide/ide/style.css index 12f2231..8c397f4 100644 --- a/ide/src/main/resources/befide/ide/style.css +++ b/ide/src/main/resources/befide/ide/style.css @@ -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; } \ No newline at end of file