Skip to content

Commit cbe5ddf

Browse files
committed
Add indentation to case/default
1 parent 74d1bb6 commit cbe5ddf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/kotlin/rhmodding/tickompiler/Functions.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ object MegamixFunctions : Functions() {
7575
SpecialOnlyFunction(0x12, "unrest"),
7676
SpecialOnlyFunction(0x14, "label"),
7777
SpecialOnlyFunction(0x15, "goto"),
78-
SpecialOnlyFunction(0x1A, "case"),
78+
SpecialOnlyFunction(0x1A, "case", indentChange = 1),
7979
SpecialOnlyFunction(0xB8, "random"),
8080
SpecificSpecialFunction(0x1, 0, "get_async", 2..2),
8181
SpecificSpecialFunction(0x1, 1, "set_func", 2..2),
@@ -152,8 +152,8 @@ object MegamixFunctions : Functions() {
152152
-1), // current adjust pushes the else back an indent
153153
alias(0x18, "endif", 0..0, -1, -1), // same here
154154
alias(0x19, "switch", 0..0, 1),
155-
alias(0x1B, "break", 0..0),
156-
alias(0x1C, "default", 0..0),
155+
alias(0x1B, "break", 0..0, -1),
156+
alias(0x1C, "default", 0..0, 1),
157157
alias(0x1D, "endswitch", 0..0, -1, -1),
158158
alias(0x24, "speed", 1..1),
159159
alias(0x25, "speed_relative", 3..3),
@@ -305,7 +305,9 @@ class OldMacroFunction: OptionalArgumentsFunction(0, "macro", 3, 0, 2000)
305305
@DeprecatedFunction("set_async is deprecated, use set_func instead")
306306
class OldSetFunction: SpecificSpecialFunction(0x1, 1, "set_async", 2..2)
307307

308-
open class SpecialOnlyFunction(opcode: Long, alias: String) : Function(opcode, alias, 1..1) {
308+
open class SpecialOnlyFunction(opcode: Long, alias: String, val indentChange: Int = 0,
309+
val currentAdjust: Int = 0)
310+
: Function(opcode, alias, 1..1) {
309311
override fun acceptOp(op: Long): Boolean {
310312
val opcode = op and 0x3FF
311313
val args = (op and 0x3C00) ushr 10
@@ -314,6 +316,8 @@ open class SpecialOnlyFunction(opcode: Long, alias: String) : Function(opcode, a
314316

315317
override fun produceTickflow(state: DecompilerState, opcode: Long, specialArg: Long, args: LongArray,
316318
comments: CommentType, specialArgStrings: Map<Int, String>): String {
319+
state.nextIndentLevel += indentChange
320+
state.currentAdjust = currentAdjust
317321
return "${this.name} ${getHex(specialArg)}"
318322
}
319323

0 commit comments

Comments
 (0)