mirror of
https://github.com/neon443/RNG_Swift.git
synced 2026-03-11 06:49:12 +00:00
Rewrote basically half the app
+ reamde + noDebug.xcscheme + ui improvements +max die is 100+overflow protextion +fix giant padding in diceview +rewrite rng2() +ui friedlification +rewrite arrCombine
This commit is contained in:
@@ -8,26 +8,36 @@
|
||||
import SwiftUI
|
||||
|
||||
struct DiceView: View {
|
||||
@State var generated: [Int] = [0]
|
||||
@State var advanced: Bool = false
|
||||
@State var generated: [Int] = []
|
||||
@State var displayDies: [Int] = []
|
||||
@State var displayMultiDieMode = ""
|
||||
@State var multiDieMode = "plus"
|
||||
@State var result = 0
|
||||
@State var result: UInt = 0
|
||||
@State var resultDescription = ""
|
||||
@State var history: [Int] = []
|
||||
let columns = [GridItem(.adaptive(minimum: 25, maximum: 75))]
|
||||
@State var dies: Double = 2
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
Section("Number of die") {
|
||||
Toggle(isOn: $advanced) {
|
||||
Text("Advanced Mode")
|
||||
}
|
||||
HStack {
|
||||
Text( String( Int(dies) ) )
|
||||
.font(.system(size: 25, weight: .bold))
|
||||
Text(String(Int(dies)))
|
||||
.font(.system(size: 20, weight: .heavy))
|
||||
.frame(width: ((dies > 99) ? 40 : (dies > 9) ? 30 : 20))
|
||||
Divider()
|
||||
Text("1")
|
||||
Slider(value: $dies, in: 1...20, step: 1)
|
||||
Text("20")
|
||||
if advanced {
|
||||
Slider(value: $dies, in: 1...100, step: 1)
|
||||
Text("100")
|
||||
} else {
|
||||
Slider(value: $dies, in: 1...20, step: 1)
|
||||
Text("20")
|
||||
}
|
||||
}
|
||||
}
|
||||
Section("Multi die mode") {
|
||||
@@ -37,36 +47,36 @@ struct DiceView: View {
|
||||
}.pickerStyle(SegmentedPickerStyle())
|
||||
}
|
||||
Section("Visual") {
|
||||
HStack {
|
||||
Spacer()
|
||||
if displayDies.isEmpty {
|
||||
Text("Results are visualised here when you press the generate button")
|
||||
.font(.subheadline)
|
||||
} else {
|
||||
LazyVGrid(columns: columns, spacing: 10) {
|
||||
ForEach(0..<displayDies.count, id: \.self) { index in
|
||||
Image(systemName: "die.face.\(displayDies[index])")
|
||||
if displayDies.isEmpty {
|
||||
Text("Tap Generate to get started!")
|
||||
.font(.headline)
|
||||
.fontWeight(.heavy)
|
||||
.frame(alignment: .center)
|
||||
} else {
|
||||
LazyVGrid(columns: columns, spacing: 2.5) {
|
||||
ForEach(0..<displayDies.count, id: \.self) { index in
|
||||
Image(systemName: "die.face.\(displayDies[index])")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 40, height: 40)
|
||||
if index != displayDies.count-1 {
|
||||
Image(systemName: displayMultiDieMode)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 50, height: 50)
|
||||
if index != displayDies.count-1 {
|
||||
Image(systemName: displayMultiDieMode)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 10, height: 10)
|
||||
}
|
||||
.frame(width: 15, height: 15)
|
||||
}
|
||||
}.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(String(result))
|
||||
.font(.system(size: 75, weight: .bold))
|
||||
.font(.system(size: 50, weight: .bold))
|
||||
.foregroundColor(.gray)
|
||||
.frame(height: 50)
|
||||
.frame(height: 40)
|
||||
Text(resultDescription)
|
||||
.frame(height: 20)
|
||||
.frame(height: 10)
|
||||
.font(.system(size: 10))
|
||||
Button {
|
||||
generated = rngN6DieArr(dies: Int(dies))
|
||||
displayDies = generated
|
||||
@@ -90,12 +100,12 @@ func describeResult(inp: [Int], combineMode: String) -> String {
|
||||
var result = ""
|
||||
var symbol = ""
|
||||
if inp.isEmpty {
|
||||
return "0"
|
||||
return ""
|
||||
} else {
|
||||
if combineMode == "plus" {
|
||||
symbol = " + "
|
||||
symbol = "+"
|
||||
} else if combineMode == "multiply" {
|
||||
symbol = " x "
|
||||
symbol = "x"
|
||||
}
|
||||
for i in 0...len {
|
||||
if i == len {
|
||||
@@ -104,7 +114,6 @@ func describeResult(inp: [Int], combineMode: String) -> String {
|
||||
result += String(inp[i]) + symbol
|
||||
}
|
||||
}
|
||||
result += " = " + String(arrCombine(arr: inp, combineMode: combineMode))
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user