Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
496c15b
commit bedfdc4
Showing
27 changed files
with
209 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// ProgressVM.swift | ||
// PlayCover | ||
// | ||
// Created by TheMoonThatRises on 1/13/23. | ||
// | ||
|
||
import Foundation | ||
|
||
class ProgressVM<Steps: RawRepresentable & Equatable>: ObservableObject where Steps.RawValue == String { | ||
@Published var progress = 0.0 | ||
@Published var inProgress = false | ||
@Published var status: Steps | ||
|
||
private let starting: Steps | ||
private let ends: [Steps] | ||
|
||
/// - Parameters: | ||
/// - starts: The initial starting value | ||
/// - ends: Ending conditions | ||
init(start: Steps, ends: [Steps]) { | ||
self.status = start | ||
self.starting = start | ||
self.ends = ends | ||
} | ||
|
||
func next(_ step: Steps, _ startProgress: Double, _ stopProgress: Double) { | ||
Task { @MainActor in | ||
self.progress = startProgress | ||
self.status = step | ||
|
||
if step == self.starting { | ||
self.inProgress = true | ||
} else if self.ends.contains(step) { | ||
self.progress = 1.0 | ||
try await Task.sleep(nanoseconds: 1500000000) | ||
self.inProgress = false | ||
} else { | ||
while self.status == step { | ||
try await Task.sleep(nanoseconds: 50000000) | ||
if self.progress < stopProgress { | ||
self.progress += 0.002 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.