Skip to content

Commit 2f333c3

Browse files
committed
fix: wrong refied type input
1 parent ed41aae commit 2f333c3

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

common/src/main/kotlin/com/lambda/newgui/GuiManager.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import com.lambda.core.Loadable
55
import com.lambda.newgui.component.core.UIBuilder
66
import com.lambda.newgui.component.layout.Layout
77
import com.lambda.newgui.impl.clickgui.settings.BooleanButton.Companion.booleanSetting
8-
import java.lang.reflect.Type
98
import kotlin.reflect.KClass
109

1110
object GuiManager : Loadable {
12-
val typeMap = mutableMapOf<Type, (owner: Layout, converted: Any) -> Layout>()
11+
val typeMap = mutableMapOf<KClass<*>, (owner: Layout, converted: Any) -> Layout>()
1312

1413
private inline fun <reified T : Any> typeAdapter(noinline block: (Layout, T) -> Layout) {
15-
typeMap[T::class.java] = { owner, converted -> block(owner, converted as T) }
14+
typeMap[T::class] = { owner, converted -> block(owner, converted as T) }
1615
}
1716

1817
override fun load(): String {
@@ -27,8 +26,9 @@ object GuiManager : Loadable {
2726
* Attempts to convert the given [reference] to the [Layout]
2827
*/
2928
@UIBuilder
30-
inline fun <reified T : Any> Layout.layoutOf(reference: T, block: Layout.() -> Unit = {}): Layout? {
31-
val adapter = typeMap[T::class.java] ?: return null
32-
return adapter(this, reference).apply(children::add).apply(block)
33-
}
34-
}
29+
inline fun Layout.layoutOf(
30+
reference: Any,
31+
block: Layout.() -> Unit = {}
32+
): Layout? =
33+
typeMap[reference::class]?.invoke(this, reference)?.apply(block)
34+
}

common/src/main/kotlin/com/lambda/newgui/impl/clickgui/ModuleLayout.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.lambda.config.settings.comparable.BooleanSetting
44
import com.lambda.graphics.animation.Animation.Companion.exp
55
import com.lambda.module.Module
66
import com.lambda.module.modules.client.NewCGui
7+
import com.lambda.newgui.GuiManager.layoutOf
78
import com.lambda.newgui.component.HAlign
89
import com.lambda.newgui.component.core.FilledRect
910
import com.lambda.newgui.component.core.UIBuilder
@@ -83,13 +84,7 @@ class ModuleLayout(
8384
}
8485

8586
content.apply {
86-
module.settings.forEach { setting ->
87-
//layoutOf(setting) doesn't work
88-
89-
when (setting) {
90-
is BooleanSetting -> booleanSetting(setting)
91-
}
92-
}
87+
module.settings.forEach { setting -> layoutOf(setting) }
9388
}
9489
}
9590

@@ -113,4 +108,4 @@ class ModuleLayout(
113108
fun Layout.moduleLayout(module: Module) =
114109
ModuleLayout(this, module).apply(children::add)
115110
}
116-
}
111+
}

0 commit comments

Comments
 (0)