Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Gacha // Keep the server gacha record timestamp intact. #180

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="rankRawValue" optional="YES" attributeType="String"/>
<attribute name="time" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="timeRawValue" optional="YES" attributeType="String"/>
<attribute name="uid" optional="YES" attributeType="String"/>
</entity>
</model>
3 changes: 3 additions & 0 deletions Features/Gacha/Model/GachaItemMO+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extension GachaEntry {
result.name = name
result.rankRawValue = rankRawValue
result.time = time
result.timeRawValue = timeRawValue
result.uid = uid
return result
}
Expand All @@ -40,6 +41,7 @@ extension GachaEntry {
result.name = name
result.rankRawValue = rankRawValue
result.time = time
result.timeRawValue = timeRawValue
result.uid = uid
return result
}
Expand All @@ -58,6 +60,7 @@ extension GachaItemMO {
name: name,
rankRawValue: rankRawValue,
time: time,
timeRawValue: timeRawValue,
uid: uid
)
}
Expand Down
1 change: 1 addition & 0 deletions Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension GachaItemMO {
@NSManaged public var name: String!
@NSManaged public var rankRawValue: String!
@NSManaged public var time: Date!
@NSManaged public var timeRawValue: String?
@NSManaged public var uid: String!

var gachaType: GachaType {
Expand Down
1 change: 1 addition & 0 deletions Features/Gacha/View/GetGacha/GetGachaViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class GetGachaViewModel: ObservableObject {
persistedItem.name = gachaItem.name
persistedItem.rank = gachaItem.rank
persistedItem.time = gachaItem.time
persistedItem.timeRawValue = gachaItem.timeRawValue
persistedItem.uid = gachaItem.uid
withAnimation {
savedTypeFetchedCount[gachaItem.gachaType]! += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public struct GachaItem: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.uid = try container.decode(String.self, forKey: .uid)
let timeString = try container.decode(String.self, forKey: .time)
self.timeRawValue = try container.decode(String.self, forKey: .time)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
// 抽卡记录的网页固定显示伺服器时间。
dateFormatter.timeZone = .init(secondsFromGMT: Self.getServerTimeZoneDelta(uid) * 3600)
if let time = dateFormatter.date(from: timeString) {
if let time = dateFormatter.date(from: timeRawValue) {
self.time = time
} else {
throw DecodingError.typeMismatch(
Expand Down Expand Up @@ -159,6 +159,7 @@ public struct GachaItem: Codable {

public let uid: String
public let time: Date
public let timeRawValue: String
public let gachaID: String
public let gachaType: GachaType
public let itemID: String
Expand Down
3 changes: 3 additions & 0 deletions Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable {
name: String,
rankRawValue: String,
time: Date,
timeRawValue: String?,
uid: String
) {
self.count = count
Expand All @@ -34,6 +35,7 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable {
self.name = name
self.rankRawValue = rankRawValue
self.time = time
self.timeRawValue = timeRawValue
self.uid = uid
}

Expand All @@ -49,5 +51,6 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable {
public var name: String
public var rankRawValue: String
public var time: Date
public var timeRawValue: String?
public var uid: String
}
7 changes: 4 additions & 3 deletions Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ extension SRGFv1.DataEntry {
langOverride: lang
) ?? name
}

let timeTyped: Date? = DateFormatter.forSRGFEntry(timeZoneDelta: timeZoneDelta).date(from: time)
return .init(
count: Int32(count ?? "1") ?? 1, // Default is 1.
gachaID: gachaID,
Expand All @@ -213,7 +213,8 @@ extension SRGFv1.DataEntry {
langRawValue: lang.rawValue,
name: name ?? "#NAME:\(id)#",
rankRawValue: rankType ?? "3",
time: DateFormatter.forSRGFEntry(timeZoneDelta: timeZoneDelta).date(from: time) ?? Date(),
time: timeTyped ?? Date(),
timeRawValue: time,
uid: uid
)
}
Expand All @@ -233,7 +234,7 @@ extension GachaEntry {
return .init(
gachaID: gachaID,
itemID: itemID,
time: time.asSRGFDate(timeZoneDelta: timeZoneDelta),
time: timeRawValue ?? time.asSRGFDate(timeZoneDelta: timeZoneDelta),
id: id,
gachaType: .init(rawValue: gachaTypeRawValue) ?? .departureWarp,
name: name,
Expand Down
Loading