Skip to content

Commit

Permalink
GachaKit // Preparing for GachaRecordRootView.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Sep 12, 2024
1 parent 56f8d9f commit c71885f
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public final class PZGachaEntryMO: Codable, PZGachaEntryProtocol {
public var id: String = PZGachaEntryMO.makeEntryID()
public var gachaID: String = "0"

public var uidWithGame: String {
"\(game.uidPrefix)-\(uid)"
}

final public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: PZGachaEntryMO.CodingKeys.self)
try container.encode(game, forKey: .game)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// (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 PZBaseKit
import SFSafeSymbols
import SwiftData
import SwiftUI

// MARK: - GachaRecordRootView

public struct GachaRecordRootView: View {
// MARK: Lifecycle

public init(legacyImporter: (() -> Void)?) {
self.importLegacyRecords = legacyImporter
}

// MARK: Public

public static var navTitle: String = "gachaKit.GachaRecordRootView.navTitle".i18nGachaKit

public static var navIcon: Image { Image("GachaRecordMgr_NavIcon", bundle: .module) }

@MainActor public var body: some View {
coreBody
.navigationTitle(Self.navTitle)
.navBarTitleDisplayMode(.large)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Menu {
Text("Temporary PlaceHolder".description)
} label: {
Image(systemSymbol: .goforwardPlus)
}
}
}
}

// MARK: Private

private let importLegacyRecords: (() -> Void)?
@Query(sort: \PZGachaEntryMO.id) private var profiles: [PZGachaEntryMO]

private var allowImporingOldRecords: Bool { importLegacyRecords != nil }
}

extension GachaRecordRootView {
@MainActor @ViewBuilder public var coreBody: some View {
List {
Text("Under construction".description)
}
}
}
29 changes: 29 additions & 0 deletions Packages/GachaKit/Sources/GachaKit/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,35 @@
}
}
}
},
"gachaKit.GachaRecordRootView.navTitle" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Gacha Record Manager"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "ガチャ記録管理"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "抽卡记录管理"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "抽卡記錄管理"
}
}
}
}
},
"version" : "1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "GachaRecordMgr_NavIcon.heic",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public actor PersistenceController {

public static func makeContainer() -> ModelContainer {
let schema = Schema([
PZProfileMO.self, PZGachaEntryMO.self
PZProfileMO.self, PZGachaEntryMO.self,
])
let modelConfiguration = ModelConfiguration(
schema: schema, isStoredInMemoryOnly: false,
Expand Down Expand Up @@ -91,4 +91,13 @@ extension PersistenceController {
}
try context.save()
}

@MainActor
public static func command4InheritingOldGachaRecord() -> Void? {
if PersistenceController.hasOldGachaDataDetected() {
return try! PersistenceController.migrateOldGachasIntoProfiles()
} else {
return nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct UtilsTabPage: View {

enum Nav {
case giAbyssRank
case gachaManager
case wallpaperGallery
case pizzaDictionary
case hoyoMap
Expand All @@ -32,6 +33,13 @@ struct UtilsTabPage: View {
AbyssRankView.navIcon.resizable().aspectRatio(contentMode: .fit)
}
}
NavigationLink(value: Nav.gachaManager) {
Label {
Text(GachaRecordRootView.navTitle)
} icon: {
GachaRecordRootView.navIcon.resizable().aspectRatio(contentMode: .fit)
}
}
}

Section {
Expand Down Expand Up @@ -93,6 +101,9 @@ struct UtilsTabPage: View {
NavigationStack {
switch selection.wrappedValue {
case .giAbyssRank: AbyssRankView()
case .gachaManager: GachaRecordRootView {
PersistenceController.command4InheritingOldGachaRecord()
}
case .wallpaperGallery: WallpaperGalleryViewContent()
case .pizzaDictionary: PZDictionaryView()
case .gachaCloudDebug: CDGachaMODebugView()
Expand Down

0 comments on commit c71885f

Please sign in to comment.