@wildshard/shard-format 0.8.0 → 0.10.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.
- package/package.json +2 -1
- package/src/format/look-light.ts +23 -11
- package/src/format/look-swing.ts +96 -0
- package/src/format/materialFamilies.ts +11 -7
- package/src/format/outputIndex.ts +5 -4
- package/src/format/scene-render.ts +12 -0
- package/src/format/shardSchema.ts +6 -5
- package/src/format/shardSections.ts +5 -4
- package/src/format/stateLineage.ts +2 -2
- package/src/format/version.ts +80 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -249,6 +249,7 @@
|
|
|
249
249
|
"./postStack": "./src/format/postStack.ts",
|
|
250
250
|
"./look-details": "./src/format/look-details.ts",
|
|
251
251
|
"./look-light": "./src/format/look-light.ts",
|
|
252
|
+
"./look-swing": "./src/format/look-swing.ts",
|
|
252
253
|
"./look-render": "./src/format/look-render.ts",
|
|
253
254
|
"./pool-surface": "./src/format/pool-surface.ts",
|
|
254
255
|
"./practiceCourseRows": "./src/format/practiceCourseRows.ts",
|
package/src/format/look-light.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* `at` in linear `colour` × `intensity` (candela), out to `distance` metres with physical (2) decay, no shadow.
|
|
14
14
|
* - `bounce` (B2): a warm fill from the ground: one shadowless directional light from the anti-sun heading, lifted
|
|
15
15
|
* by `lift` (0 level, 1 straight up), in linear `colour` × `intensity`.
|
|
16
|
+
* - `swings` (SHARD-SOURCE SS8b): hanging bodies a lamp's `swing` names, so its light swings too (`look-swing.ts`).
|
|
16
17
|
* - `environment` (B2): sky-derived ambient: an environment filtered once from the look's own sky (its keys' zenith
|
|
17
18
|
* and horizon) over a `ground` colour (linear), lighting every PBR surface at `intensity`.
|
|
18
19
|
*
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
*/
|
|
28
29
|
import {
|
|
29
30
|
array,
|
|
31
|
+
check,
|
|
30
32
|
exactOptional,
|
|
31
33
|
finite,
|
|
32
34
|
maxLength,
|
|
@@ -49,6 +51,7 @@ import {
|
|
|
49
51
|
lampFlicker,
|
|
50
52
|
lampHalo,
|
|
51
53
|
} from './look-render.ts'
|
|
54
|
+
import { LookSwingsSchema, swingNumber, swingsDeclared } from './look-swing.ts'
|
|
52
55
|
|
|
53
56
|
import type {
|
|
54
57
|
LookLampFlicker,
|
|
@@ -56,6 +59,7 @@ import type {
|
|
|
56
59
|
LookMotes,
|
|
57
60
|
LookShadow,
|
|
58
61
|
} from './look-render.ts'
|
|
62
|
+
import type { LookSwing } from './look-swing.ts'
|
|
59
63
|
import type { GenericSchema } from 'valibot'
|
|
60
64
|
|
|
61
65
|
type Rgb = [number, number, number]
|
|
@@ -130,6 +134,8 @@ interface LookLamp {
|
|
|
130
134
|
decay?: number
|
|
131
135
|
halo?: LookLampHalo
|
|
132
136
|
flicker?: LookLampFlicker
|
|
137
|
+
/** SS8b: the number of the `swings` row it hangs from */
|
|
138
|
+
swing?: number
|
|
133
139
|
}
|
|
134
140
|
/** A warm fill from the ground: a shadowless directional light from the anti-sun heading, lifted by `lift`. */
|
|
135
141
|
interface LookBounce {
|
|
@@ -149,6 +155,7 @@ interface LookLight {
|
|
|
149
155
|
heightFog?: LookHeightFog
|
|
150
156
|
pools?: LookPools
|
|
151
157
|
lamps?: LookLamp[]
|
|
158
|
+
swings?: LookSwing[]
|
|
152
159
|
bounce?: LookBounce
|
|
153
160
|
environment?: LookEnvironment
|
|
154
161
|
shadow?: LookShadow
|
|
@@ -215,6 +222,7 @@ const LookLampSchema: GenericSchema<LookLamp, LookLamp> = strictObject({
|
|
|
215
222
|
decay: lampDecay,
|
|
216
223
|
halo: lampHalo,
|
|
217
224
|
flicker: lampFlicker,
|
|
225
|
+
swing: exactOptional(swingNumber),
|
|
218
226
|
})
|
|
219
227
|
const LookLampsSchema: GenericSchema<LookLamp[], LookLamp[]> = pipe(
|
|
220
228
|
array(LookLampSchema),
|
|
@@ -232,17 +240,21 @@ const LookEnvironmentSchema: GenericSchema<LookEnvironment, LookEnvironment> =
|
|
|
232
240
|
ground: colour,
|
|
233
241
|
})
|
|
234
242
|
/** `look.light`: the optional light and post settings. */
|
|
235
|
-
const LookLightSchema: GenericSchema<LookLight, LookLight> =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
const LookLightSchema: GenericSchema<LookLight, LookLight> = pipe(
|
|
244
|
+
strictObject({
|
|
245
|
+
ao: exactOptional(LookAoSchema),
|
|
246
|
+
rim: exactOptional(LookRimSchema),
|
|
247
|
+
heightFog: exactOptional(LookHeightFogSchema),
|
|
248
|
+
pools: exactOptional(LookPoolsSchema),
|
|
249
|
+
lamps: exactOptional(LookLampsSchema),
|
|
250
|
+
swings: exactOptional(LookSwingsSchema),
|
|
251
|
+
bounce: exactOptional(LookBounceSchema),
|
|
252
|
+
environment: exactOptional(LookEnvironmentSchema),
|
|
253
|
+
shadow: exactOptional(LookShadowSchema),
|
|
254
|
+
motes: exactOptional(LookMotesSchema),
|
|
255
|
+
}),
|
|
256
|
+
check<LookLight, string>(swingsDeclared, 'A lamp on an undeclared swing'),
|
|
257
|
+
)
|
|
246
258
|
/** `look.grade.tone`: absent is AgX, as before. */
|
|
247
259
|
const LookToneSchema: GenericSchema<LookTone, LookTone> = picklist([
|
|
248
260
|
'agx',
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `look.light.swings` (meta SHARD-SOURCE SS8b): bodies that hang and swing (a lantern on its rope, a sign, a banner), at
|
|
3
|
+
* most `LOOK_SWINGS_MAX`. Each hangs from `pivot` with its body `length` metres below, swings at about `rate` hertz, leans
|
|
4
|
+
* up to `amount` radians in a gust, and swings when a player or creature comes within `reach` metres of its body (0
|
|
5
|
+
* never). A surface's `_SWING` channel (`scene-render.ts`) and a lamp's `swing` name a row by number, so the lamp's light
|
|
6
|
+
* turns with its lantern round the same pivot.
|
|
7
|
+
*
|
|
8
|
+
* Plain data and checks, no three.js.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
array,
|
|
12
|
+
finite,
|
|
13
|
+
integer,
|
|
14
|
+
maxLength,
|
|
15
|
+
maxValue,
|
|
16
|
+
minLength,
|
|
17
|
+
minValue,
|
|
18
|
+
number,
|
|
19
|
+
pipe,
|
|
20
|
+
strictObject,
|
|
21
|
+
tuple,
|
|
22
|
+
} from 'valibot'
|
|
23
|
+
|
|
24
|
+
import type { GenericSchema } from 'valibot'
|
|
25
|
+
|
|
26
|
+
type Point = [number, number, number]
|
|
27
|
+
|
|
28
|
+
/** At most this many swings in one look (one uniform array on every swinging draw, phones included). */
|
|
29
|
+
const LOOK_SWINGS_MAX = 32
|
|
30
|
+
const NONE = 0
|
|
31
|
+
const ONE = 1
|
|
32
|
+
const LENGTH_MIN = 0.05
|
|
33
|
+
const LENGTH_MAX = 10
|
|
34
|
+
const RATE_MIN = 0.05
|
|
35
|
+
const RATE_MAX = 4
|
|
36
|
+
const AMOUNT_MAX = 0.6
|
|
37
|
+
const REACH_MAX = 3
|
|
38
|
+
|
|
39
|
+
/** A hanging body: its pivot, body length, swing rate (hertz), gust lean (radians) and bump reach (metres). */
|
|
40
|
+
interface LookSwing {
|
|
41
|
+
pivot: Point
|
|
42
|
+
length: number
|
|
43
|
+
rate: number
|
|
44
|
+
amount: number
|
|
45
|
+
reach: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const real = pipe(number(), finite())
|
|
49
|
+
const range = (low: number, high: number): GenericSchema<number, number> =>
|
|
50
|
+
pipe(real, minValue(low), maxValue(high))
|
|
51
|
+
|
|
52
|
+
const LookSwingSchema: GenericSchema<LookSwing, LookSwing> = strictObject({
|
|
53
|
+
pivot: tuple([real, real, real]),
|
|
54
|
+
length: range(LENGTH_MIN, LENGTH_MAX),
|
|
55
|
+
rate: range(RATE_MIN, RATE_MAX),
|
|
56
|
+
amount: range(NONE, AMOUNT_MAX),
|
|
57
|
+
reach: range(NONE, REACH_MAX),
|
|
58
|
+
})
|
|
59
|
+
const LookSwingsSchema: GenericSchema<LookSwing[], LookSwing[]> = pipe(
|
|
60
|
+
array(LookSwingSchema),
|
|
61
|
+
minLength(ONE),
|
|
62
|
+
maxLength(LOOK_SWINGS_MAX),
|
|
63
|
+
)
|
|
64
|
+
/** A lamp's `swing`: the number of the row it hangs from. */
|
|
65
|
+
const swingNumber: GenericSchema<number, number> = pipe(
|
|
66
|
+
real,
|
|
67
|
+
integer(),
|
|
68
|
+
minValue(NONE),
|
|
69
|
+
maxValue(LOOK_SWINGS_MAX - ONE),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
/** What `swingsDeclared` reads of a `look.light`. */
|
|
73
|
+
interface SwingRefs {
|
|
74
|
+
readonly lamps?: readonly { readonly swing?: number }[] | undefined
|
|
75
|
+
readonly swings?: readonly unknown[] | undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Every lamp's `swing` names a declared swing. */
|
|
79
|
+
function swingsDeclared(light: SwingRefs): boolean {
|
|
80
|
+
const declared = light.swings?.length ?? NONE
|
|
81
|
+
for (const lamp of light.lamps ?? []) {
|
|
82
|
+
if (lamp.swing !== undefined && lamp.swing >= declared) {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
LOOK_SWINGS_MAX,
|
|
91
|
+
LookSwingSchema,
|
|
92
|
+
LookSwingsSchema,
|
|
93
|
+
swingNumber,
|
|
94
|
+
swingsDeclared,
|
|
95
|
+
}
|
|
96
|
+
export type { LookSwing, SwingRefs }
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { detailLayer } from './detail-layer.ts';
|
|
19
19
|
import type { DetailLayer } from './detail-layer.ts';
|
|
20
20
|
import { pbrEmissive, pbrEmissiveIntensity } from './pbr-emissive.ts';
|
|
21
|
-
import { emissiveCard, emissiveMotion, surfaceBlend, surfaceDepthOffset, surfaceOpacity, surfaceSway, surfaceUvScroll } from './scene-render.ts';
|
|
21
|
+
import { emissiveCard, emissiveMotion, surfaceBlend, surfaceDepthOffset, surfaceOpacity, surfaceSway, surfaceSwing, surfaceUvScroll } from './scene-render.ts';
|
|
22
22
|
import type { CardMotion, SurfaceSway } from './scene-render.ts';
|
|
23
23
|
import * as v from 'valibot';
|
|
24
24
|
|
|
@@ -212,7 +212,7 @@ export function measureUv(role: MeasureRole, u: number, up: number, w: number, h
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/** One PBR surface: metal / rough with colour, normal and packed ORM maps (occlusion r, roughness g, metalness b). */
|
|
215
|
-
export const PbrMaterialSchema: v.StrictObjectSchema<{ readonly family: v.GenericSchema<PbrMaterialParamsInput['family'], PbrMaterialParams['family']>; readonly colour: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['colour'], undefined>, PbrMaterialParams['colour']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['colour'], undefined>>>; readonly roughness: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['roughness'], undefined>, PbrMaterialParams['roughness']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['roughness'], undefined>>>; readonly metalness: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['metalness'], undefined>, PbrMaterialParams['metalness']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['metalness'], undefined>>>; readonly maps: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['maps'], undefined>, PbrMaterialParams['maps']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['maps'], undefined>>>; readonly normalScale: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['normalScale'], undefined>, PbrMaterialParams['normalScale']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['normalScale'], undefined>>>; readonly occlusion: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['occlusion'], undefined>, PbrMaterialParams['occlusion']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['occlusion'], undefined>>>; readonly envStrength: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['envStrength'], undefined>, PbrMaterialParams['envStrength']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['envStrength'], undefined>>>; readonly vertexColours: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['vertexColours'], undefined>, PbrMaterialParams['vertexColours']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['vertexColours'], undefined>>>; readonly faceted: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['faceted'], undefined>, PbrMaterialParams['faceted']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['faceted'], undefined>>>; readonly doubleSided: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['doubleSided'], undefined>, PbrMaterialParams['doubleSided']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['doubleSided'], undefined>>>; readonly alphaCutoff: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['alphaCutoff'], undefined>, PbrMaterialParams['alphaCutoff']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['alphaCutoff'], undefined>>>; readonly ground: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['ground'], undefined>, PbrMaterialParams['ground']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['ground'], undefined>>>; readonly measure: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['measure'], undefined>, PbrMaterialParams['measure']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['measure'], undefined>>>; readonly detail: typeof detailLayer; readonly emissive: typeof pbrEmissive; readonly emissiveIntensity: typeof pbrEmissiveIntensity; readonly blend: typeof surfaceBlend; readonly opacity: typeof surfaceOpacity; readonly depthOffset: typeof surfaceDepthOffset; readonly sway: typeof surfaceSway; readonly uvScroll: typeof surfaceUvScroll; }, undefined> = v.strictObject({
|
|
215
|
+
export const PbrMaterialSchema: v.StrictObjectSchema<{ readonly family: v.GenericSchema<PbrMaterialParamsInput['family'], PbrMaterialParams['family']>; readonly colour: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['colour'], undefined>, PbrMaterialParams['colour']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['colour'], undefined>>>; readonly roughness: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['roughness'], undefined>, PbrMaterialParams['roughness']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['roughness'], undefined>>>; readonly metalness: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['metalness'], undefined>, PbrMaterialParams['metalness']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['metalness'], undefined>>>; readonly maps: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['maps'], undefined>, PbrMaterialParams['maps']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['maps'], undefined>>>; readonly normalScale: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['normalScale'], undefined>, PbrMaterialParams['normalScale']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['normalScale'], undefined>>>; readonly occlusion: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['occlusion'], undefined>, PbrMaterialParams['occlusion']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['occlusion'], undefined>>>; readonly envStrength: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['envStrength'], undefined>, PbrMaterialParams['envStrength']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['envStrength'], undefined>>>; readonly vertexColours: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['vertexColours'], undefined>, PbrMaterialParams['vertexColours']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['vertexColours'], undefined>>>; readonly faceted: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['faceted'], undefined>, PbrMaterialParams['faceted']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['faceted'], undefined>>>; readonly doubleSided: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['doubleSided'], undefined>, PbrMaterialParams['doubleSided']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['doubleSided'], undefined>>>; readonly alphaCutoff: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['alphaCutoff'], undefined>, PbrMaterialParams['alphaCutoff']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['alphaCutoff'], undefined>>>; readonly ground: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['ground'], undefined>, PbrMaterialParams['ground']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['ground'], undefined>>>; readonly measure: v.OptionalSchema<v.GenericSchema<Exclude<PbrMaterialParamsInput['measure'], undefined>, PbrMaterialParams['measure']>, MaterialSchemaDefault<Exclude<PbrMaterialParamsInput['measure'], undefined>>>; readonly detail: typeof detailLayer; readonly emissive: typeof pbrEmissive; readonly emissiveIntensity: typeof pbrEmissiveIntensity; readonly blend: typeof surfaceBlend; readonly opacity: typeof surfaceOpacity; readonly depthOffset: typeof surfaceDepthOffset; readonly sway: typeof surfaceSway; readonly uvScroll: typeof surfaceUvScroll; readonly swing: typeof surfaceSwing; }, undefined> = v.strictObject({
|
|
216
216
|
family: v.literal('pbr'),
|
|
217
217
|
/** sRGB, multiplies the colour map */
|
|
218
218
|
colour: v.optional(srgb, [1, 1, 1]),
|
|
@@ -252,6 +252,8 @@ export const PbrMaterialSchema: v.StrictObjectSchema<{ readonly family: v.Generi
|
|
|
252
252
|
sway: surfaceSway,
|
|
253
253
|
/** AP12: the colour map's uv scroll (units a second); absent = still */
|
|
254
254
|
uvScroll: surfaceUvScroll,
|
|
255
|
+
/** SS8b: a hanging body, its swing per vertex in the `_SWING` channel; absent = rigid */
|
|
256
|
+
swing: surfaceSwing,
|
|
255
257
|
});
|
|
256
258
|
/** A PBR material entry with every default filled. */
|
|
257
259
|
|
|
@@ -462,7 +464,7 @@ export const SkyDomeSchema: v.GenericSchema<SkyDomeParamsInput, SkyDomeParams> =
|
|
|
462
464
|
* One emissive surface: unlit light. `colour` × `intensity` (HDR) × the vertex colours × an optional map, flickering by a
|
|
463
465
|
* seed, fogged at a share of the fog. With `tube` it draws a neon glyph from a distance field; with `sky`, a sky dome.
|
|
464
466
|
*/
|
|
465
|
-
export const EmissiveMaterialSchema: v.StrictObjectSchema<{ readonly family: v.GenericSchema<EmissiveMaterialParamsInput['family'], EmissiveMaterialParams['family']>; readonly colour: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['colour'], undefined>, EmissiveMaterialParams['colour']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['colour'], undefined>>>; readonly intensity: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['intensity'], undefined>, EmissiveMaterialParams['intensity']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['intensity'], undefined>>>; readonly vertexColours: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['vertexColours'], undefined>, EmissiveMaterialParams['vertexColours']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['vertexColours'], undefined>>>; readonly map: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['map'], undefined>, EmissiveMaterialParams['map']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['map'], undefined>>>; readonly blend: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['blend'], undefined>, EmissiveMaterialParams['blend']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['blend'], undefined>>>; readonly doubleSided: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['doubleSided'], undefined>, EmissiveMaterialParams['doubleSided']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['doubleSided'], undefined>>>; readonly fog: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['fog'], undefined>, EmissiveMaterialParams['fog']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['fog'], undefined>>>; readonly flicker: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['flicker'], undefined>, EmissiveMaterialParams['flicker']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['flicker'], undefined>>>; readonly tube: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['tube'], undefined>, EmissiveMaterialParams['tube']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['tube'], undefined>>>; readonly sky: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['sky'], undefined>, EmissiveMaterialParams['sky']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['sky'], undefined>>>; readonly card: typeof emissiveCard; readonly motion: typeof emissiveMotion; }, undefined> = v.strictObject({
|
|
467
|
+
export const EmissiveMaterialSchema: v.StrictObjectSchema<{ readonly family: v.GenericSchema<EmissiveMaterialParamsInput['family'], EmissiveMaterialParams['family']>; readonly colour: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['colour'], undefined>, EmissiveMaterialParams['colour']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['colour'], undefined>>>; readonly intensity: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['intensity'], undefined>, EmissiveMaterialParams['intensity']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['intensity'], undefined>>>; readonly vertexColours: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['vertexColours'], undefined>, EmissiveMaterialParams['vertexColours']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['vertexColours'], undefined>>>; readonly map: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['map'], undefined>, EmissiveMaterialParams['map']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['map'], undefined>>>; readonly blend: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['blend'], undefined>, EmissiveMaterialParams['blend']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['blend'], undefined>>>; readonly doubleSided: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['doubleSided'], undefined>, EmissiveMaterialParams['doubleSided']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['doubleSided'], undefined>>>; readonly fog: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['fog'], undefined>, EmissiveMaterialParams['fog']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['fog'], undefined>>>; readonly flicker: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['flicker'], undefined>, EmissiveMaterialParams['flicker']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['flicker'], undefined>>>; readonly tube: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['tube'], undefined>, EmissiveMaterialParams['tube']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['tube'], undefined>>>; readonly sky: v.OptionalSchema<v.GenericSchema<Exclude<EmissiveMaterialParamsInput['sky'], undefined>, EmissiveMaterialParams['sky']>, MaterialSchemaDefault<Exclude<EmissiveMaterialParamsInput['sky'], undefined>>>; readonly card: typeof emissiveCard; readonly motion: typeof emissiveMotion; readonly swing: typeof surfaceSwing; }, undefined> = v.strictObject({
|
|
466
468
|
family: v.literal('emissive'),
|
|
467
469
|
/** sRGB tint */
|
|
468
470
|
colour: v.optional(srgb, [1, 1, 1]),
|
|
@@ -485,6 +487,8 @@ export const EmissiveMaterialSchema: v.StrictObjectSchema<{ readonly family: v.G
|
|
|
485
487
|
card: emissiveCard,
|
|
486
488
|
/** AP12: a card's declared motion (pulse, drift, rise); absent = still */
|
|
487
489
|
motion: emissiveMotion,
|
|
490
|
+
/** SS8b: a hanging card or surface, its swing per vertex in the `_SWING` channel; absent = still */
|
|
491
|
+
swing: surfaceSwing,
|
|
488
492
|
});
|
|
489
493
|
/** An emissive material entry with every default filled. */
|
|
490
494
|
|
|
@@ -566,9 +570,9 @@ export interface GroundLayerParamsInput { wind?: [number, number] | undefined; w
|
|
|
566
570
|
export interface GroundLayerParams { wind: [number, number]; wavelength: [number, number]; lump: number; depth: [number, number]; relief: [number, number, number]; contrast: { near: number; far: number; window: [number, number]; strength: number; }; fade: [number, number]; slip: [number, number]; flat: [number, number]; patches: { floor: number; near: number; window: [number, number]; }; grain: { map: (string) | null; mean: number; glintMean: number; strength: number; }; macro: [[number, number, number], [number, number, number]]; albedo: number; streaks: { tint: [number, number, number]; amount: number; }; trail: ({ map: string; rect: [number, number, number, number]; ripples: number; tint: [number, number, number]; amount: number; }) | null; keyShadow: ({ map: string; rect: [number, number, number, number]; edge: [number, number]; floor: number; }) | null; terminator: number; crest: { band: [number, number]; gain: number; }; sheen: number; shade: { tint: [number, number, number]; gain: number; lift: [number, number, number]; amount: number; edge: number; floor: [number, number, number]; }; saturation: { flat: number; facing: number; coolTint: [number, number, number]; keep: number; }; away: { from: [number, number]; amount: number; }; pools: ({ low: [number, number, number]; high: [number, number, number]; split: number; radius: number; gain: number; source?: string; }) | null; }
|
|
567
571
|
export interface MeasureLayerParamsInput { structure?: [number, number, number] | undefined; trim?: [number, number, number] | undefined; floor?: [number, number, number] | undefined; line?: { colour: [number, number, number]; alpha: number; floorAlpha: number; width: number; } | undefined; sub?: { step: number; alpha: number; } | undefined; label?: { colour: [number, number, number]; height: number; } | undefined; lift?: number | undefined; tint?: [number, number, number]; grain?: { amount: [number, number, number]; size: number; }; grid?: [number, number, number]; }
|
|
568
572
|
export interface MeasureLayerParams { structure: [number, number, number]; trim: [number, number, number]; floor: [number, number, number]; line: { colour: [number, number, number]; alpha: number; floorAlpha: number; width: number; }; sub: { step: number; alpha: number; }; label: { colour: [number, number, number]; height: number; }; lift: number; tint?: [number, number, number]; grain?: { amount: [number, number, number]; size: number; }; grid?: [number, number, number]; }
|
|
569
|
-
export interface PbrMaterialParamsInput { family: 'pbr'; colour?: [number, number, number] | undefined; roughness?: number | undefined; metalness?: number | undefined; maps?: { colour: (string) | null; normal: (string) | null; orm: (string) | null; } | undefined; normalScale?: number | undefined; occlusion?: number | undefined; envStrength?: number | undefined; vertexColours?: boolean | undefined; faceted?: boolean | undefined; doubleSided?: boolean | undefined; alphaCutoff?: number | undefined; ground?: (GroundLayerParamsInput) | null | undefined; measure?: (MeasureLayerParamsInput) | null | undefined; detail?: DetailLayer; emissive?: [number, number, number]; emissiveIntensity?: number; blend?: 'opaque' | 'alpha'; opacity?: number; depthOffset?: number; sway?: SurfaceSway; uvScroll?: [number, number]; }
|
|
573
|
+
export interface PbrMaterialParamsInput { family: 'pbr'; colour?: [number, number, number] | undefined; roughness?: number | undefined; metalness?: number | undefined; maps?: { colour: (string) | null; normal: (string) | null; orm: (string) | null; } | undefined; normalScale?: number | undefined; occlusion?: number | undefined; envStrength?: number | undefined; vertexColours?: boolean | undefined; faceted?: boolean | undefined; doubleSided?: boolean | undefined; alphaCutoff?: number | undefined; ground?: (GroundLayerParamsInput) | null | undefined; measure?: (MeasureLayerParamsInput) | null | undefined; detail?: DetailLayer; emissive?: [number, number, number]; emissiveIntensity?: number; blend?: 'opaque' | 'alpha'; opacity?: number; depthOffset?: number; sway?: SurfaceSway; uvScroll?: [number, number]; swing?: true; }
|
|
570
574
|
// oxlint-disable-next-line typescript/consistent-type-definitions -- Graph admission requires the material alias's implicit dictionary compatibility.
|
|
571
|
-
export type PbrMaterialParams = { family: 'pbr'; colour: [number, number, number]; roughness: number; metalness: number; maps: { colour: (string) | null; normal: (string) | null; orm: (string) | null; }; normalScale: number; occlusion: number; envStrength: number; vertexColours: boolean; faceted: boolean; doubleSided: boolean; alphaCutoff: number; ground: (GroundLayerParams) | null; measure: (MeasureLayerParams) | null; detail?: DetailLayer; emissive?: [number, number, number]; emissiveIntensity?: number; blend?: 'opaque' | 'alpha'; opacity?: number; depthOffset?: number; sway?: SurfaceSway; uvScroll?: [number, number]; };
|
|
575
|
+
export type PbrMaterialParams = { family: 'pbr'; colour: [number, number, number]; roughness: number; metalness: number; maps: { colour: (string) | null; normal: (string) | null; orm: (string) | null; }; normalScale: number; occlusion: number; envStrength: number; vertexColours: boolean; faceted: boolean; doubleSided: boolean; alphaCutoff: number; ground: (GroundLayerParams) | null; measure: (MeasureLayerParams) | null; detail?: DetailLayer; emissive?: [number, number, number]; emissiveIntensity?: number; blend?: 'opaque' | 'alpha'; opacity?: number; depthOffset?: number; sway?: SurfaceSway; uvScroll?: [number, number]; swing?: true; };
|
|
572
576
|
export interface GradeParamsInput { exposure?: number | undefined; gain?: number | undefined; shoulder?: number | undefined; saturation?: number | undefined; shadowTint?: [number, number, number] | undefined; lightTint?: [number, number, number] | undefined; split?: [number, number] | undefined; contrast?: number | undefined; lookSaturation?: number | undefined; }
|
|
573
577
|
export interface GradeParams { exposure: number; gain: number; shoulder: number; saturation: number; shadowTint: [number, number, number]; lightTint: [number, number, number]; split: [number, number]; contrast: number; lookSaturation: number; }
|
|
574
578
|
export interface PainterlyLookParamsInput { shade?: [number, number, number] | undefined; rim?: [number, number, number] | undefined; warm?: number | undefined; floor?: number | undefined; wet?: number | undefined; wind?: { direction: [number, number]; strength: number; } | undefined; grade?: (GradeParamsInput) | null | undefined; }
|
|
@@ -584,8 +588,8 @@ export interface NeonTubeParamsInput { field: string; fillSpread: number; skelet
|
|
|
584
588
|
export interface NeonTubeParams { field: string; fillSpread: number; skeletonSpread: number; mono: number; radius: number; rim: number; thicken: number; seam: number; seamWidth: number; haloReach: number; haloGain: number; core: number; rimShade: number; cell: ([number, number]) | null; }
|
|
585
589
|
export interface SkyDomeParamsInput { maps: [string, (string) | null]; elevation?: [number, number] | undefined; window?: [number, number] | undefined; firstGain?: [number, number] | undefined; hold?: number | undefined; stars?: { density: number; gain: number; elevation: [number, number]; appear: [number, number]; } | undefined; dither?: number | undefined; }
|
|
586
590
|
export interface SkyDomeParams { maps: [string, (string) | null]; elevation: [number, number]; window: [number, number]; firstGain: [number, number]; hold: number; stars: { density: number; gain: number; elevation: [number, number]; appear: [number, number]; }; dither: number; }
|
|
587
|
-
export interface EmissiveMaterialParamsInput { family: 'emissive'; colour?: [number, number, number] | undefined; intensity?: number | undefined; vertexColours?: boolean | undefined; map?: (string) | null | undefined; blend?: 'opaque' | 'additive' | 'alpha' | undefined; doubleSided?: boolean | undefined; fog?: number | undefined; flicker?: number | undefined; tube?: (NeonTubeParamsInput) | null | undefined; sky?: (SkyDomeParamsInput) | null | undefined; card?: true; motion?: CardMotion; }
|
|
591
|
+
export interface EmissiveMaterialParamsInput { family: 'emissive'; colour?: [number, number, number] | undefined; intensity?: number | undefined; vertexColours?: boolean | undefined; map?: (string) | null | undefined; blend?: 'opaque' | 'additive' | 'alpha' | undefined; doubleSided?: boolean | undefined; fog?: number | undefined; flicker?: number | undefined; tube?: (NeonTubeParamsInput) | null | undefined; sky?: (SkyDomeParamsInput) | null | undefined; card?: true; motion?: CardMotion; swing?: true; }
|
|
588
592
|
// oxlint-disable-next-line typescript/consistent-type-definitions -- Graph admission requires the material alias's implicit dictionary compatibility.
|
|
589
|
-
export type EmissiveMaterialParams = { family: 'emissive'; colour: [number, number, number]; intensity: number; vertexColours: boolean; map: (string) | null; blend: 'opaque' | 'additive' | 'alpha'; doubleSided: boolean; fog: number; flicker: number; tube: (NeonTubeParams) | null; sky: (SkyDomeParams) | null; card?: true; motion?: CardMotion; };
|
|
593
|
+
export type EmissiveMaterialParams = { family: 'emissive'; colour: [number, number, number]; intensity: number; vertexColours: boolean; map: (string) | null; blend: 'opaque' | 'additive' | 'alpha'; doubleSided: boolean; fog: number; flicker: number; tube: (NeonTubeParams) | null; sky: (SkyDomeParams) | null; card?: true; motion?: CardMotion; swing?: true; };
|
|
590
594
|
export type FamilyMaterialParamsInput = (ToonMaterialParamsInput) | (PbrMaterialParamsInput) | (PainterlyMaterialParamsInput) | (EmissiveMaterialParamsInput);
|
|
591
595
|
export type FamilyMaterialParams = (ToonMaterialParams) | (PbrMaterialParams) | (PainterlyMaterialParams) | (EmissiveMaterialParams);
|
|
@@ -15,7 +15,8 @@ import { ClientPlanRuntimeSchema } from './runtime.ts';
|
|
|
15
15
|
import { RuntimeSpawnsSchema } from './runtimeSpawns.ts';
|
|
16
16
|
import { RowsSchema } from './rows.ts';
|
|
17
17
|
import { ShardHashSchema, ShardNaturalSchema, IdentitySchema, RequiresSchema, FilesSchema, type ShardIdentityInput, type ShardRequiresInput, type ShardReferencesInput, type ShardIdentity, type ShardRequires, type ShardReferences } from './shardSections.ts';
|
|
18
|
-
import {
|
|
18
|
+
import { SHARDFILE_VERSIONS } from './version.ts';
|
|
19
|
+
import type { ShardfileVersion } from './version.ts';
|
|
19
20
|
import { isJsonData, isJsonDataWithFileSchemas } from './json.ts';
|
|
20
21
|
import { clientOwnershipRules } from './clientOwnership.ts';
|
|
21
22
|
import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts';
|
|
@@ -31,7 +32,7 @@ const fileSchema = v.strictObject({ ...costs, path, kind: v.picklist(['glb', 'kt
|
|
|
31
32
|
const runtime = v.strictObject({ ...v.omit(ClientPlanRuntimeSchema.pipe[0], ['spawns']).entries, trust: v.literal('first-party'), files: v.pipe(v.array(v.strictObject({ ...measuredFile, lines: ShardNaturalSchema })), v.maxLength(0)), lines: v.literal(0) });
|
|
32
33
|
/** Format 2 inventories every emitted byte except its index and validation receipt. */
|
|
33
34
|
export const OutputIndexSchema: v.GenericSchema<OutputIndexRowsInput, OutputIndexRows> & { readonly entries: { readonly [Key in keyof OutputIndexRows]-?: v.GenericSchema<OutputIndexRowsInput[Key], OutputIndexRows[Key]> } } = v.strictObject({
|
|
34
|
-
format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.picklist(['0.2', '0.3']), version: v.
|
|
35
|
+
format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.picklist(['0.2', '0.3']), version: v.picklist(SHARDFILE_VERSIONS),
|
|
35
36
|
identity: IdentitySchema, build: v.strictObject({ sourceHash: ShardHashSchema, validator: v.pipe(v.string(), v.minLength(1), v.maxLength(160)) }), requires: RequiresSchema,
|
|
36
37
|
admission: v.strictObject({ budgets: ShardfileFieldSchemas.budgets, serverBudget: ShardfileFieldSchemas.serverBudget, authorCaps: ShardfileFieldSchemas.authorCaps, critical: ShardfileFieldSchemas.critical, library: ShardfileFieldSchemas.library, late: v.exactOptional(AdmissionLateSchema), server: v.exactOptional(AdmissionServerSchema), audioWaiver: v.exactOptional(AudioWaiverSchema) }),
|
|
37
38
|
sections: v.pipe(v.array(section), v.maxLength(256)), schemas: v.pipe(v.array(v.strictObject(measuredFile)), v.maxLength(0)),
|
|
@@ -158,7 +159,7 @@ interface OutputIndexRowsInputFields {
|
|
|
158
159
|
format: "wildshard.shardfile";
|
|
159
160
|
formatVersion: 2;
|
|
160
161
|
sdk: "0.2" | "0.3";
|
|
161
|
-
version:
|
|
162
|
+
version: ShardfileVersion;
|
|
162
163
|
identity: ShardIdentityInput;
|
|
163
164
|
build: {
|
|
164
165
|
sourceHash: string;
|
|
@@ -256,7 +257,7 @@ interface OutputIndexRowsFields {
|
|
|
256
257
|
format: "wildshard.shardfile";
|
|
257
258
|
formatVersion: 2;
|
|
258
259
|
sdk: "0.2" | "0.3";
|
|
259
|
-
version:
|
|
260
|
+
version: ShardfileVersion;
|
|
260
261
|
identity: ShardIdentity;
|
|
261
262
|
build: {
|
|
262
263
|
sourceHash: string;
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* - `sway`: foliage in the wind. Each vertex moves by its `_SWAY` vertex channel (metres, one float: 0 at the root) along
|
|
12
12
|
* `direction` (x, z) at about `rate` hertz, its phase taken from where it stands.
|
|
13
13
|
* - `uvScroll`: the colour map's uv moves this many units a second (u, v): running water, drifting cloud shadow.
|
|
14
|
+
* - `swing: true` (meta SHARD-SOURCE SS8b, PBR and emissive): a hanging body. Each vertex's `_SWING` channel (one float)
|
|
15
|
+
* names the look's `look.light.swings` row it hangs from, plus one (0: it stays still); the engine turns the vertex
|
|
16
|
+
* (and a card's seat) round that swing's pivot by the swing's tilt each frame, the way a lamp, a sign or a banner hangs.
|
|
14
17
|
*
|
|
15
18
|
* Emissive family:
|
|
16
19
|
* - `blend: 'alpha'` (beside `opaque` and `additive`): an unlit card blended over what is behind it (a flame tongue).
|
|
@@ -132,6 +135,11 @@ const emissiveCard: ExactOptionalSchema<
|
|
|
132
135
|
GenericSchema<true, true>,
|
|
133
136
|
undefined
|
|
134
137
|
> = exactOptional(literal(true))
|
|
138
|
+
/** PBR and emissive `swing` (SS8b): the `_SWING` channel names each vertex's swing. */
|
|
139
|
+
const surfaceSwing: ExactOptionalSchema<
|
|
140
|
+
GenericSchema<true, true>,
|
|
141
|
+
undefined
|
|
142
|
+
> = exactOptional(literal(true))
|
|
135
143
|
/** Emissive `motion`. */
|
|
136
144
|
const emissiveMotion: ExactOptionalSchema<
|
|
137
145
|
GenericSchema<CardMotion, CardMotion>,
|
|
@@ -140,6 +148,8 @@ const emissiveMotion: ExactOptionalSchema<
|
|
|
140
148
|
|
|
141
149
|
/** The vertex channel a swaying surface reads (GLB application attribute `_SWAY`, one float, metres). */
|
|
142
150
|
const SWAY_CHANNEL = '_SWAY'
|
|
151
|
+
/** The vertex channel a swinging surface reads (GLB application attribute `_SWING`, one float: swing number + 1, 0 still). */
|
|
152
|
+
const SWING_CHANNEL = '_SWING'
|
|
143
153
|
/** The vertex channel a card reads (GLB application attribute `_CORNER`, two floats, metres in view space). */
|
|
144
154
|
const CORNER_CHANNEL = '_CORNER'
|
|
145
155
|
|
|
@@ -147,6 +157,7 @@ export {
|
|
|
147
157
|
CORNER_CHANNEL,
|
|
148
158
|
CardMotionSchema,
|
|
149
159
|
SWAY_CHANNEL,
|
|
160
|
+
SWING_CHANNEL,
|
|
150
161
|
SurfaceSwaySchema,
|
|
151
162
|
UvScrollSchema,
|
|
152
163
|
emissiveCard,
|
|
@@ -155,6 +166,7 @@ export {
|
|
|
155
166
|
surfaceDepthOffset,
|
|
156
167
|
surfaceOpacity,
|
|
157
168
|
surfaceSway,
|
|
169
|
+
surfaceSwing,
|
|
158
170
|
surfaceUvScroll,
|
|
159
171
|
}
|
|
160
172
|
export type { CardMotion, SurfaceSway }
|
|
@@ -13,7 +13,8 @@ import { jsonDataNodes } from './json.ts';
|
|
|
13
13
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
14
14
|
import { preflightShardfile } from './preflight.ts';
|
|
15
15
|
import { preflightAssetGraph } from './shardfile-assets.ts';
|
|
16
|
-
import {
|
|
16
|
+
import { SHARDFILE_VERSIONS } from './version.ts';
|
|
17
|
+
import type { ShardfileVersion } from './version.ts';
|
|
17
18
|
import { UiSchema, uiRules } from './ui.ts';
|
|
18
19
|
import { scriptBindingRules } from './scripts.ts';
|
|
19
20
|
import { RowsSchema } from './rows.ts';
|
|
@@ -75,7 +76,7 @@ const lookGrade = v.strictObject({ exposure: finite, saturation: v.pipe(finite,
|
|
|
75
76
|
/** A colour LUT file's exact wire size: 33³ RGBA8 (the engine's render/lut format). */
|
|
76
77
|
export const LOOK_LUT_BYTES: number = 33 ** 3 * 4;
|
|
77
78
|
const rawSchema: v.GenericSchema<ShardfileRowsInput, ShardfileRows> & { readonly entries: { readonly [Key in keyof ShardfileRows]-?: v.GenericSchema<ShardfileRowsInput[Key], ShardfileRows[Key]> } } = v.strictObject({
|
|
78
|
-
version: v.
|
|
79
|
+
version: v.picklist(SHARDFILE_VERSIONS),
|
|
79
80
|
accent: AccentSchema,
|
|
80
81
|
identity: IdentitySchema,
|
|
81
82
|
presentation: v.exactOptional(PresentationSchema),
|
|
@@ -132,7 +133,7 @@ export const ShardfileFieldSchemas: { readonly [Key in keyof Shardfile]-?: v.Gen
|
|
|
132
133
|
/** Public parsed output, independently named by section. The unchanged schema
|
|
133
134
|
* is checked against this interface, so consumers need not expand its input tree. */
|
|
134
135
|
export interface Shardfile {
|
|
135
|
-
version:
|
|
136
|
+
version: ShardfileVersion;
|
|
136
137
|
accent: v.InferOutput<typeof AccentSchema>;
|
|
137
138
|
identity: v.InferOutput<typeof IdentitySchema>;
|
|
138
139
|
presentation?: v.InferOutput<typeof PresentationSchema>;
|
|
@@ -398,7 +399,7 @@ export { parseShardfile, parseShardfileField };
|
|
|
398
399
|
|
|
399
400
|
/** Admitted data contracts, independent of validator implementation metadata. */
|
|
400
401
|
interface ShardfileRowsInputFields {
|
|
401
|
-
version:
|
|
402
|
+
version: ShardfileVersion;
|
|
402
403
|
accent: v.InferInput<typeof AccentSchema>;
|
|
403
404
|
identity: v.InferInput<typeof IdentitySchema>;
|
|
404
405
|
presentation?: v.InferInput<typeof PresentationSchema>;
|
|
@@ -476,7 +477,7 @@ interface ShardfileRowsInputFields {
|
|
|
476
477
|
}
|
|
477
478
|
export type ShardfileRowsInput = { [Key in keyof ShardfileRowsInputFields]: ShardfileRowsInputFields[Key] };
|
|
478
479
|
interface ShardfileRowsFields {
|
|
479
|
-
version:
|
|
480
|
+
version: ShardfileVersion;
|
|
480
481
|
accent: v.InferOutput<typeof AccentSchema>;
|
|
481
482
|
identity: v.InferOutput<typeof IdentitySchema>;
|
|
482
483
|
presentation?: v.InferOutput<typeof PresentationSchema>;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import * as v from 'valibot';
|
|
4
4
|
import { WIRE_CELL, WIRE_TILE_SIZES } from './wireLimits.ts';
|
|
5
5
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
6
|
-
import {
|
|
6
|
+
import { SHARDFILE_VERSIONS } from './version.ts';
|
|
7
|
+
import type { ShardfileVersion } from './version.ts';
|
|
7
8
|
import { RuntimeCostSchema } from './runtimeCost.ts';
|
|
8
9
|
import { CommonsCostsSchema } from './commonsCosts.ts';
|
|
9
10
|
import { ScriptBindingsSchema } from './scripts.ts';
|
|
@@ -35,7 +36,7 @@ const tileCount = (2 * CHUNK_HALF / WIRE_TILE_SIZES.l0) ** 2 + (2 * CHUNK_HALF /
|
|
|
35
36
|
/** Stable authored shard identity and deterministic seed. */
|
|
36
37
|
export const IdentitySchema: v.GenericSchema<ShardIdentityInput, ShardIdentity> = v.strictObject({ slug: name, name: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), author: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), revision: positive, seed: ShardNaturalSchema });
|
|
37
38
|
/** Wire revision, capabilities and exact commons declarations. */
|
|
38
|
-
export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.
|
|
39
|
+
export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.picklist(SHARDFILE_VERSIONS), capabilities: ShardNamesSchema, commons: v.pipe(v.array(ShardHashSchema), v.maxLength(limits.commons)), commonsWire: v.optional(v.record(ShardHashSchema, ShardNaturalSchema), {}), commonsCosts: v.optional(CommonsCostsSchema, {}) });
|
|
39
40
|
/** Authored compressed and resident ceilings. */
|
|
40
41
|
export const BudgetsSchema: v.GenericSchema<ShardBudgetsInput, ShardBudgets> = v.strictObject({
|
|
41
42
|
/** Reviewed whole-client floor retained when an opaque runtime becomes declared data. */
|
|
@@ -216,7 +217,7 @@ interface ShardIdentityFields {
|
|
|
216
217
|
}
|
|
217
218
|
export type ShardIdentity = { [Key in keyof ShardIdentityFields]: ShardIdentityFields[Key] };
|
|
218
219
|
interface ShardRequiresInputFields {
|
|
219
|
-
sdk:
|
|
220
|
+
sdk: ShardfileVersion;
|
|
220
221
|
capabilities: ShardNamesInput;
|
|
221
222
|
commons: (ShardHashInput)[];
|
|
222
223
|
commonsWire?: Record<string, ShardNaturalInput> | undefined;
|
|
@@ -224,7 +225,7 @@ interface ShardRequiresInputFields {
|
|
|
224
225
|
}
|
|
225
226
|
export type ShardRequiresInput = { [Key in keyof ShardRequiresInputFields]: ShardRequiresInputFields[Key] };
|
|
226
227
|
interface ShardRequiresFields {
|
|
227
|
-
sdk:
|
|
228
|
+
sdk: ShardfileVersion;
|
|
228
229
|
capabilities: ShardNames;
|
|
229
230
|
commons: (ShardHash)[];
|
|
230
231
|
commonsWire: Record<string, ShardNatural>;
|
|
@@ -3,7 +3,7 @@ import { assertMigrationCompatibility } from './migrations.ts';
|
|
|
3
3
|
import { StateSchema } from './state.ts';
|
|
4
4
|
import type { Shardfile } from './shardSchema.ts';
|
|
5
5
|
import { isJsonDataWithFileSchemas } from './json.ts';
|
|
6
|
-
import {
|
|
6
|
+
import { SHARDFILE_VERSIONS } from './version.ts';
|
|
7
7
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
8
8
|
|
|
9
9
|
const identity = v.object({ slug: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u)),
|
|
@@ -17,7 +17,7 @@ const path = v.pipe(v.string(), v.maxLength(240), v.regex(/^(?:[a-zA-Z0-9_-][a-z
|
|
|
17
17
|
const measured = { path, hash: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u)),
|
|
18
18
|
bytes: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)) };
|
|
19
19
|
const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.literal('0.2'),
|
|
20
|
-
version: v.
|
|
20
|
+
version: v.picklist(SHARDFILE_VERSIONS), identity,
|
|
21
21
|
sections: v.pipe(v.array(v.strictObject({ ...measured, name: v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9-]*\/[a-zA-Z][a-zA-Z0-9_-]*$/u)),
|
|
22
22
|
schema: v.pipe(v.string(), v.maxLength(240)) })), v.maxLength(256)),
|
|
23
23
|
schemas: v.pipe(v.array(v.strictObject(measured)), v.maxLength(128)) });
|
package/src/format/version.ts
CHANGED
|
@@ -1,9 +1,81 @@
|
|
|
1
|
-
/** Canonical format
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/** Canonical format revision, separate from the npm package and script ABI (J319).
|
|
2
|
+
* The fourth component adds fields; the third changes their meaning. */
|
|
3
|
+
const ZERO = 0
|
|
4
|
+
const ONE = 1
|
|
5
|
+
|
|
6
|
+
const SHARDFILE_VERSION = '0.1.0.1'
|
|
7
|
+
/** Legacy 0.1 is the byte-preserving spelling of 0.1.0.0. */
|
|
8
|
+
const SHARDFILE_VERSIONS: readonly [
|
|
9
|
+
'0.1',
|
|
10
|
+
'0.1.0.0',
|
|
11
|
+
typeof SHARDFILE_VERSION,
|
|
12
|
+
] = ['0.1', '0.1.0.0', SHARDFILE_VERSION] as const
|
|
13
|
+
type ShardfileVersion = (typeof SHARDFILE_VERSIONS)[number]
|
|
14
|
+
type ShardfileVersionParts = readonly [number, number, number, number]
|
|
15
|
+
|
|
16
|
+
/** Read canonical bounded decimal components; the legacy two-part spelling has zero counters. */
|
|
17
|
+
function parseShardfileVersion(input: unknown): ShardfileVersionParts {
|
|
18
|
+
if (
|
|
19
|
+
typeof input !== 'string' ||
|
|
20
|
+
!/^(?:0|[1-9][0-9]{0,3})(?:\.(?:0|[1-9][0-9]{0,3}))(?:\.(?:0|[1-9][0-9]{0,3})\.(?:0|[1-9][0-9]{0,3}))?$/u.test(
|
|
21
|
+
input,
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
throw new Error('Shardfile needs a canonical format version X.Y or X.Y.B.A')
|
|
25
|
+
}
|
|
26
|
+
const [major = ZERO, minor = ZERO, breaking = ZERO, additive = ZERO] = input
|
|
27
|
+
.split('.')
|
|
28
|
+
.map(Number)
|
|
29
|
+
return [major, minor, breaking, additive]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Compare every format component numerically, including the additive counter. */
|
|
33
|
+
function compareShardfileVersions(left: unknown, right: unknown): number {
|
|
34
|
+
const leftParts = parseShardfileVersion(left),
|
|
35
|
+
rightParts = parseShardfileVersion(right)
|
|
36
|
+
for (let index = 0; index < leftParts.length; index += ONE) {
|
|
37
|
+
const difference = (leftParts[index] ?? ZERO) - (rightParts[index] ?? ZERO)
|
|
38
|
+
if (difference !== ZERO) {
|
|
39
|
+
return Math.sign(difference)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return ZERO
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A reader accepts its own additive revision and the previous one in the same breaking format.
|
|
46
|
+
* Future additions can introduce required declarations, so they still require a newer reader. */
|
|
47
|
+
function compatibleShardfileVersion(
|
|
48
|
+
input: unknown,
|
|
49
|
+
reader: unknown = SHARDFILE_VERSION,
|
|
50
|
+
): boolean {
|
|
51
|
+
try {
|
|
52
|
+
const [major, minor, breaking, additive] = parseShardfileVersion(input)
|
|
53
|
+
const [readMajor, readMinor, readBreaking, readAdditive] =
|
|
54
|
+
parseShardfileVersion(reader)
|
|
55
|
+
return (
|
|
56
|
+
major === readMajor &&
|
|
57
|
+
minor === readMinor &&
|
|
58
|
+
breaking === readBreaking &&
|
|
59
|
+
additive <= readAdditive &&
|
|
60
|
+
additive >= Math.max(ZERO, readAdditive - ONE)
|
|
61
|
+
)
|
|
62
|
+
} catch {
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Legacy callers use this only to validate the era's decimal minor; new code compares all four components. */
|
|
68
|
+
function shardfileRevision(input: unknown): number {
|
|
69
|
+
return parseShardfileVersion(input)[ONE]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
SHARDFILE_VERSION,
|
|
74
|
+
SHARDFILE_VERSIONS,
|
|
75
|
+
type ShardfileVersion,
|
|
76
|
+
type ShardfileVersionParts,
|
|
77
|
+
parseShardfileVersion,
|
|
78
|
+
compareShardfileVersions,
|
|
79
|
+
compatibleShardfileVersion,
|
|
80
|
+
shardfileRevision,
|
|
9
81
|
}
|