Skip to content

Commit 5f2117f

Browse files
committed
Helper property for UID
1 parent 1680448 commit 5f2117f

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Sources/FifthEdition/Bestiary.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ public struct Creature: Equatable, Sendable {
319319
// TODO: _versions, array /creatureVersion
320320
// TODO: _isCopy, _copy
321321

322+
/// Returns the uid used to reference this creature.
323+
public var uid: String? {
324+
guard let name, let source else {
325+
return nil
326+
}
327+
328+
return "\(name.localizedLowercase)|\(source.localizedLowercase)"
329+
}
330+
322331
/// Returns the expected token path.
323332
public var tokenPath: String? {
324333
guard let name = token?.name ?? name,

Tests/FifthEditionTests/BestiaryTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,35 @@ struct CreatureCodableTests {
447447

448448
}
449449

450+
struct CreatureUidTests {
451+
452+
@Test("UID")
453+
func uid() throws {
454+
let creature = Creature(
455+
name: "Blink Dog",
456+
source: "XMM"
457+
)
458+
#expect(creature.uid == "blink dog|xmm")
459+
}
460+
461+
@Test("No UID if no name")
462+
func noName() throws {
463+
let creature = Creature(
464+
source: "XMM"
465+
)
466+
#expect(creature.uid == nil)
467+
}
468+
469+
@Test("No UID if no source")
470+
func noSource() throws {
471+
let creature = Creature(
472+
name: "Blink Dog",
473+
)
474+
#expect(creature.uid == nil)
475+
}
476+
477+
}
478+
450479
struct CreatureTokenPathTests {
451480

452481
@Test("Token path")

0 commit comments

Comments
 (0)