Updated the Amiibo.Platform type in the library target to initialize Switch 2 games from a given payload.

This commit is contained in:
2025-11-09 21:06:07 +01:00
parent e9f244c90a
commit adaedcda07
3 changed files with 13 additions and 0 deletions
@@ -61,6 +61,7 @@ public struct Amiibo: Sendable {
self.name = payload.name
self.platform = .init(
payload.gamesSwitch,
payload.gamesSwitch2,
payload.games3DS,
payload.gamesWiiU
)
@@ -20,6 +20,9 @@ extension Amiibo {
/// A list of `Switch` games related to an amiibo item.
public let `switch`: [Game]
/// A list of `Switch 2` games related to an amiibo.
public let switch2: [Game]
/// A list of `3DS` games related to an amiibo item.
public let threeDS: [Game]
@@ -37,12 +40,15 @@ extension Amiibo {
/// - switch: A list of `Switch` games related to an amiibo item, if any.
/// - threeDS: A list of `3DS` games related to an amiibo item, if any.
/// - wiiU: A list of `WiiU` games related to an amiibo item, if any.
/// - switch2: A list of `Switch 2` games related to an amiibo, if any.
init?(
_ `switch`: [Components.Schemas.AmiiboGame]?,
_ switch2: [Components.Schemas.AmiiboGame]?,
_ threeDS: [Components.Schemas.AmiiboGame]?,
_ wiiU: [Components.Schemas.AmiiboGame]?
) {
guard (`switch` != nil && `switch`?.isEmpty == false)
|| (switch2 != nil && switch2?.isEmpty == false)
|| (threeDS != nil && threeDS?.isEmpty == false)
|| (wiiU != nil && wiiU?.isEmpty == false)
else {
@@ -53,6 +59,10 @@ extension Amiibo {
guard let `switch` else { return [] }
return `switch`.map { .init($0) }
}()
self.switch2 = {
guard let switch2 else { return [] }
return switch2.map { .init($0) }
}()
self.threeDS = {
guard let threeDS else { return [] }
return threeDS.map { .init($0) }
@@ -365,6 +365,8 @@ private extension AmiiboServiceLiveTests {
if filter.showUsage == true {
#expect(firstAmiiboPlatform.switch.first?.usages?.isEmpty == false)
// Given the live data is still not returning any Switch 2 games.
#expect(firstAmiiboPlatform.switch2.isEmpty == true)
#expect(firstAmiiboPlatform.threeDS.first?.usages?.isEmpty == false)
#expect(firstAmiiboPlatform.wiiU.first?.usages?.isEmpty == false)
}