Added release and pickup date. Pickup date is optional

This commit is contained in:
2021-06-06 10:09:33 +02:00
parent aa64cd0600
commit 87dbc9d1da
9 changed files with 32 additions and 21 deletions

View File

@@ -22,7 +22,7 @@ public class Console: NSManagedObject, Identifiable {
Game.compareByCreationDate(gameA: $0, gameB: $1)
}) else { return false }
return newestGameConsoleA.pickupOrReleaseDate > newestGameConsoleB.pickupOrReleaseDate
return newestGameConsoleA.releaseDate > newestGameConsoleB.releaseDate
}
// Defining default values during creation

View File

@@ -15,14 +15,14 @@ import SwiftUI
public class Game: NSManagedObject, Identifiable {
public static func compareByCreationDate(gameA : Game, gameB : Game) -> Bool {
return gameA.pickupOrReleaseDate < gameB.pickupOrReleaseDate
return gameA.releaseDate < gameB.releaseDate
}
@objc
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
self.pickupOrReleaseDate = Date()
self.releaseDate = Date()
self.uuid = UUID()
print("Set UUID to \(self.uuid)")
}
@@ -35,8 +35,8 @@ extension Game : Encodable {
case notes
case isDigital
case lentTo
case pickupOrReleaseDate
case isPickupDate
case releaseDate
case pickupDate
case publisher
case isFinished
case finishedDate
@@ -56,8 +56,10 @@ extension Game : Encodable {
try container.encode(notes ?? "", forKey: .notes)
try container.encode(isDigital, forKey: .isDigital)
try container.encode(lentTo ?? "", forKey: .lentTo)
try container.encode(pickupOrReleaseDate.formattedInTimeZone(), forKey: .pickupOrReleaseDate)
try container.encode(isPickupDate, forKey: .isPickupDate)
try container.encode(releaseDate.formattedInTimeZone(), forKey: .releaseDate)
if let pickupDate = pickupDate {
try container.encode(pickupDate.formattedInTimeZone(), forKey: .pickupDate)
}
try container.encode(pickupDescription ?? "", forKey: .pickupDescription)
try container.encode(publisher ?? "", forKey: .publisher)
try container.encode(isFinished, forKey: .isFinished)

View File

@@ -18,8 +18,8 @@ extension Game {
}
@NSManaged public var circumstances: String?
@NSManaged public var isPickupDate : Bool
@NSManaged public var pickupOrReleaseDate: Date
@NSManaged public var releaseDate : Date
@NSManaged public var pickupDate: Date?
@NSManaged public var pickupDescription : String?
@NSManaged public var inWishlist: Bool
@NSManaged public var isDigital: Bool

View File

@@ -92,13 +92,18 @@ class LibraryImport {
cdGame.isDigital = game.isDigital
cdGame.playtime_h = game.playtime_h ?? 0
cdGame.playtime_min = game.playtime_min ?? 0
cdGame.isPickupDate = game.isPickupDate
if let date = Date.from(string: game.pickupOrReleaseDate) {
cdGame.pickupOrReleaseDate = date
if let pickupDate = game.pickupDate, let date = Date.from(string: pickupDate) {
cdGame.pickupDate = date
}else{
print("Could not decode date '\(game.pickupDate)' for game '\(cdGame.name)'")
}
if let date = Date.from(string: game.releaseDate) {
cdGame.releaseDate = date
}else{
print("Could not decode date '\(game.pickupOrReleaseDate)' for game '\(cdGame.name)'")
print("Could not decode date '\(game.releaseDate)' for game '\(cdGame.name)'")
}
cdConsole.addToGames(cdGame)
@@ -220,8 +225,8 @@ struct BHLGame : Decodable {
let isFinished : Bool
let finishedDate : Date?
let notes : String?
let pickupOrReleaseDate : String
let isPickupDate : Bool = false
let releaseDate : String
let pickupDate : String?
let pickupDescription : String?
let publisher : String?
let console : UUID

View File

@@ -68,7 +68,7 @@ struct GameView : View {
LazyVGrid(columns: columns) {
InfoItem(headline: "Gekauft") {
Text("\(game.pickupOrReleaseDate.formattedInTimeZone(dateFormat: Date.view_date_format))")
Text("\(game.releaseDate.formattedInTimeZone(dateFormat: Date.view_date_format))")
.bold()
}

View File

@@ -181,10 +181,14 @@ struct GameEditMode : View {
Section(header: Text("Details")) {
DatePicker("In Sammlung seit",
selection: $game.pickupOrReleaseDate,
selection: $game.releaseDate,
in: ...Date(),
displayedComponents: [.date])
// Toggle(isOn: $game.isPickupDate, label: {
// Text("An dem Tag gesammelt?")
// })
HStack {
Text("Anlass")
TextEditor(text: pickupDscriptionBinding).frame(height: 100)

View File

@@ -16,7 +16,7 @@ struct GamePickupsView: View {
init() {
let gamesFR = NSFetchRequest<Game>(entityName: "Game")
gamesFR.sortDescriptors = [NSSortDescriptor(key: "pickupOrReleaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)]
gamesFR.sortDescriptors = [NSSortDescriptor(key: "releaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)]
gamesFR.fetchLimit = 50;
_games = FetchRequest(fetchRequest: gamesFR)
}

View File

@@ -54,7 +54,7 @@ struct EmptyCategory : View {
struct Overview: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "pickupOrReleaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)])
@FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "releaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)])
var games: FetchedResults<Game>
@FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "finishedDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)])

View File

@@ -27,15 +27,15 @@
<attribute name="inWishlist" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isDigital" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isFinished" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isPickupDate" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="lentTo" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String" defaultValueString=""/>
<attribute name="notes" optional="YES" attributeType="String"/>
<attribute name="pickupDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="pickupDescription" optional="YES" attributeType="String"/>
<attribute name="pickupOrReleaseDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="playtime_h" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="playtime_min" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="publisher" optional="YES" attributeType="String"/>
<attribute name="releaseDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="uuid" optional="YES" attributeType="UUID" defaultValueString="00000000-0000-0000-0000-000000000000" usesScalarValueType="NO"/>
<relationship name="console" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Console" inverseName="games" inverseEntity="Console"/>
<relationship name="series" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameSeries" inverseName="games" inverseEntity="GameSeries"/>