mirror of
https://github.com/neon443/RNG_Swift.git
synced 2026-03-11 06:49:12 +00:00
Initial Commit
This commit is contained in:
47
.swiftpm/playgrounds/CachedManifest.plist
Normal file
47
.swiftpm/playgrounds/CachedManifest.plist
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?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>CachedManifest</key>
|
||||||
|
<dict>
|
||||||
|
<key>manifestData</key>
|
||||||
|
<data>
|
||||||
|
eyJkZXBlbmRlbmNpZXMiOltdLCJkaXNwbGF5TmFtZSI6IlJORyIsInBhY2th
|
||||||
|
Z2VLaW5kIjp7InJvb3QiOnt9fSwicGxhdGZvcm1zIjpbeyJvcHRpb25zIjpb
|
||||||
|
XSwicGxhdGZvcm1OYW1lIjoiaW9zIiwidmVyc2lvbiI6IjE2LjAifV0sInBy
|
||||||
|
b2R1Y3RzIjpbeyJuYW1lIjoiUk5HIiwic2V0dGluZ3MiOlt7ImRpc3BsYXlW
|
||||||
|
ZXJzaW9uIjpbIjEuMCJdfSx7ImJ1bmRsZVZlcnNpb24iOlsiMSJdfSx7ImlP
|
||||||
|
U0FwcEluZm8iOlt7ImFjY2VudENvbG9yIjp7InByZXNldENvbG9yIjp7InBy
|
||||||
|
ZXNldENvbG9yIjp7InJhd1ZhbHVlIjoiYmx1ZSJ9fX0sImFwcENhdGVnb3J5
|
||||||
|
Ijp7InJhd1ZhbHVlIjoicHVibGljLmFwcC1jYXRlZ29yeS51dGlsaXRpZXMi
|
||||||
|
fSwiYXBwSWNvbiI6eyJwbGFjZWhvbGRlciI6eyJpY29uIjp7InJhd1ZhbHVl
|
||||||
|
IjoiY2FsY3VsYXRvciJ9fX0sImNhcGFiaWxpdGllcyI6W10sInN1cHBvcnRl
|
||||||
|
ZERldmljZUZh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ImV4ZWN1dGFibGUifV0sInRvb2xz
|
||||||
|
VmVyc2lvbiI6eyJfdmVyc2lvbiI6IjUuOS4wIn19
|
||||||
|
</data>
|
||||||
|
<key>manifestHash</key>
|
||||||
|
<data>
|
||||||
|
ZB/SWxlchPYcczKX1JhFcosGzSflW/fzQhD7DXE27Pk=
|
||||||
|
</data>
|
||||||
|
<key>schemaVersion</key>
|
||||||
|
<integer>4</integer>
|
||||||
|
<key>swiftPMVersionString</key>
|
||||||
|
<string>5.10.0-dev</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
19
.swiftpm/playgrounds/DocumentThumbnail.plist
Normal file
19
.swiftpm/playgrounds/DocumentThumbnail.plist
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?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>DocumentThumbnailConfiguration</key>
|
||||||
|
<dict>
|
||||||
|
<key>accentColorHash</key>
|
||||||
|
<data>
|
||||||
|
Fkd2iMDgBpnGz6RJejYS1+g8UyBitkslD+2JCBKO1Ug=
|
||||||
|
</data>
|
||||||
|
<key>appIconHash</key>
|
||||||
|
<data>
|
||||||
|
0tSlknALCSBljl1W7VDr+qgrH0o+EF6bz9i8uwgcLoc=
|
||||||
|
</data>
|
||||||
|
<key>thumbnailIsPrerendered</key>
|
||||||
|
<false/>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
BIN
.swiftpm/playgrounds/DocumentThumbnail.png
Normal file
BIN
.swiftpm/playgrounds/DocumentThumbnail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
13
.swiftpm/playgrounds/Workspace.plist
Normal file
13
.swiftpm/playgrounds/Workspace.plist
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?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>AppSettings</key>
|
||||||
|
<dict>
|
||||||
|
<key>appIconPlaceholderGlyphName</key>
|
||||||
|
<string>calculator</string>
|
||||||
|
<key>appSettingsVersion</key>
|
||||||
|
<integer>1</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
7
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "self:">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Bucket
|
||||||
|
uuid = "7D3468E0-8930-45B0-9787-2F5420A82D30"
|
||||||
|
type = "1"
|
||||||
|
version = "2.0">
|
||||||
|
</Bucket>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?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>SchemeUserState</key>
|
||||||
|
<dict>
|
||||||
|
<key>RNG.xcscheme_^#shared#^_</key>
|
||||||
|
<dict>
|
||||||
|
<key>orderHint</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
26
ContentView.swift
Normal file
26
ContentView.swift
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ContentView: View {
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
NavigationSplitView {
|
||||||
|
List {
|
||||||
|
NavigationLink {
|
||||||
|
DiceView()
|
||||||
|
.navigationTitle("Dice")
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
Text("Dice")
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "die.face.6.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("RNG")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
} detail: {
|
||||||
|
Image(systemName: "dice.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
72
DiceView.swift
Normal file
72
DiceView.swift
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct DiceView: View {
|
||||||
|
@State var generated: [Int] = []
|
||||||
|
@State var displayDies: [Int] = []
|
||||||
|
@State var history: [Int] = []
|
||||||
|
let columns = [GridItem(.adaptive(minimum: 50, maximum: 75))]
|
||||||
|
@State var dies: Double = 1
|
||||||
|
@State var multiDieMode = "plus"
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
List {
|
||||||
|
Section("Number of die") {
|
||||||
|
HStack {
|
||||||
|
Text(String(Int(dies)))
|
||||||
|
Slider(value: $dies, in: 1...10, step: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Section("Multi die mode") {
|
||||||
|
Picker(selection: $multiDieMode, label: Text("")) {
|
||||||
|
Image(systemName: "plus").tag("plus")
|
||||||
|
Image(systemName: "multiply").tag("multiply")
|
||||||
|
}.pickerStyle(SegmentedPickerStyle())
|
||||||
|
}
|
||||||
|
Section("Visual") {
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
if displayDies.isEmpty {
|
||||||
|
LazyVGrid(columns: columns, spacing: 10) {
|
||||||
|
|
||||||
|
ForEach(0..<displayDies.count, id: \.self) { index in
|
||||||
|
Image(systemName: "die.face.\(index > displayDies.count ? Int.random(in: 1...6) : displayDies[index])")
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(width: 50, height: 50)
|
||||||
|
Image(systemName: multiDieMode)
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(width: 25)
|
||||||
|
}
|
||||||
|
}.padding()
|
||||||
|
} else {
|
||||||
|
Text("Results are visualised here when you press the generate button")
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Section("Result") {
|
||||||
|
Button("Generate") {
|
||||||
|
generated = rngN6DieArr(dies: Int(dies))
|
||||||
|
displayDies = generated
|
||||||
|
}
|
||||||
|
Text(String(arrCombine(arr: generated, combineMode: multiDieMode)))
|
||||||
|
.bold()
|
||||||
|
.font(.largeTitle)
|
||||||
|
}
|
||||||
|
Button("Test1") {
|
||||||
|
generated = [1, 2]
|
||||||
|
multiDieMode = "plus"
|
||||||
|
}
|
||||||
|
Button("Test2") {
|
||||||
|
generated = [1, 2]
|
||||||
|
multiDieMode = "multiply"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
DiceView()
|
||||||
|
}
|
||||||
76
MyApp.swift
Normal file
76
MyApp.swift
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
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, step: Int) -> Int {
|
||||||
|
let range = (max - min) / step + 1
|
||||||
|
var rng = Int.random(in: 0..<range)
|
||||||
|
rng = min + rng * step
|
||||||
|
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 rngCDie(dies: Int, min: Int, max: Int) -> Int {
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
47
Package.swift
Normal file
47
Package.swift
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// swift-tools-version: 5.9
|
||||||
|
|
||||||
|
// WARNING:
|
||||||
|
// This file is automatically generated.
|
||||||
|
// Do not edit it by hand because the contents will be replaced.
|
||||||
|
|
||||||
|
import PackageDescription
|
||||||
|
import AppleProductTypes
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "RNG",
|
||||||
|
platforms: [
|
||||||
|
.iOS("16.0")
|
||||||
|
],
|
||||||
|
products: [
|
||||||
|
.iOSApplication(
|
||||||
|
name: "RNG",
|
||||||
|
targets: ["AppModule"],
|
||||||
|
bundleIdentifier: "com.neon443.RNG",
|
||||||
|
teamIdentifier: "8626DL2GW3",
|
||||||
|
displayVersion: "1.0",
|
||||||
|
bundleVersion: "1",
|
||||||
|
appIcon: .placeholder(icon: .calculator),
|
||||||
|
accentColor: .presetColor(.blue),
|
||||||
|
supportedDeviceFamilies: [
|
||||||
|
.pad,
|
||||||
|
.phone
|
||||||
|
],
|
||||||
|
supportedInterfaceOrientations: [
|
||||||
|
.portrait,
|
||||||
|
.landscapeRight,
|
||||||
|
.landscapeLeft,
|
||||||
|
.portraitUpsideDown(.when(deviceFamilies: [.pad]))
|
||||||
|
],
|
||||||
|
appCategory: .utilities
|
||||||
|
)
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
.executableTarget(
|
||||||
|
name: "AppModule",
|
||||||
|
path: ".",
|
||||||
|
swiftSettings: [
|
||||||
|
.enableUpcomingFeature("BareSlashRegexLiterals")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
37
RNGView.swift
Normal file
37
RNGView.swift
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct CustomRNGView: View {
|
||||||
|
@State var rangeL: String = ""
|
||||||
|
@State var rangeH: String = ""
|
||||||
|
@State var show = false
|
||||||
|
var body: some View {
|
||||||
|
Text("Unimplemented")
|
||||||
|
Form {
|
||||||
|
HStack {
|
||||||
|
TextField("From", text: $rangeL)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
Divider()
|
||||||
|
TextField("To", text: $rangeH)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
Text("Any number")
|
||||||
|
Divider()
|
||||||
|
HStack {
|
||||||
|
Text("From: ")
|
||||||
|
Text(rangeL)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
Text("To: ")
|
||||||
|
Text(rangeH)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
CustomRNGView()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user