From 26d652a77c9eb177db99e1dafa70ef946224abc3 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:07:40 +0800 Subject: [PATCH] Update --- composeApp/src/wasmJsMain/kotlin/App.kt | 89 ++++++++++++++------- composeApp/src/wasmJsMain/kotlin/MyIcons.kt | 1 - composeApp/src/wasmJsMain/kotlin/Native.kt | 59 ++++++++++++-- composeApp/src/wasmJsMain/kotlin/Version.kt | 7 +- 4 files changed, 118 insertions(+), 38 deletions(-) diff --git a/composeApp/src/wasmJsMain/kotlin/App.kt b/composeApp/src/wasmJsMain/kotlin/App.kt index 621da9c..30a25b4 100644 --- a/composeApp/src/wasmJsMain/kotlin/App.kt +++ b/composeApp/src/wasmJsMain/kotlin/App.kt @@ -76,6 +76,7 @@ private fun Customizer() { langTypeFromString(localStorage.getItem("langType")) ?: GRADLE_KOTLIN ) } + var selectedVersion by remember { mutableStateOf(V_LATEST_SNAPSHOT) } val selectedModules = remember { mutableStateMapOf().also { val item = localStorage.getItem("selectedModules") @@ -83,7 +84,7 @@ private fun Customizer() { item?.let { s -> s.split(',').mapNotNull { m -> bindingFromString(m) } } ?: emptyList() - Binding.entries.forEach { m -> it[m] = initModules.contains(m) } + selectedVersion.modules.forEach { m -> it[m] = initModules.contains(m) } it[Binding.CORE] = true } } @@ -110,7 +111,7 @@ private fun Customizer() { modules = selectedModules, joml = joml, noVariable = noVariable, - version = "$V_LATEST_SNAPSHOT-SNAPSHOT", + version = selectedVersion, natives = selectedNatives ) @@ -123,11 +124,11 @@ private fun Customizer() { // select the build type Row { - Button(onClick = {}, modifier = Modifier.padding(all = 32.dp)) { + Button(onClick = { selectedVersion = V_LATEST_SNAPSHOT }, modifier = Modifier.padding(all = 32.dp)) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Text("Snapshot", fontSize = 2.em) Text("Unstable build", fontStyle = FontStyle.Italic) - Text("$V_LATEST_SNAPSHOT-SNAPSHOT") + Text("$V_LATEST_SNAPSHOT") } } } @@ -147,7 +148,6 @@ private fun Customizer() { inline fun optionTitle(text: String) { Text( text, - modifier = Modifier.padding(start = 14.dp), fontSize = 1.2.em, fontWeight = FontWeight.Bold ) @@ -220,7 +220,7 @@ private fun Customizer() { // presets optionTitle("Presets") Row(verticalAlignment = Alignment.CenterVertically) { - RadioButton(selected = true, onClick = null, modifier = Modifier.padding(start = 14.dp)) + RadioButton(selected = true, onClick = null) Text("Custom") } @@ -241,7 +241,7 @@ private fun Customizer() { Column { // modules optionTitle("Modules") - Binding.entries.forEach { module -> + selectedVersion.modules.forEach { module -> Row(verticalAlignment = Alignment.CenterVertically) { Checkbox( checked = if (module.nonSelectable) true else selectedModules[module] ?: false, @@ -330,26 +330,25 @@ fun generatedCode( modules: Map, joml: Boolean, noVariable: Boolean, - version: String, - natives: List + version: Version, + natives: List, ): String = buildString { - val selectedModules = Binding.entries.filter { modules[it] ?: false } + val selectedModules = version.modules.filter { modules[it] ?: false } val linuxList = natives.filter { it.linux } val macosList = natives.filter { it.macos } val windowsList = natives.filter { it.windows } fun StringBuilder.gradleDependencies() { appendLine("dependencies {") - appendLine(""" implementation(platform("io.github.over-run:overrungl-bom:${if (noVariable) version else "\$overrunglVersion"}"))""") + appendLine(""" implementation(platform("io.github.over-run:overrungl-bom:${if (noVariable) "$version" else "\$overrunglVersion"}"))""") selectedModules.forEach { appendLine(""" implementation("io.github.over-run:${it.artifactName}")""") } selectedModules.filter { it.requireNative }.forEach { appendLine( """ runtimeOnly("io.github.over-run:${it.artifactName}::${ - if (!noVariable || natives.size > 1) "\$overrunglNatives" - else if (natives.isNotEmpty()) natives[0].classifierName - else "" + if (noVariable && natives.size == 1) natives[0].classifierName + else "\$overrunglNatives" }")""" ) } @@ -564,9 +563,32 @@ fun generatedCode( appendLine() } - appendLine("") - appendLine("") - appendLine() + if (!noVariable || natives.size > 1) { + appendLine("") + natives.map { it to it.os }.forEach { (native, osArr) -> + osArr.forEach { + appendLine( + """ + | + | ${it.mavenId} + | + | + | ${it.family} + ${if (it.name != null) "| ${it.name}" else ""} + | ${it.arch} + | + | + | + | ${native.classifierName} + | + | + """.trimMargin() + ) + } + } + appendLine("") + appendLine() + } if (!release) { appendLine( @@ -581,6 +603,7 @@ fun generatedCode( """.trimIndent() ) + appendLine() } appendLine( @@ -590,7 +613,7 @@ fun generatedCode( io.github.over-run overrungl-bom - ${if (noVariable) version else "\${overrungl.version}"} + ${if (noVariable) "$version" else "\${overrungl.version}"} import pom @@ -598,26 +621,38 @@ fun generatedCode( """.trimIndent() ) + appendLine() appendLine("") selectedModules.forEach { appendLine( """ - | - | io.github.over-run - | ${it.artifactName} - | + | + | io.github.over-run + | ${it.artifactName} + | + """.trimMargin() + ) + } + selectedModules.filter { it.requireNative }.forEach { + appendLine( + """ + | + | io.github.over-run + | ${it.artifactName} + | ${if (noVariable && natives.size == 1) natives[0].classifierName else "\${overrungl.natives}"} + | """.trimMargin() ) } if (joml) { appendLine( """ - | - | org.joml - | joml - | ${if (noVariable) V_JOML else "\${joml.version}"} - | + | + | org.joml + | joml + | ${if (noVariable) V_JOML else "\${joml.version}"} + | """.trimMargin() ) } diff --git a/composeApp/src/wasmJsMain/kotlin/MyIcons.kt b/composeApp/src/wasmJsMain/kotlin/MyIcons.kt index ec4731f..5f77a41 100644 --- a/composeApp/src/wasmJsMain/kotlin/MyIcons.kt +++ b/composeApp/src/wasmJsMain/kotlin/MyIcons.kt @@ -91,7 +91,6 @@ val Icons.Filled.Linux: ImageVector this.lineToRelative(dx * LINUX_ICON_HEIGHT, dy * LINUX_ICON_WIDTH) } - moveTo(220.8f, 123.3f) curveToRelative(1f, .5f, 1.8f, 1.7f, 3f, 1.7f) curveToRelative(1.1f, 0f, 2.8f, -.4f, 2.9f, -1.5f) diff --git a/composeApp/src/wasmJsMain/kotlin/Native.kt b/composeApp/src/wasmJsMain/kotlin/Native.kt index d1f5f1d..fae0f96 100644 --- a/composeApp/src/wasmJsMain/kotlin/Native.kt +++ b/composeApp/src/wasmJsMain/kotlin/Native.kt @@ -1,3 +1,11 @@ +/** + * @author squid233 + * @since 0.3.0 + */ +class Os(val family: String, val name: String? = null, val arch: String, mavenId: String = name ?: family) { + val mavenId: String = "overrungl-natives-$mavenId-$arch" +} + /** * @author squid233 * @since 0.3.0 @@ -5,17 +13,54 @@ enum class Native( val description: String, val classifierName: String, + vararg val os: Os, val linux: Boolean = false, val macos: Boolean = false, val windows: Boolean = false ) { - LINUX_X64("Linux x64", "natives-linux", linux = true), - LINUX_ARM64("Linux arm64", "natives-linux-arm64", linux = true), - LINUX_ARM32("Linux arm32", "natives-linux-arm32", linux = true), - MACOS_X64("macOS x64", "natives-macos", macos = true), - MACOS_ARM64("macOS arm64", "natives-macos-arm64", macos = true), - WINDOWS_X64("Windows x64", "natives-windows", windows = true), - WINDOWS_ARM64("Windows arm64", "natives-windows-arm64", windows = true), + LINUX_X64( + "Linux x64", + "natives-linux", + Os(family = "unix", name = "linux", arch = "amd64"), + linux = true + ), + LINUX_ARM64( + "Linux arm64", + "natives-linux-arm64", + Os(family = "unix", name = "linux", arch = "aarch64"), + linux = true + ), + LINUX_ARM32( + "Linux arm32", + "natives-linux-arm32", + Os(family = "unix", name = "linux", arch = "arm"), + Os(family = "unix", name = "linux", arch = "arm32"), + linux = true + ), + MACOS_X64( + "macOS x64", + "natives-macos", + Os(family = "mac", arch = "x86_64", mavenId = "macos"), + macos = true + ), + MACOS_ARM64( + "macOS arm64", + "natives-macos-arm64", + Os(family = "mac", arch = "aarch64", mavenId = "macos"), + macos = true + ), + WINDOWS_X64( + "Windows x64", + "natives-windows", + Os(family = "windows", arch = "amd64"), + windows = true + ), + WINDOWS_ARM64( + "Windows arm64", + "natives-windows-arm64", + Os(family = "windows", arch = "aarch64"), + windows = true + ), } fun nativeFromString(name: String?): Native? = name?.let { diff --git a/composeApp/src/wasmJsMain/kotlin/Version.kt b/composeApp/src/wasmJsMain/kotlin/Version.kt index f7b6bba..66e859d 100644 --- a/composeApp/src/wasmJsMain/kotlin/Version.kt +++ b/composeApp/src/wasmJsMain/kotlin/Version.kt @@ -2,12 +2,13 @@ * @author squid233 * @since 0.3.0 */ -class Version(val versionName: String) { +class Version(private val versionName: String, vararg modules: Binding) { + val modules: List = modules.toList() override fun toString(): String = versionName } -val V0_1_0 = Version("0.1.0") +val V0_1_0 = Version("0.1.0", Binding.CORE, Binding.GLFW, Binding.NFD, Binding.OPENGL, Binding.STB) -val V_LATEST_SNAPSHOT = V0_1_0 +val V_LATEST_SNAPSHOT = Version("0.1.0-SNAPSHOT", *V0_1_0.modules.toTypedArray()) const val V_JOML = "1.10.5"