Skip to content

Commit

Permalink
Filter invalid characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Dec 30, 2024
1 parent a37dafa commit fef5864
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ extension GachaMetaGenerator {
let nameTextMapHash: Int
var l10nMap: [String: String]?

func isCharacter(for game: SupportedGame) -> Bool {
switch game {
case .genshinImpact: return id > 114514
case .starRail: return id <= 9999
var isCharacter: Bool {
id > 114514
}

var isValid: Bool {
if isCharacter {
guard id.description.prefix(2) != "11" else { return false }
guard id < 10000900 else { return false }
guard !Self.forbiddenNameTextMapHashes.contains(id) else { return false }
return true
} else {
return true // Temporarily assume that all weapons are vaid.
}
}

Expand All @@ -72,5 +80,15 @@ extension GachaMetaGenerator {

/// This variable is only useful during decoding process.
fileprivate var qualityType: GIQualityType?

// MARK: Private

private static let forbiddenNameTextMapHashes: [Int] = [
1499745907, 1538092267, 3464027035, 594850707,
231836963, 3780343147, 1516554699, 977648923,
2597527627, 500612819, 3532343811, 302691299,
452043283, 2242027395, 565329475, 1994081075,
2824690859, 1857915418, 3293134650, 853394138,
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension GachaMetaGenerator {
}

/// Starrail only.
public class AvatarRawItem: Codable, RawItemFetchModelProtocol {
public class HSRAvatarRawItem: Codable, RawItemFetchModelProtocol {
// MARK: Lifecycle

public required init(from decoder: any Decoder) throws {
Expand Down Expand Up @@ -64,7 +64,7 @@ extension GachaMetaGenerator {
}

/// Starrail only.
public class WeaponRawItem: Codable, RawItemFetchModelProtocol {
public class HSRWeaponRawItem: Codable, RawItemFetchModelProtocol {
// MARK: Lifecycle

public required init(from decoder: any Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ extension GachaMetaGenerator.SupportedGame {
return response.map { $0.toGachaItemMeta() }
case (.starRail, .weaponData):
let (data, _) = try await URLSession.shared.asyncData(from: getExcelConfigDataURL(for: .weaponData))
let response = try JSONDecoder().decode([GachaMetaGenerator.WeaponRawItem].self, from: data)
let response = try JSONDecoder().decode([GachaMetaGenerator.HSRWeaponRawItem].self, from: data)
return response.filter(\.isValid).map { $0.toGachaItemMeta() }
case (.starRail, .characterData):
let (data, _) = try await URLSession.shared.asyncData(from: getExcelConfigDataURL(for: .characterData))
let response = try JSONDecoder().decode([GachaMetaGenerator.AvatarRawItem].self, from: data)
let response = try JSONDecoder().decode([GachaMetaGenerator.HSRAvatarRawItem].self, from: data)
return response.filter(\.isValid).map { $0.toGachaItemMeta() }
}
}
Expand Down

0 comments on commit fef5864

Please sign in to comment.