commit 968dee93b63d50bc819ca05b2b7c91713d4a1a9e
parent 8b0e9b92ace66fa4cf8f40609180e2f29f42b683
Author: therealFIGBERT <figbertwelner@gmail.com>
Date: Fri, 25 Oct 2019 20:09:40 -0700
Initial global variable implementation
Diffstat:
6 files changed, 112 insertions(+), 58 deletions(-)
diff --git a/GlobalVars.swift b/GlobalVars.swift
@@ -1,8 +1,8 @@
//
-// File.swift
+// GlobalVars.swift
// captainsLog
//
-// Created by Benjamin Welner on 10/21/19.
+// Created by Benjamin Welner on 10/25/19.
// Copyright © 2019 FIGBERT Industries. All rights reserved.
//
@@ -11,24 +11,24 @@ import GameKit
import Combine
import SwiftUI
-class SettingsVars: ObservableObject {
- let objectWillChange = PassthroughSubject<settingsVars,Never>()
- var saveLocally = true {
+class GlobalVars: ObservableObject {
+ let objectWillChange = PassthroughSubject<GlobalVars,Never>()
+ var saveLocally: Bool = true {
didSet {
objectWillChange.send(self)
}
}
- var saveICloud = true {
+ var saveICloud: Bool = true {
didSet {
objectWillChange.send(self)
}
}
- var currentDateFormat = 0 {
+ var currentDateFormat: Int = 0 {
didSet {
objectWillChange.send(self)
}
}
- var currentMessage = 0 {
+ var currentMessage: Int = 0 {
didSet {
objectWillChange.send(self)
}
@@ -38,4 +38,60 @@ class SettingsVars: ObservableObject {
objectWillChange.send(self)
}
}
+ let dateFormats = [
+ "Stardate",
+ "Jewish",
+ "Islamic",
+ "Persian",
+ "Indian",
+ "Coptic",
+ "Chinese",
+ "Japanese",
+ "Ethiopian",
+ "Gregorian"
+ ]
+ var messages: [String] {
+ didSet {
+ objectWillChange.send(self)
+ }
+ }
+ var date: String {
+ didSet {
+ objectWillChange.send(self)
+ }
+ }
+ init() {
+ switch currentDateFormat {
+ case 1:
+ date = Date().multi(type: "Jewish")
+ case 2:
+ date = Date().multi(type: "Islamic")
+ case 3:
+ date = Date().multi(type: "Persian")
+ case 4:
+ date = Date().multi(type: "Indian")
+ case 5:
+ date = Date().multi(type: "Coptic")
+ case 6:
+ date = Date().multi(type: "Chinese")
+ case 7:
+ date = Date().multi(type: "Japanese")
+ case 8:
+ date = Date().multi(type: "Ethiopian")
+ case 9:
+ date = Date().multi(type: "Gregorian")
+ default:
+ date = Date().stardate()
+ }
+ messages = [
+ "Captain’s log, \(date)",
+ "A day in the life of \(name), entry [NUM]",
+ "\(name)'s audio journal, day [NUM]",
+ "Hi, I'm \(name)",
+ "\(name)'s audio journal, for your ears only.",
+ "Random thoughts, entry [NUM]",
+ "Here's the tea, sis",
+ "Rise and grind, gamers"
+ ]
+ }
}
diff --git a/Settings.swift b/Settings.swift
@@ -10,51 +10,30 @@ import SwiftUI
import GameKit
struct Settings: View {
- @State private var saveLocally = true
- @State private var saveICloud = true
- @State private var currentDateFormat = 0
- @State private var currentMessage = 0
- @State private var name = GKPlayer.init().alias
- var dateFormats = [
- "Stardate",
- "Gregorian date",
- "Jewish date",
- "Islamic date",
- "Chinese date"
- ]
- var messages = [
- "Captain’s log, [DATE]",
- "A day in the life of [NAME], entry [NUM]",
- "[NAME]'s audio journal, day [NUM]",
- "Hi, I'm [NAME]",
- "[NAME]'s audio journal, for your ears only.",
- "Random thoughts, entry [NUM]",
- "Here's the tea, sis",
- "Rise and grind, gamers"
- ]
+ @EnvironmentObject var globalVars: GlobalVars
var body: some View {
Form {
Section(header: Text("Save")) {
- Toggle(isOn: $saveLocally) {
+ Toggle(isOn: $globalVars.saveLocally) {
Text("Save on device")
}
- Toggle(isOn: $saveICloud) {
+ Toggle(isOn: $globalVars.saveICloud) {
Text("Save to iCloud")
}
}
Section(header: Text("Name")) {
- TextField("Name", text: $name)
+ TextField("Name", text: $globalVars.name)
}
Section(header: Text("Prompt")) {
- Picker("Date format", selection: $currentDateFormat) {
- ForEach(0 ..< dateFormats.count) {
- Text("\(self.dateFormats[$0])")
+ Picker("Date format", selection: $globalVars.currentDateFormat) {
+ ForEach(0 ..< globalVars.dateFormats.count) {
+ Text("\(self.globalVars.dateFormats[$0])")
}
}
- Picker("Intro message", selection: $currentMessage) {
- ForEach(0 ..< messages.count) {
- Text("\(self.messages[$0])")
+ Picker("Intro message", selection: $globalVars.currentMessage) {
+ ForEach(0 ..< globalVars.messages.count) {
+ Text("\(self.globalVars.messages[$0])")
}
}
}
@@ -68,6 +47,6 @@ struct Settings: View {
struct Settings_Previews: PreviewProvider {
static var previews: some View {
- Settings()
+ Settings().environmentObject(GlobalVars())
}
}
diff --git a/captainsLog.xcodeproj/project.pbxproj b/captainsLog.xcodeproj/project.pbxproj
@@ -13,6 +13,7 @@
3A35D6E623579F7C005B7610 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A35D6E523579F7C005B7610 /* Assets.xcassets */; };
3A35D6E923579F7C005B7610 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A35D6E823579F7C005B7610 /* Preview Assets.xcassets */; };
3A35D6EC23579F7C005B7610 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3A35D6EA23579F7C005B7610 /* LaunchScreen.storyboard */; };
+ 3A64E4F52363E98A00B5389D /* GlobalVars.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A64E4F42363E98A00B5389D /* GlobalVars.swift */; };
3A76A1E8235AD08C00964901 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A76A1E7235AD08C00964901 /* Settings.swift */; };
3A76A1EA235AE6D500964901 /* Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A76A1E9235AE6D500964901 /* Elements.swift */; };
/* End PBXBuildFile section */
@@ -26,6 +27,7 @@
3A35D6E823579F7C005B7610 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3A35D6EB23579F7C005B7610 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
3A35D6ED23579F7C005B7610 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ 3A64E4F42363E98A00B5389D /* GlobalVars.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalVars.swift; sourceTree = SOURCE_ROOT; };
3A76A1E7235AD08C00964901 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = SOURCE_ROOT; };
3A76A1E9235AE6D500964901 /* Elements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Elements.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -65,6 +67,7 @@
3A35D6E323579F7B005B7610 /* ContentView.swift */,
3A76A1E7235AD08C00964901 /* Settings.swift */,
3A76A1E9235AE6D500964901 /* Elements.swift */,
+ 3A64E4F42363E98A00B5389D /* GlobalVars.swift */,
3A35D6E523579F7C005B7610 /* Assets.xcassets */,
3A35D6EA23579F7C005B7610 /* LaunchScreen.storyboard */,
3A35D6ED23579F7C005B7610 /* Info.plist */,
@@ -156,6 +159,7 @@
3A35D6E223579F7B005B7610 /* SceneDelegate.swift in Sources */,
3A35D6E423579F7B005B7610 /* ContentView.swift in Sources */,
3A76A1E8235AD08C00964901 /* Settings.swift in Sources */,
+ 3A64E4F52363E98A00B5389D /* GlobalVars.swift in Sources */,
3A76A1EA235AE6D500964901 /* Elements.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
diff --git a/captainsLog/ContentView.swift b/captainsLog/ContentView.swift
@@ -9,6 +9,7 @@
import SwiftUI
struct ContentView: View {
+ @EnvironmentObject var globalVars: GlobalVars
@State private var recording: Bool = false
@State private var timeElapsed: Double = 0.00
@State private var timer:Timer?
@@ -95,6 +96,6 @@ struct ContentView: View {
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
- ContentView()
+ ContentView().environmentObject(GlobalVars())
}
}
diff --git a/captainsLog/Elements.swift b/captainsLog/Elements.swift
@@ -49,7 +49,7 @@ extension Date {
}
func multi(type: String) -> String {
let calendar_list: [String: [String]] = [
- "jewish": [
+ "Jewish": [
"Tishrei",
"Cheshvan",
"Kislev",
@@ -64,7 +64,7 @@ extension Date {
"Av",
"Elul"
],
- "islamic": [
+ "Islamic": [
"Muharram",
"Safar",
"Rabi al-Awwal",
@@ -78,7 +78,7 @@ extension Date {
"Zulqiddah",
"Zulhijjah"
],
- "persian": [
+ "Persian": [
"Farvardin",
"Ordibehesht",
"Khordad",
@@ -92,7 +92,7 @@ extension Date {
"Bahman",
"Esfand"
],
- "indian": [
+ "Indian": [
"Vaisakha",
"Jyeshtha",
"Ashadha",
@@ -106,7 +106,7 @@ extension Date {
"Phalguna",
"Chaitra"
],
- "coptic": [
+ "Coptic": [
"Thout",
"Paopi",
"Hathor",
@@ -121,7 +121,7 @@ extension Date {
"Mesori",
"Pi Kogi Enavot"
],
- "chinese": [
+ "Chinese": [
"yínyuè",
"mǎoyuè",
"chényuè",
@@ -135,7 +135,7 @@ extension Date {
"zǐyuè",
"chǒuyuè"
],
- "japanese": [
+ "Japanese": [
"Mutsuki",
"Kisaragi",
"Yayoi",
@@ -149,7 +149,7 @@ extension Date {
"Shimotsuki",
"Shiwasu"
],
- "ethiopian": [
+ "Ethiopian": [
"Mäskäräm",
"Ṭəqəmt",
"Ḫədar",
@@ -163,25 +163,39 @@ extension Date {
"Ḥamle",
"Nähase",
"Ṗagume"
+ ],
+ "Gregorian": [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December"
]
]
var calendar: Calendar
switch type {
- case "jewish":
+ case "Jewish":
calendar = Calendar.init(identifier: .hebrew)
- case "islamic":
+ case "Islamic":
calendar = Calendar.init(identifier: .islamic)
- case "persian":
+ case "Persian":
calendar = Calendar.init(identifier: .persian)
- case "indian":
+ case "Indian":
calendar = Calendar.init(identifier: .indian)
- case "coptic":
+ case "Coptic":
calendar = Calendar.init(identifier: .coptic)
- case "ethiopian":
+ case "Ethiopian":
calendar = Calendar.init(identifier: .ethiopicAmeteAlem)
- case "chinese":
+ case "Chinese":
calendar = Calendar.init(identifier: .chinese)
- case "japanese":
+ case "Japanese":
calendar = Calendar.init(identifier: .japanese)
default:
calendar = Calendar.init(identifier: .gregorian)
diff --git a/captainsLog/SceneDelegate.swift b/captainsLog/SceneDelegate.swift
@@ -25,7 +25,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
- window.rootViewController = UIHostingController(rootView: contentView)
+ window.rootViewController = UIHostingController(rootView: contentView.environmentObject(GlobalVars()))
self.window = window
window.makeKeyAndVisible()
}