@wildshard/shard-format 0.59.0 → 0.61.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.59.0",
3
+ "version": "0.61.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": {
@@ -0,0 +1,111 @@
1
+ // Validator output rows deliberately retain the format's mutable public data types.
2
+ /* oxlint-disable typescript/prefer-readonly-parameter-types */
3
+ // The portable library targets ES2022; sort only new arrays.
4
+ /* oxlint-disable unicorn/no-array-sort */
5
+ import { validationSourceBytes } from './validationReceipt.ts'
6
+
7
+ import type { ShardRows } from './rows.ts'
8
+ import type { SkinBinding, SkinRow } from './skinData.ts'
9
+ import type { SkinLookParameters } from './skins.ts'
10
+
11
+ /** A skin file read from its bytes: its rig row and its binding. */
12
+ interface ResolvedSkinFile {
13
+ readonly hash: string
14
+ readonly row: SkinRow
15
+ readonly binding: SkinBinding
16
+ }
17
+ type Look = ShardRows['looks'][number]
18
+ const FIRST = 0
19
+ /** A coat: what a variant or phone skin may wear of its own (OF27b), its maps (a painterly `map`), its fur's sheen and rim, and its glow. */
20
+ const COAT: ReadonlySet<string> = new Set([
21
+ 'map',
22
+ 'maps',
23
+ 'sheen',
24
+ 'rim',
25
+ 'emissive',
26
+ 'emissiveIntensity',
27
+ ])
28
+
29
+ function sharedMaterial(
30
+ material: Readonly<Record<string, unknown>>,
31
+ ): Record<string, unknown> {
32
+ return Object.fromEntries(
33
+ Object.entries(material).filter(([key]): boolean => !COAT.has(key)),
34
+ )
35
+ }
36
+
37
+ /** The rig and material a look's skins all share: a variant or phone skin differs only in its mesh and coat. */
38
+ function skinContract({ row, binding }: ResolvedSkinFile): string {
39
+ return new TextDecoder().decode(
40
+ validationSourceBytes({
41
+ family: row.family,
42
+ skeleton: row.rig.skeleton,
43
+ joints: [...(row.rig.joints[FIRST] ?? [])].sort(),
44
+ clips: [...row.rig.clips].sort(),
45
+ sockets: [...row.rig.sockets].sort(),
46
+ material: sharedMaterial(binding.material),
47
+ materials: binding.materials ?? {},
48
+ }),
49
+ )
50
+ }
51
+
52
+ /** A phone skin keeps its desktop skin's rig and material contract and draws at most its triangles (CC51b). */
53
+ function phoneSkin(
54
+ desktop: ResolvedSkinFile,
55
+ phone: ResolvedSkinFile,
56
+ look: Look,
57
+ ): ResolvedSkinFile {
58
+ if (skinContract(phone) !== skinContract(desktop)) {
59
+ throw new Error(`skin look ${look.id}: phone skin rig or material differs`)
60
+ }
61
+ if (phone.row.cost.triangles > desktop.row.cost.triangles) {
62
+ throw new Error(`skin look ${look.id}: phone skin draws more triangles`)
63
+ }
64
+ return phone
65
+ }
66
+
67
+ /** OF23f: a variant look has a phone tier only as a phone skin and a phone variant table together. */
68
+ function checkPhonePairing(look: Look, parameters: SkinLookParameters): void {
69
+ const { variants, phone, phoneVariants } = parameters
70
+ if (phoneVariants !== undefined && variants === undefined) {
71
+ throw new Error(
72
+ `skin look ${look.id}: a phone variant table needs a variant table`,
73
+ )
74
+ }
75
+ if (phoneVariants !== undefined && phone === undefined) {
76
+ throw new Error(
77
+ `skin look ${look.id}: a phone variant table needs its phone skin`,
78
+ )
79
+ }
80
+ if (
81
+ variants !== undefined &&
82
+ phone !== undefined &&
83
+ phoneVariants === undefined
84
+ ) {
85
+ throw new Error(
86
+ `skin look ${look.id}: a variant look's phone skin needs a phone variant table`,
87
+ )
88
+ }
89
+ }
90
+
91
+ /** OF23f: each variant's phone skin against that variant's desktop skin. */
92
+ function phoneVariantSkins(
93
+ phones: ReadonlyMap<string, ResolvedSkinFile>,
94
+ {
95
+ desktop,
96
+ look,
97
+ }: { desktop: ReadonlyMap<string, ResolvedSkinFile>; look: Look },
98
+ ): ReadonlyMap<string, ResolvedSkinFile> {
99
+ const checked = new Map<string, ResolvedSkinFile>()
100
+ for (const [variant, phone] of phones) {
101
+ const own = desktop.get(variant)
102
+ if (own === undefined) {
103
+ throw new Error(`skin look ${look.id}: no desktop variant ${variant}`)
104
+ }
105
+ checked.set(variant, phoneSkin(own, phone, look))
106
+ }
107
+ return checked
108
+ }
109
+
110
+ export { checkPhonePairing, phoneSkin, phoneVariantSkins, skinContract }
111
+ export type { ResolvedSkinFile }
@@ -42,6 +42,9 @@ function skinLookParameters(
42
42
  ? {}
43
43
  : { variants: look.output.variants }),
44
44
  ...(look.output.phone === undefined ? {} : { phone: look.output.phone }),
45
+ ...(look.output.phoneVariants === undefined
46
+ ? {}
47
+ : { phoneVariants: look.output.phoneVariants }),
45
48
  }
46
49
  }
47
50
 
@@ -0,0 +1,90 @@
1
+ // ONE-FORMAT OF23f: which skin files a device tier leaves out.
2
+ import { safeParse } from 'valibot'
3
+
4
+ import {
5
+ SKIN_LOOK_RECIPE,
6
+ SkinLookParametersSchema,
7
+ skinLookTierRoots,
8
+ } from './skins.ts'
9
+
10
+ /** The look rows tier selection reads: a skin look names each tier's skin files in its parameters. */
11
+ type SkinTierLooks = readonly {
12
+ readonly recipe: string
13
+ readonly parameters: unknown
14
+ }[]
15
+ interface SkinTierSource {
16
+ readonly files: readonly {
17
+ readonly hash: string
18
+ readonly dependencies: readonly string[]
19
+ }[]
20
+ readonly rows?: { readonly looks: SkinTierLooks }
21
+ }
22
+ type Tier = 'phone' | 'desktop'
23
+ const NONE = 0
24
+
25
+ function closure(
26
+ dependencies: ReadonlyMap<string, readonly string[]>,
27
+ roots: readonly string[],
28
+ ): Set<string> {
29
+ const seen = new Set<string>()
30
+ const pending = [...roots]
31
+ for (let hash = pending.pop(); hash !== undefined; hash = pending.pop()) {
32
+ if (!seen.has(hash)) {
33
+ seen.add(hash)
34
+ pending.push(...(dependencies.get(hash) ?? []))
35
+ }
36
+ }
37
+ return seen
38
+ }
39
+
40
+ /**
41
+ * A skin look with a phone skin draws one tier's skin files. The other tier's skin files and variant table, and the GLBs
42
+ * and maps only they reach, are that tier's download, even where the look row names them. `looks` are the rows as this
43
+ * tier reads them (a tiered look names only its tier's roots), for the string walk.
44
+ */
45
+ function skinTierOff(
46
+ source: SkinTierSource,
47
+ tier: Tier,
48
+ ): { readonly off: ReadonlySet<string>; readonly looks: SkinTierLooks } {
49
+ const rows = source.rows?.looks ?? []
50
+ const on: string[] = []
51
+ const other: string[] = []
52
+ const looks = rows.map((row): SkinTierLooks[number] => {
53
+ const parsed =
54
+ row.recipe === SKIN_LOOK_RECIPE
55
+ ? safeParse(SkinLookParametersSchema, row.parameters)
56
+ : undefined
57
+ if (parsed?.success !== true) {
58
+ return row
59
+ }
60
+ const roots = skinLookTierRoots(parsed.output, tier)
61
+ on.push(...roots)
62
+ if (parsed.output.phone === undefined) {
63
+ return row
64
+ }
65
+ other.push(
66
+ ...skinLookTierRoots(
67
+ parsed.output,
68
+ tier === 'phone' ? 'desktop' : 'phone',
69
+ ),
70
+ )
71
+ return { ...row, parameters: roots }
72
+ })
73
+ if (other.length === NONE) {
74
+ return { off: new Set(), looks: rows }
75
+ }
76
+ const dependencies = new Map(
77
+ source.files.map((file): [string, readonly string[]] => [
78
+ file.hash,
79
+ file.dependencies,
80
+ ]),
81
+ )
82
+ const kept = closure(dependencies, on)
83
+ const off = [...closure(dependencies, other)].filter(
84
+ (hash): boolean => !kept.has(hash),
85
+ )
86
+ return { off: new Set(off), looks }
87
+ }
88
+
89
+ export { skinTierOff }
90
+ export type { SkinTierLooks }
@@ -5,38 +5,32 @@
5
5
  import { parse } from 'valibot'
6
6
 
7
7
  import { MaterialsSchema, materialTextureRefs } from './materials.ts'
8
+ import {
9
+ checkPhonePairing,
10
+ phoneSkin,
11
+ phoneVariantSkins,
12
+ skinContract,
13
+ } from './skin-contract.ts'
8
14
  import { parseSkinFile, skinLookParameters } from './skin-file.ts'
9
- import { SkinVariantsSchema } from './skins.ts'
10
- import { validationSourceBytes } from './validationReceipt.ts'
15
+ import { SkinVariantsSchema, skinLookTierRoots } from './skins.ts'
11
16
 
12
17
  import type { ShardRows } from './rows.ts'
13
18
  import type { Shardfile } from './shardSchema.ts'
19
+ import type { ResolvedSkinFile } from './skin-contract.ts'
14
20
  import type { SkinBinding, SkinRow } from './skinData.ts'
21
+ import type { SkinLookParameters } from './skins.ts'
15
22
 
16
- interface ResolvedSkinFile {
17
- readonly hash: string
18
- readonly row: SkinRow
19
- readonly binding: SkinBinding
20
- }
21
23
  interface SkinLookFiles {
22
24
  readonly skin: ResolvedSkinFile
23
25
  readonly variants?: ReadonlyMap<string, ResolvedSkinFile>
24
26
  /** The phone tier's lighter mesh (ONE-FORMAT CC51b): the same contract as `skin`, at most its triangles. */
25
27
  readonly phone?: ResolvedSkinFile
28
+ /** OF23f: a variant look's phone variants, each the same contract as its desktop variant and at most its triangles. */
29
+ readonly phoneVariants?: ReadonlyMap<string, ResolvedSkinFile>
26
30
  }
27
31
  type Source = Pick<Shardfile, 'rows' | 'files'>
28
32
  type Look = ShardRows['looks'][number]
29
- const FIRST = 0
30
33
  const REST = 1
31
- /** A coat: what a variant or phone skin may wear of its own (OF27b), its maps (a painterly `map`), its fur's sheen and rim, and its glow. */
32
- const COAT: ReadonlySet<string> = new Set([
33
- 'map',
34
- 'maps',
35
- 'sheen',
36
- 'rim',
37
- 'emissive',
38
- 'emissiveIntensity',
39
- ])
40
34
 
41
35
  /** A skin file's exact dependencies: its GLB, then its material's textures, sorted and once each (OF27b). */
42
36
  function skinFileDependencies(row: SkinRow, binding: SkinBinding): string[] {
@@ -46,28 +40,6 @@ function skinFileDependencies(row: SkinRow, binding: SkinBinding): string[] {
46
40
  return [row.file, ...[...new Set(textures)].sort()]
47
41
  }
48
42
 
49
- function sharedMaterial(
50
- material: Readonly<Record<string, unknown>>,
51
- ): Record<string, unknown> {
52
- return Object.fromEntries(
53
- Object.entries(material).filter(([key]): boolean => !COAT.has(key)),
54
- )
55
- }
56
-
57
- function skinContract({ row, binding }: ResolvedSkinFile): string {
58
- return new TextDecoder().decode(
59
- validationSourceBytes({
60
- family: row.family,
61
- skeleton: row.rig.skeleton,
62
- joints: [...(row.rig.joints[FIRST] ?? [])].sort(),
63
- clips: [...row.rig.clips].sort(),
64
- sockets: [...row.rig.sockets].sort(),
65
- material: sharedMaterial(binding.material),
66
- materials: binding.materials ?? {},
67
- }),
68
- )
69
- }
70
-
71
43
  function readSkinFile(
72
44
  files: ReadonlyMap<string, Source['files'][number]>,
73
45
  assets: ReadonlyMap<string, Uint8Array>,
@@ -198,31 +170,50 @@ function resolveVariants(
198
170
  return variants
199
171
  }
200
172
 
201
- function phoneLook(
202
- skin: ResolvedSkinFile,
203
- {
204
- phone: hash,
205
- look,
206
- read,
207
- variants,
208
- }: {
209
- phone: string
210
- look: Look
211
- read: (hash: string) => ResolvedSkinFile
212
- variants: string | undefined
213
- },
214
- ): SkinLookFiles {
215
- if (variants !== undefined) {
216
- throw new Error(`skin look ${look.id}: a variant look has no phone skin`)
173
+ interface TableContext {
174
+ readonly source: Source
175
+ readonly look: Look
176
+ readonly assets: ReadonlyMap<string, Uint8Array>
177
+ readonly read: (hash: string) => ResolvedSkinFile
178
+ }
179
+
180
+ /** A variant table's skins, each with its default's contract; none without a table. */
181
+ function tableVariants(
182
+ context: TableContext,
183
+ head: ResolvedSkinFile,
184
+ table: string | undefined,
185
+ ): ReadonlyMap<string, ResolvedSkinFile> | undefined {
186
+ if (table === undefined) {
187
+ return undefined
217
188
  }
218
- const phone = read(hash)
219
- if (skinContract(phone) !== skinContract(skin)) {
220
- throw new Error(`skin look ${look.id}: phone skin rig or material differs`)
189
+ const { source, look, assets, read } = context
190
+ const skins = variantTable(source, look, {
191
+ assets,
192
+ parameters: { variants: table, skin: head.hash },
193
+ })
194
+ return resolveVariants(skins, head, read)
195
+ }
196
+
197
+ /** The phone tier beside a look's skin and variants: its phone skin and, on a variant look, its phone variants (OF23f). */
198
+ function phoneTier(
199
+ context: TableContext,
200
+ desktop: Pick<SkinLookFiles, 'skin' | 'variants'>,
201
+ parameters: Pick<SkinLookParameters, 'phone' | 'phoneVariants'>,
202
+ ): SkinLookFiles {
203
+ if (parameters.phone === undefined) {
204
+ return desktop
221
205
  }
222
- if (phone.row.cost.triangles > skin.row.cost.triangles) {
223
- throw new Error(`skin look ${look.id}: phone skin draws more triangles`)
206
+ const { look, read } = context
207
+ const phone = phoneSkin(desktop.skin, read(parameters.phone), look)
208
+ const phones = tableVariants(context, phone, parameters.phoneVariants)
209
+ if (desktop.variants === undefined || phones === undefined) {
210
+ return { ...desktop, phone }
224
211
  }
225
- return { skin, phone }
212
+ const phoneVariants = phoneVariantSkins(phones, {
213
+ desktop: desktop.variants,
214
+ look,
215
+ })
216
+ return { ...desktop, phone, phoneVariants }
226
217
  }
227
218
 
228
219
  /** Resolve exact variant coverage and compatible rig/material declarations once at admission/load. */
@@ -232,25 +223,37 @@ function resolveSkinLookFiles(
232
223
  assets: ReadonlyMap<string, Uint8Array>,
233
224
  ): SkinLookFiles {
234
225
  const parameters = skinLookParameters(look)
235
- const read = skinReader(source, assets)
236
- const skin = read(parameters.skin)
237
- if (parameters.phone !== undefined) {
238
- return phoneLook(skin, {
239
- phone: parameters.phone,
240
- look,
241
- read,
242
- variants: parameters.variants,
243
- })
244
- }
245
- if (parameters.variants === undefined) {
246
- return { skin }
247
- }
248
- const table = variantTable(source, look, {
226
+ checkPhonePairing(look, parameters)
227
+ const context = { source, look, assets, read: skinReader(source, assets) }
228
+ const skin = context.read(parameters.skin)
229
+ const variants = tableVariants(context, skin, parameters.variants)
230
+ return phoneTier(
231
+ context,
232
+ variants === undefined ? { skin } : { skin, variants },
233
+ parameters,
234
+ )
235
+ }
236
+
237
+ /**
238
+ * OF23f: the skin files one tier draws, read from that tier's bytes only. Tier selection leaves a look's desktop skins
239
+ * out of the phone's files where the look has a phone skin, so the phone resolves its phone skin and phone variant table
240
+ * alone; admission (`resolveSkinLookFiles`) has already held them to the desktop contract.
241
+ */
242
+ function resolveSkinLookTier(
243
+ source: Source,
244
+ look: Look,
245
+ {
249
246
  assets,
250
- parameters: { variants: parameters.variants, skin: parameters.skin },
251
- })
252
- const variants = resolveVariants(table, skin, read)
253
- return { skin, variants }
247
+ tier,
248
+ }: { assets: ReadonlyMap<string, Uint8Array>; tier: 'phone' | 'desktop' },
249
+ ): Pick<SkinLookFiles, 'skin' | 'variants'> {
250
+ const parameters = skinLookParameters(look)
251
+ checkPhonePairing(look, parameters)
252
+ const [head, table] = skinLookTierRoots(parameters, tier)
253
+ const context = { source, look, assets, read: skinReader(source, assets) }
254
+ const skin = context.read(head)
255
+ const variants = tableVariants(context, skin, table)
256
+ return variants === undefined ? { skin } : { skin, variants }
254
257
  }
255
258
 
256
259
  /** Every skin file a look draws: its skin, each variant's and the phone tier's. */
@@ -259,8 +262,15 @@ function lookSkins(resolved: SkinLookFiles): ResolvedSkinFile[] {
259
262
  resolved.skin,
260
263
  ...(resolved.variants?.values() ?? []),
261
264
  ...(resolved.phone === undefined ? [] : [resolved.phone]),
265
+ ...(resolved.phoneVariants?.values() ?? []),
262
266
  ]
263
267
  }
264
268
 
265
- export { lookSkins, resolveSkinLookFiles, skinFileDependencies }
266
- export type { ResolvedSkinFile, SkinLookFiles }
269
+ export {
270
+ lookSkins,
271
+ resolveSkinLookFiles,
272
+ resolveSkinLookTier,
273
+ skinFileDependencies,
274
+ }
275
+ export type { SkinLookFiles }
276
+ export type { ResolvedSkinFile } from './skin-contract.ts'
@@ -35,13 +35,14 @@ function skinLookRules(source: Pick<Shardfile, 'rows' | 'files' | 'library'>): s
35
35
  for (const row of source.rows.looks) {
36
36
  if (row.recipe !== SKIN_LOOK_RECIPE) { if (row.animation.recipe === SKIN_CLIPS_RECIPE) {errors.push('skin clips without a skin look');} continue; }
37
37
  let parameters: ReturnType<typeof skinLookParameters>; try { parameters = skinLookParameters(row); } catch { errors.push('skin look parameters'); continue; }
38
- const { skin, variants, phone } = parameters, file = files.get(skin), glb = files.get(file?.dependencies[0] ?? '');
38
+ const { skin, variants, phone, phoneVariants } = parameters, file = files.get(skin), glb = files.get(file?.dependencies[0] ?? '');
39
39
  // OF27b: a skin file depends on its GLB, then its material's textures (KTX2 files or commons)
40
40
  const textures = file?.dependencies.slice(1) ?? [];
41
41
  if (file?.kind !== 'json' || glb?.kind !== 'glb' || !source.library.includes(skin)
42
42
  || textures.some((ref): boolean => !ref.startsWith('commons:') && files.get(ref)?.kind !== 'ktx2')) {errors.push('skin look file references');}
43
43
  if (!libraryJson(source.library, kinds, variants)) {errors.push('skin variant table references');}
44
44
  if (!libraryJson(source.library, kinds, phone)) {errors.push('skin phone file references');}
45
+ if (!libraryJson(source.library, kinds, phoneVariants)) {errors.push('skin phone variant table references');}
45
46
  }
46
47
  return errors;
47
48
  }
@@ -112,6 +113,7 @@ function validateSkinAssets(source: Pick<Shardfile, 'rows' | 'files'> & { readon
112
113
  }
113
114
 
114
115
  export { parseSkinFile, skinLookParameters } from './skin-file.ts';
115
- export { resolveSkinLookFiles, skinFileDependencies } from './skin-variants.ts';
116
+ export { resolveSkinLookFiles, resolveSkinLookTier, skinFileDependencies } from './skin-variants.ts';
117
+ export { skinLookTierRoots } from './skins.ts';
116
118
  export { skinLookRules, validateSkinAssets };
117
119
  export { skinLookTextureRefs } from './skin-textures.ts';
@@ -8,7 +8,7 @@ const SKIN_LOOK_RECIPE = 'platform.skin';
8
8
  const SKIN_CLIPS_RECIPE = 'platform.clips';
9
9
  const hash = v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/u));
10
10
  /** The look row's parameters. */
11
- const SkinLookParametersSchema: v.GenericSchema<SkinLookParametersRowsInput, SkinLookParametersRows> = v.strictObject({ skin: hash, variants: v.exactOptional(hash), phone: v.exactOptional(hash) });
11
+ const SkinLookParametersSchema: v.GenericSchema<SkinLookParametersRowsInput, SkinLookParametersRows> = v.strictObject({ skin: hash, variants: v.exactOptional(hash), phone: v.exactOptional(hash), phoneVariants: v.exactOptional(hash) });
12
12
  /** Complete variant-to-skin declarations in one ordinary content-addressed JSON file. */
13
13
  const VARIANTS_VERSION = 1;
14
14
  const MIN_VARIANTS = 1;
@@ -43,8 +43,9 @@ const SkinClipParametersSchema: v.GenericSchema<SkinClipParametersRowsInput, Ski
43
43
  const ShardSkinFileSchema: v.GenericSchema<ShardSkinFileRowsInput, ShardSkinFileRows> = v.strictObject({ row: v.unknown(), binding: v.unknown() });
44
44
 
45
45
  /** A parsed skin look: the file it names and the attack span its clip was sampled with. */
46
- /** `phone` (ONE-FORMAT CC51b) names a lighter skin file the phone tier draws instead: same rig, clips, sockets and material. */
47
- interface SkinLookParameters { skin: string; variants?: string; phone?: string; attackSpan: number; clipMap?: SkinClipMap }
46
+ /** `phone` (ONE-FORMAT CC51b) names a lighter skin file the phone tier draws instead: same rig, clips, sockets and material.
47
+ * `phoneVariants` (OF23f) is a variant look's phone variant table: every variant's lighter skin, `phone` its default. */
48
+ interface SkinLookParameters { skin: string; variants?: string; phone?: string; phoneVariants?: string; attackSpan: number; clipMap?: SkinClipMap }
48
49
 
49
50
  /** Admitted data contracts, independent of validator implementation metadata. */
50
51
  type SkinLookParametersRowsInput = SkinLookParametersRows;
@@ -52,6 +53,7 @@ interface SkinLookParametersRowsFields {
52
53
  skin: string;
53
54
  variants?: string;
54
55
  phone?: string;
56
+ phoneVariants?: string;
55
57
  }
56
58
  type SkinLookParametersRows = { [Key in keyof SkinLookParametersRowsFields]: SkinLookParametersRowsFields[Key] };
57
59
  interface SkinClipParametersRowsInputFields {
@@ -69,4 +71,13 @@ interface ShardSkinFileRowsFields {
69
71
  }
70
72
  type ShardSkinFileRows = { [Key in keyof ShardSkinFileRowsFields]: ShardSkinFileRowsFields[Key] };
71
73
 
72
- export { SKIN_LOOK_RECIPE, SKIN_CLIPS_RECIPE, SkinLookParametersSchema, type SkinVariants, SkinVariantsSchema, SkinClipParametersSchema, SkinClipMapSchema, ShardSkinFileSchema, type SkinClipMap, type SkinClipState, type SkinLookParameters, type SkinLookParametersRowsInput, type SkinLookParametersRows, type SkinClipParametersRowsInput, type SkinClipParametersRows, type ShardSkinFileRowsInput, type ShardSkinFileRows };
74
+ /** OF23f: the skin file and variant table a look's tier draws: on the phone its phone skin and phone variant table
75
+ * where it has them, else its skin and variant table (tier selection keeps only these of the look's files). */
76
+ function skinLookTierRoots(parameters: Pick<SkinLookParametersRows, 'skin' | 'variants' | 'phone' | 'phoneVariants'>, tier: 'phone' | 'desktop'): [string] | [string, string] {
77
+ const phone = tier === 'phone' ? parameters.phone : undefined;
78
+ const table = phone === undefined ? parameters.variants : parameters.phoneVariants;
79
+ const head = phone ?? parameters.skin;
80
+ return table === undefined ? [head] : [head, table];
81
+ }
82
+
83
+ export { skinLookTierRoots, SKIN_LOOK_RECIPE, SKIN_CLIPS_RECIPE, SkinLookParametersSchema, type SkinVariants, SkinVariantsSchema, SkinClipParametersSchema, SkinClipMapSchema, ShardSkinFileSchema, type SkinClipMap, type SkinClipState, type SkinLookParameters, type SkinLookParametersRowsInput, type SkinLookParametersRows, type SkinClipParametersRowsInput, type SkinClipParametersRows, type ShardSkinFileRowsInput, type ShardSkinFileRows };
@@ -1,7 +1,7 @@
1
1
  import * as v from 'valibot';
2
2
  import { isJsonData } from './json.ts';
3
3
  import { hookRules, type ShardHooks } from './hooks.ts';
4
- import type { StateSchema } from './state.ts';
4
+ import type { StateFieldRows, StateSchema } from './state.ts';
5
5
  import type { ShardScriptBindings } from './scripts.ts';
6
6
  import type { ShardItems } from './items.ts';
7
7
 
@@ -10,6 +10,7 @@ const finite = v.pipe(v.number(), v.finite());
10
10
  const coord = v.pipe(finite, v.minValue(-250), v.maxValue(250));
11
11
  /** How many talks a shard may declare. */
12
12
  const TALK_ROWS = 64;
13
+ const NO_BINDINGS = 0;
13
14
  /** A prompt's place, reach and text: an interaction's, and a talk's (TE-ENG3). */
14
15
  const prompt = { id, at: v.tuple([coord, coord, coord]), radius: v.pipe(finite, v.minValue(0.1), v.maxValue(8)), label: v.pipe(v.string(), v.minLength(1), v.maxLength(128)) };
15
16
  /** A use target: its prompt runs `scene`. `unless` (TE-ENG6) names a `hooks.conditions` row: while it holds, the use is
@@ -94,13 +95,14 @@ function spentRules(
94
95
  panels: readonly Readonly<{ scope: string; fieldId: number; colliders: readonly string[] }>[];
95
96
  itemFields?: readonly Readonly<{ fieldId: number }>[];
96
97
  }>,
97
- conditions: readonly Readonly<{ id: string; scope: string; fieldId: number }>[]): string[] {
98
+ conditions: readonly Readonly<{ id: string; scope: string; fieldId: number }>[],
99
+ scriptFields: readonly number[]): string[] {
98
100
  const projected = new Set<number>();
99
101
  for (const row of targets.itemFields ?? []) {
100
102
  projected.add(row.fieldId);
101
103
  }
102
104
  const errors: string[] = [];
103
- if (unlessRefused(targets.interactions, conditions, projected)) {
105
+ if (unlessRefused(targets.interactions, conditions, new Set([...projected, ...scriptFields]))) {
104
106
  errors.push('declared target interaction conditions');
105
107
  }
106
108
  if (projectedColliders(targets.panels, projected)) {
@@ -127,6 +129,13 @@ function talksRefused(
127
129
  }
128
130
  return false;
129
131
  }
132
+ /** The script lane publishes each visible numeric player field to its owner. */
133
+ function ownedScriptFields(fields: readonly Readonly<StateFieldRows>[], hasBindings: boolean): number[] {
134
+ if (!hasBindings) {
135
+ return [];
136
+ }
137
+ return fields.filter((field): boolean => field.privacy !== 'host' && field.type !== 'string').map((field): number => field.id);
138
+ }
130
139
  /** Refuse dangling identities, private fields and two writers for the same visual or collider. */
131
140
  export function targetRules(targets: ShardTargets, shard: { state: v.InferOutput<typeof StateSchema>; hooks: ShardHooks; sim: { scripts: readonly string[]; bindings: ShardScriptBindings }; items: ShardItems; quests?: { dialogue: readonly { id: string }[]; flags?: readonly string[] } }, props: { panels: readonly { id: string }[]; colliders: readonly { id: string }[]; models?: readonly { id: string }[] } | null): string[] {
132
141
  const errors = hookRules({ conditions: targets.panels.map((row) => ({ id: row.panel, ...row })), scenes: [] }, shard.state);
@@ -134,7 +143,8 @@ export function targetRules(targets: ShardTargets, shard: { state: v.InferOutput
134
143
  const bound = targets.panels.flatMap((row) => row.colliders);
135
144
  if (new Set(bound).size !== bound.length || targets.panels.some((row) => !panels.has(row.panel) || row.colliders.some((collider) => !colliders.has(collider)))) errors.push('declared target panel/collider references');
136
145
  if (new Set(targets.interactions.map((row) => row.id)).size !== targets.interactions.length || targets.interactions.some((row) => !scenes.has(row.scene))) errors.push('declared target interaction scenes');
137
- errors.push(...spentRules(targets, shard.hooks.conditions));
146
+ const scriptFields = ownedScriptFields(shard.state.player, shard.sim.bindings.length > NO_BINDINGS);
147
+ errors.push(...spentRules(targets, shard.hooks.conditions, scriptFields));
138
148
  if (targets.panels.length > 0 && shard.sim.bindings.length === 0) errors.push('target fields require script bindings');
139
149
  const actions = targets.itemActions ?? [], fields = targets.itemFields ?? [];
140
150
  if (new Set(actions.map((row) => row.scene)).size !== actions.length || actions.some((row) => !scenes.has(row.scene) || !shard.items.rows.some((item) => item.id === row.item && (item.kind === 'tool' || item.family === LEVER_FAMILY || item.family === MELEE_FAMILY && row.action === RACK_TAKE)))) errors.push('declared item action scenes');
@@ -3,6 +3,8 @@ import { parseWorldScenes, worldScenesForTier } from './worldScenes.ts';
3
3
  import { parseRiggedHullBook } from './riggedHulls.ts';
4
4
  import { PosedLibrarySchema } from './namedJsonContracts.ts';
5
5
  import { parseClientPlan } from './clientPlan.ts';
6
+ import { skinTierOff } from './skin-tier.ts';
7
+ import type { SkinTierLooks } from './skin-tier.ts';
6
8
  import * as v from 'valibot';
7
9
 
8
10
  /** Only immutable addressing and typed alternatives are needed for selection.
@@ -14,6 +16,8 @@ export interface TierSelectionSource {
14
16
  /** Scheduling metadata never creates a synchronous consumer or a tier pin. */
15
17
  readonly late?: readonly LateFile[];
16
18
  readonly manifest?: { readonly horizonStrips?: { readonly day: string; readonly night: string; readonly phone?: { readonly day: string; readonly night: string } } };
19
+ /** OF23f: skin looks name each tier's skin files (`phone`, `phoneVariants`); other rows are read by the string walk. */
20
+ readonly rows?: { readonly looks: SkinTierLooks };
17
21
  }
18
22
 
19
23
  /** Pure typed-alternative selection, shared by boot compilation and admission.
@@ -86,6 +90,8 @@ export function* tierLibrarySteps(source: TierSelectionSource, tier: 'phone' | '
86
90
  for (const row of group) if (row !== kept) otherTier.add(row.hash);
87
91
  }
88
92
  for (const hash of otherTier) inactive.add(hash);
93
+ const skins = skinTierOff(source, tier);
94
+ for (const hash of skins.off) { inactive.add(hash); }
89
95
  const alternative = (selected: string, other: string): void => {
90
96
  const off = names.get(other); if (off !== undefined) inactive.add(off);
91
97
  const on = names.get(selected); if (on !== undefined) used.add(on);
@@ -188,8 +194,11 @@ export function* tierLibrarySteps(source: TierSelectionSource, tier: 'phone' | '
188
194
  }
189
195
  if (inactive.size === 0) return inactive;
190
196
  const { files: _files, library: _library, critical: _critical, manifest: _manifest, late: _late, ...fields } = source;
191
- yield* stringsSteps([{ ...fields, manifest }, ...sections.values()], text => { const hash = names.get(text); if (hash !== undefined) used.add(hash); });
192
- const pinned = new Set([...source.critical, ...source.files.flatMap(file => file.dependencies)]);
193
- for (const file of source.files) for (const ref of file.dependencies) used.add(ref);
197
+ const tiered = skins.looks === source.rows?.looks ? fields : { ...fields, rows: { ...fields.rows, looks: skins.looks } };
198
+ yield* stringsSteps([{ ...tiered, manifest }, ...sections.values()], text => { const hash = names.get(text); if (hash !== undefined) used.add(hash); });
199
+ // The other tier's skin files reach their GLBs and maps; only this tier's files pin a dependency.
200
+ const live = source.files.filter((file): boolean => !skins.off.has(file.hash));
201
+ const pinned = new Set([...source.critical, ...live.flatMap(file => file.dependencies)]);
202
+ for (const file of live) for (const ref of file.dependencies) used.add(ref);
194
203
  return new Set([...inactive].filter(hash => otherTier.has(hash) ? !pinned.has(hash) : !used.has(hash)));
195
204
  }
@@ -102,12 +102,26 @@ interface VehicleDock {
102
102
  at: Vec3
103
103
  yaw: number
104
104
  per: 'player' | 'shared'
105
+ /** The owning player must have this quest flag before taking the vehicle. */
106
+ requiresFlag?: string
105
107
  respawn: number
106
108
  }
109
+ type GroundPoint = [number, number]
110
+ /** Metres in cell-local x/z. A road uses its full width, with rounded ends. */
111
+ type VehicleGripPatch =
112
+ | { shape: 'circle'; at: GroundPoint; radius: number; grip: number }
113
+ | { shape: 'road'; line: GroundPoint[]; width: number; grip: number }
114
+
115
+ /** Multiplies a kind's tyre grip. The last covering patch wins; outside every patch use `base`. */
116
+ interface VehicleSurfaceGrip {
117
+ base: number
118
+ patches: VehicleGripPatch[]
119
+ }
107
120
  /** The `world/vehicles` section. */
108
121
  interface Vehicles {
109
122
  kinds: VehicleKind[]
110
123
  docks: VehicleDock[]
124
+ surfaceGrip?: VehicleSurfaceGrip
111
125
  }
112
126
  type VehiclesInput = Vehicles
113
127
  /** What a kind's references must find in the rest of the shard file. */
@@ -120,6 +134,9 @@ interface VehicleReferences {
120
134
  // MSZ1's bounds: kinds and docks a shard; seats and hull boxes a kind; metres, m/s, m/s², kg, seconds and characters.
121
135
  const MAX_KINDS = 8
122
136
  const MAX_DOCKS = 32
137
+ const MAX_GRIP_PATCHES = 32
138
+ const MIN_ROAD_POINTS = 2
139
+ const MAX_ROAD_POINTS = 128
123
140
  const MAX_SEATS = 4
124
141
  const MAX_HULL_BOXES = 16
125
142
  const MAX_HULL_HALF = 8
@@ -267,14 +284,21 @@ const kind = strictObject({
267
284
  health: exactOptional(bounded(ONE, MAX_HEALTH)),
268
285
  sounds: exactOptional(sounds),
269
286
  })
270
- const dock = strictObject({
287
+ const dockRow = strictObject({
271
288
  id,
272
289
  kind: id,
273
290
  at: tuple([cellAxis, cellHeight, cellAxis]),
274
291
  yaw: angle,
275
292
  per: union([literal('player'), literal('shared')]),
293
+ requiresFlag: exactOptional(id),
276
294
  respawn: bounded(NONE, MAX_RESPAWN),
277
295
  })
296
+ const playerRequirement = check(
297
+ (row: VehicleDock): boolean =>
298
+ row.per === 'player' || row.requiresFlag === undefined,
299
+ 'only a player dock can require a quest flag',
300
+ )
301
+ const dock = pipe(dockRow, playerRequirement)
278
302
  const kinds = pipe(
279
303
  array(kind),
280
304
  maxLength(
@@ -291,10 +315,35 @@ const docks = pipe(
291
315
  ),
292
316
  check(dockIdsUnique, 'vehicle dock ids are unique'),
293
317
  )
318
+ const groundPoint = tuple([cellAxis, cellAxis])
319
+ const patchExtent = bounded(LEAST, WIRE_CELL.half + WIRE_CELL.half)
320
+ const grip = bounded(NONE, ONE)
321
+ const circlePatch = strictObject({
322
+ shape: literal('circle'),
323
+ at: groundPoint,
324
+ radius: patchExtent,
325
+ grip,
326
+ })
327
+ const roadLine = pipe(
328
+ array(groundPoint),
329
+ minLength(MIN_ROAD_POINTS),
330
+ maxLength(MAX_ROAD_POINTS),
331
+ )
332
+ const roadPatch = strictObject({
333
+ shape: literal('road'),
334
+ line: roadLine,
335
+ width: patchExtent,
336
+ grip,
337
+ })
338
+ const gripPatch = union([circlePatch, roadPatch])
339
+ const surfaceGrip = strictObject({
340
+ base: grip,
341
+ patches: pipe(array(gripPatch), maxLength(MAX_GRIP_PATCHES)),
342
+ })
294
343
 
295
344
  /** The `world/vehicles` section (MSZ1): unique ids, docks of declared kinds, at most 8 kinds and 32 docks. */
296
345
  const VehiclesSchema: GenericSchema<VehiclesInput, Vehicles> = pipe(
297
- strictObject({ kinds, docks }),
346
+ strictObject({ kinds, docks, surfaceGrip: exactOptional(surfaceGrip) }),
298
347
  check(docksOfKinds, 'a vehicle dock names a declared kind'),
299
348
  )
300
349
 
@@ -358,6 +407,7 @@ export type {
358
407
  VehicleReferences,
359
408
  VehicleSeat,
360
409
  VehicleSounds,
410
+ VehicleSurfaceGrip,
361
411
  VehicleWind,
362
412
  Vehicles,
363
413
  VehiclesInput,