Create hello-platform for macOS (#10)
Co-authored-by: Михаил Капелько <kornerr@gmail.com>
This commit is contained in:
1 parent
8913022044
commit
1aa218d0bb
186 files changed
+519
-7
No files matched your search
@@ -1,8 +1,3 @@
|
||||
## Targets
|
||||
|
||||
| № | Target | macOS | iOS/iPadOS | Android |
|
||||
| 1 | ogs-blue | √ | √ | ? |
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### macOS
|
||||
@@ -15,3 +10,9 @@
|
||||
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
||||
|
||||
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
||||
|
||||
## Components
|
||||
|
||||
| Name | Description | macOS | iOS | Android | Linux | Windows | Raspberry Pi |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| hp | **hello-platform** is a simple UI to validate platform support | √ | | | | | |
|
||||
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Combine
|
||||
|
||||
final class HPVM: ObservableObject {
|
||||
@Published var countText = ""
|
||||
|
||||
static private(set) weak var shared: HPVM?
|
||||
|
||||
init() {
|
||||
Self.shared = self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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.monospacedDigit())
|
||||
Button("Increment") {
|
||||
hpSet(F.didClickIncrement, true)
|
||||
}
|
||||
}
|
||||
.padding(40)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
version: 4
|
||||
|
||||
output:
|
||||
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
|
||||
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/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
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||
|
||||
T=$SDIR/step
|
||||
|
||||
STEP=0
|
||||
source $T/runMac hello-platform hello-platform
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for macOS"
|
||||
|
||||
cd $SDIR/../ver-mac
|
||||
swift build
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'"
|
||||
|
||||
$SDIR/../../../../dialect/util/run-generator --file=$SDIR/../dialect.yml
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/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/"
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/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"
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,15 @@
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "hello-platform",
|
||||
platforms: [
|
||||
.macOS(.v13)
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "hello-platform",
|
||||
path: "src"
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../res/AppIcon.icns
|
||||
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
|
||||
// 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 },
|
||||
|
||||
])
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hp/hp.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hp/hpVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/hp/mac/view/HPView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/other.swift
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 186 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user