Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Feb 18, 2024
1 parent 0a1a683 commit 26d652a
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 38 deletions.
89 changes: 62 additions & 27 deletions composeApp/src/wasmJsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ private fun Customizer() {
langTypeFromString(localStorage.getItem("langType")) ?: GRADLE_KOTLIN
)
}
var selectedVersion by remember { mutableStateOf(V_LATEST_SNAPSHOT) }
val selectedModules = remember {
mutableStateMapOf<Binding, Boolean>().also {
val item = localStorage.getItem("selectedModules")
val initModules =
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
}
}
Expand All @@ -110,7 +111,7 @@ private fun Customizer() {
modules = selectedModules,
joml = joml,
noVariable = noVariable,
version = "$V_LATEST_SNAPSHOT-SNAPSHOT",
version = selectedVersion,
natives = selectedNatives
)

Expand All @@ -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")
}
}
}
Expand All @@ -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
)
Expand Down Expand Up @@ -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")
}

Expand All @@ -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,
Expand Down Expand Up @@ -330,26 +330,25 @@ fun generatedCode(
modules: Map<Binding, Boolean>,
joml: Boolean,
noVariable: Boolean,
version: String,
natives: List<Native>
version: Version,
natives: List<Native>,
): 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"
}")"""
)
}
Expand Down Expand Up @@ -564,9 +563,32 @@ fun generatedCode(
appendLine()
}

appendLine("<profiles>")
appendLine("</profiles>")
appendLine()
if (!noVariable || natives.size > 1) {
appendLine("<profiles>")
natives.map { it to it.os }.forEach { (native, osArr) ->
osArr.forEach {
appendLine(
"""
| <profile>
| <id>${it.mavenId}</id>
| <activation>
| <os>
| <family>${it.family}</family>
${if (it.name != null) "| <name>${it.name}</name>" else ""}
| <arch>${it.arch}</arch>
| </os>
| </activation>
| <properties>
| <overrungl.natives>${native.classifierName}</overrungl.natives>
| </properties>
| </profile>
""".trimMargin()
)
}
}
appendLine("</profiles>")
appendLine()
}

if (!release) {
appendLine(
Expand All @@ -581,6 +603,7 @@ fun generatedCode(
</repositories>
""".trimIndent()
)
appendLine()
}

appendLine(
Expand All @@ -590,34 +613,46 @@ fun generatedCode(
<dependency>
<groupId>io.github.over-run</groupId>
<artifactId>overrungl-bom</artifactId>
<version>${if (noVariable) version else "\${overrungl.version}"}</version>
<version>${if (noVariable) "$version" else "\${overrungl.version}"}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
""".trimIndent()
)
appendLine()

appendLine("<dependencies>")
selectedModules.forEach {
appendLine(
"""
| <dependency>
| <groupId>io.github.over-run</groupId>
| <artifactId>${it.artifactName}</artifactId>
| </dependency>
| <dependency>
| <groupId>io.github.over-run</groupId>
| <artifactId>${it.artifactName}</artifactId>
| </dependency>
""".trimMargin()
)
}
selectedModules.filter { it.requireNative }.forEach {
appendLine(
"""
| <dependency>
| <groupId>io.github.over-run</groupId>
| <artifactId>${it.artifactName}</artifactId>
| <classifier>${if (noVariable && natives.size == 1) natives[0].classifierName else "\${overrungl.natives}"}</classifier>
| </dependency>
""".trimMargin()
)
}
if (joml) {
appendLine(
"""
| <dependency>
| <groupId>org.joml</groupId>
| <artifactId>joml</artifactId>
| <version>${if (noVariable) V_JOML else "\${joml.version}"}</version>
| </dependency>
| <dependency>
| <groupId>org.joml</groupId>
| <artifactId>joml</artifactId>
| <version>${if (noVariable) V_JOML else "\${joml.version}"}</version>
| </dependency>
""".trimMargin()
)
}
Expand Down
1 change: 0 additions & 1 deletion composeApp/src/wasmJsMain/kotlin/MyIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 52 additions & 7 deletions composeApp/src/wasmJsMain/kotlin/Native.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,66 @@
/**
* @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
*/
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 {
Expand Down
7 changes: 4 additions & 3 deletions composeApp/src/wasmJsMain/kotlin/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Binding> = 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"

0 comments on commit 26d652a

Please sign in to comment.