diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a672f32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +build +.build +.DS_Store +.gradle +gradle-daemon-jvm.properties +.idea +.kotlin +local.properties +Package.resolved +*.xcodeproj diff --git a/components/other/other.swift b/components/other/other.swift new file mode 100644 index 0000000..a4f2737 --- /dev/null +++ b/components/other/other.swift @@ -0,0 +1,70 @@ +import Foundation + +/// Decode a base64 string back into a regular string +func otherBase64ToString(_ encoded: String) -> String { + guard + let data = Data(base64Encoded: encoded), + let str = String(data: data, encoding: .utf8) + else { + return "" + } + return str +} + +/// Capitalize the first letter of a string +func otherCapitalize(_ s: String) -> String { + guard let first = s.first else { + return s + } + return String(first).uppercased() + String(s.dropFirst()) +} + +/// Launch to wait for asynchrnous actions +func otherLaunch() { + RunLoop.current.run() +} + +/// Count leading spaces in a line +func otherLineIndent(_ line: String) -> Int { + var count = 0 + for ch in line { + if ch == " " { + count += 1 + } else { + break + } + } + return count +} + +/// Print to stderr +func otherPrintStderr(_ txt: String) { + if let dat = "\(txt)\n".data(using: .utf8) { + FileHandle.standardError.write(dat) + } +} + +/// Print each key/value processed by a controller into stderr +func otherSetupConsoleLogging( + _ ctrl: DialectController, + _ prefix: String +) { + ctrl.registerCallback { c -> Void in + let value = c.fieldAny(c.recentField) + let line = "ИГР \(prefix) k/v: '\(c.recentField)'/'\(value)'" + otherPrintStderr(line) + } +} + +/// Write output text to a file +func otherWriteFile( + _ path: String, + _ content: String +) { + try? content.write(toFile: path, atomically: true, encoding: .utf8) +} + +/// Terminate the main RunLoop +func otherShutdown() { + exit(0) +} diff --git a/dialect.yml b/dialect.yml index ba619a4..4258641 100644 --- a/dialect.yml +++ b/dialect.yml @@ -1,7 +1,7 @@ version: 4 output: - ver-mac/src/dialect.swift: + game/ver-mac/src/dialect.swift: type: swift RootComponent: diff --git a/game/ver-mac/src/other/other.swift b/game/ver-mac/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/game/ver-mac/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/game/ver-mac/src/root/root.swift b/game/ver-mac/src/root/root.swift new file mode 120000 index 0000000..5f11ed3 --- /dev/null +++ b/game/ver-mac/src/root/root.swift @@ -0,0 +1 @@ +../../../../components/root/root.swift \ No newline at end of file diff --git a/game/ver-mac/src/root/rootVM.swift b/game/ver-mac/src/root/rootVM.swift new file mode 120000 index 0000000..adfc760 --- /dev/null +++ b/game/ver-mac/src/root/rootVM.swift @@ -0,0 +1 @@ +../../../../components/root/rootVM.swift \ No newline at end of file diff --git a/game/ver-mac/src/root/view/RootView.swift b/game/ver-mac/src/root/view/RootView.swift new file mode 120000 index 0000000..c81285e --- /dev/null +++ b/game/ver-mac/src/root/view/RootView.swift @@ -0,0 +1 @@ +../../../../../components/root/mac/view/RootView.swift \ No newline at end of file diff --git a/util/build-mac b/util/build-mac new file mode 100755 index 0000000..872a9f5 --- /dev/null +++ b/util/build-mac @@ -0,0 +1,10 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +STEP=0 +source $T/generateDialect +source $T/buildMac +source $T/packageMac diff --git a/util/paths b/util/paths new file mode 100644 index 0000000..8df056d --- /dev/null +++ b/util/paths @@ -0,0 +1 @@ +APP_MAC=$SDIR/../game/ver-mac/.build/ogs-mahjong.app diff --git a/util/rm-mac-geom b/util/rm-mac-geom new file mode 100755 index 0000000..6b96fe6 --- /dev/null +++ b/util/rm-mac-geom @@ -0,0 +1,9 @@ +#!/bin/bash -e + +killall cfprefsd 2>/dev/null || true +sleep 1 + +rm -f $HOME/Library/Preferences/OGS\ Mahjong.plist \ + $HOME/Library/Preferences/org.opengamestudio.Mahjong.plist + +echo "removed app preferences (window geometry)" diff --git a/util/run-mac b/util/run-mac new file mode 100755 index 0000000..4a795e9 --- /dev/null +++ b/util/run-mac @@ -0,0 +1,8 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +STEP=0 +source $T/runMac diff --git a/util/step/buildMac b/util/step/buildMac new file mode 100755 index 0000000..f4867bf --- /dev/null +++ b/util/step/buildMac @@ -0,0 +1,7 @@ +#!/bin/bash -e + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Build for macOS" + +cd $SDIR/../game/ver-mac +swift build diff --git a/util/step/generateDialect b/util/step/generateDialect new file mode 100755 index 0000000..65357f5 --- /dev/null +++ b/util/step/generateDialect @@ -0,0 +1,6 @@ +#!/bin/bash -e + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Generate Dialect" + +$SDIR/../../dialect/util/run-generator --file=$SDIR/../dialect.yml diff --git a/util/step/packageMac b/util/step/packageMac new file mode 100755 index 0000000..527df00 --- /dev/null +++ b/util/step/packageMac @@ -0,0 +1,15 @@ +#!/bin/bash -e + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Make an app package for macOS" + +rm -rf $APP_MAC + +APP_DAT=$APP_MAC/Contents + +mkdir -p $APP_DAT/MacOS +mkdir -p $APP_DAT/Resources + +cp $SDIR/../game/ver-mac/.build/debug/ogs-mahjong $APP_DAT/MacOS/ogs-mahjong +cp $SDIR/../game/ver-mac/Info.plist $APP_DAT/Info.plist +cp $SDIR/../game/ver-mac/Resources/AppIcon.icns $APP_DAT/Resources/AppIcon.icns diff --git a/util/step/runMac b/util/step/runMac new file mode 100755 index 0000000..f43b321 --- /dev/null +++ b/util/step/runMac @@ -0,0 +1,6 @@ +#!/bin/bash -e + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Run macOS app" + +$SDIR/../game/ver-mac/.build/ogs-mahjong.app/Contents/MacOS/ogs-mahjong