Building w/ Xcodeproj

This commit is contained in:
neon443
2024-10-10 16:44:29 +01:00
parent 2d007127ae
commit b94536cea1
24 changed files with 1133 additions and 607 deletions

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

59
RNG/ContentView.swift Normal file
View File

@@ -0,0 +1,59 @@
//
// ContentView.swift
// RNG
//
// Created by Nihaal on 09/10/2024.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
NavigationSplitView {
List {
NavigationLink {
NumberView()
.navigationTitle("Random Number Generator")
} label: {
HStack {
Text("Random Number Generator")
Spacer()
Image(systemName: "textformat.123")
}
}
NavigationLink {
DiceView()
.navigationTitle("Dice")
} label: {
HStack {
Text("Dice")
Spacer()
Image(systemName: "die.face.1")
Image(systemName: "die.face.2.fill")
Image(systemName: "die.face.3")
Image(systemName: "die.face.4.fill")
Image(systemName: "die.face.5")
Image(systemName: "die.face.6.fill")
}
}
NavigationLink {
PasswordView()
.navigationTitle("Password")
} label: {
HStack {
Text("Password")
Spacer()
Image(systemName: "rectangle.and.pencil.and.ellipsis")
}
}
}
.navigationTitle("RNG")
.navigationBarTitleDisplayMode(.inline)
} detail: {
Image(systemName: "dice.fill")
}
}
}
}

114
RNG/DiceView.swift Normal file
View File

@@ -0,0 +1,114 @@
//
// DiceView.swift
// RNG
//
// Created by Nihaal on 30/05/2024.
//
import SwiftUI
struct DiceView: View {
@State var generated: [Int] = [0]
@State var displayDies: [Int] = []
@State var displayMultiDieMode = ""
@State var multiDieMode = "plus"
@State var result = 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") {
HStack {
Text( String( Int(dies) ) )
.font(.system(size: 25, weight: .bold))
Divider()
Text("1")
Slider(value: $dies, in: 1...20, step: 1)
Text("20")
}
}
Section("Multi die mode") {
Picker(selection: $multiDieMode, label: Text("ioug")) {
Image(systemName: "plus").tag("plus")
Image(systemName: "multiply").tag("multiply")
}.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])")
.resizable()
.scaledToFit()
.frame(width: 50, height: 50)
if index != displayDies.count-1 {
Image(systemName: displayMultiDieMode)
.resizable()
.scaledToFit()
.frame(width: 10, height: 10)
}
}
}.padding()
}
}
}
}
Text(String(result))
.font(.system(size: 75, weight: .bold))
.foregroundColor(.gray)
.frame(height: 50)
Text(resultDescription)
.frame(height: 20)
Button {
generated = rngN6DieArr(dies: Int(dies))
displayDies = generated
displayMultiDieMode = multiDieMode
result = arrCombine(arr: generated, combineMode: multiDieMode)
resultDescription = describeResult(inp: displayDies, combineMode: multiDieMode)
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)
.padding(.bottom)
}
}
}
func describeResult(inp: [Int], combineMode: String) -> String {
let len = inp.count-1
var result = ""
var symbol = ""
if inp.isEmpty {
return "0"
} else {
if combineMode == "plus" {
symbol = " + "
} else if combineMode == "multiply" {
symbol = " x "
}
for i in 0...len {
if i == len {
result += String(inp[i])
} else {
result += String(inp[i]) + symbol
}
}
result += " = " + String(arrCombine(arr: inp, combineMode: combineMode))
return result
}
}
#Preview {
DiceView()
}

175
RNG/NumberView.swift Normal file
View File

@@ -0,0 +1,175 @@
//
// RNGView.swift
// RNG
//
// Created by Nihaal on 09/10/2024.
//
//fix date created
//TODO: readd ios 16 support
//TODO: try to use inject
import SwiftUI
struct NumberView: View {
@State var low: String = "1"
@State var high: String = "10"
@State var exclude: String = "none"
@State var generated = "5"
@State var prevGen = ""
@State var generatedInt: Int = 0
@State var prevGenInt: Int = 0
@State var dispResult = 5
var body: some View {
List {
HStack {
Spacer()
TextField("From", text: $low)
.keyboardType(.numberPad)
.textFieldStyle(RoundedBorderTextFieldStyle())
.multilineTextAlignment(.center)
Image(systemName: "minus")
.resizable()
.scaledToFit()
.bold()
.frame(width: 20)
TextField("To", text: $high)
.keyboardType(.numberPad)
.textFieldStyle(RoundedBorderTextFieldStyle())
.multilineTextAlignment(.center)
Spacer()
}
Section("Exclude") {
Picker(selection: $exclude, label: Text("")) {
Text("Start").tag("start")
Text("None").tag("none")
Text("End").tag("end")
Text("Both").tag("both")
}
.pickerStyle(.segmented)
}
Section("Description") {
Text(describeInputs(min: low, max: high, exclude: exclude))
}
}
Text(String(dispResult))
.font(.system(size: 75, weight: .bold))
.foregroundColor(.gray)
.frame(height: 50)
Button {
prevGen = generated
generated = rng2(min: low, max: high, exclude: exclude)
prevGenInt = Int(prevGen)!
generatedInt = Int(generated)!
if prevGenInt < generatedInt {
for _ in prevGenInt...generatedInt {
dispResult += 1
//sleep( UInt32( 1 / (generatedInt - prevGenInt) ) )
}
} else if prevGenInt > generatedInt {
for _ in generatedInt...prevGenInt {
dispResult -= 1
//sleep( UInt32( 1 / (prevGenInt - generatedInt) ) )
}
} else if prevGenInt == generatedInt {
dispResult = generatedInt
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)
.padding(.bottom)
}
}
func describeInputs(min: String, max: String, exclude: String) -> String {
let validExcludes = ["start", "end", "both", "none"]
guard validExcludes.contains(exclude) else {
print("invalid exclude: " + exclude)
return "invalid exclude: " + exclude
}
var result = "Any number from "
result += min != "" ? min : "_"
result += " to "
result += max != "" ? max : "_"
if min == "" || max == "" {
return "Enter values above."
} else {
switch exclude {
case "start":
result += ", excluding \(min)"
case "end":
result += ", excluding \(max)"
case "both":
result += ", excluding \(min) and \(max)"
case "none":
break
default:
result = "invalid 'exclude'"
}
}
result += "."
return result
}
enum rng2Errors: Error {
case h
}
func rng2(min: String, max: String, exclude: String) -> String {
guard min != "" || max != "" else {
return "Enter values above."
}
guard var minInt = Int(min) else {
print("invalid min")
return "-1"
}
guard var maxInt = Int(max), maxInt >= minInt else {
print("invalid max or is less than min")
return "-1"
}
guard exclude != "both", min != max else {
print("excluding both but min == max")
return "No possible numbers, both bounds equal."
}
let minIntPlus1 = minInt + 1
guard exclude != "both", minIntPlus1 != maxInt else {
print("excluding both but min +1 == max")
return "No possible numbers."
}
var generated = 0
if exclude == "both" {
maxInt -= 1
minInt += 1
} else if exclude == "start" {
minInt += 1
} else if exclude == "end" {
maxInt -= 1
}
generated = rng(min: minInt, max: maxInt)
return String(generated)
}
#Preview {
NumberView()
}

122
RNG/PasswordView.swift Normal file
View File

@@ -0,0 +1,122 @@
//
// PasswordView.swift
// RNG
//
// Created by Nihaal on 30/05/2024.
//
import SwiftUI
struct PasswordView: View {
@State var selectedOptions: [PassOption] = []
let options: [PassOption] = [
PassOption(name: "0-9", chars: Array("0123456789")),
PassOption(name: "a-z", chars: Array("abcdefghijklmnopqrstuvwxyz")),
PassOption(name: "A-Z", chars: Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
]
@State var presetLen = 4
@State var customLen = 8
@State var generated = ""
@State var result = ""
@State var history: [Int] = []
var body: some View {
VStack {
List {
Text("Hello, world!")
.font(.largeTitle)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.padding()
.background(Color.mint)
.padding()
.background(Color.green)
Section("Include") {
ForEach(options) { option in
Toggle(isOn: Binding(
get: {
self.selectedOptions.contains(where: { $0.id == option.id })
},
set: { isSelected in
if isSelected {
self.selectedOptions.append(option)
} else {
self.selectedOptions.removeAll { $0.id == option.id }
}
}
)) {
Text(option.name)
}
}
}
Section("Length") {
Picker("", selection: $presetLen) {
Text("4").tag(4)
Text("6").tag(6)
Text("Custom: \(customLen)").tag(-1)
}
.pickerStyle(SegmentedPickerStyle())
}
if presetLen == -1 {
TextField("Custom", value: $customLen, formatter: NumberFormatter())
.keyboardType(.numberPad)
.frame(width: 50)
}
Text(String(result))
.font(.system(size: 75, weight: .bold))
.foregroundColor(.gray)
.frame(height: 50)
Text(String(generated))
.font(.system(size: 75, weight: .bold))
.foregroundColor(.gray)
.frame(height: 50)
Button {
generated = genPass(selectdOpts: selectedOptions, len: (presetLen == -1 ? customLen : presetLen))
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)
.padding(.vertical)
}
}
}
}
struct Option: Identifiable {
let id: Int
let name: String
}
struct PassOption: Identifiable {
var id = UUID()
var name: String
var chars: [Character]
}
func genPass(selectdOpts: [PassOption], len: Int) -> String {
let characters = selectdOpts.flatMap { $0.chars }
guard !(characters.isEmpty) else {
print("characters empty")
return ""
}
return (0..<len).compactMap { _ in
characters.randomElement()
}
.map { String($0) }
.joined()
}
#Preview {
PasswordView()
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

10
RNG/RNG.entitlements Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>

110
RNG/RNGApp.swift Normal file
View File

@@ -0,0 +1,110 @@
//
// RNGApp.swift
// RNG
//
// Created by Nihaal on 24/05/2024.
//
import SwiftUI
@main
struct RNGApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
// array combiner, adds up all ints in an array
func totalIntArr(arr: [Int]) -> Int {
var total = 0
for num in arr {
total += num
}
return total
}
// array combiner, adds up all doubles in an array
func totalDoubleArr(arr: [Double]) -> Double {
var total: Double = 0
for num in arr {
total += num
}
return total
}
// array combiner, adds or multiplies all ints in an array
func arrCombine(arr: [Int], combineMode: String) -> Int {
var output = 0
if combineMode == "plus" {
for num in arr {
output += num
}
} else if combineMode == "multiply" {
output = 1
for num in arr {
output *= num
}
} else {
print("invalid combineMode '\(combineMode)'. must be 'plus' or 'multiply', returning 0")
return 0
}
return output
}
func rng(min: Int, max: Int) -> Int {
var rng = 0
rng = Int.random(in: min...max)
return rng
}
func rng6Die() -> Int {
return Int.random(in: 1...6)
}
func rngCDie(min: Int, max: Int) -> Int {
return Int.random(in: min...max)
}
func rngN6DieArr(dies: Int) -> [Int] {
var output: [Int] = []
for _ in 1...dies {
output.append(rng6Die())
}
return output
}
func rngNCDie(dies: Int, min: Int, max: Int) -> [Int] {
var output: [Int] = []
for _ in 1...dies {
output.append(rngCDie(min: min, max: max))
}
return output
}
func rngInt(len: Int) async -> Int {
var resultI: Int = 0
var latestElement = 0
for _ in 1...len {
latestElement = Int.random(in: 0...9)
if latestElement == 0 {
resultI *= 10
} else {
resultI *= 10
resultI += latestElement
}
}
return resultI
}
func rngString(len: Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
return String((1..<len).map{ _ in letters.randomElement()! })
}
#Preview("ContentView") {
ContentView()
}