Skip to content

Commit

Permalink
Merge pull request #16 from teogor/feature/drifter-annotation-processor
Browse files Browse the repository at this point in the history
Enable code generation for Drifter modules with KSP plugin
  • Loading branch information
teogor authored Feb 24, 2024
2 parents 2a19a00 + bc520af commit 6152451
Show file tree
Hide file tree
Showing 51 changed files with 2,065 additions and 136 deletions.
21 changes: 15 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
plugins {
alias(libs.plugins.ceres.android.application)
alias(libs.plugins.ceres.android.application.compose)
alias(libs.plugins.ksp)
}

android {
namespace = "dev.teogor.drifter.demo"

defaultConfig {
applicationId = "dev.teogor.drifter.demo"
applicationId = "com.zeoowl.lwp.aquarium"
versionCode = 1
versionName = "1.0.0-alpha01"

Expand Down Expand Up @@ -51,12 +52,16 @@ android {
}

dependencies {
implementation(project(":module-unity"))
implementation(projects.moduleUnity)

implementation(project(":drifter-compose"))
implementation(project(":drifter-core"))
implementation(project(":drifter-integration"))
implementation(project(":drifter-wallpaper"))
implementation(projects.runtime)
ksp(projects.ksp)

implementation(projects.drifterCommon)
implementation(projects.drifterCompose)
implementation(projects.drifterCore)
implementation(projects.drifterIntegration)
implementation(projects.drifterWallpaper)

implementation(libs.gson)
implementation(libs.core.ktx)
Expand All @@ -75,3 +80,7 @@ dependencies {
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)
}

ksp {
logging.captureStandardError(LogLevel.INFO)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.teogor.drifter.common

object StatusBarHeightPlugin {
val statusBarHeight: Int
get() { return 200 }
}
58 changes: 58 additions & 0 deletions app/src/main/kotlin/dev/teogor/drifter/demo/AquariumModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2024 teogor (Teodor Grigor)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.teogor.drifter.demo

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import dev.teogor.drifter.DrifterEncoder
import dev.teogor.drifter.DrifterMappingKey
import dev.teogor.drifter.DrifterModule
import dev.teogor.drifter.DrifterUnityMethod
import dev.teogor.drifter.demo.models.CycleOption

@DrifterModule(
name = "Aquarium",
receiver = "BridgeController",
methods = AquariumMethods::class,
)
data class AquariumModule(
@DrifterMappingKey(
exposedMethod = "SetEditorMode",
)
val isEditorMode: Boolean? = null,
val waterColor: Color? = null,
val animated: Boolean? = null,
val cycleOption: CycleOption,
val statusBarColor: Color,
val statusBarIsVisible: Boolean,
val statusBarOpacity: Float,
val statusBarHeight: Int,
)

interface AquariumMethods {
@DrifterUnityMethod(
name = "animateToWaterColor",
parameters = [
"waterColor",
"animated",
],
)
fun animateToWaterColor()
}

@DrifterEncoder
fun Color.encodeFromColor() = toArgb()
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,54 @@
* limitations under the License.
*/

package dev.teogor.drifter.demo.unity
package dev.teogor.drifter.demo

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import dev.teogor.drifter.demo.unity.models.CycleOption
import dev.teogor.drifter.demo.unity.models.StorageKeys
import dev.teogor.drifter.integration.common.TypeConverter
import dev.teogor.drifter.integration.core.UnityStorageBase
import dev.teogor.drifter.common.UnityPlayerPrefs
import dev.teogor.drifter.common.UnityPrefAccess
import dev.teogor.drifter.common.createSerializable
import dev.teogor.drifter.demo.models.CycleOption

class UnityStorage : UnityStorageBase() {

private val colorConverter = TypeConverter(
toString = { color -> color.toArgb().toString() },
fromString = { string -> Color(string.toInt()) },
class AquariumStorage : UnityPlayerPrefs() {
private val colorConverter = createSerializable(
encodeToString = { color -> color.toArgb().toString() },
decodeFromString = { string -> Color(string.toInt()) },
)

@OptIn(UnityPrefAccess::class)
var waterColor: Color = Color(0xFF6FA3EF)
get() {
field = getStorageElement(
key = StorageKeys.WaterColor,
field = get(
key = AquariumKeyConstants.WATER_COLOR,
defaultValue = field,
converter = colorConverter,
)
return field
}
set(value) {
println("Write Color ::")
field = writeElement(
key = StorageKeys.WaterColor,
content = value,
field = set(
key = AquariumKeyConstants.WATER_COLOR,
value = value,
converter = colorConverter,
)
}

@OptIn(UnityPrefAccess::class)
var cycleOption: CycleOption = CycleOption.Day
get() {
val cycleOptionContent = getStorageElement(
key = StorageKeys.CycleOption,
val cycleOptionContent = get(
key = AquariumKeyConstants.CYCLE_OPTION,
defaultValue = field.ordinal,
)
field = CycleOption.entries[cycleOptionContent]
return field
}
set(value) {
field = value
writeElement(
key = StorageKeys.CycleOption,
content = value.ordinal,
set(
key = AquariumKeyConstants.CYCLE_OPTION,
value = value.ordinal,
)
}
}
18 changes: 8 additions & 10 deletions app/src/main/kotlin/dev/teogor/drifter/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ import androidx.lifecycle.Lifecycle
import dev.teogor.drifter.compose.OnLifecycleEvent
import dev.teogor.drifter.compose.UvpComposable
import dev.teogor.drifter.demo.ui.theme.UnityViewTheme
import dev.teogor.drifter.demo.unity.UnityController
import dev.teogor.drifter.demo.unity.UnityStorage
import dev.teogor.drifter.wallpaper.LiveWallpaperUtility

class MainActivity : ComponentActivity() {
Expand All @@ -84,8 +82,8 @@ class MainActivity : ComponentActivity() {
) {
val context = LocalContext.current

val controller = UnityController()
val storage = UnityStorage()
val controller = AquariumMessageSender()
val storage = AquariumStorage()

UvpComposable(
modifier = Modifier
Expand All @@ -98,8 +96,8 @@ class MainActivity : ComponentActivity() {
onCreated = {
controller.apply {
setEditorMode(true)
setEditorColor(storage.waterColor, false)
setEditorCycleOption(storage.cycleOption)
animateToWaterColor(storage.waterColor, false)
cycleOption(storage.cycleOption)
}
},
)
Expand Down Expand Up @@ -128,8 +126,8 @@ class MainActivity : ComponentActivity() {

@Composable
fun UnityColorPicker(
controller: UnityController,
storage: UnityStorage,
controller: AquariumMessageSender,
storage: AquariumStorage,
) {
val colors = listOf(
Color(0xFFB19CD9), // Lavender
Expand Down Expand Up @@ -166,14 +164,14 @@ fun UnityColorPicker(
}

LaunchedEffect(selectedColor) {
controller.setEditorColor(selectedColor)
controller.animateToWaterColor(selectedColor, true)
}

OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
controller.setEditorMode(true)
controller.setEditorColor(selectedColor)
controller.animateToWaterColor(selectedColor, true)
}

Lifecycle.Event.ON_PAUSE -> {
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/kotlin/dev/teogor/drifter/demo/models/CycleOption.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 teogor (Teodor Grigor)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.teogor.drifter.demo.models

enum class CycleOption {
Day,
Night,
Auto,
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.kotlin.jvm) apply false

alias(libs.plugins.ceres.android.application) apply false
alias(libs.plugins.ceres.android.application.compose) apply false
Expand Down Expand Up @@ -80,6 +81,8 @@ winds {

val excludedModulesForWinds = listOf(
":drifter-plugin",
":app",
":module-unity",
)
afterWindsPluginConfiguration { winds ->
if (!excludedModulesForWinds.contains(path)) {
Expand Down Expand Up @@ -118,6 +121,8 @@ val ktlintVersion = "0.50.0"

val excludeModules = listOf(
project.name,
"app",
"module-unity",
)

subprojects {
Expand Down
1 change: 1 addition & 0 deletions codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit 6152451

Please sign in to comment.