Skip to content

Commit

Permalink
Adds mock data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mntone committed Feb 5, 2024
1 parent 2c10af9 commit 74826e7
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 48 deletions.
20 changes: 20 additions & 0 deletions src/Core/DataSources/MockData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
55 changes: 7 additions & 48 deletions src/Core/DataSources/MockDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions src/Core/DataSources/Mocks/Previews/en.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
59 changes: 59 additions & 0 deletions src/Core/DataSources/Mocks/Previews/index.json
Original file line number Diff line number Diff line change
@@ -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_"
}
]
}
48 changes: 48 additions & 0 deletions src/Core/DataSources/Mocks/Previews/ja.json
Original file line number Diff line number Diff line change
@@ -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": "ブチャネコ"
}
]
}
12 changes: 12 additions & 0 deletions src/MonsterAnalyzer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -453,6 +456,9 @@
EB19D6772B1F025300C90417 /* Publishers+RetryIf.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publishers+RetryIf.swift"; sourceTree = "<group>"; };
EB1AE8062B7082380037C1E4 /* NavigationBarHideMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarHideMode.swift; sourceTree = "<group>"; };
EB1AE8082B7084960037C1E4 /* NavigationBarHideMode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NavigationBarHideMode+Extensions.swift"; sourceTree = "<group>"; };
EB1AE80A2B70D16D0037C1E4 /* index.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = index.json; sourceTree = "<group>"; };
EB1AE80B2B70D16D0037C1E4 /* ja.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ja.json; sourceTree = "<group>"; };
EB1AE80C2B70D16D0037C1E4 /* en.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = en.json; sourceTree = "<group>"; };
EB2550132B288C84004823BA /* Backport+ListStyleInsetAlternatingRowBackgrounds.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Backport+ListStyleInsetAlternatingRowBackgrounds.swift"; sourceTree = "<group>"; };
EB28F1B22B370F0700291055 /* DividedHStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DividedHStack.swift; sourceTree = "<group>"; };
EB2956392B30139A002C5CA8 /* AppAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAssembly.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1216,6 +1222,9 @@
isa = PBXGroup;
children = (
EB6A4F472B48A951008AB7CE /* bucha_cat.json */,
EB1AE80C2B70D16D0037C1E4 /* en.json */,
EB1AE80A2B70D16D0037C1E4 /* index.json */,
EB1AE80B2B70D16D0037C1E4 /* ja.json */,
);
path = Previews;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down

0 comments on commit 74826e7

Please sign in to comment.