Introduce a textured cube with raylib (#2)
This commit was merged in pull request #2.
This commit is contained in:
1 parent
925b8602e8
commit
e59610cc90
35 files changed
+861
-14
No files matched your search
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RootView: View {
|
||||
@ObservedObject var vm: RootVM
|
||||
|
||||
init(_ vm: RootVM) {
|
||||
self.vm = vm
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
Text("Hello, World!")
|
||||
.font(.largeTitle)
|
||||
|
||||
Text(vm.countText)
|
||||
.font(.title3.monospacedDigit())
|
||||
|
||||
Button("Increment") {
|
||||
rootSet(F.didClickIncrement, true)
|
||||
}
|
||||
}
|
||||
.padding(40)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class RootComponent {
|
||||
let ctrl = DialectController(RootContext())
|
||||
static private(set) weak var singleton: RootComponent?
|
||||
|
||||
init() {
|
||||
Self.singleton = self
|
||||
rootRegisterEffects(ctrl)
|
||||
rootRegisterShoulds(ctrl)
|
||||
}
|
||||
|
||||
func setup() {
|
||||
rootSet(F.didSetup, true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Combine
|
||||
|
||||
final class RootVM: ObservableObject {
|
||||
@Published var countText = ""
|
||||
|
||||
static private(set) weak var shared: RootVM?
|
||||
|
||||
init() {
|
||||
Self.shared = self
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user