@wildshard/shard-format 0.14.0 → 0.16.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,148 @@
1
+ /* oxlint-disable capitalized-comments, curly, import/exports-last, import/group-exports, no-magic-numbers, typescript/explicit-function-return-type, typescript/explicit-member-accessibility, typescript/prefer-readonly-parameter-types, unicorn/consistent-function-scoping -- verbatim port of the engine's law (SDK-SPLIT SP4); golden vectors pin it, so it keeps the engine's form */
2
+ /**
3
+ * SDK-SPLIT SP4f3 (Q35): the item catalogue reader moved from engine `shared/game/loadout/itemCatalogue.ts`, with the
4
+ * portable equipment and ammunition vocabulary it returns. The shard-augmented maps (`EquipmentSlotMap`,
5
+ * `EquipmentIconMap`) stay in the engine, which fills them by declaration merging and narrows these rows to its own.
6
+ */
7
+ import { parseItems } from './items.ts'
8
+
9
+ /** a sound cue's id */
10
+ export type CueId = `cue.${string}`
11
+ export type ToolId = `tool.${string}`
12
+ export type EquipmentId = `weapon.${string}` | ToolId
13
+ export type AmmoId = `ammo.${string}`
14
+ /** a weapon's sound cues: fire, reload, impact, and the optional dry, hit, heavy and charge cues */
15
+ export interface EquipmentCues {
16
+ fire: CueId
17
+ reload: CueId
18
+ impact: CueId
19
+ dry?: CueId
20
+ hit?: CueId
21
+ heavy?: CueId
22
+ charge?: Readonly<Record<string, CueId>>
23
+ }
24
+
25
+ type ItemRow = ReturnType<typeof parseItems>['rows'][number]
26
+ type ItemEquipment = NonNullable<ItemRow['equipment']>
27
+ /** An item's portable equipment presentation: its admitted row, with the engine's equipment id and cue ids. */
28
+ export type ItemEquipmentRow = Omit<ItemEquipment, 'id' | 'cues'> & {
29
+ id: EquipmentId
30
+ cues?: EquipmentCues
31
+ }
32
+ /** An ammunition's portable row (the engine's `AmmoRow`): its flight, wet flight increments applied, and its id as its one tag. */
33
+ export interface ItemAmmoRow {
34
+ id: AmmoId
35
+ label: string
36
+ name: string
37
+ flight: { gravity: number; drag: number }
38
+ wet?: { gravity: number; drag: number }
39
+ tags: readonly AmmoId[]
40
+ material?: string
41
+ pouchMax: number
42
+ }
43
+
44
+ /** One admitted item catalogue for equipment, ammunition and native inventory.
45
+ * Pine, Driftwood, Nalati and Nine share this metadata reader; no state, clock or callback is installed. */
46
+ export class ItemCatalogue {
47
+ private readonly items: ReturnType<typeof parseItems>
48
+ constructor(input: unknown) {
49
+ this.items = parseItems(input)
50
+ }
51
+ /** Resolve admitted equipment metadata without factories, callbacks or a second state owner.
52
+ * Native constructors keep their profile and pickup service; this supplies only portable presentation. */
53
+ equipment(id: string): ItemEquipmentRow {
54
+ const item = this.items.rows.find(row => row.id === id)
55
+ if (item?.equipment === undefined)
56
+ throw new Error(`Missing declared equipment presentation: ${id}`)
57
+ const { id: equipmentId, cues, ...presentation } = item.equipment
58
+ const cueId = (value: string): `cue.${string}` => `cue.${value.slice(4)}`
59
+ return {
60
+ ...presentation,
61
+ id:
62
+ item.kind === 'weapon'
63
+ ? `weapon.${equipmentId.slice(7)}`
64
+ : `tool.${equipmentId.slice(5)}`,
65
+ ...(cues === undefined
66
+ ? {}
67
+ : {
68
+ cues: {
69
+ fire: cueId(cues.fire),
70
+ reload: cueId(cues.reload),
71
+ impact: cueId(cues.impact),
72
+ ...(cues.dry === undefined ? {} : { dry: cueId(cues.dry) }),
73
+ ...(cues.hit === undefined ? {} : { hit: cueId(cues.hit) }),
74
+ ...(cues.heavy === undefined ? {} : { heavy: cueId(cues.heavy) }),
75
+ ...(cues.charge === undefined
76
+ ? {}
77
+ : {
78
+ charge: Object.fromEntries(
79
+ Object.entries(cues.charge).map(([phase, value]) => [
80
+ phase,
81
+ cueId(value),
82
+ ]),
83
+ ),
84
+ }),
85
+ },
86
+ }),
87
+ }
88
+ }
89
+
90
+ /** Page ammunition borrows the same admitted flight/target coefficients as native projectiles.
91
+ * The returned rows retain the weather convention (absolute wet multipliers) and carry no effects or clocks. */
92
+ ammunition(id: string): ReadonlyMap<
93
+ string,
94
+ {
95
+ row: ItemAmmoRow
96
+ damage: {
97
+ readonly default: number
98
+ readonly kinds: Readonly<Record<string, number>>
99
+ }
100
+ }
101
+ > {
102
+ const item = this.items.rows.find(row => row.id === id)
103
+ if (item?.kind !== 'weapon' || item.ranged === undefined)
104
+ throw new Error('Missing declared ammunition')
105
+ return new Map(
106
+ item.ranged.ammunition.map(ammo => {
107
+ if (ammo.presentation === undefined)
108
+ throw new Error('Missing declared ammunition presentation')
109
+ const ammoId = `ammo.${ammo.id}` as const
110
+ return [
111
+ ammo.id,
112
+ {
113
+ row: {
114
+ id: ammoId,
115
+ ...ammo.presentation,
116
+ flight: { ...ammo.flight },
117
+ tags: [ammoId],
118
+ ...(ammo.wet === undefined
119
+ ? {}
120
+ : {
121
+ wet: {
122
+ gravity: 1 + ammo.wet.gravity,
123
+ drag: 1 + ammo.wet.drag,
124
+ },
125
+ }),
126
+ },
127
+ damage: {
128
+ default: 1,
129
+ kinds: Object.fromEntries(
130
+ ammo.targets.map(kind => [kind, ammo.damage]),
131
+ ),
132
+ },
133
+ },
134
+ ]
135
+ }),
136
+ )
137
+ }
138
+
139
+ /** Read the admitted saved-pack policy; NativeInventory remains the only stacking/trade state owner. */
140
+ get inventory(): NonNullable<
141
+ ReturnType<typeof parseItems>['loadout']['inventory']
142
+ > {
143
+ const profile = this.items.loadout.inventory
144
+ if (profile === undefined)
145
+ throw new Error('Missing declared inventory policy')
146
+ return profile
147
+ }
148
+ }
@@ -0,0 +1,46 @@
1
+ /* oxlint-disable curly, id-length, import/group-exports, max-statements, no-magic-numbers, prefer-named-capture-group, typescript/explicit-function-return-type, typescript/prefer-readonly-parameter-types -- verbatim port of the engine's law (SDK-SPLIT SP4); golden vectors pin it, so it keeps the engine's form */
2
+ /** SDK-SPLIT SP4f1 (Q35): a kinematic mover's published pose and boxes (from engine `shared/engine/physics/mover.ts`) and the
3
+ * observations a channel program copies from it (`moverChannelValues`, from `client/game/plugin/clientChannelView.ts`): the
4
+ * map raster's rest pose and the page's read one law. The Rapier body stays engine. */
5
+
6
+ /** Local boxes for a script-owned platform; the physics layer alone constructs Rapier descriptors. */
7
+ export interface MoverBox {
8
+ x: number
9
+ y: number
10
+ z: number
11
+ hx: number
12
+ hy: number
13
+ hz: number
14
+ rot: { x: number; y: number; z: number; w: number }
15
+ }
16
+ /** Published mover pose, in the world's local frame; Euler order is always YXZ. */
17
+ export interface MoverPose {
18
+ position: { x: number; y: number; z: number }
19
+ euler: { x: number; y: number; z: number }
20
+ enabled: boolean
21
+ }
22
+
23
+ /** Copy only the fixed mover ABI's published observations, never its world or module memory. */
24
+ export function moverChannelValues(
25
+ reads: readonly string[],
26
+ pose: MoverPose,
27
+ fields: Readonly<Record<number, number>>,
28
+ ): number[] {
29
+ return reads.map(read => {
30
+ if (read === 'enabled') return Number(pose.enabled)
31
+ if (read.startsWith('position.')) {
32
+ const axis = read.slice(9)
33
+ if (axis === 'x' || axis === 'y' || axis === 'z')
34
+ return pose.position[axis]
35
+ }
36
+ if (read.startsWith('euler.')) {
37
+ const axis = read.slice(6)
38
+ if (axis === 'x' || axis === 'y' || axis === 'z') return pose.euler[axis]
39
+ }
40
+ const field = /^field\.([1-6])$/u.exec(read),
41
+ key = field?.[1]
42
+ const value = key === undefined ? undefined : fields[Number(key)]
43
+ if (value === undefined) throw new Error('Missing copied mover field')
44
+ return value
45
+ })
46
+ }
@@ -0,0 +1,64 @@
1
+ /* oxlint-disable id-length, import/exports-last, import/group-exports, import/no-namespace, no-magic-numbers -- verbatim port of the engine's law (SDK-SPLIT SP4); the stored layout is pinned by golden vectors, so it keeps the engine's form */
2
+ /** SDK-SPLIT SP4e (Q35): the stored geometry channel layout moved from engine `client/engine/models/nativeGeometry.ts`; the
3
+ * three.js restoration (`nativeWholeGeometry`, `restoreDrawnChannels`) stays in the engine. */
4
+ import * as v from 'valibot'
5
+
6
+ /** Portable accessor metadata for one original typed application channel. */
7
+ export const NativeAttributeSchema: v.GenericSchema<
8
+ BoundedNativeAttributeInput,
9
+ BoundedNativeAttribute
10
+ > = v.strictObject({
11
+ semantic: v.string(),
12
+ storage: v.picklist([
13
+ 'Float32Array',
14
+ 'Float16Array',
15
+ 'Uint16Array',
16
+ 'Uint32Array',
17
+ 'Int16Array',
18
+ 'Int8Array',
19
+ 'Uint8Array',
20
+ ]),
21
+ normalized: v.boolean(),
22
+ itemSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(4)),
23
+ })
24
+ /** Original application channel names mapped to their exact stored accessors. */
25
+ export const NativeAttributesSchema: v.GenericSchema<
26
+ BoundedNativeAttributesInput,
27
+ BoundedNativeAttributes
28
+ > = v.record(v.string(), NativeAttributeSchema)
29
+
30
+ /** Complete admitted data, independent of validator implementation metadata. */
31
+ type BoundedNativeAttributeInput = BoundedNativeAttribute
32
+ interface BoundedNativeAttributeFields {
33
+ semantic: string
34
+ storage:
35
+ | 'Float32Array'
36
+ | 'Float16Array'
37
+ | 'Uint16Array'
38
+ | 'Uint32Array'
39
+ | 'Int16Array'
40
+ | 'Int8Array'
41
+ | 'Uint8Array'
42
+ normalized: boolean
43
+ itemSize: number
44
+ }
45
+ export type BoundedNativeAttribute = {
46
+ [Key in keyof BoundedNativeAttributeFields]: BoundedNativeAttributeFields[Key]
47
+ }
48
+ type BoundedNativeAttributesInput = BoundedNativeAttributes
49
+ export type BoundedNativeAttributes = Record<
50
+ string,
51
+ {
52
+ semantic: string
53
+ storage:
54
+ | 'Float32Array'
55
+ | 'Float16Array'
56
+ | 'Uint16Array'
57
+ | 'Uint32Array'
58
+ | 'Int16Array'
59
+ | 'Int8Array'
60
+ | 'Uint8Array'
61
+ normalized: boolean
62
+ itemSize: number
63
+ }
64
+ >
@@ -0,0 +1,106 @@
1
+ /* oxlint-disable capitalized-comments, curly, id-length, import/group-exports, max-params, max-statements, no-bitwise, no-inline-comments, no-magic-numbers, no-plusplus, prefer-destructuring, sort-vars, typescript/explicit-member-accessibility, typescript/prefer-readonly -- verbatim port of the engine's law (SDK-SPLIT SP4); bit-exact output is pinned by golden vectors, so it keeps the engine's form */
2
+ /** SDK-SPLIT SP4b (Q35): moved from engine `shared/engine/core/noise.ts`; the bake and the engine sample one copy. */
3
+ // 2D simplex noise (Stefan Gustavson's reference implementation, seeded permutation).
4
+ import { Rng } from './seeded-rng.ts'
5
+
6
+ const F2 = 0.5 * (Math.sqrt(3) - 1)
7
+ const G2 = (3 - Math.sqrt(3)) / 6
8
+ const grad3: readonly (readonly [number, number])[] = [
9
+ [1, 1],
10
+ [-1, 1],
11
+ [1, -1],
12
+ [-1, -1],
13
+ [1, 0],
14
+ [-1, 0],
15
+ [0, 1],
16
+ [0, -1],
17
+ ]
18
+ const G_NONE: readonly [number, number] = [0, 0] // never hit: `% 8` keeps the index in range; satisfies noUncheckedIndexedAccess
19
+
20
+ export class Noise2D {
21
+ private perm = new Uint8Array(512)
22
+ constructor(seed: number) {
23
+ const rng = new Rng(seed)
24
+ const p = new Uint8Array(256)
25
+ for (let i = 0; i < 256; i++) p[i] = i
26
+ for (let i = 255; i > 0; i--) {
27
+ const j = Math.floor(rng.next() * (i + 1))
28
+ ;[p[i], p[j]] = [p[j] ?? 0, p[i] ?? 0]
29
+ }
30
+ for (let i = 0; i < 512; i++) this.perm[i] = p[i & 255] ?? 0
31
+ }
32
+ /** returns roughly [-1, 1] */
33
+ get(xin: number, yin: number): number {
34
+ const perm = this.perm
35
+ const s = (xin + yin) * F2
36
+ const i = Math.floor(xin + s),
37
+ j = Math.floor(yin + s)
38
+ const t = (i + j) * G2
39
+ const x0 = xin - (i - t),
40
+ y0 = yin - (j - t)
41
+ const i1 = x0 > y0 ? 1 : 0,
42
+ j1 = x0 > y0 ? 0 : 1
43
+ const x1 = x0 - i1 + G2,
44
+ y1 = y0 - j1 + G2
45
+ const x2 = x0 - 1 + 2 * G2,
46
+ y2 = y0 - 1 + 2 * G2
47
+ const ii = i & 255,
48
+ jj = j & 255
49
+ let n = 0
50
+ let t0 = 0.5 - x0 * x0 - y0 * y0
51
+ if (t0 > 0) {
52
+ const g = grad3[(perm[ii + (perm[jj] ?? 0)] ?? 0) % 8] ?? G_NONE
53
+ t0 *= t0
54
+ n += t0 * t0 * (g[0] * x0 + g[1] * y0)
55
+ }
56
+ let t1 = 0.5 - x1 * x1 - y1 * y1
57
+ if (t1 > 0) {
58
+ const g = grad3[(perm[ii + i1 + (perm[jj + j1] ?? 0)] ?? 0) % 8] ?? G_NONE
59
+ t1 *= t1
60
+ n += t1 * t1 * (g[0] * x1 + g[1] * y1)
61
+ }
62
+ let t2 = 0.5 - x2 * x2 - y2 * y2
63
+ if (t2 > 0) {
64
+ const g = grad3[(perm[ii + 1 + (perm[jj + 1] ?? 0)] ?? 0) % 8] ?? G_NONE
65
+ t2 *= t2
66
+ n += t2 * t2 * (g[0] * x2 + g[1] * y2)
67
+ }
68
+ return 70 * n
69
+ }
70
+ fbm(x: number, y: number, octaves = 5, lacunarity = 2, gain = 0.5): number {
71
+ let a = 1,
72
+ f = 1,
73
+ sum = 0,
74
+ norm = 0
75
+ for (let o = 0; o < octaves; o++) {
76
+ sum += a * this.get(x * f, y * f)
77
+ norm += a
78
+ a *= gain
79
+ f *= lacunarity
80
+ }
81
+ return sum / norm
82
+ }
83
+ /** ridged multifractal, [0,1] */
84
+ ridged(x: number, y: number, octaves = 4): number {
85
+ let a = 1,
86
+ f = 1,
87
+ sum = 0,
88
+ norm = 0
89
+ for (let o = 0; o < octaves; o++) {
90
+ const n = 1 - Math.abs(this.get(x * f, y * f))
91
+ sum += a * n * n
92
+ norm += a
93
+ a *= 0.5
94
+ f *= 2.1
95
+ }
96
+ return sum / norm
97
+ }
98
+ }
99
+
100
+ export const smoothstep = (a: number, b: number, x: number): number => {
101
+ const t = Math.min(1, Math.max(0, (x - a) / (b - a)))
102
+ return t * t * (3 - 2 * t)
103
+ }
104
+ export const clamp = (x: number, a: number, b: number): number =>
105
+ Math.min(b, Math.max(a, x))
106
+ export const lerp = (a: number, b: number, t: number): number => a + (b - a) * t
@@ -0,0 +1,47 @@
1
+ /* oxlint-disable import/group-exports, no-magic-numbers -- verbatim port of the engine's law (SDK-SPLIT SP4); golden vectors pin it, so it keeps the engine's form */
2
+ /** SDK-SPLIT SP4f1 (Q35): the road's key light (`ROAD_SKY`, from engine `client/game/grid/frameModel.ts`) and the far
3
+ * cliffs' light floor (`FAR_CLIFF_FLOOR`, from `client/game/grid/farView.ts`): the far impostor bake lights like the engine. */
4
+ /**
5
+ * G165 (Jake: "A, road light over everything") and G242 (Jake's pick B, "grid dawn", `art/grid/round-26-road-sky/B-grid-dawn.jpg`):
6
+ * the road's own sky and key light, which replace the page's while the player is on the road (`roadSky.ts`). One shader
7
+ * dome, no textures: a dawn gradient (a peach horizon, a lavender band, a clear blue zenith), a thin cyan horizon line and a
8
+ * faint cyan grid round the horizon echoing the HUD and the VR void; a low warm dawn sun. Colours are linear RGB.
9
+ * - `air`: the road's air (the frame's fog colour on the road, which the far proxies haze into) and the dome's horizon;
10
+ * - `mid` / `zenith`: the dome's lavender band and its zenith;
11
+ * - `line` / `grid`: the cyan horizon line and grid, `gridStrength` the grid's opacity at the horizon;
12
+ * - `void`: G630, the blue-violet past the grid floor (the dome below the horizon, the grid page's background), on the road
13
+ * and with a cell entered alike (the shipped 10-13 hero's);
14
+ * - `sun`: the key light (compass degrees, its colour, its intensity) and the glow it puts in the dome;
15
+ * - `hemi`, `env`, `fogSun`: the fill, the environment's intensity and the fog's in-scatter colour under it.
16
+ */
17
+ export const ROAD_SKY = {
18
+ air: [0.95, 0.56, 0.44] as const,
19
+ mid: [0.58, 0.46, 0.8] as const,
20
+ zenith: [0.1, 0.24, 0.72] as const,
21
+ line: [0.25, 1.1, 1.4] as const,
22
+ grid: [0.3, 0.85, 1.1] as const,
23
+ gridStrength: 0.3,
24
+ void: [0.17, 0.17, 0.27] as const,
25
+ sun: {
26
+ azimuth: 70,
27
+ elevation: 13,
28
+ colour: [1, 0.8, 0.66] as const,
29
+ intensity: 2.4,
30
+ glow: [1, 0.62, 0.42] as const,
31
+ },
32
+ hemi: {
33
+ sky: [0.6, 0.62, 0.86] as const,
34
+ ground: [0.42, 0.36, 0.34] as const,
35
+ intensity: 1.1,
36
+ },
37
+ env: 0.7,
38
+ fogSun: [1, 0.72, 0.56] as const,
39
+ } as const
40
+
41
+ /**
42
+ * Playtest round 2: the light floor of the boundary face, as a multiple of its rock colour added after lighting. A face that
43
+ * turns away from the frame's sun got no light at all under a frame without an ambient term (any page where no admitted
44
+ * shard brings its sky light), so every shaded cliff drew as a pitch-black 100 m slab beside the road; with the floor a
45
+ * shaded face is the rock's own colour dimmed (×0.8) and a sunlit one only slightly brighter than before.
46
+ */
47
+ export const FAR_CLIFF_FLOOR = 0.8