diff --git a/src/Core/DataSources/MockData.swift b/src/Core/DataSources/MockData.swift index 51ec6be..ce9a89c 100644 --- a/src/Core/DataSources/MockData.swift +++ b/src/Core/DataSources/MockData.swift @@ -8,6 +8,26 @@ public enum MockMonsterKey: String, CaseIterable { } public enum MockData { + static func localization(_ key: String) -> MHLocalization? { + let bundle = Bundle(for: NetworkDataSource.self) + guard let url = bundle.url(forResource: key, withExtension: "json"), + let data = try? Data(contentsOf: url), + let json = try? JSONDecoder().decode(MHLocalization.self, from: data) else { + return nil + } + return json + } + + static func game() -> MHGame? { + let bundle = Bundle(for: NetworkDataSource.self) + guard let url = bundle.url(forResource: "index", withExtension: "json"), + let data = try? Data(contentsOf: url), + let json = try? JSONDecoder().decode(MHGame.self, from: data) else { + return nil + } + return json + } + static func monster(_ key: MockMonsterKey) -> MHMonster? { let bundle = Bundle(for: NetworkDataSource.self) guard let url = bundle.url(forResource: key.rawValue, withExtension: "json"), diff --git a/src/Core/DataSources/MockDataSource.swift b/src/Core/DataSources/MockDataSource.swift index 2156269..96a971b 100644 --- a/src/Core/DataSources/MockDataSource.swift +++ b/src/Core/DataSources/MockDataSource.swift @@ -3,49 +3,6 @@ import Foundation public struct MockDataSource { static let config = MHConfig(version: 3, games: ["mockgame"], languages: ["en", "ja"], source: nil) - static let localizationEnglish = MHLocalization( - games: [ - MHLocalizationGame(id: "mockgame", - name: "H.Fest!", - fullName: "Hunster Festival!", - abbreviation: "HF") - ], - monsters: [ - MHLocalizationMonster(id: "gulu_qoo", - name: "Gulu Qoo", - anotherName: nil, - keywords: []), - MHLocalizationMonster(id: "bucha_cat", - name: "Bucha Cat", - anotherName: nil, - keywords: []) - ], - states: [:]) - - static let localizationJapanese = MHLocalization( - games: [ - MHLocalizationGame(id: "mockgame", - name: "狩りカニ!", - fullName: "狩り狩りカーニバル!", - abbreviation: "HF") - ], - monsters: [ - MHLocalizationMonster(id: "gulu_qoo", - name: "グークー", - anotherName: nil, - keywords: []), - MHLocalizationMonster(id: "bucha_cat", - name: "ブチャネコ", - anotherName: nil, - keywords: []) - ], - states: [:]) - - static let game = MHGame(id: "mockgame", - copyright: nil, - url: nil, - monsters: [MHGameMonster(id: "gulu_qoo", type: "piyopiyo")]) - public static var physiology1: Physiologies { let monster = MockData.monster(.guluQoo)! let mapper = PhysiologyMapper(languageService: PassthroughtLanguageService()) @@ -64,15 +21,17 @@ extension MockDataSource: DataSource { } func getGame(of titleId: String) async throws -> MHGame { - Self.game + guard let mock = MockData.game() else { + throw StarSwingsError.notExists + } + return mock } func getLocalization(of key: String) async throws -> MHLocalization { - if key == "ja" { - return Self.localizationJapanese - } else { - return Self.localizationEnglish + guard let mock = MockData.localization(key) else { + throw StarSwingsError.notExists } + return mock } func getMonster(of id: String, for titleId: String) async throws -> MHMonster { diff --git a/src/Core/DataSources/Mocks/Previews/en.json b/src/Core/DataSources/Mocks/Previews/en.json new file mode 100644 index 0000000..1457ded --- /dev/null +++ b/src/Core/DataSources/Mocks/Previews/en.json @@ -0,0 +1,48 @@ +{ + "games": [ + { + "id": "mockgame", + "name": "H.Fest!", + "full_name": "Hunster Festival!", + "abbreviation": "HF" + } + ], + "monsters": [ + { + "id": "super_bug", + "name": "Super Bug" + }, + { + "id": "super_oraora", + "name": "Super Ora-Ora" + }, + { + "id": "gulu_qoo", + "name": "Gulu Qoo" + }, + { + "id": "super_warota", + "name": "Super Warota" + }, + { + "id": "paos", + "name": "Paos" + }, + { + "id": "lambii", + "name": "Lambii" + }, + { + "id": "vivi_papa", + "name": "Vivi Papa" + }, + { + "id": "kurururu", + "name": "Ku-Ru-Ru-Ru" + }, + { + "id": "bucha_cat", + "name": "Bucha Cat" + } + ] +} diff --git a/src/Core/DataSources/Mocks/Previews/index.json b/src/Core/DataSources/Mocks/Previews/index.json new file mode 100644 index 0000000..fe0b147 --- /dev/null +++ b/src/Core/DataSources/Mocks/Previews/index.json @@ -0,0 +1,59 @@ +{ + "id": "mockgame", + "monsters": [ + { + "id": "super_bug", + "type": "piyopiyo", + "size": 825, + "weakness": "fwTi_" + }, + { + "id": "super_oraora", + "type": "piyopiyo", + "size": 824, + "weakness": "Fwt " + }, + { + "id": "gulu_qoo", + "type": "piyopiyo", + "size": 903, + "weakness": "Fwtid" + }, + { + "id": "super_warota", + "type": "piyopiyo", + "size": 725, + "weakness": " w_I " + }, + { + "id": "paos", + "type": "piyopiyo", + "size": 324, + "weakness": "F_ti " + }, + { + "id": "lambii", + "type": "piyopiyo", + "size": 764, + "weakness": "F t " + }, + { + "id": "vivi_papa", + "type": "piyopiyo", + "size": 1245, + "weakness": " W_i " + }, + { + "id": "kurururu", + "type": "piyopiyo", + "size": 999, + "weakness": " Wt_ " + }, + { + "id": "bucha_cat", + "type": "piyopiyo", + "size": 1600, + "weakness": "fW i_" + } + ] +} diff --git a/src/Core/DataSources/Mocks/Previews/ja.json b/src/Core/DataSources/Mocks/Previews/ja.json new file mode 100644 index 0000000..9b5ce31 --- /dev/null +++ b/src/Core/DataSources/Mocks/Previews/ja.json @@ -0,0 +1,48 @@ +{ + "games": [ + { + "id": "mockgame", + "name": "狩りカニ!", + "full_name": "狩り狩りカーニバル!", + "abbreviation": "HF" + } + ], + "monsters": [ + { + "id": "super_bug", + "name": "超蟲" + }, + { + "id": "super_oraora", + "name": "超突" + }, + { + "id": "gulu_qoo", + "name": "グークー" + }, + { + "id": "super_warota", + "name": "超草" + }, + { + "id": "paos", + "name": "パオス" + }, + { + "id": "lambii", + "name": "ランビィ" + }, + { + "id": "vivi_papa", + "name": "ヴィヴィ・パパ" + }, + { + "id": "kurururu", + "name": "クルルル" + }, + { + "id": "bucha_cat", + "name": "ブチャネコ" + } + ] +} diff --git a/src/MonsterAnalyzer.xcodeproj/project.pbxproj b/src/MonsterAnalyzer.xcodeproj/project.pbxproj index 3c0f31c..16c9f66 100644 --- a/src/MonsterAnalyzer.xcodeproj/project.pbxproj +++ b/src/MonsterAnalyzer.xcodeproj/project.pbxproj @@ -15,6 +15,9 @@ EB19D6782B1F025300C90417 /* Publishers+RetryIf.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB19D6772B1F025300C90417 /* Publishers+RetryIf.swift */; }; EB1AE8072B7082380037C1E4 /* NavigationBarHideMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB1AE8062B7082380037C1E4 /* NavigationBarHideMode.swift */; platformFilter = ios; }; EB1AE8092B7084960037C1E4 /* NavigationBarHideMode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB1AE8082B7084960037C1E4 /* NavigationBarHideMode+Extensions.swift */; platformFilter = ios; }; + EB1AE80D2B70D16D0037C1E4 /* index.json in Resources */ = {isa = PBXBuildFile; fileRef = EB1AE80A2B70D16D0037C1E4 /* index.json */; }; + EB1AE80E2B70D16D0037C1E4 /* ja.json in Resources */ = {isa = PBXBuildFile; fileRef = EB1AE80B2B70D16D0037C1E4 /* ja.json */; }; + EB1AE80F2B70D16D0037C1E4 /* en.json in Resources */ = {isa = PBXBuildFile; fileRef = EB1AE80C2B70D16D0037C1E4 /* en.json */; }; EB2550142B288C84004823BA /* Backport+ListStyleInsetAlternatingRowBackgrounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2550132B288C84004823BA /* Backport+ListStyleInsetAlternatingRowBackgrounds.swift */; platformFilters = (macos, ); }; EB28F1B32B370F0700291055 /* DividedHStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB28F1B22B370F0700291055 /* DividedHStack.swift */; }; EB29563A2B30139A002C5CA8 /* AppAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2956392B30139A002C5CA8 /* AppAssembly.swift */; }; @@ -453,6 +456,9 @@ EB19D6772B1F025300C90417 /* Publishers+RetryIf.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publishers+RetryIf.swift"; sourceTree = ""; }; EB1AE8062B7082380037C1E4 /* NavigationBarHideMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarHideMode.swift; sourceTree = ""; }; EB1AE8082B7084960037C1E4 /* NavigationBarHideMode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NavigationBarHideMode+Extensions.swift"; sourceTree = ""; }; + EB1AE80A2B70D16D0037C1E4 /* index.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = index.json; sourceTree = ""; }; + EB1AE80B2B70D16D0037C1E4 /* ja.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ja.json; sourceTree = ""; }; + EB1AE80C2B70D16D0037C1E4 /* en.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = en.json; sourceTree = ""; }; EB2550132B288C84004823BA /* Backport+ListStyleInsetAlternatingRowBackgrounds.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Backport+ListStyleInsetAlternatingRowBackgrounds.swift"; sourceTree = ""; }; EB28F1B22B370F0700291055 /* DividedHStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DividedHStack.swift; sourceTree = ""; }; EB2956392B30139A002C5CA8 /* AppAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAssembly.swift; sourceTree = ""; }; @@ -1216,6 +1222,9 @@ isa = PBXGroup; children = ( EB6A4F472B48A951008AB7CE /* bucha_cat.json */, + EB1AE80C2B70D16D0037C1E4 /* en.json */, + EB1AE80A2B70D16D0037C1E4 /* index.json */, + EB1AE80B2B70D16D0037C1E4 /* ja.json */, ); path = Previews; sourceTree = ""; @@ -1629,7 +1638,10 @@ buildActionMask = 2147483647; files = ( EB6A4F492B48A951008AB7CE /* bucha_cat.json in Resources */, + EB1AE80F2B70D16D0037C1E4 /* en.json in Resources */, EB6A4F4A2B48A951008AB7CE /* gulu_qoo.json in Resources */, + EB1AE80D2B70D16D0037C1E4 /* index.json in Resources */, + EB1AE80E2B70D16D0037C1E4 /* ja.json in Resources */, EB8729B22B4D682000E0E5A1 /* Localizable.xcstrings in Resources */, EB8F07DA2B2FB229006AC575 /* Parts.xcstrings in Resources */, );