update to littlekt 0.9.0 and add wasm target (#5)

This commit is contained in:
Colt Daily 2024-03-23 20:15:04 -04:00 committed by GitHub
parent f71c5b753f
commit a544e4e349
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 175 additions and 32 deletions

View file

@ -31,13 +31,24 @@ property in the `gradle.properties` file to ensure that the `packageFatJar` task
**Running:**
Run the `other/jsRun` gradle task like any other **Kotlin/JS** project to run in development mode.
Run the `kotlin browser/jsBrowserRun` gradle task like any other **Kotlin/JS** project to run in development mode.
**Deploying:**
Run the `kotlin browser/jsBrowserDistribution` gradle task to create a distribution build. This build will require a
webserver in order to run.
### WASM
**Running:**
Run the `kotlin browser/wasmJsBrowserRun` gradle task like any other **Kotlin/Wasm** project to run in development mode.
**Deploying:**
Run the `kotlin browser/wasmJsBrowserDistribution` gradle task to create a distribution build. This build will require a
webserver in order to run.
### Android
**Running:**

View file

@ -1,12 +1,6 @@
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath(libs.bundles.plugins)
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
}
allprojects {

View file

@ -1,15 +1,15 @@
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
repositories {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
plugins {
kotlin("multiplatform")
id("com.android.application")
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.multiplatform)
}
kotlin {
@ -69,7 +69,7 @@ kotlin {
}
}
compilations.all {
kotlinOptions.jvmTarget = "11"
kotlinOptions.jvmTarget = "17"
}
testRuns["test"].executionTask.configure {
useJUnit()
@ -95,6 +95,23 @@ kotlin {
}
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
binaries.executable()
browser {
commonWebpackConfig(Action {
devServer =
(devServer ?: org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.DevServer()).copy(
open = mapOf(
"app" to mapOf(
"name" to "firefox"
)
),
)
})
}
}
sourceSets {
val commonMain by getting {
dependencies {
@ -115,11 +132,14 @@ kotlin {
}
}
val jsTest by getting
val wasmJsMain by getting
val wasmJsTest by getting
val androidMain by getting
}
}
android {
namespace = "com.game.template"
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
assets.srcDirs("src/commonMain/resources")
@ -131,8 +151,8 @@ android {
targetSdk = (findProperty("android.targetSdk") as String).toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.template">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.VIBRATE"/>
<application

View file

@ -0,0 +1,15 @@
package com.template.game
import com.game.template.Game
import com.lehaine.littlekt.createLittleKtApp
import com.lehaine.littlekt.graphics.Color
fun main() {
createLittleKtApp {
title = "LittleKt Game Template"
backgroundColor = Color.DARK_GRAY
canvasId = "canvas"
}.start {
Game(it)
}
}

View file

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- http://localhost:80 -->
<meta http-equiv="origin-trial"
content="AjytAe1FWUIWH/RzqsOWlXYw7kGwt11ejbvR/ArmAU4QbXIPg69wzpniDhPByiOZ9pdNqsdMsXsoxggVtfGhwwMAAABOeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwIiwiZmVhdHVyZSI6IldlYkFzc2VtYmx5R0MiLCJleHBpcnkiOjE2OTg5Njk1OTl9">
<!-- http://localhost:8080 -->
<meta http-equiv="origin-trial"
content="AtSRFRWKTCcQHDFUUQL1VaVz9mjmsK1xm5k0S8etkmvMLa5TsiNeQsle/eDgdZVkm1PM1WmrSMx52kI8yAP2UgEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8081 -->
<meta http-equiv="origin-trial"
content="AspyK9xe4tO2aIvJWnr5HTRT9GqpGJID2qZjj+0OvhKHp9JrUP+92PF+Rt11Tyi7cKSEB7OFFGdeVs7Ns5TMhAUAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODEiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8082 -->
<meta http-equiv="origin-trial"
content="AoPGqwBGEQW3twSDYvXt1JHz5zg7Z4o+Orwr8NxdVoXJ68zjwOi2C8/0w4xFYW6UUH8w97eIjykGOa/+jIBfTQMAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODIiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8083 -->
<meta http-equiv="origin-trial"
content="AvV2HYiHMw7lpIVcmGMSVmm6xC0Gzu4W5xBnZExmfHtE5zyNKFszcyNGm5IfCFQ6swnMotbn16lS1ozkJ0QzEAEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODMiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<title>LittleKt - WASM</title>
<style>
#warning {
display: none;
}
#warning li {
padding-bottom: 15px;
}
#warning span.code {
font-family: monospace;
}
</style>
</head>
<body>
<div id="warning">
⚠️ Please make sure that your runtime environment supports the latest version of Wasm GC and Exception-Handling
proposals.
For more information, see <a href="https://kotl.in/wasm-help">https://kotl.in/wasm-help</a>.
<br/>
<br/>
<ul>
<li>For <b>Chrome</b> and <b>Chromium-based</b> browsers (Edge, Brave etc.), it <b>should just work</b> since
version 119.
</li>
<li>For <b>Firefox</b> 120 it <b>should just work</b>.</li>
<li>For <b>Firefox</b> 119:
<ol>
<li>Open <span class="code">about:config</span> in the browser.</li>
<li>Enable <strong>javascript.options.wasm_gc</strong>.</li>
<li>Refresh this page.</li>
</ol>
</li>
</ul>
</div>
<div id="canvas-container" style="text-align:center;">
<canvas id="canvas" width="960" height="540" style="border:1px solid #000000;"></canvas>
</div>
</body>
<script type="text/javascript" src="game.js"></script>
<script type="application/javascript">
const unhandledError = (event, error) => {
if (error instanceof WebAssembly.CompileError) {
document.getElementById("warning").style.display="initial";
}
}
addEventListener("error", (event) => unhandledError(event, event.error));
addEventListener("unhandledrejection", (event) => unhandledError(event, event.reason));
</script>
</html>

View file

@ -0,0 +1,37 @@
// Replace paths unavailable during compilation with `null`, so they will not be shown in devtools
;
(() => {
const fs = require("fs");
const path = require("path");
const outDir = __dirname + "/kotlin/"
const projecName = path.basename(__dirname);
const mapFileLegacy = outDir + projecName + ".map"
const mapFile = outDir + projecName + ".wasm.map"
let sourcemap
try {
sourcemap = JSON.parse(fs.readFileSync(mapFileLegacy))
} catch (e) {
sourcemap = JSON.parse(fs.readFileSync(mapFile))
}
const sources = sourcemap["sources"]
srcLoop: for (let i in sources) {
const srcFilePath = sources[i];
if (srcFilePath == null) continue;
const srcFileCandidates = [
outDir + srcFilePath,
outDir + srcFilePath.substring("../".length),
outDir + "../" + srcFilePath,
];
for (let srcFile of srcFileCandidates) {
if (fs.existsSync(srcFile)) continue srcLoop;
}
sources[i] = null;
}
fs.writeFileSync(mapFile, JSON.stringify(sourcemap));
})();

View file

@ -11,10 +11,9 @@ kotlin.js.generate.executable.default=false
kotlin.mpp.androidSourceSetLayoutVersion=2
#Android
android.compileSdk=33
android.targetSdk=33
android.compileSdk=34
android.targetSdk=34
android.minSdk=21
android.disableAutomaticComponentCreation=true
#JVM
jvm.mainClass=com.game.template.LwjglApp

View file

@ -1,20 +1,16 @@
[versions]
plugin-android = "7.3.1"
plugin-kotlin = "1.9.21"
agp = "8.2.0"
kotlin = "1.9.23"
kotlinx-html = "0.9.1"
kotlinx-coroutines = "1.8.0-RC2"
littlekt = "0.8.1"
kotlinx-coroutines = "1.8.0"
littlekt = "0.9.0"
[libraries]
plugin-android = { module = "com.android.tools.build:gradle", version.ref = "plugin-android" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-html-js = { module = "org.jetbrains.kotlinx:kotlinx-html-js", version.ref = "kotlinx-html" }
littlekt-core = { module = "com.lehaine.littlekt:core", version.ref = "littlekt" }
[bundles]
plugins = ["plugin-android", "plugin-kotlin"]
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }