Skip to content

Commit 04f2ceb

Browse files
committed
refactor!: more canonical language
1 parent 69b564e commit 04f2ceb

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

core/src/main/kotlin/vip/cdms/allaymc/kotlinx/Typealias.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ package vip.cdms.allaymc.kotlinx
22

33
import org.allaymc.api.entity.interfaces.EntityPlayer
44

5-
// kotlinx
6-
typealias Receiver<T> = T.() -> Unit
7-
8-
// allaymc
95
typealias Player = EntityPlayer

core/src/main/kotlin/vip/cdms/allaymc/kotlinx/form/ModalFormBuilder.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ package vip.cdms.allaymc.kotlinx.form
33
import org.allaymc.api.form.Forms
44
import org.allaymc.api.form.type.ModalForm
55
import vip.cdms.allaymc.kotlinx.Player
6-
import vip.cdms.allaymc.kotlinx.Receiver
76

87
class ModalFormBuilder : FormBuilder<ModalForm, ModalFormBuilder.Response>(){
98
var content = ""
109

11-
data class Action(val text: String, val callbacks: MutableList<Receiver<Player>?>)
12-
fun actionOf(text: String, callback: Receiver<Player>? = null) = Action(text, mutableListOf()).apply { callbacks += callback }
10+
data class Action(val text: String, val callbacks: MutableList<(Player.() -> Unit)?>)
11+
fun actionOf(text: String, callback: (Player.() -> Unit)? = null) =
12+
Action(text, mutableListOf()).apply { callbacks += callback }
1313
var confirm: Action? = null
1414
var cancel: Action? = null
1515

16-
fun confirm(text: String? = null, callback: Receiver<Player>? = null) {
16+
fun confirm(text: String? = null, callback: (Player.() -> Unit)? = null) {
1717
confirm = confirm?.copy(text = text ?: confirm!!.text) ?: actionOf(text ?: "")
1818
confirm!!.callbacks += callback
1919
}
20-
fun cancel(text: String? = null, callback: Receiver<Player>? = null) {
20+
fun cancel(text: String? = null, callback: (Player.() -> Unit)? = null) {
2121
cancel = cancel?.copy(text = text ?: cancel!!.text) ?: actionOf(text ?: "")
2222
cancel!!.callbacks += callback
2323
}

core/src/main/kotlin/vip/cdms/allaymc/kotlinx/form/SimpleFormBuilder.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package vip.cdms.allaymc.kotlinx.form
22

3-
import org.allaymc.api.entity.interfaces.EntityPlayer
43
import org.allaymc.api.form.Forms
54
import org.allaymc.api.form.element.Button
65
import org.allaymc.api.form.element.ImageData
76
import org.allaymc.api.form.type.SimpleForm
87
import vip.cdms.allaymc.kotlinx.Player
9-
import vip.cdms.allaymc.kotlinx.Receiver
108

119
class SimpleFormBuilder : FormBuilder<SimpleForm, SimpleFormBuilder.Response>() {
1210
var content = ""
@@ -23,12 +21,12 @@ class SimpleFormBuilder : FormBuilder<SimpleForm, SimpleFormBuilder.Response>()
2321
fun Button.convert() = Button(text, image?.convert())
2422

2523
val buttons = mutableListOf<Button>()
26-
val callbacks = linkedMapOf<Button, MutableList<Receiver<EntityPlayer>?>>()
24+
val callbacks = linkedMapOf<Button, MutableList<(Player.() -> Unit)?>>()
2725

28-
fun buttonOf(text: String, image: Image? = null, callback: Receiver<EntityPlayer>? = null) =
26+
fun buttonOf(text: String, image: Image? = null, callback: (Player.() -> Unit)? = null) =
2927
Button(text, image).apply { callbacks.getOrPut(this) { mutableListOf() } += callback }
30-
fun button(text: String, image: Image? = null, callback: Receiver<EntityPlayer>? = null) =
31-
buttonOf(text, image, callback).apply { buttons += this }
28+
fun button(text: String, image: Image? = null, callback: (Player.() -> Unit)? = null) =
29+
buttonOf(text, image, callback).also { buttons += it }
3230

3331
@JvmInline
3432
value class Response(val index: Int) : FormBuilder.Response

0 commit comments

Comments
 (0)