Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d11461c5ae | ||
|
|
db71e37cd2 | ||
|
|
199ec2d7b9 | ||
|
|
c2ab69c3d0 | ||
|
|
ed8803dbc1 | ||
|
|
325499d404 | ||
|
|
3bcfc32ef1 | ||
|
|
5e5537aee6 | ||
|
|
cd82f445d3 | ||
|
|
f0972f0d5b | ||
|
|
f4fd8cb523 | ||
|
|
d4da4325f9 | ||
|
|
3ab45ab003 | ||
|
|
32dd0ab113 | ||
|
|
b750dace76 | ||
|
|
ea68f48608 | ||
|
|
de36ad782c | ||
|
|
7bd72fc60a | ||
|
|
26528819a7 | ||
|
|
360be210c2 | ||
|
|
b9b7e91bcd | ||
|
|
6c142f794c | ||
|
|
f76932fd91 | ||
|
|
1f92c8e41c | ||
|
|
7b8c3181d5 | ||
|
|
b1dd0a5107 | ||
|
|
2fbaba4a51 | ||
|
|
cc2748efb7 | ||
|
|
9757a40b36 | ||
|
|
48f7d37c78 | ||
|
|
ac649266ac | ||
|
|
d613f3ace1 | ||
|
|
701e3a983a | ||
|
|
1dc202b1af | ||
|
|
aa541a8e23 | ||
|
|
3f94adf13a | ||
|
|
2ecd15e79f | ||
|
|
9d6c2aeb27 | ||
|
|
36392764f7 | ||
|
|
4d639fc6b5 | ||
|
|
730da461c3 | ||
|
|
bfc4b22b48 | ||
|
|
433afa5f9e | ||
|
|
7361f5c212 | ||
|
|
e6056ae8b2 | ||
|
|
9c5b298131 | ||
|
|
64bb22560c | ||
|
|
dfe16133df | ||
|
|
5a3f45dfa4 | ||
|
|
e3844dfb18 | ||
|
|
21605f98b4 | ||
|
|
1c841a18bb | ||
|
|
d0b45b6b99 | ||
|
|
cfd9f9c0af | ||
|
|
9101b9f5d4 | ||
|
|
3ee51fd355 | ||
|
|
7e511afb73 | ||
|
|
6e5a355fc8 | ||
|
|
5a875b44a8 | ||
|
|
4263d65090 |
No files matched your search
@@ -1,73 +1,176 @@
|
|||||||
# OGS applications (`mj`)
|
# OGS applications (`mj`)
|
||||||
|
|
||||||
Native SwiftUI and Compose apps on the Dialect v4 declarative reactive engine.
|
Native SwiftUI applications using the Dialect v4 declarative reactive engine.
|
||||||
Remote: `https://git.opengamestudio.org/mahjong/mahjong`.
|
Version: `2.0.0`. Remote: `https://git.opengamestudio.org/mahjong/mahjong`.
|
||||||
|
|
||||||
## Apps
|
## Current status
|
||||||
|
|
||||||
- `hello/hello-platform/` — macOS + iOS + Android platform-support sample (Hello counter). Its
|
- `ogs-blue/` is the active minimal graphics example for macOS and iOS: a solid
|
||||||
structure, startup flow and dialect rules are in
|
blue raylib background with a SwiftUI overlay. It has no model/texture/shadow
|
||||||
[docs/hello-platform.md](docs/hello-platform.md); read that file whenever anything
|
scene; rlgl still creates its default internal GPU resources.
|
||||||
from hello-platform is referenced.
|
- `ogs-mahjong/` contains the macOS Mahjong scaffold and counter-template logic;
|
||||||
|
Mahjong gameplay has not been implemented.
|
||||||
|
- `ogs-chkgfx/` is a companion graphics scaffold with macOS/iOS project files.
|
||||||
|
Older targets can lag behind shared-component changes; verify each target
|
||||||
|
separately before claiming it builds.
|
||||||
|
- The previous `game/ver-mac` and root `dialect.yml` layout is obsolete.
|
||||||
|
|
||||||
## Layout
|
## Source layout
|
||||||
|
|
||||||
- `<app>/dialect.yml` → generates `<app>/ver-mac/src/dialect.swift` and
|
- `<app>/dialect.yml`: per-application logic; generates
|
||||||
`<app>/ver-android/.../dialect.kt`.
|
`<app>/ver-mac/src/dialect.swift`. Blue iOS links to its macOS generated file.
|
||||||
- `components/` — shared source of truth; app `src/` entries are relative symlinks:
|
- `components/`: shared source of truth. App `src/` files use relative symlinks;
|
||||||
edit the real files and keep symlink parity.
|
edit real component files and preserve symlink parity.
|
||||||
- `hello-platform` uses `components/hp/` for its component, view models and views
|
- `components/render/`: shared component/model/constants, plus mirrored `ios/`
|
||||||
(`mac/`, `ios/`, `android/`), and `components/other/` for shared helpers.
|
and `mac/` effects, helpers and native/SwiftUI views. macOS additionally has
|
||||||
- `history/gitjs/` — historical JS reference, outside the build.
|
`renderConstMac.swift` for native pixel-format attributes.
|
||||||
|
- `components/raybri/raybri.h`: declarations plus implementation gated by
|
||||||
|
`RAYBRI_IMPLEMENTATION`; clears blue, renders and shuts down rlgl.
|
||||||
|
- `components/raybri/raybriConst.h`: shared constants with an implementation macro.
|
||||||
|
`components/raybri/mac/raybriAux.h`: macOS OpenGL symbol loader.
|
||||||
|
- `components/egl/egl.h` and `eglConst.h`: EGL state/helpers and configuration,
|
||||||
|
using single-header implementation macros.
|
||||||
|
- `ogs-blue/ver-{mac,ios}/src/Blue.c`: platform C implementation translation units.
|
||||||
|
- `history/gitjs/`: historical JavaScript Mahjong reference, outside the build.
|
||||||
|
`ref/swiftraylib` links to the sibling renderer sample.
|
||||||
|
|
||||||
## Build
|
## Graphics ownership and platform differences
|
||||||
|
|
||||||
Prereqs: sibling `../dialect` checkout (`util/build-generator`).
|
Every GPU operation requires its context current on the calling thread.
|
||||||
|
`rlLoadExtensions` also requires an existing current context; it precedes
|
||||||
|
`rlglInit`, not native context creation.
|
||||||
|
|
||||||
|
macOS uses `NSOpenGLView` (OpenGL 3.2 Core). `renderInit` makes its context
|
||||||
|
current, enables VSync, loads extensions with the C loader callback and starts
|
||||||
|
raylib. The timer requests `needsDisplay`; `draw(_:)` forwards to `renderDraw`,
|
||||||
|
which activates the context, renders and presents via `flushBuffer`.
|
||||||
|
|
||||||
|
Blue's SPM `RaylibBridge` target compiles `src/Blue.c`, exposes headers in
|
||||||
|
`src/raybri`, and links Homebrew raylib. It does NOT define
|
||||||
|
`RLGL_IMPLEMENTATION`: Homebrew headers omit the `external/glad.h` needed to
|
||||||
|
compile desktop rlgl locally. Swift imports `RaylibBridge`. `RAYLIB_PREFIX`
|
||||||
|
defaults to `/opt/homebrew`; build scripts detect `brew --prefix raylib`.
|
||||||
|
The installed raylib may produce a deployment-target linker warning.
|
||||||
|
|
||||||
|
On iOS, UIKit owns the view/layer and `RenderGLView.st` owns an `EGLState`.
|
||||||
|
Swift effects create EGL/ANGLE state and surface, make the context current,
|
||||||
|
and initialize raylib. Timer ticks call rendering directly; presentation uses
|
||||||
|
`eglSwapBuffers`. Pixel sizes come from view bounds and content scale.
|
||||||
|
Dialect's resize event triggers `renderRecreateSurface`; the macOS helper is
|
||||||
|
intentionally a no-op. Teardown must stop the timer, activate the context,
|
||||||
|
release rlgl resources, then destroy EGL surface/context/display resources.
|
||||||
|
|
||||||
|
Blue iOS uses `src/BlueBridgingHeader.h` to expose C APIs to Swift. `Blue.c`
|
||||||
|
compiles EGL helpers and rlgl using their implementation macros exactly once.
|
||||||
|
It uses the raylib-iOS XCFramework headers but does not link its full raylib
|
||||||
|
library. The app links/embeds `libEGL` and `libGLESv2` (ANGLE's Metal backend).
|
||||||
|
The XcodeGen settings define `PLATFORM_IOS`, `GRAPHICS_API_OPENGL_ES3`, and
|
||||||
|
`GL_GLEXT_PROTOTYPES`. Minimum iOS is 15.0; portrait and both landscape
|
||||||
|
orientations are enabled in Blue's Info.plist.
|
||||||
|
|
||||||
|
## Build and prerequisites
|
||||||
|
|
||||||
|
- macOS: `brew install raylib`.
|
||||||
|
- iOS project generation: `brew install xcodegen`; supply sibling
|
||||||
|
`../raylib-ios-xcframeworks` containing raylib/libEGL/libGLESv2 XCFrameworks.
|
||||||
|
`checkRaylibIOS` checks presence; it does not download them.
|
||||||
|
- Dialect: sibling `../dialect`, built with `(cd ../dialect && util/build-generator)`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd hello/hello-platform
|
util/build-ogs-blue-mac
|
||||||
util/build-mac
|
util/run-ogs-blue-mac
|
||||||
util/run-mac
|
util/prepare-ogs-blue-ios
|
||||||
util/prepare-ios # xcodegen; xcodebuild command is in docs/hello-platform.md
|
|
||||||
util/prepare-android # generate dialect.kt; gradlew command is in docs/hello-platform.md
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`build-mac` regenerates Dialect, runs `swift build` in `ver-mac/`, then packages the
|
The corresponding macOS build/run scripts also exist for `ogs-chkgfx` and
|
||||||
binary and `ver-mac/res/` into `ver-mac/.build/<App Name>.app`. `ver-ios/` mirrors
|
`ogs-mahjong`; `prepare-ogs-chkgfx-ios` exists as well. Inspect their individual
|
||||||
`ver-mac/` and shares `dialect.swift`, `HPView` and the app icon via symlinks.
|
configuration before assuming parity with Blue.
|
||||||
`ver-android/` has its own generated `dialect.kt` and Compose view. Kotlin output is
|
|
||||||
LLM-transpiled: run `ollama serve` before generating (model `qwen2.5-coder:3b`).
|
|
||||||
Dangling-symlink audit:
|
|
||||||
`find components hello -type l ! -exec test -e {} \; -not -path '*/.build/*'`
|
|
||||||
|
|
||||||
iOS simulator: use **IVA** (`EB867790-F2C0-4392-9F99-C509D4487FDA`, iPhone 17,
|
macOS build scripts generate Dialect, run `swift build`, and package resources
|
||||||
iOS 26.5), not iPhone 15 Pro. Android emulator: **Small_30** (`-gpu
|
from `ver-mac/res/` into `ver-mac/.build/<App Name>.app`. iOS preparation checks
|
||||||
swiftshader_indirect` avoids a headless crash).
|
XCFrameworks, generates Dialect, stages ANGLE include/library symlinks in
|
||||||
|
`ver-ios/.build/`, then runs XcodeGen. Build Blue for Simulator with:
|
||||||
|
|
||||||
## Dialect
|
```sh
|
||||||
|
xcodebuild -project 'ogs-blue/ver-ios/OGS blue.xcodeproj' -scheme ogs-blue \
|
||||||
|
-sdk iphonesimulator -destination 'generic/platform=iOS Simulator' \
|
||||||
|
CODE_SIGNING_ALLOWED=NO build
|
||||||
|
```
|
||||||
|
|
||||||
- Edit `<app>/dialect.yml` / `components/`, then `util/build-mac`; manual edits to the
|
Audit dangling source symlinks after moves (SPM can silently skip them):
|
||||||
generated `dialect.swift` / `dialect.kt` are overwritten.
|
|
||||||
- `struct F` (field names) exists only in the generated files: a new field needs
|
```sh
|
||||||
`static let <field> = "<field>"` hand-patched in ASCII order in both
|
find components ogs-blue ogs-chkgfx ogs-mahjong -type l ! -exec test -e {} \; -not -path '*/.build/*'
|
||||||
`dialect.swift` and `dialect.kt` or `F.<field>` will not build.
|
```
|
||||||
- Validate: `ruby -ryaml -e 'YAML.load_file("hello/hello-platform/dialect.yml")'`.
|
|
||||||
Every should-label (`1. Upon each ...`) MUST end with a colon —
|
## Editing the dialect
|
||||||
`../dialect/components/yml/ymlFun.swift` blindly `dropLast()`s it. Complaints
|
|
||||||
inside `if:`/`then:` (unquoted `: `) are expected.
|
- Add/modify contexts and components in `<app>/dialect.yml`, then run
|
||||||
|
`util/build-<app>-mac` to regenerate `dialect.swift`.
|
||||||
|
- **Chicken-egg**: `struct F` (field-name constants) lives only in the
|
||||||
|
generated `dialect.swift`. Adding a new field to a context in `<app>/dialect.yml`
|
||||||
|
requires hand-patching its `static let <field> = "<field>"` into `struct F`
|
||||||
|
in `dialect.swift` (ASCII-alphabetical order) if you cannot regenerate first,
|
||||||
|
otherwise the build fails on `F.<field>` being unresolved.
|
||||||
|
- `dialect.swift` is generated — edits there are overwritten on the next
|
||||||
|
`util/build-<app>-mac`. Change the source (`<app>/dialect.yml` / `components/`) instead.
|
||||||
|
- **Validate `<app>/dialect.yml` after edits** (e.g. `ruby -ryaml -e 'YAML.load_file("ogs-blue/dialect.yml")'`).
|
||||||
|
Every should-branch label (`1. Upon each ...`) MUST end with a colon — the
|
||||||
|
parser (`components/yml/ymlFun.swift`) blindly `dropLast()`s it, so a missing
|
||||||
|
colon silently eats the label's last character in the generated `about`
|
||||||
|
comment. Note the file can never pass a *strict* YAML parser: condition and
|
||||||
|
reaction lines (under `if:` / `then:`) contain unquoted `: ` (e.g.
|
||||||
|
`c.countText = "Count: '\(c.count)'"`), which standard YAML rejects. So treat
|
||||||
|
a parser complaint pointing *inside* an `if:`/`then:` block as expected; any
|
||||||
|
complaint elsewhere (like a missing branch-label colon) is a real bug.
|
||||||
|
|
||||||
|
## Swift 6
|
||||||
|
|
||||||
|
The project currently builds in Swift 5 language mode
|
||||||
|
(`util/step/buildMac` has the Swift 6 flag commented out). Enabling
|
||||||
|
`-Xswiftc -swift-version -Xswiftc 6` fails today on the singleton/`@MainActor`
|
||||||
|
concurrency errors (`RootComponent.singleton`, `RootVM.shared` in
|
||||||
|
`components/root/`, `RenderComponent.singleton`, `RenderVM.shared` in
|
||||||
|
`components/render/`, and the `RootVM.shared!.countText = ...` /
|
||||||
|
`RenderVM.shared!.pixelSize = ...` oneliners in the generated `dialect.swift`).
|
||||||
|
Do not flip it on without addressing those.
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
- Mirror Swift/iOS into Android (naming, text, layout, styling).
|
- When generating or mirroring Swift/iOS code into Android, stay as close to
|
||||||
- Compose: named `MaterialTheme.typography` styles over `fontSize`.
|
the Swift original as possible: preserve naming, capitalization, visible text,
|
||||||
- Kotlin: wildcard imports for multiple declarations from one package, including
|
layout, styling, behavior and structure. Use the closest platform equivalent
|
||||||
generated ones; subpackages need separate imports.
|
where a direct translation is unavailable; avoid unrelated redesigns or
|
||||||
- `.build/`, `build/`, `.DS_Store`, Xcode/Gradle artifacts are git-ignored.
|
Android-specific changes unless requested. In particular, use `OGS blue`
|
||||||
|
(not `OGS Blue`) for the Android project name and app labels, matching iOS.
|
||||||
|
|
||||||
## Source studies
|
- Android Compose typography: prefer named `MaterialTheme.typography` styles
|
||||||
|
over explicit numeric `fontSize` values. Use `headlineLarge` for Blue's title
|
||||||
|
as the counterpart to SwiftUI's `.largeTitle`, on both overlaid text layers.
|
||||||
|
|
||||||
Follow [docs/file-summary.md](docs/file-summary.md) (single-file) and
|
- Android Kotlin imports: use wildcard imports (`package.*`) when importing
|
||||||
[docs/mirror-summary.md](docs/mirror-summary.md) (mirrored platforms: one
|
multiple declarations from the same package, including newly generated imports.
|
||||||
self-contained HTML with aligned function starts, original line numbers, green/orange
|
Keep single imports and aliases explicit where needed to avoid name conflicts.
|
||||||
fills, counts, non-repetitive explanations); never substitute working-tree code for a
|
Wildcards do not include subpackages; import those separately.
|
||||||
requested historical revision.
|
|
||||||
|
- `game/ver-mac/.build/`, `build/`, `.DS_Store`, Xcode/Gradle artifacts are
|
||||||
|
git-ignored.
|
||||||
|
- Prefer editing files in `components/` (the real files); the `src/` entries are
|
||||||
|
symlinks.
|
||||||
|
- The generated UI callback plumbing is nonisolated; UI singletons are weak
|
||||||
|
(`RootComponent.singleton`, `RootVM.shared`, `RenderComponent.singleton`,
|
||||||
|
`RenderVM.shared`) and are accessed from the generated oneliners with
|
||||||
|
force-unwrap (`RootVM.shared!.countText = ...`, `RenderVM.shared!.pixelSize = ...`).
|
||||||
|
- Never call raylib / `raybri_*` without making the view's GL context current first
|
||||||
|
(see the GL context rule above).
|
||||||
|
|
||||||
|
## Source study documents
|
||||||
|
|
||||||
|
- Single-file source studies: follow [docs/file-summary.md](docs/file-summary.md).
|
||||||
|
- Mirrored platform studies: follow [docs/mirror-summary.md](docs/mirror-summary.md).
|
||||||
|
Produce one self-contained downloadable HTML with aligned function starts,
|
||||||
|
original line numbers, green/orange number fills, counts/percentages and a
|
||||||
|
non-repetitive explanation column.
|
||||||
|
- Existing mirrored example: `docs/render-platform-comparison.html`, documenting
|
||||||
|
the revision named in its header. Never silently substitute working-tree code
|
||||||
|
for a requested historical revision.
|
||||||
@@ -1,94 +1,17 @@
|
|||||||
|
## Targets
|
||||||
|
|
||||||
|
| № | Target | macOS | iOS/iPadOS | Android |
|
||||||
|
| 1 | ogs-blue | √ | √ | ? |
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
### Android
|
|
||||||
|
|
||||||
* Install Android Studio Quail 3 (2026.1.3)
|
|
||||||
|
|
||||||
### iOS
|
|
||||||
|
|
||||||
* Install Xcode 26
|
|
||||||
* Install XcodeGen
|
|
||||||
|
|
||||||
`brew install xcodegen`
|
|
||||||
* Get ghera's [raylib-ios-xcframeworks][rzip]
|
|
||||||
|
|
||||||
Unpack and place it alongside the project
|
|
||||||
|
|
||||||
### Linux
|
|
||||||
|
|
||||||
* Install Ubuntu 24.04
|
|
||||||
* Install [Swiftly][swiftly] + Swift (installed by Swiftly)
|
|
||||||
* Install Swift dependencies (proposed by Swiftly after Swift installation)
|
|
||||||
|
|
||||||
`apt-get -y install binutils git gnupg2 libcurl4-openssl-dev libgcc-13-dev libpython3-dev libstdc++-13-dev libxml2-dev libncurses-dev libz3-dev pkg-config zlib1g-dev`
|
|
||||||
* Install CrossSwiftUI dependency
|
|
||||||
|
|
||||||
`apt-get -y install libgtk-4-dev`
|
|
||||||
|
|
||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
* Install Xcode 26
|
* `brew install raylib`
|
||||||
* Install Raylib 6
|
|
||||||
|
|
||||||
`brew install raylib`
|
### iOS
|
||||||
|
|
||||||
### Windows
|
* `brew install xcodegen`
|
||||||
|
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
||||||
![Developer mode][w11-dev-mode]
|
|
||||||
|
|
||||||
* Install Windows 11
|
|
||||||
|
|
||||||
Use x64 Windows if you want to target both Intel and ARM
|
|
||||||
|
|
||||||
* Install [Visual Studio 2022 and Swift toolchain][vs]
|
|
||||||
* Install App Runtime
|
|
||||||
|
|
||||||
`winget install --id Microsoft.WindowsAppRuntime.1.5 -e --source winget`
|
|
||||||
|
|
||||||
* Enable developer mode
|
|
||||||
|
|
||||||
Settings -> System -> Advanced -> Developer Mode: On (see the screenshot above)
|
|
||||||
|
|
||||||
* Install Git Bash
|
|
||||||
|
|
||||||
`winget install --id Git.Git -e --source winget`
|
|
||||||
|
|
||||||
While in Git Bash installation wizard, select defaults
|
|
||||||
|
|
||||||
* Inside Git Bash: configure Git to use actual symlinks
|
|
||||||
|
|
||||||
`git config --global core.symlinks true`
|
|
||||||
|
|
||||||
* Inside GitBash: find the location of `swift.exe`
|
|
||||||
|
|
||||||
```
|
|
||||||
$ find /c -name swift.exe
|
|
||||||
/c/Users/mk/AppData/Local/Programs/Swift/Toolchains/6.4.2+Asserts/usr/bin/swift.exe
|
|
||||||
```
|
|
||||||
|
|
||||||
* Inside Git Bash: to `~/.bash_profile` add Swift location (without `swift.exe`) to `PATH`
|
|
||||||
|
|
||||||
`export PATH="$PATH:/c/Users/mk/AppData/Local/Programs/Swift/Toolchains/6.4.2+Asserts/usr/bin"`
|
|
||||||
|
|
||||||
* Restart Git Bash
|
|
||||||
|
|
||||||
* Make sure Swift compiler is working
|
|
||||||
|
|
||||||
```
|
|
||||||
$ swift --version
|
|
||||||
Swift version 6.4.2 (swift-6.4.2-RELEASE)
|
|
||||||
Target: aarch64-unknown-windows-msvc
|
|
||||||
Build config: +assertions
|
|
||||||
```
|
|
||||||
|
|
||||||
## Components
|
|
||||||
|
|
||||||
| Component | macOS | iOS | Android | Linux | Windows | Description |
|
|
||||||
| --- | --- | --- | --- | --- | --- | --- |
|
|
||||||
| hp | √ | √ | √ | √ | √ | **h**ello-**p**latform is a simple UI to validate platform support |
|
|
||||||
| hrb | | | | | | **h**ello-**r**ayli**b** is a simple raylib rendering to validate platform support |
|
|
||||||
|
|
||||||
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
||||||
[swiftly]: https://www.swift.org/install/linux/
|
|
||||||
[vs]: https://www.swift.org/install/windows/
|
|
||||||
[w11-dev-mode]: docs/img/w11-dev-mode.jpg
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.opengamestudio
|
|
||||||
|
|
||||||
object HPComponent {
|
|
||||||
val ctrl = DialectController(HPContext())
|
|
||||||
|
|
||||||
init {
|
|
||||||
hpRegisterEffects(ctrl)
|
|
||||||
hpRegisterShoulds(ctrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setup() {
|
|
||||||
hpSet(F.didSetup, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package org.opengamestudio
|
|
||||||
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
|
|
||||||
object HPVM {
|
|
||||||
var countText by mutableStateOf("")
|
|
||||||
|
|
||||||
var shared: HPVM? = this
|
|
||||||
private set
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package org.opengamestudio
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.*
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun HPView() {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier.padding(40.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
style = MaterialTheme.typography.headlineLarge,
|
|
||||||
text = "Hello, platform!"
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
fontFamily = FontFamily.Monospace,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
text = HPVM.countText
|
|
||||||
)
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = { hpSet(F.didClickIncrement, true) }
|
|
||||||
) {
|
|
||||||
Text("Increment")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
class HPComponent {
|
|
||||||
let ctrl = DialectController(HPContext())
|
|
||||||
static private(set) weak var singleton: HPComponent?
|
|
||||||
|
|
||||||
init() {
|
|
||||||
Self.singleton = self
|
|
||||||
hpRegisterEffects(ctrl)
|
|
||||||
hpRegisterShoulds(ctrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setup() {
|
|
||||||
hpSet(F.didSetup, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import Combine
|
|
||||||
|
|
||||||
final class HPVM: ObservableObject {
|
|
||||||
@Published var countText = ""
|
|
||||||
|
|
||||||
static private(set) weak var shared: HPVM?
|
|
||||||
|
|
||||||
init() {
|
|
||||||
Self.shared = self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../hp/mac/view/HPView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../hp.swift
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SwiftCrossUI
|
|
||||||
|
|
||||||
final class HPVM: ObservableObject {
|
|
||||||
@Published var countText = ""
|
|
||||||
|
|
||||||
static private(set) weak var shared: HPVM?
|
|
||||||
|
|
||||||
init() {
|
|
||||||
Self.shared = self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import SwiftCrossUI
|
|
||||||
|
|
||||||
struct HPView: View {
|
|
||||||
@State var vm: HPVM
|
|
||||||
|
|
||||||
init(_ vm: HPVM) {
|
|
||||||
self.vm = vm
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 16) {
|
|
||||||
Text("Hello, platform!")
|
|
||||||
.font(.largeTitle)
|
|
||||||
Text(vm.countText)
|
|
||||||
.font(.title3.monospaced())
|
|
||||||
Button("Increment") {
|
|
||||||
hpSet(F.didClickIncrement, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(40)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct HPView: View {
|
|
||||||
@ObservedObject var vm: HPVM
|
|
||||||
|
|
||||||
init(_ vm: HPVM) {
|
|
||||||
self.vm = vm
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 16) {
|
|
||||||
Text("Hello, platform!")
|
|
||||||
.font(.largeTitle)
|
|
||||||
Text(vm.countText)
|
|
||||||
.font(.title3.monospaced())
|
|
||||||
Button("Increment") {
|
|
||||||
hpSet(F.didClickIncrement, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(40)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import WinSDK
|
|
||||||
|
|
||||||
func otherSetupWindowIcon(_ iconId: Int) {
|
|
||||||
// Only visit windows owned by this UI thread, never another application's window
|
|
||||||
EnumThreadWindows(GetCurrentThreadId(), { wnd, iconId in
|
|
||||||
let resource = UnsafePointer<WCHAR>(bitPattern: Int(iconId))
|
|
||||||
let module = GetModuleHandleW(nil)
|
|
||||||
|
|
||||||
// Small icon
|
|
||||||
if let small = LoadImageW(
|
|
||||||
module,
|
|
||||||
resource,
|
|
||||||
UINT(IMAGE_ICON),
|
|
||||||
GetSystemMetrics(SM_CXSMICON),
|
|
||||||
GetSystemMetrics(SM_CYSMICON),
|
|
||||||
UINT(LR_SHARED)
|
|
||||||
) {
|
|
||||||
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_SMALL), LPARAM(Int(bitPattern: small)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Large icon
|
|
||||||
if let large = LoadImageW(
|
|
||||||
module,
|
|
||||||
resource,
|
|
||||||
UINT(IMAGE_ICON),
|
|
||||||
GetSystemMetrics(SM_CXICON),
|
|
||||||
GetSystemMetrics(SM_CYICON),
|
|
||||||
UINT(LR_SHARED)
|
|
||||||
) {
|
|
||||||
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_BIG), LPARAM(Int(bitPattern: large)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}, LPARAM(iconId))
|
|
||||||
}
|
|
||||||
@@ -1,258 +0,0 @@
|
|||||||
# hello-platform
|
|
||||||
|
|
||||||
Minimal macOS, iOS and Android app that validates the platform foundation: a
|
|
||||||
"Hello, platform!" title, a count label and an Increment button. All state lives
|
|
||||||
in Dialect; SwiftUI and Compose only render the view model and send one input
|
|
||||||
event.
|
|
||||||
|
|
||||||
## Layout
|
|
||||||
|
|
||||||
```text
|
|
||||||
hello/hello-platform/
|
|
||||||
├── dialect.yml Dialect v4 source: fields, oneliners, shoulds
|
|
||||||
├── util/
|
|
||||||
│ ├── build-mac generate → build → package
|
|
||||||
│ ├── run-mac run the packaged .app
|
|
||||||
│ ├── prepare-ios generate → xcodegen project
|
|
||||||
│ ├── prepare-android generate Kotlin dialect.kt
|
|
||||||
│ └── step/
|
|
||||||
│ ├── generateDialect sibling ../dialect generator on dialect.yml
|
|
||||||
│ ├── buildMac swift build in ver-mac/
|
|
||||||
│ ├── packageMac ver-mac/.build/hello-platform.app
|
|
||||||
│ ├── runMac launch Contents/MacOS/hello-platform
|
|
||||||
│ └── prepareIOS xcodegen in ver-ios/
|
|
||||||
├── ver-mac/
|
|
||||||
│ ├── Package.swift one executable target, path "src", macOS 13
|
|
||||||
│ ├── Info.plist org.opengamestudio.hello-platform, AppIcon
|
|
||||||
│ ├── res/AppIcon.icns copied into the bundle's Resources
|
|
||||||
│ ├── .build/ SPM output + packaged .app (git-ignored)
|
|
||||||
│ └── src/
|
|
||||||
│ ├── HPApp.swift @main WindowGroup → HPView
|
|
||||||
│ ├── HPAppDelegate.swift builds HPComponent + HPVM, logs, calls setup()
|
|
||||||
│ ├── dialect.swift generated by Dialect, never hand-edited
|
|
||||||
│ ├── hp/ relative symlinks into components/hp
|
|
||||||
│ │ ├── hp.swift
|
|
||||||
│ │ ├── hpVM.swift
|
|
||||||
│ │ └── view/HPView.swift → components/hp/mac/view/HPView.swift
|
|
||||||
│ └── other/other.swift relative symlink into components/other
|
|
||||||
└── ver-ios/
|
|
||||||
├── project.yml xcodegen: target hello-platform, iOS 15
|
|
||||||
├── Info.plist org.opengamestudio.hello-platform
|
|
||||||
├── Assets.xcassets/ AppIcon.appiconset/AppIcon.png → res/AppIcon.png
|
|
||||||
├── hello-platform.xcodeproj generated, git-ignored
|
|
||||||
├── .build/ xcodebuild DerivedData (git-ignored)
|
|
||||||
└── src/
|
|
||||||
├── HPApp.swift @main WindowGroup → HPView
|
|
||||||
├── HPAppDelegate.swift same HPComponent + HPVM + logging as macOS
|
|
||||||
├── dialect.swift symlink → ../../ver-mac/src/dialect.swift
|
|
||||||
├── hp/ same links as ver-mac, except view/HPView.swift
|
|
||||||
│ → components/hp/ios/view/HPView.swift
|
|
||||||
└── other/other.swift same symlink as the macOS tree
|
|
||||||
```
|
|
||||||
|
|
||||||
The Android target mirrors the same layout:
|
|
||||||
|
|
||||||
```text
|
|
||||||
hello/hello-platform/ver-android/
|
|
||||||
├── settings.gradle.kts rootProject "hello-platform", includes app
|
|
||||||
├── app/build.gradle.kts org.opengamestudio.helloplatform, Compose
|
|
||||||
├── gradle/ AGP 8.7.3, Kotlin 2.1.0, wrapper 9.3.1
|
|
||||||
├── local.properties sdk.dir, git-ignored
|
|
||||||
├── build/ Gradle output and APK (git-ignored)
|
|
||||||
└── app/src/main/
|
|
||||||
├── AndroidManifest.xml label hello-platform, Theme.MyApplication
|
|
||||||
├── res/ strings, theme, adaptive launcher icon
|
|
||||||
└── kotlin/org/opengamestudio/
|
|
||||||
├── MainActivity.kt Compose Box → HPView, edge-to-edge
|
|
||||||
├── HPActivityDelegate.kt HPComponent + logging, calls setup()
|
|
||||||
├── dialect.kt generated Kotlin, never hand-edited
|
|
||||||
├── hp/ relative symlinks into components/hp/android
|
|
||||||
│ ├── hp.kt
|
|
||||||
│ ├── hpVM.kt
|
|
||||||
│ └── view/HPView.kt → components/hp/android/view/HPView.kt
|
|
||||||
└── other/other.kt relative symlink into components/other
|
|
||||||
```
|
|
||||||
|
|
||||||
`components/` is the source of truth. The `src/hp` and `src/other` entries are
|
|
||||||
symlinks, so edit the real files under `components/` and keep the links intact.
|
|
||||||
macOS and iOS share one `dialect.swift` (the iOS one is a symlink to `ver-mac`),
|
|
||||||
one `HPView` body (the iOS `components/hp/ios/view/HPView.swift` links back to
|
|
||||||
the macOS view) and one `res/AppIcon.png`. Android has its own generated
|
|
||||||
`dialect.kt` and Compose view, with the same state and layout.
|
|
||||||
|
|
||||||
## Shared components
|
|
||||||
|
|
||||||
- `components/hp/hp.swift` — `HPComponent` owns `DialectController(HPContext)`,
|
|
||||||
registers the generated effects and shoulds, publishes `singleton` and exposes
|
|
||||||
`setup()` (`hpSet(F.didSetup, true)`).
|
|
||||||
- `components/hp/hpVM.swift` — `HPVM` is an `ObservableObject` with
|
|
||||||
`@Published countText` and a weak `shared` instance.
|
|
||||||
- `components/hp/mac/view/HPView.swift` — SwiftUI view observing `HPVM`; the
|
|
||||||
button dispatches `hpSet(F.didClickIncrement, true)`. It is platform-neutral,
|
|
||||||
so `components/hp/ios/view/HPView.swift` is a symlink back to it and both
|
|
||||||
`src/hp/view/HPView.swift` links resolve to the same file.
|
|
||||||
- `components/hp/android/` — the Android mirror: `hp.kt` (same `HPComponent`),
|
|
||||||
`hpVM.kt` (`HPVM` with a Compose `mutableStateOf`) and `view/HPView.kt`
|
|
||||||
(Compose `Column`, headline, monospaced label, Increment button).
|
|
||||||
- `components/other/other.swift` / `other.kt` — helpers, including
|
|
||||||
`otherSetupConsoleLogging(ctrl, "HP")`, which prints every processed field to
|
|
||||||
stderr as `ИГР HP k/v: '<field>'/'<value>'`.
|
|
||||||
|
|
||||||
## Startup flow
|
|
||||||
|
|
||||||
1. `HPAppDelegate` creates `HPComponent` (which sets `HPComponent.singleton`)
|
|
||||||
and then `HPVM` (which sets `HPVM.shared`).
|
|
||||||
2. The launch callback (`applicationDidFinishLaunching` on macOS,
|
|
||||||
`application(_:didFinishLaunchingWithOptions:)` on iOS,
|
|
||||||
`HPActivityDelegate.setup()` in `MainActivity.onCreate` on Android) registers
|
|
||||||
console logging and calls `hp.setup()`; the macOS one also activates the app.
|
|
||||||
3. `setup()` queues `didSetup` in the controller.
|
|
||||||
4. The controller applies the changed field, runs every registered should in
|
|
||||||
order, and queues each new `recentField` a should returns. Finally it reports
|
|
||||||
the context to callbacks: logging plus the `countText` oneliner, which copies
|
|
||||||
`c.countText` into `HPVM.shared`.
|
|
||||||
5. `HPView` re-renders from the published view model.
|
|
||||||
|
|
||||||
## Dialect rules (`dialect.yml`)
|
|
||||||
|
|
||||||
Fields: `count`, `countText`, `didClickIncrement`, `didLaunch`, `didSetup`.
|
|
||||||
Shoulds exist for `count`, `countText` and `didLaunch`; `didClickIncrement` and
|
|
||||||
`didSetup` are pure inputs.
|
|
||||||
|
|
||||||
- `count`:
|
|
||||||
- on `didClickIncrement` when `count == 7` → `count += 10`;
|
|
||||||
- on every `didClickIncrement` → `count += 1`.
|
|
||||||
The first matching rule returns, so the click made while the count is 7 adds
|
|
||||||
10 and jumps to 17.
|
|
||||||
- `countText`:
|
|
||||||
- on `count` → `"Count: '<count>'"`;
|
|
||||||
- on `didLaunch` → `"Press the button to count"`.
|
|
||||||
- `didLaunch`: on `didSetup` while `didLaunch == false` → `true`, once.
|
|
||||||
|
|
||||||
Oneliners: `countText` → `HPVM.shared!.countText = c.countText`.
|
|
||||||
|
|
||||||
## Build and run
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cd hello/hello-platform
|
|
||||||
util/build-mac
|
|
||||||
util/run-mac
|
|
||||||
```
|
|
||||||
|
|
||||||
`generateDialect` expects the sibling `../dialect` checkout (so
|
|
||||||
`/Volumes/MOE/p/dialect` for this workspace). `build-mac` runs the steps in
|
|
||||||
order: regenerate `ver-mac/src/dialect.swift` and the Android `dialect.kt`,
|
|
||||||
`swift build`, then package `ver-mac/.build/debug/hello-platform`, `Info.plist`
|
|
||||||
and `res/` into `ver-mac/.build/hello-platform.app`.
|
|
||||||
|
|
||||||
iOS needs `xcodegen` (see README prerequisites):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cd hello/hello-platform
|
|
||||||
util/prepare-ios
|
|
||||||
xcodebuild -project ver-ios/hello-platform.xcodeproj \
|
|
||||||
-scheme hello-platform -sdk iphonesimulator \
|
|
||||||
-destination 'generic/platform=iOS Simulator' \
|
|
||||||
CODE_SIGNING_ALLOWED=NO build
|
|
||||||
```
|
|
||||||
|
|
||||||
`prepare-ios` regenerates `dialect.swift` and then runs `xcodegen` in
|
|
||||||
`ver-ios/`. The generated `.xcodeproj` and `.build/` are git-ignored, so
|
|
||||||
re-run it after changing `project.yml` or `Info.plist`.
|
|
||||||
|
|
||||||
Android needs the SDK and a JDK; `prepare-android` writes the Kotlin dialect,
|
|
||||||
then Gradle builds the app:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cd hello/hello-platform
|
|
||||||
util/prepare-android
|
|
||||||
cd ver-android
|
|
||||||
JAVA_HOME="$HOME/.gradle/jdks/eclipse_adoptium-21-aarch64-os_x.2/jdk-21.0.7+6/Contents/Home" \
|
|
||||||
./gradlew assembleDebug
|
|
||||||
```
|
|
||||||
|
|
||||||
`ver-android/local.properties` points at `~/Library/Android/sdk` and is
|
|
||||||
git-ignored, so each checkout needs it once. Install the APK with
|
|
||||||
`adb install -r app/build/outputs/apk/debug/app-debug.apk` and start
|
|
||||||
`org.opengamestudio.helloplatform/org.opengamestudio.MainActivity`. Use JDK 21:
|
|
||||||
AGP 8.7.3 does not accept every newer JDK.
|
|
||||||
|
|
||||||
## Pitfalls
|
|
||||||
|
|
||||||
- Change `dialect.yml`, not the generated `dialect.swift` / `dialect.kt`;
|
|
||||||
retyping or reformatting them is pointless because every build overwrites
|
|
||||||
them.
|
|
||||||
- The Kotlin output is transpiled through the local LLM, so `ollama serve` must
|
|
||||||
be running (with `qwen2.5-coder:3b` pulled) before `prepare-android` or
|
|
||||||
`build-mac`; otherwise generation aborts and `dialect.kt` is left stale.
|
|
||||||
- Every should label (`1. Upon ...`) must end with a colon: the sibling generator
|
|
||||||
drops its last character (`../dialect/components/yml/ymlFun.swift`).
|
|
||||||
- A should function may change only one field; its returned `recentField` drives
|
|
||||||
the next queue entry.
|
|
||||||
- The generated oneliner and `hpSet` force-unwrap `HPVM.shared` /
|
|
||||||
`HPComponent.singleton`; both must exist before dispatch.
|
|
||||||
- Only one `dialect.swift` exists: `ver-ios/src/dialect.swift` is a symlink to
|
|
||||||
the macOS file, so `prepare-ios` regenerates the same source. The Kotlin
|
|
||||||
`dialect.kt` lives in `ver-android` and is generated from the same
|
|
||||||
`dialect.yml`.
|
|
||||||
|
|
||||||
## Linux launcher icon
|
|
||||||
|
|
||||||
`ver-linux` uses GtkBackend with application ID
|
|
||||||
`org.opengamestudio.hello-platform`. On Linux run
|
|
||||||
`hello/hello-platform/util/build-linux` from the repository root to build and install
|
|
||||||
the executable under `~/.local/bin`, the desktop entry under
|
|
||||||
`${XDG_DATA_HOME:-~/.local/share}/applications`, and the shared 1024px
|
|
||||||
`res/AppIcon.png` under the matching hicolor icon name. The launcher uses an
|
|
||||||
absolute executable path. Launch from the desktop application menu after
|
|
||||||
installation; GTK's application ID matches the desktop and icon names.
|
|
||||||
Desktop-entry installation uses `cp` and GNU `sed -i`; Python is not required.
|
|
||||||
The replacement supports spaces but assumes paths contain no sed replacement
|
|
||||||
metacharacters (`&`, `|`, backslashes) or desktop-entry quoting characters.
|
|
||||||
Requires the normal Swift/GTK build dependencies. Installation is per-user and
|
|
||||||
requires no root privileges.
|
|
||||||
|
|
||||||
The Linux build runs `step/buildLinux` followed by `step/packageLinux`.
|
|
||||||
The shared launcher template is `res/linux-app.desktop`; packaging copies it
|
|
||||||
and substitutes `%APP_NAME%`, `%APP_EXEC%` and `%APP_ID%`.
|
|
||||||
`util/run-linux` uses `gtk-launch org.opengamestudio.hello-platform` to launch
|
|
||||||
the installed desktop entry with its icon association. Run `util/build-linux`
|
|
||||||
first to install/update that entry and executable; `gtk-launch` must be available.
|
|
||||||
`packageLinux` is sourced with the target and display name, like `packageMac`;
|
|
||||||
it installs the executable, launcher and icon for the current user and refreshes
|
|
||||||
the desktop/icon caches. It requires GNU sed, gtk-update-icon-cache and
|
|
||||||
update-desktop-database. The standalone `install-linux` script has been replaced
|
|
||||||
by this packaging step.
|
|
||||||
|
|
||||||
## Windows (WinUI)
|
|
||||||
|
|
||||||
`ver-windows/` mirrors the Linux SwiftCrossUI target with `WinUIBackend`.
|
|
||||||
It shares the counter component and generated Swift dialect via
|
|
||||||
relative symlinks. It reuses the SwiftCrossUI model and view in `components/hp/linux`. Check out the repository with Git symlinks enabled on Windows
|
|
||||||
(Developer Mode or appropriate symlink permissions are needed).
|
|
||||||
|
|
||||||
With the Windows Swift toolchain, Windows SDK, and the Windows App SDK runtime
|
|
||||||
required by SwiftCrossUI's WinUI backend installed, run in Git Bash from `hello/hello-platform`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
util/build-windows
|
|
||||||
util/run-windows
|
|
||||||
```
|
|
||||||
|
|
||||||
The build uses the existing generated Swift dialect, like the Linux build.
|
|
||||||
The run script locates the existing debug executable without rebuilding it.
|
|
||||||
|
|
||||||
### Windows executable icon
|
|
||||||
|
|
||||||
`res/AppIcon.res` is a ready-made Windows resource containing six icon sizes
|
|
||||||
(16–256px) from the shared `res/AppIcon.png`, with icon group ID 101.
|
|
||||||
`ver-windows/res/AppIcon.res` links to it. No ICO or RC file is required by the
|
|
||||||
Windows target, and the build does not compile resources.
|
|
||||||
|
|
||||||
`step/buildWindows` exports `APP_RES_DIR` as the absolute Git Bash
|
|
||||||
`ver-windows/res` path derived from `$SDIR/../ver-windows/res`.
|
|
||||||
The entry script obtains `SDIR` with `pwd -P`;
|
|
||||||
no resource copy is needed. The manifest appends `/AppIcon.res` and passes it to the linker.
|
|
||||||
Manual SwiftPM commands that evaluate the manifest also need `APP_RES_DIR`.
|
|
||||||
Windows compilation and the live window/taskbar icon require verification on
|
|
||||||
Windows; no Windows build was performed when this wiring was added.
|
|
||||||
|
Before Width: | Height: | Size: 116 KiB |
@@ -1,53 +0,0 @@
|
|||||||
version: 4
|
|
||||||
|
|
||||||
output:
|
|
||||||
ver-android/app/src/main/kotlin/org/opengamestudio/dialect.kt:
|
|
||||||
type: kotlin
|
|
||||||
ver-mac/src/dialect.swift:
|
|
||||||
type: swift
|
|
||||||
|
|
||||||
HPContext:
|
|
||||||
type: context
|
|
||||||
fields:
|
|
||||||
count: Int
|
|
||||||
countText: String
|
|
||||||
didClickIncrement: Bool
|
|
||||||
didLaunch: Bool
|
|
||||||
didSetup: Bool
|
|
||||||
|
|
||||||
HPComponent:
|
|
||||||
type: component
|
|
||||||
oneliners:
|
|
||||||
- countText: HPVM.shared!.countText = c.countText
|
|
||||||
shoulds:
|
|
||||||
count:
|
|
||||||
1. Upon hitting 7:
|
|
||||||
if:
|
|
||||||
c.recentField == F.didClickIncrement &&
|
|
||||||
c.count == 7
|
|
||||||
then:
|
|
||||||
c.count += 10
|
|
||||||
2. Upon each button click:
|
|
||||||
if:
|
|
||||||
c.recentField == F.didClickIncrement
|
|
||||||
then:
|
|
||||||
c.count += 1
|
|
||||||
countText:
|
|
||||||
1. Upon each count change:
|
|
||||||
if:
|
|
||||||
c.recentField == F.count
|
|
||||||
then:
|
|
||||||
c.countText = "Count: '\(c.count)'"
|
|
||||||
2. Upon launch:
|
|
||||||
if:
|
|
||||||
c.recentField == F.didLaunch
|
|
||||||
then:
|
|
||||||
c.countText = "Press the button to count"
|
|
||||||
didLaunch:
|
|
||||||
1. Only once during the first setup:
|
|
||||||
if:
|
|
||||||
c.recentField == F.didSetup &&
|
|
||||||
c.didLaunch == false
|
|
||||||
then:
|
|
||||||
c.didLaunch = true
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/buildLinux $TARGET
|
|
||||||
source $T/packageLinux $TARGET hello-platform
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/generateDialect $TARGET
|
|
||||||
source $T/buildMac $TARGET
|
|
||||||
source $T/packageMac $TARGET hello-platform
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" && pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source "$T/buildWindows" "$TARGET"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/generateDialect $TARGET
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/generateDialect $TARGET
|
|
||||||
source $T/prepareIOS $TARGET
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/runLinux hello-platform hello-platform
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source $T/runMac hello-platform hello-platform
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
SDIR=$(cd "$(dirname "$0")" && pwd -P)
|
|
||||||
|
|
||||||
T=$SDIR/step
|
|
||||||
TARGET=hello-platform
|
|
||||||
|
|
||||||
STEP=0
|
|
||||||
source "$T/runWindows" "$TARGET"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for Linux"
|
|
||||||
|
|
||||||
cd $SDIR/../ver-linux
|
|
||||||
swift build
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for macOS"
|
|
||||||
|
|
||||||
cd $SDIR/../ver-mac
|
|
||||||
swift build
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for Windows"
|
|
||||||
|
|
||||||
cd "$SDIR/../ver-windows"
|
|
||||||
export APP_RES_DIR="$SDIR/../ver-windows/res"
|
|
||||||
swift build
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'"
|
|
||||||
|
|
||||||
$SDIR/../../../util/run-generator --file=$SDIR/../dialect.yml
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
APP_NAME=$2
|
|
||||||
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Make '$APP_NAME' Linux package for '$TARGET'"
|
|
||||||
APP_DIR="$SDIR/../ver-linux"
|
|
||||||
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
||||||
BIN_DIR="$HOME/.local/bin"
|
|
||||||
APP_ID=org.opengamestudio.$TARGET
|
|
||||||
|
|
||||||
mkdir -p "$BIN_DIR" "$DATA_DIR/applications" "$DATA_DIR/icons/hicolor/1024x1024/apps"
|
|
||||||
cp "$APP_DIR/.build/debug/$TARGET" "$BIN_DIR/$TARGET"
|
|
||||||
cp "$SDIR/../../../res/AppIcon.png" \
|
|
||||||
"$DATA_DIR/icons/hicolor/1024x1024/apps/$APP_ID.png"
|
|
||||||
|
|
||||||
# Use an absolute executable path: graphical sessions may omit ~/.local/bin.
|
|
||||||
DESKTOP_FILE="$DATA_DIR/applications/$APP_ID.desktop"
|
|
||||||
cp "$SDIR/../../../res/linux-app.desktop" "$DESKTOP_FILE"
|
|
||||||
sed -i \
|
|
||||||
-e "s|%APP_NAME%|$APP_NAME|g" \
|
|
||||||
-e "s|%APP_EXEC%|$BIN_DIR/$TARGET|g" \
|
|
||||||
-e "s|%APP_ID%|$APP_ID|g" \
|
|
||||||
"$DESKTOP_FILE"
|
|
||||||
|
|
||||||
# Update icon cache for new icon to be visible
|
|
||||||
gtk-update-icon-cache --force --ignore-theme-index "$DATA_DIR/icons/hicolor"
|
|
||||||
update-desktop-database "$DATA_DIR/applications"
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
APP_NAME=$2
|
|
||||||
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Make '$APP_NAME' macOS package for '$TARGET'"
|
|
||||||
|
|
||||||
APP_MAC="$SDIR/../ver-mac/.build/$APP_NAME.app"
|
|
||||||
rm -rf "$APP_MAC"
|
|
||||||
|
|
||||||
APP_DAT="$APP_MAC/Contents"
|
|
||||||
mkdir -p "$APP_DAT/MacOS"
|
|
||||||
mkdir -p "$APP_DAT/Resources"
|
|
||||||
cp $SDIR/../ver-mac/.build/debug/$TARGET "$APP_DAT/MacOS/$TARGET"
|
|
||||||
cp $SDIR/../ver-mac/Info.plist "$APP_DAT/Info.plist"
|
|
||||||
# Copy resources with symlink dereferencing
|
|
||||||
cp -R -L $SDIR/../ver-mac/res/* "$APP_DAT/Resources/"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Generate Xcode project for '$TARGET' iOS"
|
|
||||||
|
|
||||||
cd $SDIR/../ver-ios
|
|
||||||
xcodegen
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
APP_NAME=$2
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Run Linux app for '$TARGET'"
|
|
||||||
|
|
||||||
gtk-launch "org.opengamestudio.$TARGET"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
APP_NAME=$2
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Run macOS app for '$TARGET'"
|
|
||||||
|
|
||||||
"$SDIR/../ver-mac/.build/$APP_NAME.app/Contents/MacOS/$TARGET"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
TARGET=$1
|
|
||||||
STEP=$((STEP+1))
|
|
||||||
echo -e "\n> > > > Step №$STEP. Run Windows app for '$TARGET'"
|
|
||||||
|
|
||||||
cd "$SDIR/../ver-windows"
|
|
||||||
"./.build/debug/$TARGET.exe"
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.*
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
alias(libs.plugins.android.application)
|
|
||||||
alias(libs.plugins.kotlin.android)
|
|
||||||
alias(libs.plugins.kotlin.compose)
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "org.opengamestudio"
|
|
||||||
compileSdk = 35
|
|
||||||
|
|
||||||
buildFeatures {
|
|
||||||
compose = true
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
defaultConfig {
|
|
||||||
applicationId = "org.opengamestudio.helloplatform"
|
|
||||||
minSdk = 24
|
|
||||||
targetSdk = 35
|
|
||||||
versionCode = 1
|
|
||||||
versionName = "1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(libs.androidx.activity.compose)
|
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
|
||||||
implementation(libs.androidx.core.ktx)
|
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
|
||||||
implementation(libs.androidx.material3)
|
|
||||||
implementation(libs.androidx.ui)
|
|
||||||
implementation(libs.androidx.ui.graphics)
|
|
||||||
implementation(libs.androidx.ui.tooling.preview)
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
compilerOptions {
|
|
||||||
jvmTarget = JVM_1_8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?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="@string/app_name"
|
|
||||||
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="@string/app_name"
|
|
||||||
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>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.opengamestudio
|
|
||||||
|
|
||||||
object HPActivityDelegate {
|
|
||||||
val hp = HPComponent
|
|
||||||
|
|
||||||
init {
|
|
||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setup() {
|
|
||||||
hp.setup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
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)
|
|
||||||
|
|
||||||
HPActivityDelegate.setup()
|
|
||||||
|
|
||||||
enableEdgeToEdge(
|
|
||||||
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
|
||||||
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
|
|
||||||
)
|
|
||||||
setContent {
|
|
||||||
MyApplicationTheme {
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(ComposeColor.White)
|
|
||||||
) {
|
|
||||||
HPView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
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 count = "count"
|
|
||||||
const val countText = "countText"
|
|
||||||
const val didClickIncrement = "didClickIncrement"
|
|
||||||
const val didLaunch = "didLaunch"
|
|
||||||
const val didSetup = "didSetup"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
data class HPContext(
|
|
||||||
var count: Int = 0,
|
|
||||||
var countText: String = "",
|
|
||||||
var didClickIncrement: Boolean = false,
|
|
||||||
var didLaunch: Boolean = false,
|
|
||||||
var didSetup: Boolean = false,
|
|
||||||
|
|
||||||
override var recentField: String = ""
|
|
||||||
) : DialectContext {
|
|
||||||
override fun <T> field(name: String): T {
|
|
||||||
if (name == "count") {
|
|
||||||
return count as T
|
|
||||||
}
|
|
||||||
else if (name == "countText") {
|
|
||||||
return countText as T
|
|
||||||
}
|
|
||||||
else if (name == "didClickIncrement") {
|
|
||||||
return didClickIncrement as T
|
|
||||||
}
|
|
||||||
else 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 == "count") {
|
|
||||||
count = value as Int
|
|
||||||
}
|
|
||||||
else if (name == "countText") {
|
|
||||||
countText = value as String
|
|
||||||
}
|
|
||||||
else if (name == "didClickIncrement") {
|
|
||||||
didClickIncrement = value as Boolean
|
|
||||||
}
|
|
||||||
else if (name == "didLaunch") {
|
|
||||||
didLaunch = value as Boolean
|
|
||||||
}
|
|
||||||
else if (name == "didSetup") {
|
|
||||||
didSetup = value as Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hpSet(
|
|
||||||
key: String,
|
|
||||||
value: Any
|
|
||||||
) {
|
|
||||||
HPComponent.ctrl.set(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hpShouldResetCount(c: HPContext): HPContext {
|
|
||||||
val c = c
|
|
||||||
|
|
||||||
// 1. Upon hitting 7
|
|
||||||
if (
|
|
||||||
c.recentField == F.didClickIncrement &&
|
|
||||||
c.count == 7
|
|
||||||
) {
|
|
||||||
c.count += 10
|
|
||||||
c.recentField = F.count
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
// 2. Upon each button click
|
|
||||||
if (
|
|
||||||
c.recentField == F.didClickIncrement
|
|
||||||
) {
|
|
||||||
c.count += 1
|
|
||||||
c.recentField = F.count
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hpShouldResetCountText(c: HPContext): HPContext {
|
|
||||||
val c = c
|
|
||||||
|
|
||||||
// 1. Upon each count change
|
|
||||||
if (
|
|
||||||
c.recentField == F.count
|
|
||||||
) {
|
|
||||||
c.countText = "Count: '${c.count}'"
|
|
||||||
c.recentField = F.countText
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
// 2. Upon launch
|
|
||||||
if (
|
|
||||||
c.recentField == F.didLaunch
|
|
||||||
) {
|
|
||||||
c.countText = "Press the button to count"
|
|
||||||
c.recentField = F.countText
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hpShouldResetDidLaunch(c: HPContext): HPContext {
|
|
||||||
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 hpRegisterShoulds(ctrl: DialectController) {
|
|
||||||
listOf(
|
|
||||||
::hpShouldResetCount,
|
|
||||||
::hpShouldResetCountText,
|
|
||||||
::hpShouldResetDidLaunch,
|
|
||||||
|
|
||||||
).forEach { f ->
|
|
||||||
ctrl.registerFunction { c -> f(c as HPContext) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hpRegisterEffects(ctrl: DialectController) {
|
|
||||||
registerOneliners(ctrl, arrayOf(
|
|
||||||
F.countText, { c: HPContext -> HPVM.shared!!.countText = c.countText },
|
|
||||||
|
|
||||||
))
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../../../../../components/hp/android/hp.kt
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../../../../../components/hp/android/hpVM.kt
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../../../../../../components/hp/android/view/HPView.kt
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../../../../../components/other/other.kt
|
|
||||||
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB |
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<string name="app_name">hello-platform</string>
|
|
||||||
</resources>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<style name="Theme.MyApplication" parent="android:Theme.Material.NoActionBar">
|
|
||||||
<item name="android:windowBackground">#FFFFFF</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
google {
|
|
||||||
content {
|
|
||||||
includeGroupByRegex("com\\.android.*")
|
|
||||||
includeGroupByRegex("com\\.google.*")
|
|
||||||
includeGroupByRegex("androidx.*")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mavenCentral()
|
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dependencyResolutionManagement {
|
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rootProject.name = "hello-platform"
|
|
||||||
include("app")
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../res/AppIcon.png
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"images" : [
|
|
||||||
{
|
|
||||||
"filename" : "AppIcon.png",
|
|
||||||
"idiom" : "universal",
|
|
||||||
"platform" : "ios",
|
|
||||||
"size" : "1024x1024"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"info" : {
|
|
||||||
"author" : "xcode",
|
|
||||||
"version" : 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundleDisplayName</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>org.opengamestudio.hello-platform</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
<key>UILaunchScreen</key>
|
|
||||||
<dict/>
|
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
|
||||||
<array>
|
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
|
||||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
name: hello-platform
|
|
||||||
options:
|
|
||||||
bundleIdPrefix: org.opengamestudio
|
|
||||||
targets:
|
|
||||||
hello-platform:
|
|
||||||
type: application
|
|
||||||
platform: iOS
|
|
||||||
deploymentTarget: "15.0"
|
|
||||||
sources:
|
|
||||||
- path: Assets.xcassets
|
|
||||||
- path: src
|
|
||||||
settings:
|
|
||||||
base:
|
|
||||||
INFOPLIST_FILE: Info.plist
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER: org.opengamestudio.hello-platform
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct HPApp: App {
|
|
||||||
@UIApplicationDelegateAdaptor(HPAppDelegate.self) private var appDelegate
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
HPView(appDelegate.hpVM)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import UIKit
|
|
||||||
|
|
||||||
final class HPAppDelegate:
|
|
||||||
NSObject,
|
|
||||||
UIApplicationDelegate
|
|
||||||
{
|
|
||||||
let hp = HPComponent()
|
|
||||||
let hpVM = HPVM()
|
|
||||||
|
|
||||||
func application(
|
|
||||||
_ application: UIApplication,
|
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
||||||
) -> Bool {
|
|
||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
|
||||||
hp.setup()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/hp.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/hpVM.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../components/hp/ios/view/HPView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/other/other.swift
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
// swift-tools-version: 5.10
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "hello-platform",
|
|
||||||
dependencies: [
|
|
||||||
.package(url: "https://github.com/moreSwift/swift-cross-ui", branch: "v0.10.0")
|
|
||||||
],
|
|
||||||
targets: [
|
|
||||||
.executableTarget(
|
|
||||||
name: "hello-platform",
|
|
||||||
dependencies: [
|
|
||||||
.product(name: "GtkBackend", package: "swift-cross-ui"),
|
|
||||||
.product(name: "SwiftCrossUI", package: "swift-cross-ui")
|
|
||||||
],
|
|
||||||
path: "src"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import GtkBackend
|
|
||||||
import SwiftCrossUI
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct HPApp: App {
|
|
||||||
var backend: GtkBackend {
|
|
||||||
GtkBackend(appIdentifier: "org.opengamestudio.hello-platform")
|
|
||||||
}
|
|
||||||
let delegate = HPAppDelegate()
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup("Hello platform") {
|
|
||||||
HPView(delegate.hpVM)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SwiftCrossUI
|
|
||||||
|
|
||||||
final class HPAppDelegate {
|
|
||||||
let hp = HPComponent()
|
|
||||||
let hpVM = HPVM()
|
|
||||||
|
|
||||||
init() {
|
|
||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
|
||||||
hp.setup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/linux/hp.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/linux/hpVM.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../components/hp/linux/view/HPView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/other/other.swift
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundleDisplayName</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>org.opengamestudio.hello-platform</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>hello-platform</string>
|
|
||||||
<key>CFBundleIconFile</key>
|
|
||||||
<string>AppIcon</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
<key>LSMinimumSystemVersion</key>
|
|
||||||
<string>11.0</string>
|
|
||||||
<key>NSHighResolutionCapable</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// swift-tools-version: 5.9
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "hello-platform",
|
|
||||||
platforms: [
|
|
||||||
.macOS(.v13)
|
|
||||||
],
|
|
||||||
targets: [
|
|
||||||
.executableTarget(
|
|
||||||
name: "hello-platform",
|
|
||||||
path: "src"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../res/AppIcon.icns
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import AppKit
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct HPApp: App {
|
|
||||||
@NSApplicationDelegateAdaptor(HPAppDelegate.self) private var appDelegate
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
HPView(appDelegate.hpVM)
|
|
||||||
}
|
|
||||||
.defaultSize(width: 640, height: 480)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import AppKit
|
|
||||||
|
|
||||||
final class HPAppDelegate:
|
|
||||||
NSObject,
|
|
||||||
NSApplicationDelegate
|
|
||||||
{
|
|
||||||
let hp = HPComponent()
|
|
||||||
let hpVM = HPVM()
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
||||||
// Bring the app to the foreground
|
|
||||||
NSApp.setActivationPolicy(.regular)
|
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
|
||||||
|
|
||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
|
||||||
hp.setup()
|
|
||||||
}
|
|
||||||
|
|
||||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
|
|
||||||
// Reusable "none" constant
|
|
||||||
public let DIALECT_CONTEXT_RECENT_FIELD_NONE = "none"
|
|
||||||
|
|
||||||
// Base protocol for each component's state
|
|
||||||
public protocol DialectContext {
|
|
||||||
var recentField: String { get set }
|
|
||||||
|
|
||||||
func field<T>(_ name: String) -> T
|
|
||||||
func fieldAny(_ name: String) -> Any
|
|
||||||
mutating func setField(_ name: String, _ value: Any)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default implementation of `fieldAny` method for the protocol
|
|
||||||
public extension DialectContext {
|
|
||||||
func fieldAny(_ name: String) -> Any {
|
|
||||||
return field(name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The engine of the dialect components
|
|
||||||
public class DialectController {
|
|
||||||
var callbacks = [(DialectContext) -> Void]()
|
|
||||||
var context: DialectContext
|
|
||||||
var functions = [(DialectContext) -> DialectContext]()
|
|
||||||
var isProcessingQueue = false
|
|
||||||
var queue = [DialectContext]()
|
|
||||||
|
|
||||||
public init(_ context: DialectContext) {
|
|
||||||
self.context = context
|
|
||||||
}
|
|
||||||
|
|
||||||
func executeFunctions() {
|
|
||||||
let c = queue.removeFirst()
|
|
||||||
// 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 {
|
|
||||||
let ctx = f(context)
|
|
||||||
if ctx.recentField != DIALECT_CONTEXT_RECENT_FIELD_NONE {
|
|
||||||
queue.append(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reportContext()
|
|
||||||
}
|
|
||||||
|
|
||||||
func processQueue() {
|
|
||||||
// Prevent recursion.
|
|
||||||
if isProcessingQueue {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isProcessingQueue = true
|
|
||||||
|
|
||||||
while (queue.count > 0) {
|
|
||||||
executeFunctions()
|
|
||||||
}
|
|
||||||
|
|
||||||
isProcessingQueue = false
|
|
||||||
}
|
|
||||||
|
|
||||||
public func registerCallback(_ cb: @escaping (DialectContext) -> Void) {
|
|
||||||
callbacks.append(cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func registerFieldCallback(
|
|
||||||
_ fieldName: String,
|
|
||||||
_ cb: @escaping (DialectContext) -> Void
|
|
||||||
) {
|
|
||||||
callbacks.append({ c in
|
|
||||||
if c.recentField == fieldName {
|
|
||||||
cb(c)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public func registerFunction(_ f: @escaping (DialectContext) -> DialectContext) {
|
|
||||||
functions.append(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportContext() {
|
|
||||||
for cb in callbacks {
|
|
||||||
cb(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public func set(
|
|
||||||
_ fieldName: String,
|
|
||||||
_ value: Any
|
|
||||||
) {
|
|
||||||
var c = context
|
|
||||||
c.setField(fieldName, value)
|
|
||||||
c.recentField = fieldName
|
|
||||||
queue.append(c)
|
|
||||||
processQueue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register several oneliner callbacks to a controller
|
|
||||||
func registerOneliners<T>(
|
|
||||||
_ ctrl: DialectController,
|
|
||||||
_ items: [Any]
|
|
||||||
) -> T? {
|
|
||||||
let halfCount = items.count / 2
|
|
||||||
for i in 0..<halfCount {
|
|
||||||
let field = items[i * 2] as! String
|
|
||||||
let callback = items[i * 2 + 1] as! (T) -> Void
|
|
||||||
ctrl.registerFieldCallback(field) { cc in
|
|
||||||
let c = cc as! T
|
|
||||||
callback(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A hack for generics to operate
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Context field names for static type check
|
|
||||||
public struct F {
|
|
||||||
public static let count = "count"
|
|
||||||
public static let countText = "countText"
|
|
||||||
public static let didClickIncrement = "didClickIncrement"
|
|
||||||
public static let didLaunch = "didLaunch"
|
|
||||||
public static let didSetup = "didSetup"
|
|
||||||
|
|
||||||
}
|
|
||||||
public struct HPContext: DialectContext {
|
|
||||||
public var count = Int()
|
|
||||||
public var countText = String()
|
|
||||||
public var didClickIncrement = Bool()
|
|
||||||
public var didLaunch = Bool()
|
|
||||||
public var didSetup = Bool()
|
|
||||||
|
|
||||||
public var recentField = ""
|
|
||||||
|
|
||||||
public func field<T>(_ name: String) -> T {
|
|
||||||
if (name == "count") {
|
|
||||||
return count as! T
|
|
||||||
}
|
|
||||||
else if (name == "countText") {
|
|
||||||
return countText as! T
|
|
||||||
}
|
|
||||||
else if (name == "didClickIncrement") {
|
|
||||||
return didClickIncrement as! T
|
|
||||||
}
|
|
||||||
else if (name == "didLaunch") {
|
|
||||||
return didLaunch as! T
|
|
||||||
}
|
|
||||||
else if (name == "didSetup") {
|
|
||||||
return didSetup as! T
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown-field-name" as! T
|
|
||||||
}
|
|
||||||
|
|
||||||
public mutating func setField(
|
|
||||||
_ name: String,
|
|
||||||
_ value: Any
|
|
||||||
) {
|
|
||||||
if (name == "count") {
|
|
||||||
count = value as! Int
|
|
||||||
}
|
|
||||||
else if (name == "countText") {
|
|
||||||
countText = value as! String
|
|
||||||
}
|
|
||||||
else if (name == "didClickIncrement") {
|
|
||||||
didClickIncrement = value as! Bool
|
|
||||||
}
|
|
||||||
else if (name == "didLaunch") {
|
|
||||||
didLaunch = value as! Bool
|
|
||||||
}
|
|
||||||
else if (name == "didSetup") {
|
|
||||||
didSetup = value as! Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public func hpSet(
|
|
||||||
_ key: String,
|
|
||||||
_ value: Any
|
|
||||||
) {
|
|
||||||
HPComponent.singleton!.ctrl.set(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func hpShouldResetCount(_ c: HPContext) -> HPContext {
|
|
||||||
var c = c
|
|
||||||
|
|
||||||
/* 1. Upon hitting 7 */
|
|
||||||
if
|
|
||||||
c.recentField == F.didClickIncrement &&
|
|
||||||
c.count == 7
|
|
||||||
{
|
|
||||||
c.count += 10
|
|
||||||
c.recentField = F.count
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2. Upon each button click */
|
|
||||||
if
|
|
||||||
c.recentField == F.didClickIncrement
|
|
||||||
{
|
|
||||||
c.count += 1
|
|
||||||
c.recentField = F.count
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func hpShouldResetCountText(_ c: HPContext) -> HPContext {
|
|
||||||
var c = c
|
|
||||||
|
|
||||||
/* 1. Upon each count change */
|
|
||||||
if
|
|
||||||
c.recentField == F.count
|
|
||||||
{
|
|
||||||
c.countText = "Count: '\(c.count)'"
|
|
||||||
c.recentField = F.countText
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2. Upon launch */
|
|
||||||
if
|
|
||||||
c.recentField == F.didLaunch
|
|
||||||
{
|
|
||||||
c.countText = "Press the button to count"
|
|
||||||
c.recentField = F.countText
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func hpShouldResetDidLaunch(_ c: HPContext) -> HPContext {
|
|
||||||
var 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func hpRegisterShoulds(_ ctrl: DialectController) {
|
|
||||||
[
|
|
||||||
hpShouldResetCount,
|
|
||||||
hpShouldResetCountText,
|
|
||||||
hpShouldResetDidLaunch,
|
|
||||||
|
|
||||||
].forEach { f in
|
|
||||||
ctrl.registerFunction { c in f(c as! HPContext) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func hpRegisterEffects(_ ctrl: DialectController) {
|
|
||||||
let _: HPContext? = registerOneliners(ctrl, [
|
|
||||||
F.countText, { (c: HPContext) in HPVM.shared!.countText = c.countText },
|
|
||||||
|
|
||||||
])
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/hp.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/hpVM.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../components/hp/mac/view/HPView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/other/other.swift
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// swift-tools-version: 5.10
|
|
||||||
import Foundation
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let resDir = ProcessInfo.processInfo.environment["APP_RES_DIR"]!
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "hello-platform",
|
|
||||||
dependencies: [
|
|
||||||
.package(url: "https://github.com/moreSwift/swift-cross-ui", branch: "v0.10.0")
|
|
||||||
],
|
|
||||||
targets: [
|
|
||||||
.executableTarget(
|
|
||||||
name: "hello-platform",
|
|
||||||
dependencies: [
|
|
||||||
.product(name: "SwiftCrossUI", package: "swift-cross-ui"),
|
|
||||||
.product(name: "WinUIBackend", package: "swift-cross-ui")
|
|
||||||
],
|
|
||||||
path: "src",
|
|
||||||
linkerSettings: [
|
|
||||||
.unsafeFlags(["-Xlinker", "\(resDir)/AppIcon.res"])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../res/AppIcon.res
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import SwiftCrossUI
|
|
||||||
import WinUIBackend
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct HPApp: App {
|
|
||||||
let delegate = HPAppDelegate()
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup("Hello platform") {
|
|
||||||
HPView(delegate.hpVM)
|
|
||||||
.onAppear {
|
|
||||||
delegate.setup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
final class HPAppDelegate {
|
|
||||||
let hp = HPComponent()
|
|
||||||
let hpVM = HPVM()
|
|
||||||
|
|
||||||
func setup() {
|
|
||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
|
||||||
hp.setup()
|
|
||||||
otherSetupWindowIcon(101)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../ver-mac/src/dialect.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/hp.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/hp/linux/hpVM.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../../components/hp/linux/view/HPView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/other/other.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/other/windows/otherWindows.swift
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||