From 148a40c0c6fefcc048affcbc88404b52907427a5 Mon Sep 17 00:00:00 2001 From: Andrew Skurlatov Date: Wed, 10 Jan 2024 23:53:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(project.pbxproj):=20update?= =?UTF-8?q?=20CURRENT=5FPROJECT=5FVERSION=20and=20MARKETING=5FVERSION=20to?= =?UTF-8?q?=202.0.3=20=E2=9C=A8=20feat(Word.swift):=20add=20function=20to?= =?UTF-8?q?=20generate=20comparative=20adjective=20forms=20=F0=9F=90=9B=20?= =?UTF-8?q?fix(WordService.swift):=20add=20missing=20variables=20for=20gen?= =?UTF-8?q?erating=20comparative=20adjective=20forms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔨 refactor(DynamicTable.swift): reformat code for better readability and maintainability --- OldNorseDictionary.xcodeproj/project.pbxproj | 16 +-- Source/Models/Word.swift | 72 ++++++++++++- Source/Services/WordService.swift | 5 +- Source/Views/DynamicTable.swift | 101 ++++++++++++++++++- 4 files changed, 180 insertions(+), 14 deletions(-) diff --git a/OldNorseDictionary.xcodeproj/project.pbxproj b/OldNorseDictionary.xcodeproj/project.pbxproj index e6368fc..6023911 100644 --- a/OldNorseDictionary.xcodeproj/project.pbxproj +++ b/OldNorseDictionary.xcodeproj/project.pbxproj @@ -575,7 +575,7 @@ CODE_SIGN_ENTITLEMENTS = Source/OldNorseDictionary.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2.0.1; + CURRENT_PROJECT_VERSION = 2.0.3; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 4V482C5WA8; ENABLE_HARDENED_RUNTIME = YES; @@ -596,7 +596,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.0.3; PRODUCT_BUNDLE_IDENTIFIER = Andskur.OldNorseDictionary; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -618,7 +618,7 @@ CODE_SIGN_ENTITLEMENTS = Source/OldNorseDictionary.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2.0.1; + CURRENT_PROJECT_VERSION = 2.0.3; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 4V482C5WA8; ENABLE_HARDENED_RUNTIME = YES; @@ -639,7 +639,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.0.3; PRODUCT_BUNDLE_IDENTIFIER = Andskur.OldNorseDictionary; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -701,7 +701,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2.0.1; + CURRENT_PROJECT_VERSION = 2.0.3; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 4V482C5WA8; ENABLE_PREVIEWS = YES; @@ -713,7 +713,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.0.3; PRODUCT_BUNDLE_IDENTIFIER = Andskur.OldNorseDictionary.watchkitapp; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; @@ -731,7 +731,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2.0.1; + CURRENT_PROJECT_VERSION = 2.0.3; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 4V482C5WA8; ENABLE_PREVIEWS = YES; @@ -743,7 +743,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.0.3; PRODUCT_BUNDLE_IDENTIFIER = Andskur.OldNorseDictionary.watchkitapp; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; diff --git a/Source/Models/Word.swift b/Source/Models/Word.swift index ce2a6e4..55398a6 100644 --- a/Source/Models/Word.swift +++ b/Source/Models/Word.swift @@ -63,6 +63,69 @@ struct Word: Codable, Identifiable { var id = UUID() + func generateComparativeAdjective(number: Number, gender: Gender, caseWeak: Case) -> String? { + if type != .adjective { + return nil + } + + var weak = base + + switch caseWeak { + case .nominative: + switch number { + case .singular: + switch gender { + case .masculine, .feminine: + return base! + "ari" + default: + return weak! + "ara" + } + case .dual, .plural: + return weak! + "ari" + } + case .accusative: + switch number { + case .singular: + switch gender { + case .feminine: + return weak! + "ari" + default: + return weak! + "ara" + } + case .dual, .plural: + return weak! + "ari" + } + case .dative: + switch number { + case .singular: + switch gender { + case .feminine: + return weak! + "ari" + default: + return weak! + "ara" + } + case .dual, .plural: + if base?.last == "v" { + weak?.removeLast() + } + + return weak! + "urum" + } + case .genitive: + switch number { + case .singular: + switch gender { + case .feminine: + return weak! + "ari" + default: + return weak! + "ara" + } + case .dual, .plural: + return weak! + "ari" + } + } + } + func generateWeakAdjective(number: Number, gender: Gender, caseWeak: Case) -> String? { if type != .adjective { return nil @@ -127,11 +190,12 @@ struct Word: Codable, Identifiable { if acc.hasSuffix("ja") { weak! += "j" } - - if base?.last == "v" { - weak?.removeLast() - } } + + if base?.last == "v" { + weak?.removeLast() + } + return weak! + "u" } case .dative: diff --git a/Source/Services/WordService.swift b/Source/Services/WordService.swift index cb38e8f..94d2879 100644 --- a/Source/Services/WordService.swift +++ b/Source/Services/WordService.swift @@ -191,12 +191,15 @@ class WordService { let accGenitivePluralNeuter = word.generateCase(wordCase: .genitive, number: .plural, gender: .neuter)?.lowercased().contains(query) == true let accComparative = word.generateComparative()?.lowercased().contains(query) == true + let accComparativeAdjective1 = word.generateComparativeAdjective(number: .singular, gender: .masculine, caseWeak: .nominative)?.lowercased().contains(query) == true + let accComparativeAdjective2 = word.generateComparativeAdjective(number: .singular, gender: .neuter, caseWeak: .nominative)?.lowercased().contains(query) == true + let accComparativeAdjective3 = word.generateComparativeAdjective(number: .plural, gender: .any, caseWeak: .dative)?.lowercased().contains(query) == true let accInfinitive = word.generateInfinitive()?.lowercased().contains(query) == true let accImerativeSingular = word.generateImperative(number: .singular)?.lowercased().contains(query) == true let accImerativePlural = word.generateImperative(number: .plural)?.lowercased().contains(query) == true - return wordMatchesQuery || nominativeSingularMatchesQuery || nominativeDualMatchesQuery || nominativePluralMatchesQuery || accusativeSingularMatchesQuery || accusativeDualMatchesQuery || accusativePluralMatchesQuery || dativeSingularMatchesQuery || dativeDualMatchesQuery || dativePluralMatchesQuery || firstSingularMatchesQuery || secondSingularMatchesQuery || thirdSingularMatchesQuery || firstPluralMatchesQuery || secondPluralMatchesQuery || thirdPluralMatchesQuery || firstSingularMatchesQueryPast || secondSingularMatchesQueryPast || thirdSingularMatchesQueryPast || firstPluralMatchesQueryPast || secondPluralMatchesQueryPast || thirdPluralMatchesQueryPast || genitiveSingularMatchesQuery || genitiveDualMatchesQuery || genitivePluralMatchesQuery || accNominativeSingularMasculine || accNominativeSingularFemenine || accNominativeSingularNeuter || accNominativeDualMasculine || accNominativeDualFemenine || accNominativeDualNeuter || accNominativePluralMasculine || accNominativePluralFemenine || accAccusativePluralNeuter || accAccusativeSingularMasculine || accAccusativeSingularFemenine || accAccusativeSingularNeuter || accAccusativeDualMasculine || accAccusativeDualFemenine || accAccusativeDualNeuter || accAccusativePluralMasculine || accDativePluralFemenine || accDativePluralNeuter || accGenitiveSingularMasculine || accGenitiveSingularFemenine || accGenitiveSingularNeuter || accGenitiveDualMasculine || accGenitiveDualFemenine || accGenitiveDualNeuter || accGenitivePluralMasculine || accGenitivePluralFemenine || accGenitivePluralNeuter || accNominativePluralNeuter || accDativeSingularMasculine || accDativePluralMasculine || accDativeDualNeuter || accDativeDualFemenine || accDativeDualMasculine || accDativeSingularFemenine || accDativeSingularNeuter || accAccusativePluralFemenine || accComparative || accInfinitive || accImerativeSingular || accImerativePlural + return wordMatchesQuery || nominativeSingularMatchesQuery || nominativeDualMatchesQuery || nominativePluralMatchesQuery || accusativeSingularMatchesQuery || accusativeDualMatchesQuery || accusativePluralMatchesQuery || dativeSingularMatchesQuery || dativeDualMatchesQuery || dativePluralMatchesQuery || firstSingularMatchesQuery || secondSingularMatchesQuery || thirdSingularMatchesQuery || firstPluralMatchesQuery || secondPluralMatchesQuery || thirdPluralMatchesQuery || firstSingularMatchesQueryPast || secondSingularMatchesQueryPast || thirdSingularMatchesQueryPast || firstPluralMatchesQueryPast || secondPluralMatchesQueryPast || thirdPluralMatchesQueryPast || genitiveSingularMatchesQuery || genitiveDualMatchesQuery || genitivePluralMatchesQuery || accNominativeSingularMasculine || accNominativeSingularFemenine || accNominativeSingularNeuter || accNominativeDualMasculine || accNominativeDualFemenine || accNominativeDualNeuter || accNominativePluralMasculine || accNominativePluralFemenine || accAccusativePluralNeuter || accAccusativeSingularMasculine || accAccusativeSingularFemenine || accAccusativeSingularNeuter || accAccusativeDualMasculine || accAccusativeDualFemenine || accAccusativeDualNeuter || accAccusativePluralMasculine || accDativePluralFemenine || accDativePluralNeuter || accGenitiveSingularMasculine || accGenitiveSingularFemenine || accGenitiveSingularNeuter || accGenitiveDualMasculine || accGenitiveDualFemenine || accGenitiveDualNeuter || accGenitivePluralMasculine || accGenitivePluralFemenine || accGenitivePluralNeuter || accNominativePluralNeuter || accDativeSingularMasculine || accDativePluralMasculine || accDativeDualNeuter || accDativeDualFemenine || accDativeDualMasculine || accDativeSingularFemenine || accDativeSingularNeuter || accAccusativePluralFemenine || accComparative || accInfinitive || accImerativeSingular || accImerativePlural || accComparativeAdjective1 || accComparativeAdjective2 || accComparativeAdjective3 } } diff --git a/Source/Views/DynamicTable.swift b/Source/Views/DynamicTable.swift index 37dd1eb..9f6b290 100644 --- a/Source/Views/DynamicTable.swift +++ b/Source/Views/DynamicTable.swift @@ -193,7 +193,106 @@ struct DynamicTable: View { .padding(.vertical, 10) .border(Color.black, width: 1) } - + } + } + } + } + } + } + } + + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text("Comparative") + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + + // Main Headers + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + let headerWidthValue = headerWidth(for: num) + Text(num.rawValue.capitalized) + .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + } + } + + // Sub-Headers + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + ForEach(Number.allCases, id: \.rawValue) { num in + if num == .plural { + Text("Any") + .frame(minWidth: 261, maxWidth: 261) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } else { + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + Text(gen.rawValue.capitalized) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + } + } + } + } + } + + // Rows + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) + + ForEach(Number.allCases, id: \.rawValue) { num in + if num == .plural { + if let weakAdjective = word.generateComparativeAdjective(number: num, gender: .any, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: 261, maxWidth: 261) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } else { + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if let weakAdjective = word.generateComparativeAdjective(number: num, gender: gen, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } } } }