Skip to content

Commit

Permalink
Merge pull request #196 from CubeStuffs/import-export
Browse files Browse the repository at this point in the history
import export
  • Loading branch information
pdtxie authored Mar 22, 2024
2 parents f7d2675 + 065fb8e commit b254b98
Show file tree
Hide file tree
Showing 9 changed files with 658 additions and 33 deletions.
54 changes: 48 additions & 6 deletions CubeTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
231827E729B5E86B00A40C78 /* FloatingPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231827E629B5E86B00A40C78 /* FloatingPanel.swift */; };
2319F8B9276872F200644EB3 /* TimeTrend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2319F8B8276872F200644EB3 /* TimeTrend.swift */; };
231B2E2E29BDECF9007E5DC2 /* HelperButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231B2E2D29BDECF9007E5DC2 /* HelperButtons.swift */; };
231F37C22B81F7F60016A137 /* TNoodle.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 231F37C02B81F7F00016A137 /* TNoodle.xcframework */; };
231F37C32B81F7F60016A137 /* TNoodle.xcframework in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 231F37C02B81F7F00016A137 /* TNoodle.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
231F37C52B81FD290016A137 /* ImportExport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231F37C42B81FD290016A137 /* ImportExport.swift */; };
2326436028C4927600F6322E /* TimerHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2326435F28C4927600F6322E /* TimerHeader.swift */; };
23329E9029C31CA60017AE99 /* libz.1.1.3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 23329E8F29C31CA60017AE99 /* libz.1.1.3.tbd */; settings = {ATTRIBUTES = (Required, ); }; };
233F86382B82125A00459A45 /* TNoodle.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23F0C7372B820F1A00634C35 /* TNoodle.xcframework */; };
Expand All @@ -23,8 +26,6 @@
235D6A7029C2CE09002D90D8 /* CloudkitStatusManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 235D6A6F29C2CE09002D90D8 /* CloudkitStatusManager.swift */; };
2377418829A9A05A00A4F917 /* HelperUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2377418729A9A05A00A4F917 /* HelperUI.swift */; };
237B35502761995F00CC39BF /* SettingsCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 237B354F2761995F00CC39BF /* SettingsCard.swift */; };
238949982B46470100BFE1E6 /* TNoodle.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 238949962B4646B300BFE1E6 /* TNoodle.xcframework */; };
238949992B46470100BFE1E6 /* TNoodle.xcframework in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 238949962B4646B300BFE1E6 /* TNoodle.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
238FB42029B8175C008EC1D4 /* GradientManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 238FB41F29B8175C008EC1D4 /* GradientManager.swift */; };
239560A629C3056E00735035 /* SplashPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 239560A529C3056E00735035 /* SplashPad.storyboard */; };
2397131F2791032300268DFA /* AveragePhases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2397131E2791032300268DFA /* AveragePhases.swift */; };
Expand Down Expand Up @@ -90,6 +91,9 @@
AF8A157429AF15B500F6818E /* ScrambleOnlyTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8A157329AF15B500F6818E /* ScrambleOnlyTool.swift */; };
AF8B305B29B5C7010023D23B /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8B305A29B5C7010023D23B /* SettingsManager.swift */; };
AFA444A229C4290500795434 /* SettingsWidgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA444A129C4290400795434 /* SettingsWidgets.swift */; };
E5A559602B83456F004093B3 /* ExportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5A5595F2B83456F004093B3 /* ExportViewModel.swift */; };
E5A742D42BA8184100321D24 /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = E5A742D32BA8184100321D24 /* ZIPFoundation */; };
E5B3B1532BA5B68600179BDC /* LZString in Frameworks */ = {isa = PBXBuildFile; productRef = E5B3B1522BA5B68600179BDC /* LZString */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -116,7 +120,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
238949992B46470100BFE1E6 /* TNoodle.xcframework in Embed Libraries */,
231F37C32B81F7F60016A137 /* TNoodle.xcframework in Embed Libraries */,
);
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -127,6 +131,8 @@
231827E629B5E86B00A40C78 /* FloatingPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FloatingPanel.swift; path = CubeTime/Tabs/FloatingPanel.swift; sourceTree = SOURCE_ROOT; };
2319F8B8276872F200644EB3 /* TimeTrend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeTrend.swift; sourceTree = "<group>"; };
231B2E2D29BDECF9007E5DC2 /* HelperButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelperButtons.swift; sourceTree = "<group>"; };
231F37C02B81F7F00016A137 /* TNoodle.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = TNoodle.xcframework; sourceTree = "<group>"; };
231F37C42B81FD290016A137 /* ImportExport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportExport.swift; sourceTree = "<group>"; };
2326435F28C4927600F6322E /* TimerHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimerHeader.swift; sourceTree = "<group>"; };
23329E8F29C31CA60017AE99 /* libz.1.1.3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.1.1.3.tbd; path = usr/lib/libz.1.1.3.tbd; sourceTree = SDKROOT; };
233FE7B5274F109600C6F1DF /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = "<group>"; };
Expand All @@ -140,7 +146,6 @@
2377418729A9A05A00A4F917 /* HelperUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelperUI.swift; sourceTree = "<group>"; };
23783DA429AB55750036FE2B /* getBestAverage.h++ */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = "getBestAverage.h++"; sourceTree = "<group>"; };
237B354F2761995F00CC39BF /* SettingsCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCard.swift; sourceTree = "<group>"; };
238949962B4646B300BFE1E6 /* TNoodle.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = TNoodle.xcframework; sourceTree = "<group>"; };
238FB41F29B8175C008EC1D4 /* GradientManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientManager.swift; sourceTree = "<group>"; };
239560A529C3056E00735035 /* SplashPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = SplashPad.storyboard; sourceTree = "<group>"; };
2397131E2791032300268DFA /* AveragePhases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AveragePhases.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -210,6 +215,7 @@
AF8B305A29B5C7010023D23B /* SettingsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsManager.swift; sourceTree = "<group>"; };
AF977E5B29BEE9E100A246C0 /* CubeTimeData.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CubeTimeData.xcdatamodel; sourceTree = "<group>"; };
AFA444A129C4290400795434 /* SettingsWidgets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWidgets.swift; sourceTree = "<group>"; };
E5A5595F2B83456F004093B3 /* ExportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportViewModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -220,7 +226,9 @@
23329E9029C31CA60017AE99 /* libz.1.1.3.tbd in Frameworks */,
AF7697DC293C1EFA00FF1C50 /* SVGView in Frameworks */,
23A1CDBD29399FE000F0895D /* SwiftfulLoadingIndicators in Frameworks */,
238949982B46470100BFE1E6 /* TNoodle.xcframework in Frameworks */,
231F37C22B81F7F60016A137 /* TNoodle.xcframework in Frameworks */,
E5B3B1532BA5B68600179BDC /* LZString in Frameworks */,
E5A742D42BA8184100321D24 /* ZIPFoundation in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -303,6 +311,7 @@
23CE093327A76D610013E227 /* SessionCard.swift */,
23AB648329385D310049993B /* NewSessionRootView.swift */,
23D7722329B1E3540044AFBA /* NewSessionView.swift */,
231F37C42B81FD290016A137 /* ImportExport.swift */,
AF8874BF29AAC8AD001E49D0 /* Tools */,
);
path = Sessions;
Expand All @@ -329,7 +338,7 @@
23B45E7129A855F400BDF49E /* Frameworks */ = {
isa = PBXGroup;
children = (
238949962B4646B300BFE1E6 /* TNoodle.xcframework */,
231F37C02B81F7F00016A137 /* TNoodle.xcframework */,
23329E8F29C31CA60017AE99 /* libz.1.1.3.tbd */,
);
path = Frameworks;
Expand All @@ -348,6 +357,7 @@
AF81757629B07712004838B9 /* FontManager.swift */,
238FB41F29B8175C008EC1D4 /* GradientManager.swift */,
235D6A6F29C2CE09002D90D8 /* CloudkitStatusManager.swift */,
E5A5595F2B83456F004093B3 /* ExportViewModel.swift */,
);
path = StopwatchManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -510,6 +520,8 @@
packageProductDependencies = (
23A1CDBC29399FE000F0895D /* SwiftfulLoadingIndicators */,
AF7697DB293C1EFA00FF1C50 /* SVGView */,
E5B3B1522BA5B68600179BDC /* LZString */,
E5A742D32BA8184100321D24 /* ZIPFoundation */,
);
productName = txmer;
productReference = 23DE3BD7274DDBE200254D29 /* CubeTime.app */;
Expand Down Expand Up @@ -586,6 +598,8 @@
packageReferences = (
23A1CDBB29399FE000F0895D /* XCRemoteSwiftPackageReference "SwiftfulLoadingIndicators" */,
AF7697DA293C1EFA00FF1C50 /* XCRemoteSwiftPackageReference "SVGView" */,
E5B3B1512BA5B68600179BDC /* XCRemoteSwiftPackageReference "lzstring-swift" */,
E5A742D22BA8184100321D24 /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
);
productRefGroup = 23DE3BD8274DDBE200254D29 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -643,6 +657,8 @@
23DE3BE4274DDBE300254D29 /* Persistence.swift in Sources */,
23AAF99629B0219200C5C1FF /* ScrollableLineChart.swift in Sources */,
7D3D3154278D3CA400BBDF55 /* TimerTouchView.swift in Sources */,
231F37C52B81FD290016A137 /* ImportExport.swift in Sources */,
E5A559602B83456F004093B3 /* ExportViewModel.swift in Sources */,
7D2B805E279422BD0006AEDD /* AppDelegate.swift in Sources */,
238FB42029B8175C008EC1D4 /* GradientManager.swift in Sources */,
AF6EAC2029ADDA1C00171F73 /* TimerMenu.swift in Sources */,
Expand Down Expand Up @@ -1099,6 +1115,22 @@
minimumVersion = 1.0.0;
};
};
E5A742D22BA8184100321D24 /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/weichsel/ZIPFoundation.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.9.18;
};
};
E5B3B1512BA5B68600179BDC /* XCRemoteSwiftPackageReference "lzstring-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Ibrahimhass/lzstring-swift";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -1112,6 +1144,16 @@
package = AF7697DA293C1EFA00FF1C50 /* XCRemoteSwiftPackageReference "SVGView" */;
productName = SVGView;
};
E5A742D32BA8184100321D24 /* ZIPFoundation */ = {
isa = XCSwiftPackageProductDependency;
package = E5A742D22BA8184100321D24 /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
productName = ZIPFoundation;
};
E5B3B1522BA5B68600179BDC /* LZString */ = {
isa = XCSwiftPackageProductDependency;
package = E5B3B1512BA5B68600179BDC /* XCRemoteSwiftPackageReference "lzstring-swift" */;
productName = LZString;
};
/* End XCSwiftPackageProductDependency section */

/* Begin XCVersionGroup section */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"originHash" : "39fe4ee35ee814703984e14981b2e8cd61fea134e2fb2224739f36891d8014a3",
"originHash" : "bd0066f47568b67feb1deaee757eb87a190ba2aad49ef359417423e2412468a4",
"pins" : [
{
"identity" : "lzstring-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Ibrahimhass/lzstring-swift",
"state" : {
"branch" : "main",
"revision" : "7f62f21de5b18582a950e1753b775cc614722407"
}
},
{
"identity" : "svgview",
"kind" : "remoteSourceControl",
Expand All @@ -18,6 +27,15 @@
"revision" : "85858c0246dcd781228301f9928519f75ce89758",
"version" : "0.0.4"
}
},
{
"identity" : "zipfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/weichsel/ZIPFoundation.git",
"state" : {
"revision" : "b979e8b52c7ae7f3f39fa0182e738e9e7257eb78",
"version" : "0.9.18"
}
}
],
"version" : 3
Expand Down
51 changes: 36 additions & 15 deletions CubeTime/Helper/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
import Combine
import CoreData
import AVFoundation
import ZIPFoundation

// MARK: - GLOBAL LETS
let sessionTypeForID: [SessionType: Session.Type] = [
Expand All @@ -28,21 +29,21 @@ let iconNamesForType: [SessionType: String] = [


let puzzleTypes: [PuzzleType] = [
PuzzleType(name: "2x2"),
PuzzleType(name: "3x3"),
PuzzleType(name: "4x4"),
PuzzleType(name: "5x5"),
PuzzleType(name: "6x6"),
PuzzleType(name: "7x7"),
PuzzleType(name: "Square-1"),
PuzzleType(name: "Megaminx"),
PuzzleType(name: "Pyraminx"),
PuzzleType(name: "Clock"),
PuzzleType(name: "Skewb"),
PuzzleType(name: "3x3 OH"),
PuzzleType(name: "3x3 BLD"),
PuzzleType(name: "4x4 BLD"),
PuzzleType(name: "5x5 BLD"),
PuzzleType(name: "2x2", cstimerName: "222so"),
PuzzleType(name: "3x3", cstimerName: "333"),
PuzzleType(name: "4x4", cstimerName: "444wca"),
PuzzleType(name: "5x5", cstimerName: "555wca"),
PuzzleType(name: "6x6", cstimerName: "666wca"),
PuzzleType(name: "7x7", cstimerName: "777wca"),
PuzzleType(name: "Square-1", cstimerName: "sqrs"),
PuzzleType(name: "Megaminx", cstimerName: "mgmp"),
PuzzleType(name: "Pyraminx", cstimerName: "pyrso"),
PuzzleType(name: "Clock", cstimerName: "clkwca"),
PuzzleType(name: "Skewb", cstimerName: "skbso"),
PuzzleType(name: "3x3 OH", cstimerName: "333oh"),
PuzzleType(name: "3x3 BLD", cstimerName: "333bld"),
PuzzleType(name: "4x4 BLD", cstimerName: "444bld"),
PuzzleType(name: "5x5 BLD", cstimerName: "555bld"),
]


Expand Down Expand Up @@ -95,6 +96,13 @@ extension RandomAccessCollection where Element: Solve {
}
}

extension Archive {
func addEntry(with: String, data: Data) throws {
try addEntry(with: with, type: .file, uncompressedSize: Int64(data.count), provider: { (position: Int64, size) -> Data in
return data.subdata(in: Int(position)..<Int(position)+size)
})
}
}

// MARK: - UIDEVICE EXTENSIONS
extension UIDevice {
Expand Down Expand Up @@ -228,6 +236,19 @@ func formatLegendTime(secs: Double, dp: Int) -> String {
}
}

func jsonSerialize(obj: Any) throws -> Data {
var error: NSError?
let exportStream = OutputStream(toMemory: ())
exportStream.open()
JSONSerialization.writeJSONObject(obj, to: exportStream, error: &error)
exportStream.close()
if let error {
throw error
}
return (exportStream.property(forKey: .dataWrittenToMemoryStreamKey) as! NSData) as Data

}

// MARK: - MANUAL ENTRY FUNCS + VIEW MODIFIERS
// formatting funcs
@inline(__always) func filteredStrFromTime(_ time: Double?) -> String {
Expand Down
12 changes: 12 additions & 0 deletions CubeTime/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ enum Penalty: Int16, Hashable {
case none
case plustwo
case dnf

func exportName() -> String? {
return switch self {
case .plustwo:
"PlusTwo"
case .dnf:
"DNF"
default:
nil
}
}
}

enum SessionType: Int16 {
Expand All @@ -148,6 +159,7 @@ enum SessionType: Int16 {
// MARK: - Wrappers
struct PuzzleType {
let name: String
let cstimerName: String
// let puzzle: OrgWorldcubeassociationTnoodleScramblesPuzzleRegistry
}

Expand Down
Loading

0 comments on commit b254b98

Please sign in to comment.