-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleSetting.swift
More file actions
86 lines (68 loc) · 2.17 KB
/
SimpleSetting.swift
File metadata and controls
86 lines (68 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Foundation
import Narratore
public enum SimpleSetting: Setting {
public enum Generate: Generating {
public actor Fixed {
public static let shared = Fixed()
public var randomRatio: Double?
public var uniqueString: String?
public func set(randomRatio: Double?) {
self.randomRatio = randomRatio
}
public func set(uniqueString: String?) {
self.uniqueString = uniqueString
}
}
public static func randomRatio() async -> Double {
await Fixed.shared.randomRatio ?? Double((0...1000).randomElement()!) / 1000
}
public static func uniqueString() async -> String {
await Fixed.shared.uniqueString ?? UUID().uuidString
}
}
public struct Message: Messaging, ExpressibleByStringLiteral {
public var id: ID?
public var text: String
public init(id: ID?, text: String) {
self.id = id
self.text = text
}
public init(stringLiteral value: String) {
self.init(id: nil, text: value)
}
public struct ID: Hashable, Codable, Sendable, ExpressibleByStringLiteral, CustomStringConvertible {
public var description: String
public init(stringLiteral value: String) {
description = value
}
}
}
public struct Tag: Tagging, CustomStringConvertible {
public var value: String
public var shouldObserve: Bool
public init(_ value: String, shouldObserve: Bool = false) {
self.value = value
self.shouldObserve = shouldObserve
}
public var description: String {
value
}
}
public struct World: Codable, Sendable {
public var value: [Key: Value] = [:]
public var list: [Key: [Value]] = [:]
public init() {}
public struct Key: ExpressibleByStringLiteral, CustomStringConvertible, Codable, Equatable, Hashable, Sendable {
public var description: String
public init(stringLiteral value: String) {
description = value
}
}
public struct Value: ExpressibleByStringLiteral, CustomStringConvertible, Codable, Equatable, Sendable {
public var description: String
public init(stringLiteral value: String) {
description = value
}
}
}
}