mirror of
https://github.com/Theaninova/BeatMapLanguage.git
synced 2025-12-12 17:16:15 +00:00
Pattern Loops
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
class Interpreter(val code: String) {
|
class Interpreter(val code: String) {
|
||||||
class BslFunction(val name: String, val pos: Int)
|
class BslFunction(val name: String, val pos: Int)
|
||||||
|
class BslVariable(val name: String, var value: String)
|
||||||
|
|
||||||
var error = false
|
var error = false
|
||||||
|
|
||||||
val functions = ArrayList<BslFunction>()
|
val functions = ArrayList<BslFunction>()
|
||||||
|
val variables = ArrayList<BslVariable>()
|
||||||
|
|
||||||
val key_fun = '#'
|
val key_fun = '#'
|
||||||
val key_comment = '?'
|
val key_comment = '?'
|
||||||
@@ -12,6 +14,10 @@ class Interpreter(val code: String) {
|
|||||||
val key_opening_bracket = '{'
|
val key_opening_bracket = '{'
|
||||||
val key_closing_bracket = '}'
|
val key_closing_bracket = '}'
|
||||||
val key_section_marker = '"'
|
val key_section_marker = '"'
|
||||||
|
val key_variable = '_'
|
||||||
|
|
||||||
|
val key_return_one = '<'
|
||||||
|
val key_return_two = '-'
|
||||||
|
|
||||||
val fun_typ_pattern = "fun"
|
val fun_typ_pattern = "fun"
|
||||||
val fun_typ_main = "main"
|
val fun_typ_main = "main"
|
||||||
@@ -29,7 +35,11 @@ class Interpreter(val code: String) {
|
|||||||
var inverted = false
|
var inverted = false
|
||||||
|
|
||||||
fun placeCube(timestamp: Double, type: Int, value: Int) {
|
fun placeCube(timestamp: Double, type: Int, value: Int) {
|
||||||
System.out.println("Cube placed: " + timestamp + " " + type + " " + value)
|
val my_timestamp = currentOffset + timestamp
|
||||||
|
|
||||||
|
//TODO: Invert
|
||||||
|
|
||||||
|
System.out.println("Cube placed: " + my_timestamp + " " + type + " " + value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun placeBomb(timestamp: Double, value: Int) {
|
fun placeBomb(timestamp: Double, value: Int) {
|
||||||
@@ -84,7 +94,7 @@ class Interpreter(val code: String) {
|
|||||||
return argsList.toTypedArray()
|
return argsList.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun executeFun(my_pos: Int, agrsNames: Array<String>, args: Array<String>) {
|
fun executeFun(my_pos: Int, agrsNames: Array<String>, args: Array<String>): String {
|
||||||
val old_pos = pos
|
val old_pos = pos
|
||||||
pos = my_pos
|
pos = my_pos
|
||||||
|
|
||||||
@@ -106,13 +116,22 @@ class Interpreter(val code: String) {
|
|||||||
inverted = t_inverted.toBoolean()
|
inverted = t_inverted.toBoolean()
|
||||||
|
|
||||||
for (i in 0..runs) {
|
for (i in 0..runs) {
|
||||||
executeFun(pos, arrayOf("p_timestamp", "p_inverted", "p_total_runs", "p_current_run_index"), arrayOf(timestamp, t_inverted, runs.toString(), i.toString()))
|
val len = executeFun(pos, arrayOf("p_timestamp", "p_inverted", "p_total_runs", "p_current_run_index"), arrayOf(timestamp, t_inverted, runs.toString(), i.toString()))
|
||||||
|
|
||||||
|
currentOffset += len.toDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoNext(key_closing_bracket)
|
gotoNext(key_closing_bracket)
|
||||||
|
|
||||||
currentOffset = oldOffset
|
currentOffset = oldOffset
|
||||||
inverted = oldInverted
|
inverted = oldInverted
|
||||||
|
} else if (code[pos] == key_return_one && code[pos + 1] == key_return_two) {
|
||||||
|
pos += 2
|
||||||
|
val out = popNextWord(' ')
|
||||||
|
pos = old_pos
|
||||||
|
return out
|
||||||
|
} else if (code[pos] == key_variable) {
|
||||||
|
TODO()
|
||||||
} else {
|
} else {
|
||||||
val fun_call = popNextWord(' ')
|
val fun_call = popNextWord(' ')
|
||||||
gotoNext(fun_opening_bracket)
|
gotoNext(fun_opening_bracket)
|
||||||
@@ -123,6 +142,8 @@ class Interpreter(val code: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = old_pos
|
pos = old_pos
|
||||||
|
|
||||||
|
return "NO_RETURN"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun callFunction(name: String, args: Array<String>) {
|
fun callFunction(name: String, args: Array<String>) {
|
||||||
|
|||||||
13
src/test.bml
13
src/test.bml
@@ -1,7 +1,9 @@
|
|||||||
#fun test () {
|
#fun test () {
|
||||||
Cube (1.0, 3, 5,)
|
Cube (1.0, 3, 5,)
|
||||||
Cube (1.1, 2, 3,)
|
Cube (1.5, 2, 3,)
|
||||||
Cube (1.4, 5, 3,)
|
Cube (2.0, 5, 3,)
|
||||||
|
|
||||||
|
<-2.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#fun test_two () {
|
#fun test_two () {
|
||||||
@@ -11,5 +13,10 @@
|
|||||||
#main () {
|
#main () {
|
||||||
test_two ()
|
test_two ()
|
||||||
Cube (1.2, 3, 6,)
|
Cube (1.2, 3, 6,)
|
||||||
!24.6:false:4 {test ()}
|
|
||||||
|
|
||||||
|
!24.6:false:4 {
|
||||||
|
test ()
|
||||||
|
<-2.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user