Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Feb 16, 2024
1 parent b22ef09 commit 1a3488e
Show file tree
Hide file tree
Showing 22 changed files with 742 additions and 830 deletions.
14 changes: 14 additions & 0 deletions .fleet/receipt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Project generated by Kotlin Multiplatform Wizard
{
"spec": {
"template_id": "kmt",
"targets": {
"web": {
"ui": [
"compose"
]
}
}
},
"timestamp": "2024-02-16T06:46:50.981192499Z"
}
14 changes: 7 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ jobs:
name: Test and Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Setup Java 17 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- name: Grant execute permission for gradlew
if: ${{ runner.os != 'Windows' }}
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Execute Gradle build
run: ./gradlew build

# If main branch update, deploy to gh-pages
- name: Deploy
Expand All @@ -28,5 +28,5 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: build/dist/js/productionExecutable # The folder the action should deploy.
folder: composeApp/build/dist/wasmJs/productionExecutable # The folder the action should deploy.
clean: true # Automatically remove deleted files from the deploy branch
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ bin/
.DS_Store

.idea/
**/build/
xcuserdata
!src/**/build/
local.properties
captures
.externalNativeBuild
.cxx
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OverrunGL Artifacts Customizer
# OverrunGL Modules Customizer

[![pages-build-deployment](https://github.com/Over-Run/overrungl-gen/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/Over-Run/overrungl-gen/actions/workflows/pages/pages-build-deployment)

The customizer for OverrunGL is available on [GitHub](https://over-run.github.io/overrungl-gen/).
The customizer for [OverrunGL](https://github.com/Over-Run/overrungl) is available on [GitHub](https://over-run.github.io/overrungl-gen/).
65 changes: 4 additions & 61 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
plugins {
kotlin("multiplatform") version "1.9.0"
application
}

group = "io.github.over-run"
version = "0.2.2"

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}

kotlin {
jvm {
jvmToolchain(17)
withJava()
}
js {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
}
}
sourceSets {
val commonMain by getting
val commonTest by getting
val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-server-netty:2.0.2")
implementation("io.ktor:ktor-server-html-builder-jvm:2.0.2")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
}
}
val jvmTest by getting
val jsMain by getting {
dependencies {
implementation("org.jetbrains.kotlin-wrappers:kotlin-react:18.2.0-pre.346")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:18.2.0-pre.346")
implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion:11.9.3-pre.346")
}
}
val jsTest by getting
}
}

application {
mainClass.set("io.github.overrun.application.ServerKt")
}

tasks.named<Copy>("jvmProcessResources") {
val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
from(jsBrowserDistribution)
}

tasks.named<JavaExec>("run") {
dependsOn(tasks.named<Jar>("jvmJar"))
classpath(tasks.named<Jar>("jvmJar"))
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
}
40 changes: 40 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kotlinMultiplatform)

alias(libs.plugins.jetbrainsCompose)
}

kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
browser {
commonWebpackConfig {
outputFileName = "composeApp.js"
}
}
binaries.executable()
}

sourceSets {

commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
}
}
}



compose.experimental {
web.application {}
}
154 changes: 154 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import LangType.GRADLE_GROOVY
import LangType.GRADLE_KOTLIN
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import kotlinx.browser.localStorage
import kotlinx.browser.window
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.Font
import org.jetbrains.compose.resources.FontResource

@Composable
fun App() {
MaterialTheme {
Scaffold(topBar = {
TopAppBar(title = {
Text("OverrunGL Modules Customizer")
Text("v0.3.0", fontSize = 0.8.em)
})
}) {
Surface(modifier = Modifier.fillMaxSize()) {
Customizer()
}
}
}
}

@OptIn(ExperimentalResourceApi::class)
@Composable
private fun Customizer() {
val JetBrainsMono = FontFamily(
Font(FontResource("jetbrainsmono_regular.ttf"), weight = FontWeight.Normal)
)
var langType by remember {
mutableStateOf(
langTypeFromString(localStorage.getItem("langType")) ?: GRADLE_KOTLIN
)
}
val generatedCode = remember {
when (langType) {
GRADLE_GROOVY -> generateGroovy()
GRADLE_KOTLIN -> generateKotlin()
}
}

Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
// disclaimer
Text(
"Disclaimer: this customizer uses experimental features and might occur errors when any key is pressed",
fontWeight = FontWeight.Bold
)

// select the build type
Row {
Button(onClick = {}, 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")
}
}
}

Surface(modifier = Modifier.fillMaxSize().padding(all = 16.dp)) {
// inside
Surface(
modifier = Modifier.fillMaxSize(),
border = BorderStroke(width = 2.dp, color = MaterialTheme.colors.onSurface)
) {
Column {
Row(modifier = Modifier.fillMaxWidth().padding(all = 16.dp)) {
@Composable
inline fun optionTitle(text: String) {
Text(text, fontSize = 1.2.em, fontWeight = FontWeight.Bold)
}

Column {
// natives
optionTitle("Natives")
}

Column(modifier = Modifier.padding(start = 16.dp, end = 16.dp)) {
// addons
optionTitle("Addons")

// version
optionTitle("Version")
}

Column {
// modules
optionTitle("Modules")
}
}

// generated code
Column(modifier = Modifier.padding(all = 16.dp)) {
Row {
langTypeButton(GRADLE_GROOVY) { langType = it }
langTypeButton(GRADLE_KOTLIN) { langType = it }
}
Surface(
modifier = Modifier.fillMaxWidth(),
border = ButtonDefaults.outlinedBorder
) {
// SelectionContainer {
Text(
generatedCode, modifier = Modifier.padding(2.dp), fontFamily = JetBrainsMono
)
// }
}
Button(onClick = {
window.navigator.clipboard.writeText(generatedCode)
}) {
Icon(Icons.Default.ContentCopy, contentDescription = null)
Text("Copy to clipboard")
}
}
}

}
}
}
}

fun generateGroovy(): String = buildString {
appendLine("dependencies {")
append("}")
}

fun generateKotlin(): String = buildString {
appendLine("dependencies {")
append("}")
}

@Composable
fun langTypeButton(langType: LangType, onClick: (LangType) -> Unit) {
OutlinedButton(onClick = {
onClick(langType)
localStorage.setItem("langType", langType.name)
}) {
Text(langType.typeName)
}
}
6 changes: 6 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/Binding.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @author squid233
* @since 0.3.0
*/
enum class Binding {
}
14 changes: 14 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/LangType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @author squid233
* @since 0.3.0
*/
enum class LangType(val typeName: String) {
GRADLE_GROOVY("Gradle (Groovy)"),
GRADLE_KOTLIN("Gradle (Kotlin)"),
}

fun langTypeFromString(name: String?): LangType? = when (name) {
"GRADLE_GROOVY" -> LangType.GRADLE_GROOVY
"GRADLE_KOTLIN" -> LangType.GRADLE_KOTLIN
else -> null
}
11 changes: 11 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @author squid233
* @since 0.3.0
*/
class Version(val versionName: String) {
override fun toString(): String = versionName
}

val V0_1_0 = Version("0.1.0")

val V_LATEST = V0_1_0
Loading

0 comments on commit 1a3488e

Please sign in to comment.