File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010import MemberwiseInit
1111
12+ @MemberwiseInit ( . public)
13+ public struct Bestiary : Equatable , Codable , Sendable {
14+ public static let entryBasePath : String = " data/bestiary "
15+ public static let indexEntryPath : String = " \( entryBasePath) /index.json "
16+
17+ public var monster : [ Creature ] = [ ]
18+ }
19+
1220@MemberwiseInit ( . public)
1321public struct Creature : Equatable , Sendable {
1422 public enum AbilityScore : Equatable , Sendable {
Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ extension Alignment: Hashable {
2727 static let any : Self = . all
2828}
2929
30+ @MemberwiseInit ( . public)
31+ public struct IndexFile : Equatable , Sendable {
32+ public var entries : [ String : String ] = [ : ]
33+ }
34+
3035public enum Page : Equatable , Hashable , Sendable {
3136 case number( Int )
3237 case numeral( String )
@@ -173,6 +178,18 @@ extension Alignment: Codable {
173178 }
174179}
175180
181+ extension IndexFile : Codable {
182+ public init ( from decoder: any Decoder ) throws {
183+ let container = try decoder. singleValueContainer ( )
184+ entries = try container. decode ( [ String : String ] . self)
185+ }
186+
187+ public func encode( to encoder: any Encoder ) throws {
188+ var container = encoder. singleValueContainer ( )
189+ try container. encode ( entries)
190+ }
191+ }
192+
176193extension Page : Codable {
177194 public init ( from decoder: any Decoder ) throws {
178195 let container = try decoder. singleValueContainer ( )
Original file line number Diff line number Diff line change @@ -71,6 +71,31 @@ struct AlignmentCodableTests {
7171
7272}
7373
74+ struct IndexFileCodableTests {
75+
76+ @Test ( " Index file " )
77+ func index( ) throws {
78+ try testCodable (
79+ json: """
80+ {
81+ " XDMG " : " foo-xdmg.json " ,
82+ " XMM " : " foo-xmm.json " ,
83+ " XPHB " : " foo-xphb.json "
84+ }
85+ """ ,
86+ value: IndexFile (
87+ entries: [
88+ " XDMG " : " foo-xdmg.json " ,
89+ " XMM " : " foo-xmm.json " ,
90+ " XPHB " : " foo-xphb.json " ,
91+ ] ,
92+ )
93+ )
94+
95+ }
96+
97+ }
98+
7499struct PageCodableTests {
75100
76101 @Test ( " Numeric page " )
You can’t perform that action at this time.
0 commit comments