Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pdtxie committed Mar 24, 2024
1 parent 52d2223 commit 6f14c97
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CubeTime/Helper/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let iconNamesForType: [SessionType: String] = [
]


let puzzleTypes: [PuzzleType] = [
let PUZZLE_TYPES: [PuzzleType] = [
PuzzleType(name: "2x2", cstimerName: "222so"),
PuzzleType(name: "3x3", cstimerName: "333"),
PuzzleType(name: "4x4", cstimerName: "444wca"),
Expand Down
63 changes: 15 additions & 48 deletions CubeTime/Helper/HelperUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ struct GlobalGeometryGetter: View {
}



// MARK: - BUBBLE
struct CTSessionBubble: View {
@ScaledMetric private var iconSize: CGFloat = 11
Expand All @@ -234,31 +233,15 @@ struct CTSessionBubble: View {

let scrambleType: Int

let hasMultiple: Bool

init(sessionType: SessionType, scrambleType: Int) {
self.scrambleType = scrambleType

switch sessionType {
case .playground:
self.icon = Image(systemName: "square.on.square")
self.text = "Playground"

init(session: Session) {
self.icon = session.icon
self.text = session.typeName
self.scrambleType = Int(session.scrambleType)

case .algtrainer:
self.icon = Image(systemName: "command.square")
self.text = "Algorithm Trainer"

case .multiphase:
self.icon = Image(systemName: "square.stack")
self.text = "Multiphase"

case .compsim:
self.icon = Image(systemName: "globe.asia.australia")
self.text = "Compsim"

case .standard:
self.icon = nil
self.text = nil
}
self.hasMultiple = [SessionType.compsim, SessionType.multiphase].contains(SessionType(rawValue: session.sessionType))
}

var body: some View {
Expand All @@ -275,8 +258,7 @@ struct CTSessionBubble: View {
}
}

#warning("todo: make better")
if self.text == "Compsim" || self.text == "Multiphase" {
if (hasMultiple) {
CTPuzzleBubble(scrambleType: scrambleType)
}
} else {
Expand All @@ -292,8 +274,13 @@ struct CTPuzzleBubble: View {
let text: String

init(scrambleType: Int) {
icon = Image(puzzleTypes[scrambleType].name)
text = puzzleTypes[scrambleType].name
icon = Image(PUZZLE_TYPES[scrambleType].name)
text = PUZZLE_TYPES[scrambleType].name
}

init(session: Session) {
icon = session.icon
text = session.typeName
}

var body: some View {
Expand All @@ -310,23 +297,3 @@ struct CTPuzzleBubble: View {
}
}
}

#Preview {
VStack {
CTBubble(type: .lightMono, size: .bubble) {
HStack(spacing: 4) {
Image(systemName: "square.on.square")
.resizable()
.scaledToFit()
.frame(maxWidth: 14, maxHeight: 14)
.font(.system(size: 11, weight: .semibold, design: .default))

Text("Playground")
}
}

CTSessionBubble(sessionType: .multiphase, scrambleType: 3)

CTPuzzleBubble(scrambleType: 3)
}
}
25 changes: 21 additions & 4 deletions CubeTime/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,39 @@ extension Session {
get {
switch (SessionType(rawValue: sessionType)!) {
case .standard:
return "Standard Session"
return PUZZLE_TYPES[Int(scrambleType)].name
case .algtrainer:
return "Alg trainer"
return "Algorithm Trainer"
case .multiphase:
return "Multiphase"
case .playground:
return "Playground"
case .compsim:
return "Comp Sim"
return "Compsim"
}
}
}

var icon: Image {
get {
switch (SessionType(rawValue: sessionType)!) {
case .standard:
return Image(PUZZLE_TYPES[Int(scrambleType)].name)
case .algtrainer:
return Image(systemName: "command.square")
case .multiphase:
return Image(systemName: "square.stack")
case .playground:
return Image(systemName: "square.on.square")
case .compsim:
return Image(systemName: "globe.asia.australia")
}
}
}

var shortcutName: String {
get {
let scrname = puzzleTypes[Int(scrambleType)].name
let scrname = PUZZLE_TYPES[Int(scrambleType)].name
switch (SessionType(rawValue: sessionType)!) {
case .standard:
return scrname
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Sessions/NewSessionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct NewSessionView: View {
VStack (spacing: 16) {
VStack (alignment: .center, spacing: 0) {
if sessionType != SessionType.playground {
PuzzleHeaderImage(imageName: puzzleTypes[Int(sessionEventType)].name)
PuzzleHeaderImage(imageName: PUZZLE_TYPES[Int(sessionEventType)].name)
}

SessionNameField(name: $name)
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/Sessions/SessionCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SessionCardBase: View {
.foregroundColor(Color("dark"))

HStack(spacing: 4) {
CTSessionBubble(sessionType: self.sessionType, scrambleType: self.scrambleType)
CTSessionBubble(session: item)
}
}

Expand All @@ -66,7 +66,7 @@ struct SessionCardBase: View {
Spacer()

if (!forExportUse) {
Image(puzzleTypes[scrambleType].name)
Image(PUZZLE_TYPES[scrambleType].name)
.resizable()
.frame(width: 45, height: 45)
.aspectRatio(contentMode: .fit)
Expand Down
8 changes: 4 additions & 4 deletions CubeTime/Sessions/SessionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct CustomiseSessionView: View {
ScrollView {
VStack(spacing: 16) {
VStack(alignment: .center, spacing: 0) {
PuzzleHeaderImage(imageName: puzzleTypes[Int(sessionEventType)].name)
PuzzleHeaderImage(imageName: PUZZLE_TYPES[Int(sessionEventType)].name)

SessionNameField(name: $name)
}
Expand Down Expand Up @@ -280,13 +280,13 @@ struct EventPicker: View {

Menu {
Picker("", selection: $sessionEventType) {
ForEach(Array(puzzleTypes.enumerated()), id: \.offset) {index, element in
ForEach(Array(PUZZLE_TYPES.enumerated()), id: \.offset) {index, element in
Text(element.name).tag(Int32(index))
.font(.body)
}
}
} label: {
Text(puzzleTypes[Int(sessionEventType)].name)
Text(PUZZLE_TYPES[Int(sessionEventType)].name)
.font(.body)
.frame(maxWidth: 120, alignment: .trailing)

Expand All @@ -299,7 +299,7 @@ struct EventPicker: View {
.padding(.horizontal)

LazyVGrid(columns: [GridItem(.adaptive(minimum: spacing), spacing: 8)], spacing: 8) {
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
CTButton(type: (index == sessionEventType) ? .halfcoloured(nil) : .mono,
size: .ultraLarge,
square: true,
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Sessions/Tools/ScrambleGeneratorTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct ScrambleGeneratorTool: View {
VStack {
ToolHeader(name: tools[2].name, image: tools[2].iconName, onClose: scrambleGenerator.cancel, content: {
Picker("", selection: $scrambleGenerator.scrambleType) {
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
Text(element.name).tag(index)
.font(.system(size: 15, weight: .regular))
}
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Sessions/Tools/ScrambleOnlyTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct ScrambleOnlyTool: View {

ToolHeader(name: tools[1].name, image: tools[1].iconName, content: {
Picker("", selection: $scrambleController.scrambleType) {
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
Text(element.name).tag(Int32(index))
.font(.system(size: 15, weight: .regular))
}
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Stats/ScrollableLineChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class TimeDistributionPointCard: UIStackView {
lazy var iconView: UIImageView = {
var iconView = UIImageView()

iconView = UIImageView(image: UIImage(named: puzzleTypes[Int(solve?.scrambleType ?? 0)].name))
iconView = UIImageView(image: UIImage(named: PUZZLE_TYPES[Int(solve?.scrambleType ?? 0)].name))
iconView.frame = CGRect(x: 0, y: 0, width: 24, height: 24)
iconView.tintColor = UIColor(Color("dark"))
iconView.translatesAutoresizingMaskIntoConstraints = false
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/Stats/StatsDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ struct StatsDetailView: View {
.frame(width: 16, height: 16)

} else {
Text(puzzleTypes[Int(session.scrambleType)].name)
Text(PUZZLE_TYPES[Int(session.scrambleType)].name)

Image(puzzleTypes[Int(session.scrambleType)].name)
Image(PUZZLE_TYPES[Int(session.scrambleType)].name)
.resizable()
.frame(width: 16, height: 16)

Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Stats/TimeTrendDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct TimeTrendDetail: View {
VStack {
HStack(spacing: 8) {
CTButton(type: .mono, size: .large, square: true, onTapRun: {
self.interval = max(10, self.interval - (self.interval / 2))
self.interval = max(2, self.interval - (self.interval / 2))
}) {
Image(systemName: "minus.magnifyingglass")
}
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/StopwatchManager/ExportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class CSTimerExportFormat: ExportFormat {

sessionData["\(idx+1)"] = [
"name": "CubeTime Export - \(session.name ?? "")",
"scrType": puzzleTypes[Int(session.scrambleType)].cstimerName
"scrType": PUZZLE_TYPES[Int(session.scrambleType)].cstimerName
]
}

Expand Down
9 changes: 8 additions & 1 deletion CubeTime/StopwatchManager/ScrambleController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ class ScrambleController: ObservableObject {
var isolate: OpaquePointer? = nil
var thread: OpaquePointer? = nil


/*
let ret = graal_create_isolate(nil, &isolate, &thread)
print(ret)
let s = String(cString: tnoodle_lib_scramble(thread!, scrambleType))
graal_tear_down_isolate(thread);
*/

let s = ""

return s
}
Expand Down Expand Up @@ -65,13 +68,17 @@ class ScrambleController: ObservableObject {

graal_create_isolate(nil, &isolate, &thread)

/*
var svg: String!
scramble.withCString { s in
svg = String(cString: tnoodle_lib_draw_scramble(thread!, scrTypeAtWorkStart, UnsafeMutablePointer(mutating: s)))
}
graal_tear_down_isolate(thread);
*/

let svg = ""


DispatchQueue.main.async {
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/StopwatchManager/StopwatchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class StopwatchManager: ObservableObject {
""", currentSession)

let results = try! managedObjectContext.fetch(req)
sessionsCanMoveToPlayground = Array(repeating: [], count: puzzleTypes.count)
sessionsCanMoveToPlayground = Array(repeating: [], count: PUZZLE_TYPES.count)

for result in results {
if result.sessionType == SessionType.playground.rawValue {
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/TimeList/TimeDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct TimeDetailView: View {
self.solve = solve
self.date = solve.date ?? Date(timeIntervalSince1970: 0)
self.time = formatSolveTime(secs: solve.time, penalty: Penalty(rawValue: solve.penalty)!)
self.puzzle_type = puzzleTypes[Int(solve.scrambleType)]
self.puzzle_type = PUZZLE_TYPES[Int(solve.scrambleType)]
self.scramble = solve.scramble ?? "Retrieving scramble failed."

if let multiphaseSolve = (solve as? MultiphaseSolve), let phases = multiphaseSolve.phases {
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/TimeList/TimeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct SortByMenu: View {
Menu("Puzzle Type") {
Picker("", selection: $stopwatchManager.scrambleTypeFilter) {
Text("All Puzzles").tag(-1)
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
Label(element.name, image: element.name).tag(index)
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ struct SessionHeader: View {
Spacer()

if (SessionType(rawValue: stopwatchManager.currentSession.sessionType) != .playground) {
Text(puzzleTypes[Int(stopwatchManager.currentSession.scrambleType)].name)
Text(PUZZLE_TYPES[Int(stopwatchManager.currentSession.scrambleType)].name)
.font(.body.weight(.medium))
.padding(.trailing)
}
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/Timer/TimerHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct TimerHeader: View {
// i hate swiftui i hate apple i hate everything
if #available(iOS 16, *) {
Picker("", selection: $stopwatchManager.playgroundScrambleType) {
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
Text(element.name).tag(Int32(index)).font(.body)
}
}
Expand All @@ -127,7 +127,7 @@ struct TimerHeader: View {
.frame(maxHeight: .infinity)
} else {
Picker("", selection: $stopwatchManager.playgroundScrambleType) {
ForEach(Array(zip(puzzleTypes.indices, puzzleTypes)), id: \.0) { index, element in
ForEach(Array(zip(PUZZLE_TYPES.indices, PUZZLE_TYPES)), id: \.0) { index, element in
Text(element.name).tag(Int32(index)).font(.body)
}
}
Expand Down

0 comments on commit 6f14c97

Please sign in to comment.