Create hello-platform for macOS (#10)
Co-authored-by: Михаил Капелько <kornerr@gmail.com>
No files matched your search
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="OGS blue"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyApplication"
|
||||
tools:targetApi="35">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="OGS blue"
|
||||
android:theme="@style/Theme.MyApplication"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.opengamestudio
|
||||
|
||||
object ActivityDelegate {
|
||||
val blue = BlueComponent
|
||||
|
||||
init {
|
||||
otherSetupConsoleLogging(blue.ctrl, "Blue")
|
||||
}
|
||||
|
||||
fun setup() {
|
||||
blue.setup()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.opengamestudio
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import androidx.activity.*
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.ui.*
|
||||
import androidx.compose.ui.graphics.Color as ComposeColor
|
||||
import org.opengamestudio.ui.theme.MyApplicationTheme
|
||||
|
||||
class MainActivity: ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
ActivityDelegate.setup()
|
||||
|
||||
enableEdgeToEdge(
|
||||
navigationBarStyle = SystemBarStyle.dark(Color.TRANSPARENT),
|
||||
statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT)
|
||||
)
|
||||
setContent {
|
||||
MyApplicationTheme {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(ComposeColor.White)
|
||||
) {
|
||||
BlueView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../components/blue/android/blue.kt
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../../components/blue/android/view/BlueView.kt
|
||||
@@ -0,0 +1,209 @@
|
||||
package org.opengamestudio
|
||||
|
||||
|
||||
val DIALECT_CONTEXT_RECENT_FIELD_NONE = "none"
|
||||
|
||||
interface DialectContext {
|
||||
/**
|
||||
* Name of the field that has just been changed
|
||||
*
|
||||
* Allows should-functions (reducers) to react only to
|
||||
* relevant changes and ignore other changes of DialectContext
|
||||
*/
|
||||
var recentField: String
|
||||
|
||||
/**
|
||||
* Get field's value by its name
|
||||
*/
|
||||
fun <T> field(name: String): T
|
||||
/**
|
||||
* Erase type
|
||||
*
|
||||
* Used by DialectController to assign recent field's value
|
||||
*/
|
||||
fun fieldAny(name: String): Any {
|
||||
return field(name)
|
||||
}
|
||||
/**
|
||||
* Create a copy of the DialectContext derivative
|
||||
*
|
||||
* Used by DialectController to treat all derived contexts as DialectContext
|
||||
*/
|
||||
fun selfCopy(): DialectContext
|
||||
/**
|
||||
* Set field's value by its name
|
||||
*/
|
||||
fun setField(name: String, value: Any?)
|
||||
}
|
||||
|
||||
|
||||
class DialectController(
|
||||
var context: DialectContext
|
||||
) {
|
||||
internal var callbacks = mutableListOf<(c: DialectContext) -> Unit>()
|
||||
internal var functions = mutableListOf<(c: DialectContext) -> DialectContext>()
|
||||
var isProcessingQueue = false
|
||||
internal var queue = mutableListOf<DialectContext>()
|
||||
|
||||
fun executeFunctions() {
|
||||
val c = queue.removeAt(0)
|
||||
// Keep SSOT: Only allow single field change per should-function
|
||||
context.recentField = c.recentField
|
||||
context.setField(c.recentField, c.fieldAny(c.recentField))
|
||||
|
||||
for (f in functions) {
|
||||
val ctx = f(context.selfCopy())
|
||||
if (ctx.recentField != DIALECT_CONTEXT_RECENT_FIELD_NONE) {
|
||||
queue.add(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
reportContext()
|
||||
}
|
||||
|
||||
fun processQueue() {
|
||||
// Prevent recursion.
|
||||
if (isProcessingQueue) {
|
||||
return
|
||||
}
|
||||
|
||||
isProcessingQueue = true
|
||||
|
||||
while (queue.size > 0) {
|
||||
executeFunctions()
|
||||
}
|
||||
|
||||
isProcessingQueue = false
|
||||
}
|
||||
|
||||
fun registerCallback(cb: (c: DialectContext) -> Unit) {
|
||||
callbacks.add(cb)
|
||||
}
|
||||
|
||||
fun registerFieldCallback(
|
||||
fieldName: String,
|
||||
cb: (DialectContext) -> Unit
|
||||
) {
|
||||
callbacks.add({ c ->
|
||||
if (c.recentField == fieldName) {
|
||||
cb(c)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun registerFunction(f: (DialectContext) -> DialectContext) {
|
||||
functions.add(f)
|
||||
}
|
||||
|
||||
fun reportContext() {
|
||||
for (cb in callbacks) {
|
||||
cb(context)
|
||||
}
|
||||
}
|
||||
|
||||
fun set(fieldName: String, value: Any) {
|
||||
var c = context.selfCopy()
|
||||
c.setField(fieldName, value)
|
||||
c.recentField = fieldName
|
||||
queue.add(c)
|
||||
processQueue()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Register several oneliner callbacks to a controller
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun registerOneliners(
|
||||
ctrl: DialectController,
|
||||
items: Array<Any>
|
||||
) {
|
||||
val halfCount = items.size / 2
|
||||
for (i in 0..<halfCount) {
|
||||
val field = items[i * 2] as String
|
||||
val callback = items[i * 2 + 1] as (c: DialectContext) -> Unit
|
||||
ctrl.registerFieldCallback(field, callback)
|
||||
}
|
||||
}
|
||||
|
||||
// Context field names for static type check
|
||||
object F {
|
||||
const val didLaunch = "didLaunch"
|
||||
const val didSetup = "didSetup"
|
||||
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
data class BlueContext(
|
||||
var didLaunch: Boolean = false,
|
||||
var didSetup: Boolean = false,
|
||||
|
||||
override var recentField: String = ""
|
||||
) : DialectContext {
|
||||
override fun <T> field(name: String): T {
|
||||
if (name == "didLaunch") {
|
||||
return didLaunch as T
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
return didSetup as T
|
||||
}
|
||||
|
||||
return "" as T
|
||||
}
|
||||
|
||||
override fun selfCopy(): DialectContext {
|
||||
return this.copy()
|
||||
}
|
||||
|
||||
override fun setField(
|
||||
name: String,
|
||||
value: Any?
|
||||
) {
|
||||
if (name == "didLaunch") {
|
||||
didLaunch = value as Boolean
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
didSetup = value as Boolean
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun blueSet(
|
||||
key: String,
|
||||
value: Any
|
||||
) {
|
||||
BlueComponent.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
fun blueShouldResetDidLaunch(c: BlueContext): BlueContext {
|
||||
val c = c
|
||||
|
||||
// 1. Only once during the first setup
|
||||
if (
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
) {
|
||||
c.didLaunch = true
|
||||
c.recentField = F.didLaunch
|
||||
return c
|
||||
}
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
fun blueRegisterShoulds(ctrl: DialectController) {
|
||||
listOf(
|
||||
::blueShouldResetDidLaunch,
|
||||
|
||||
).forEach { f ->
|
||||
ctrl.registerFunction { c -> f(c as BlueContext) }
|
||||
}
|
||||
}
|
||||
|
||||
fun blueRegisterEffects(ctrl: DialectController) {
|
||||
registerOneliners(ctrl, arrayOf(
|
||||
F.didLaunch, { c: BlueContext -> print("Blue launched") },
|
||||
|
||||
))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../components/other/other.kt
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.opengamestudio.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.opengamestudio.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80
|
||||
)
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun MyApplicationTheme(
|
||||
darkTheme: Boolean = false,
|
||||
dynamicColor: Boolean = false,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
|
||||
if (darkTheme) dynamicDarkColorScheme(LocalContext.current)
|
||||
else dynamicLightColorScheme(LocalContext.current)
|
||||
darkTheme -> DarkColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.opengamestudio.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.*
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
)
|
||||
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_artwork" />
|
||||
<foreground android:drawable="@android:color/transparent" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_artwork" />
|
||||
<foreground android:drawable="@android:color/transparent" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">OGS blue</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.MyApplication" parent="android:Theme.Material.NoActionBar">
|
||||
<item name="android:windowBackground">#000000</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
</full-backup-content>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<exclude domain="root" />
|
||||
</cloud-backup>
|
||||
<device-transfer>
|
||||
<exclude domain="root" />
|
||||
</device-transfer>
|
||||
</data-extraction-rules>
|
||||