@wildshard/shard-format 0.75.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ // FORMAT-PRUNE FP22d: where a row names a held weapon (a loadout slot, a finish's weapon), it names an engine-native closed
2
+ // name (until `items.legacySlot` goes, FP22e) or the declared item the weapon plays under, `declared.<equipment id>`.
3
+ import { custom, picklist, union } from 'valibot'
4
+
5
+ import type { GenericSchema } from 'valibot'
6
+
7
+ type DeclaredWeaponId = `declared.weapon.${string}`
8
+ type WeaponSlot =
9
+ | 'crossbow'
10
+ | 'sword'
11
+ | 'rifle'
12
+ | 'sword-iron'
13
+ | 'bow'
14
+ | 'sabre'
15
+ | 'spear'
16
+ | 'empty'
17
+ | DeclaredWeaponId
18
+
19
+ const DECLARED_LIMIT = 256
20
+ const DECLARED_PATTERN: string = String.raw`^declared\.weapon\.[a-z][a-zA-Z0-9.-]*$`
21
+ const DECLARED = new RegExp(DECLARED_PATTERN, 'u')
22
+
23
+ /** A declared weapon id: `declared.weapon.` and the rest of its equipment id. */
24
+ function isDeclaredWeapon(input: unknown): input is DeclaredWeaponId {
25
+ return (
26
+ typeof input === 'string' &&
27
+ input.length <= DECLARED_LIMIT &&
28
+ DECLARED.test(input)
29
+ )
30
+ }
31
+
32
+ const DeclaredWeaponSchema: GenericSchema<DeclaredWeaponId> =
33
+ custom<DeclaredWeaponId>(isDeclaredWeapon, 'a declared weapon id')
34
+ const WeaponSlotSchema: GenericSchema<WeaponSlot> = union([
35
+ picklist([
36
+ 'crossbow',
37
+ 'sword',
38
+ 'rifle',
39
+ 'sword-iron',
40
+ 'bow',
41
+ 'sabre',
42
+ 'spear',
43
+ 'empty',
44
+ ]),
45
+ DeclaredWeaponSchema,
46
+ ])
47
+
48
+ export {
49
+ DECLARED_LIMIT,
50
+ DECLARED_PATTERN,
51
+ DeclaredWeaponSchema,
52
+ WeaponSlotSchema,
53
+ type DeclaredWeaponId,
54
+ type WeaponSlot,
55
+ }