Browse Source

Unify build.gradle.kts for experimental samples (#2445)

+ add Android traget for Minesweeper example
pull/2447/head
Nikita Lipsky 2 years ago committed by GitHub
parent
commit
85faea7243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      experimental/examples/chat-mpp/build.gradle.kts
  2. 1
      experimental/examples/chat-mpp/gradle.properties
  3. 11
      experimental/examples/chat-mpp/settings.gradle.kts
  4. 3
      experimental/examples/chat-mpp/src/androidMain/res/res/values/strings.xml
  5. 2
      experimental/examples/chat-mpp/src/androidMain/res/values/strings.xml
  6. 45
      experimental/examples/falling-balls-mpp/build.gradle.kts
  7. 1
      experimental/examples/falling-balls-mpp/gradle.properties
  8. 1
      experimental/examples/falling-balls-mpp/settings.gradle.kts
  9. 2
      experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml
  10. 82
      experimental/examples/minesweeper/build.gradle.kts
  11. 10
      experimental/examples/minesweeper/gradle.properties
  12. 15
      experimental/examples/minesweeper/settings.gradle.kts
  13. 22
      experimental/examples/minesweeper/src/androidMain/AndroidManifest.xml
  14. 15
      experimental/examples/minesweeper/src/androidMain/kotlin/MainActivity.kt
  15. 7
      experimental/examples/minesweeper/src/androidMain/kotlin/actualfuns.android.kt
  16. 3
      experimental/examples/minesweeper/src/androidMain/res/values/strings.xml
  17. 23
      experimental/examples/minesweeper/src/commonMain/kotlin/game.kt
  18. 51
      experimental/examples/minesweeper/src/commonMain/kotlin/gameInteraction.kt
  19. 2
      experimental/examples/minesweeper/src/desktopMain/kotlin/main.desktop.kt
  20. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/clock.png
  21. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/flag.png
  22. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/mine.png
  23. 19
      experimental/examples/minesweeper/src/jsMain/kotlin/main.js.kt
  24. 19
      experimental/examples/minesweeper/src/macosMain/kotlin/main.macos.kt
  25. 31
      experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

18
experimental/examples/chat-mpp/build.gradle.kts

@ -50,7 +50,7 @@ kotlin {
// Workaround for an issue: // Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location // https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose comiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors. // Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8 // TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false" val disableKonanVerification = "-Xverify-compiler=false"
@ -103,15 +103,15 @@ kotlin {
dependsOn(commonMain) dependsOn(commonMain)
kotlin.srcDirs("src/jvmMain/kotlin") kotlin.srcDirs("src/jvmMain/kotlin")
dependencies { dependencies {
api("androidx.appcompat:appcompat:1.4.1") implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-compose:1.4.0") implementation("androidx.activity:activity-compose:1.5.0")
} }
} }
val desktopMain by getting { val desktopMain by getting {
dependencies { dependencies {
implementation(compose.desktop.currentOs) implementation(compose.desktop.currentOs)
} }
} }
val jsMain by getting { val jsMain by getting {
@ -195,13 +195,6 @@ afterEvaluate {
} }
} }
// TODO: remove when https://youtrack.jetbrains.com/issue/KT-50778 fixed
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.java).configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xir-dce-runtime-diagnostic=log"
)
}
android { android {
compileSdk = 32 compileSdk = 32
@ -222,4 +215,3 @@ android {
} }
} }
} }

1
experimental/examples/chat-mpp/gradle.properties

@ -7,6 +7,7 @@ kotlin.native.cacheKind=none
kotlin.native.useEmbeddableCompilerJar=true kotlin.native.useEmbeddableCompilerJar=true
kotlin.native.enableDependencyPropagation=false kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.enableGranularSourceSetsMetadata=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true compose.desktop.verbose=true
android.useAndroidX=true android.useAndroidX=true

11
experimental/examples/chat-mpp/settings.gradle.kts

@ -1,6 +1,7 @@
pluginManagement { pluginManagement {
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral()
gradlePluginPortal() gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google() google()
@ -8,15 +9,13 @@ pluginManagement {
plugins { plugins {
val kotlinVersion = extra["kotlin.version"] as String val kotlinVersion = extra["kotlin.version"] as String
val agpVersion = extra["agp.version"] as String
val composeVersion = extra["compose.version"] as String
kotlin("jvm").version(kotlinVersion)
kotlin("multiplatform").version(kotlinVersion) kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion) kotlin("android").version(kotlinVersion)
id("com.android.base").version(agpVersion)
val agpVersion = extra["agp.version"] as String
id("com.android.application").version(agpVersion) id("com.android.application").version(agpVersion)
id("com.android.library").version(agpVersion)
val composeVersion = extra["compose.version"] as String
id("org.jetbrains.compose").version(composeVersion) id("org.jetbrains.compose").version(composeVersion)
} }
} }

3
experimental/examples/chat-mpp/src/androidMain/res/res/values/strings.xml

@ -1,3 +0,0 @@
<resources>
<string name="app_name">Chat app</string>
</resources>

2
experimental/examples/chat-mpp/src/androidMain/res/values/strings.xml

@ -1,3 +1,3 @@
<resources> <resources>
<string name="app_name">Chat app</string> <string name="app_name">Chat</string>
</resources> </resources>

45
experimental/examples/falling-balls-mpp/build.gradle.kts

@ -5,15 +5,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.compose.experimental.dsl.IOSDevices import org.jetbrains.compose.experimental.dsl.IOSDevices
buildscript {
repositories {
mavenLocal()
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
plugins { plugins {
id("com.android.application") id("com.android.application")
kotlin("multiplatform") kotlin("multiplatform")
@ -24,10 +15,10 @@ version = "1.0-SNAPSHOT"
repositories { repositories {
mavenLocal() mavenLocal()
google()
mavenCentral() mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()} }
kotlin { kotlin {
android() android()
@ -56,6 +47,13 @@ kotlin {
} }
} }
} }
// Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false"
iosX64("uikitX64") { iosX64("uikitX64") {
binaries { binaries {
executable() { executable() {
@ -63,7 +61,8 @@ kotlin {
freeCompilerArgs += listOf( freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal", "-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText", "-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics" "-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
) )
} }
} }
@ -75,10 +74,9 @@ kotlin {
freeCompilerArgs += listOf( freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal", "-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText", "-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics" "-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
) )
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
} }
} }
} }
@ -187,15 +185,6 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11" kotlinOptions.jvmTarget = "11"
} }
kotlin {
targets.withType<KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
compose.desktop.nativeApplication { compose.desktop.nativeApplication {
targets(kotlin.targets.getByName("macosX64")) targets(kotlin.targets.getByName("macosX64"))
distributions { distributions {
@ -214,14 +203,6 @@ afterEvaluate {
} }
} }
// TODO: remove when https://youtrack.jetbrains.com/issue/KT-50778 fixed
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.java).configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xir-dce-runtime-diagnostic=log"
)
}
android { android {
compileSdk = 32 compileSdk = 32

1
experimental/examples/falling-balls-mpp/gradle.properties

@ -11,6 +11,7 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.binary.memoryModel=experimental kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true compose.desktop.verbose=true
android.useAndroidX=true android.useAndroidX=true
kotlin.js.webpack.major.version=4
org.jetbrains.compose.experimental.jscanvas.enabled=true org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true org.jetbrains.compose.experimental.uikit.enabled=true

1
experimental/examples/falling-balls-mpp/settings.gradle.kts

@ -21,4 +21,3 @@ pluginManagement {
} }
rootProject.name = "falling-balls-mpp" rootProject.name = "falling-balls-mpp"

2
experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml

@ -1,3 +1,3 @@
<resources> <resources>
<string name="app_name">Chat app</string> <string name="app_name">Falling Balls</string>
</resources> </resources>

82
experimental/examples/minesweeper/build.gradle.kts

@ -5,30 +5,23 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.compose.experimental.dsl.IOSDevices import org.jetbrains.compose.experimental.dsl.IOSDevices
buildscript {
repositories {
mavenLocal()
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
plugins { plugins {
kotlin("multiplatform") version "1.7.10" id("com.android.application")
id("org.jetbrains.compose") version "1.3.0-alpha01-dev827" kotlin("multiplatform")
id("org.jetbrains.compose")
} }
version = "1.0-SNAPSHOT" version = "1.0-SNAPSHOT"
repositories { repositories {
mavenLocal() mavenLocal()
google()
mavenCentral() mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
} }
kotlin { kotlin {
android()
jvm("desktop") jvm("desktop")
js(IR) { js(IR) {
browser() browser()
@ -54,6 +47,13 @@ kotlin {
} }
} }
} }
// Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false"
iosX64("uikitX64") { iosX64("uikitX64") {
binaries { binaries {
executable() { executable() {
@ -61,22 +61,22 @@ kotlin {
freeCompilerArgs += listOf( freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal", "-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText", "-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics" "-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
) )
} }
} }
} }
iosArm64("uikitArm64") { iosArm64("uikitArm64") {
binaries { binaries {
executable() { executable() {
entryPoint = "main" entryPoint = "main"
freeCompilerArgs += listOf( freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal", "-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText", "-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics" "-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
) )
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
} }
} }
} }
@ -88,15 +88,23 @@ kotlin {
implementation(compose.foundation) implementation(compose.foundation)
implementation(compose.material) implementation(compose.material)
implementation(compose.runtime) implementation(compose.runtime)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3")
//TODO hotfix of issue https://github.com/JetBrains/compose-jb/issues/2113
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
} }
} }
val commonTest by getting { val commonTest by getting {
dependencies { dependencies {
implementation(kotlin("test")) implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependsOn(commonMain)
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-compose:1.5.0")
} }
} }
@ -180,15 +188,6 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11" kotlinOptions.jvmTarget = "11"
} }
kotlin {
targets.withType<KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
// a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273 // a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273
afterEvaluate { afterEvaluate {
rootProject.extensions.configure<NodeJsRootExtension> { rootProject.extensions.configure<NodeJsRootExtension> {
@ -197,3 +196,24 @@ afterEvaluate {
nodeVersion = "16.0.0" nodeVersion = "16.0.0"
} }
} }
android {
compileSdk = 32
defaultConfig {
minSdk = 26
targetSdk = 32
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res", "src/commonMain/resources")
}
}
}

10
experimental/examples/minesweeper/gradle.properties

@ -1,11 +1,17 @@
compose.version=1.3.0-alpha01-dev827
kotlin.version=1.7.10
agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g
kotlin.code.style=official
kotlin.native.cacheKind=none kotlin.native.cacheKind=none
kotlin.native.useEmbeddableCompilerJar=true kotlin.native.useEmbeddableCompilerJar=true
org.gradle.jvmargs=-Xmx3g
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
# Enable kotlin/native experimental memory model # Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true compose.desktop.verbose=true
android.useAndroidX=true
kotlin.js.webpack.major.version=4
org.jetbrains.compose.experimental.jscanvas.enabled=true org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true org.jetbrains.compose.experimental.uikit.enabled=true

15
experimental/examples/minesweeper/settings.gradle.kts

@ -1,11 +1,22 @@
pluginManagement { pluginManagement {
repositories { repositories {
mavenLocal() mavenLocal()
gradlePluginPortal()
mavenCentral() mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") } gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google() google()
} }
plugins {
val kotlinVersion = extra["kotlin.version"] as String
kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
val agpVersion = extra["agp.version"] as String
id("com.android.application").version(agpVersion)
val composeVersion = extra["compose.version"] as String
id("org.jetbrains.compose").version(composeVersion)
}
} }
rootProject.name = "minesweeper" rootProject.name = "minesweeper"

22
experimental/examples/minesweeper/src/androidMain/AndroidManifest.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jetbrains.minesweeper">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:exported="true"
android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

15
experimental/examples/minesweeper/src/androidMain/kotlin/MainActivity.kt

@ -0,0 +1,15 @@
package org.jetbrains.minesweeper
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import Game
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Game()
}
}
}

7
experimental/examples/minesweeper/src/androidMain/kotlin/actualfuns.android.kt

@ -0,0 +1,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
@Composable
actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
actual fun isMobileDevice() = true

3
experimental/examples/minesweeper/src/androidMain/res/values/strings.xml

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Minesweeper</string>
</resources>

23
experimental/examples/minesweeper/src/commonMain/kotlin/game.kt

@ -5,7 +5,9 @@ import androidx.compose.foundation.*
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.ui.* import androidx.compose.ui.*
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.* import androidx.compose.ui.unit.*
import kotlin.math.max import kotlin.math.max
@ -13,6 +15,27 @@ import kotlin.math.max
@Composable @Composable
expect fun loadImage(src: String): Painter expect fun loadImage(src: String): Painter
fun loadImageAsColoredRect(src: String): Painter {
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
expect fun isMobileDevice(): Boolean
object Difficulty { object Difficulty {
val EASY = GameSettings(9, 9, 10) val EASY = GameSettings(9, 9, 10)
val MEDIUM = GameSettings(16, 16, 40) val MEDIUM = GameSettings(16, 16, 40)

51
experimental/examples/minesweeper/src/commonMain/kotlin/gameInteraction.kt

@ -1,30 +1,47 @@
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.* import androidx.compose.ui.input.pointer.*
@OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun Modifier.gameInteraction(open: () -> Unit, flag: () -> Unit, seek: () -> Unit): Modifier = fun Modifier.gameInteraction(open: () -> Unit, flag: () -> Unit, seek: () -> Unit): Modifier =
pointerInput(open, flag, seek) { if (isMobileDevice()) {
awaitPointerEventScope { combinedClickable(
while (true) { onClick = {
val event = awaitPointerEvent(PointerEventPass.Main) open()
with(event) { },
if (type == PointerEventType.Press) { onDoubleClick = {
// TODO does not work yet, all events are of Unknown type ( seek()
val lmb = buttons.isPrimaryPressed },
val rmb = buttons.isSecondaryPressed onLongClick = {
flag()
}
)
} else {
pointerInput(open, flag, seek) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent(PointerEventPass.Main)
with(event) {
if (type == PointerEventType.Press) {
// TODO does not work yet, all events are of Unknown type (
val lmb = buttons.isPrimaryPressed
val rmb = buttons.isSecondaryPressed
if (lmb && !rmb) { if (lmb && !rmb) {
if (keyboardModifiers.isShiftPressed) { if (keyboardModifiers.isShiftPressed) {
seek() seek()
} else { } else {
open() open()
}
} else if (rmb && !lmb) {
flag()
} }
} else if (rmb && !lmb) {
flag()
} }
} }
} }
} }
} }
} }

2
experimental/examples/minesweeper/src/desktopMain/kotlin/main.desktop.kt

@ -28,3 +28,5 @@ fun main() = application {
@Composable @Composable
actual fun loadImage(src: String): Painter = painterResource(src) actual fun loadImage(src: String): Painter = painterResource(src)
actual fun isMobileDevice() = false

0
experimental/examples/minesweeper/src/commonMain/resources/assets/clock.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/clock.png

Before

Width:  |  Height:  |  Size: 896 B

After

Width:  |  Height:  |  Size: 896 B

0
experimental/examples/minesweeper/src/commonMain/resources/assets/flag.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/flag.png

Before

Width:  |  Height:  |  Size: 780 B

After

Width:  |  Height:  |  Size: 780 B

0
experimental/examples/minesweeper/src/commonMain/resources/assets/mine.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/mine.png

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

19
experimental/examples/minesweeper/src/jsMain/kotlin/main.js.kt

@ -19,21 +19,6 @@ fun main() {
} }
@Composable @Composable
actual fun loadImage(src: String): Painter { actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() { actual fun isMobileDevice() = false
drawRect(color = color)
}
}
}

19
experimental/examples/minesweeper/src/macosMain/kotlin/main.macos.kt

@ -30,21 +30,6 @@ fun main() {
} }
@Composable @Composable
actual fun loadImage(src: String): Painter { actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() { actual fun isMobileDevice() = false
drawRect(color = color)
}
}
}

31
experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

@ -3,46 +3,21 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/ */
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application import androidx.compose.ui.window.Application
import androidx.compose.ui.main.defaultUIKitMain import androidx.compose.ui.main.defaultUIKitMain
fun main() { fun main() {
defaultUIKitMain("Minesweeper", Application("Minesweeper") { defaultUIKitMain("Minesweeper", Application("Minesweeper") {
Column { Game()
// To skip upper part of screen.
Box(modifier = Modifier
.height(100.dp))
Game()
}
}) })
} }
@Composable @Composable
actual fun loadImage(src: String): Painter { actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() { actual fun isMobileDevice() = true
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
Loading…
Cancel
Save