-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PZAccountKit // Add Echo-of-War support for HSR daily notes.
- Loading branch information
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...s/PZKit/Sources/PZAccountKit/HoYoAPIs/DailyNoteRelated/Models4HSR/EchoOfWarInfo4HSR.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// (c) 2024 and onwards Pizza Studio (AGPL v3.0 License or later). | ||
// ==================== | ||
// This code is released under the SPDX-License-Identifier: `AGPL-3.0-or-later`. | ||
|
||
import Foundation | ||
import PZBaseKit | ||
|
||
/// Echo of War weekly attempts(HSR). Unavailable if daily note is fetched from Widget API. | ||
public struct EchoOfWarInfo4HSR: AbleToCodeSendHash { | ||
// MARK: Lifecycle | ||
|
||
public init(from decoder: any Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.weeklyEOWAttemptsCount = try container.decode(Int.self, forKey: .weeklyEOWAttemptsCount) | ||
self.weeklyEOWAttemptsLimit = try container.decode(Int.self, forKey: .weeklyEOWAttemptsLimit) | ||
} | ||
|
||
// MARK: Public | ||
|
||
public let weeklyEOWAttemptsCount: Int | ||
public let weeklyEOWAttemptsLimit: Int | ||
|
||
public var isFinished: Bool { weeklyEOWAttemptsCount == weeklyEOWAttemptsLimit } | ||
|
||
public var textDescription: String { | ||
guard !isFinished else { return "✔︎" } | ||
return "\(weeklyEOWAttemptsCount) / \(weeklyEOWAttemptsLimit)" | ||
} | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(weeklyEOWAttemptsCount, forKey: .weeklyEOWAttemptsCount) | ||
try container.encode(weeklyEOWAttemptsLimit, forKey: .weeklyEOWAttemptsLimit) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case weeklyEOWAttemptsCount = "weekly_cocoon_cnt" | ||
case weeklyEOWAttemptsLimit = "weekly_cocoon_limit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...es/PZKit/Sources/PZAccountKit/HoYoAPIs/DailyNoteRelated/Models4HSR/NoteMetaData4HSR.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// (c) 2024 and onwards Pizza Studio (AGPL v3.0 License or later). | ||
// ==================== | ||
// This code is released under the SPDX-License-Identifier: `AGPL-3.0-or-later`. | ||
|
||
import Foundation | ||
import PZBaseKit | ||
|
||
/// Daily Note Metadata. Unavailable if daily note is fetched from Widget API. | ||
public struct NoteMetaData4HSR: AbleToCodeSendHash { | ||
// MARK: Lifecycle | ||
|
||
public init(from decoder: any Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.currentTs = try container.decode(Int.self, forKey: .currentTs) | ||
self.signURL = try container.decode(URL.self, forKey: .signURL) | ||
self.homeURL = try container.decode(URL.self, forKey: .homeURL) | ||
self.noteURL = try container.decode(URL.self, forKey: .noteURL) | ||
} | ||
|
||
// MARK: Public | ||
|
||
public let currentTs: Int | ||
public let signURL: URL | ||
public let homeURL: URL | ||
public let noteURL: URL | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(currentTs, forKey: .currentTs) | ||
try container.encode(signURL, forKey: .signURL) | ||
try container.encode(homeURL, forKey: .homeURL) | ||
try container.encode(noteURL, forKey: .noteURL) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case currentTs = "current_ts" | ||
case signURL = "sign_url" | ||
case homeURL = "home_url" | ||
case noteURL = "note_url" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters