@wildshard/shard-format 0.49.1 → 0.50.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 +3 -2
- package/src/format/clientOwnership.ts +7 -5
- package/src/format/rig-looks.ts +186 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.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": {
|
|
@@ -446,7 +446,8 @@
|
|
|
446
446
|
"./interact-table.golden.json": "./src/format/interact-table.golden.json",
|
|
447
447
|
"./itemCatalogue": "./src/format/item-catalogue.ts",
|
|
448
448
|
"./item-catalogue.golden.json": "./src/format/item-catalogue.golden.json",
|
|
449
|
-
"./baked-terrain.golden.json": "./src/format/baked-terrain.golden.json"
|
|
449
|
+
"./baked-terrain.golden.json": "./src/format/baked-terrain.golden.json",
|
|
450
|
+
"./rigLooks": "./src/format/rig-looks.ts"
|
|
450
451
|
},
|
|
451
452
|
"engines": {
|
|
452
453
|
"node": ">=24.18.0"
|
|
@@ -2,17 +2,19 @@ import { hasDeclaredClientPage } from './runtimeBinds.ts';
|
|
|
2
2
|
import type { Shardfile } from './shardSchema.ts';
|
|
3
3
|
import { parseClientPlan } from './clientPlan.ts';
|
|
4
4
|
import { parseNativeRuntimePlan, nativeRuntimeActorIds } from './nativeRuntimePlan.ts';
|
|
5
|
+
import { pageDrawsDeclaredLooks, rigLookRules } from './rig-looks.ts';
|
|
5
6
|
|
|
6
7
|
/** Cross-section ownership replaces the former runtime-only requirement. This
|
|
7
8
|
* runs on author output and checked network/native products before allocation. */
|
|
8
9
|
export function clientOwnershipRules(source: Shardfile, sections: ReadonlyMap<string, unknown>): readonly string[] {
|
|
9
|
-
const raw = sections.get('client/plan');
|
|
10
|
+
const raw = sections.get('client/plan'), rigs = rigLookRules(source.rows.looks, sections);
|
|
10
11
|
const features = raw === undefined ? [] : parseClientPlan(raw).features;
|
|
11
12
|
const page = hasDeclaredClientPage(source), native = features.some(row => row.kind === 'population.homes');
|
|
12
|
-
if (!page && !native) return
|
|
13
|
-
|
|
13
|
+
if (!page && !native) return rigs;
|
|
14
|
+
// OF19d1: a page drawing its declared bodies from their looks needs no species program
|
|
15
|
+
const errors: string[] = [...rigs], program = !pageDrawsDeclaredLooks(source, sections.get('sim/runtime-plan'), features);
|
|
14
16
|
if (!page || source.runtime !== null) errors.push('Native client features require their typed data page owner');
|
|
15
|
-
for (const kind of ['world.scenes', 'motion.channels', 'species.program', 'held.melee', 'quest.page', 'population.homes'] as const)
|
|
17
|
+
for (const kind of ['world.scenes', 'motion.channels', ...program ? ['species.program'] as const : [], 'held.melee', 'quest.page', 'population.homes'] as const)
|
|
16
18
|
if (!features.some(row => row.kind === kind)) errors.push(`Data page requires ${kind}`);
|
|
17
19
|
const quest = features.find(row => row.kind === 'quest.page'), held = features.find(row => row.kind === 'held.melee');
|
|
18
20
|
const declared = source.questHost?.page;
|
|
@@ -24,7 +26,7 @@ export function clientOwnershipRules(source: Shardfile, sections: ReadonlyMap<st
|
|
|
24
26
|
// ONE-FORMAT OF19b0/OF19c0: declared spawns, their species and encounters run beside the plan's keeper (the engine
|
|
25
27
|
// refuses a body both own); declared crowds do not
|
|
26
28
|
if (source.crowds.length > 0) errors.push('Data page native roster cannot also install declared crowds');
|
|
27
|
-
for (const name of ['world/scenes', 'world/targets', 'actors/species-programs', 'sim/runtime-plan', 'sim/scripts', 'look/painted'])
|
|
29
|
+
for (const name of ['world/scenes', 'world/targets', ...program ? ['actors/species-programs'] : [], 'sim/runtime-plan', 'sim/scripts', 'look/painted'])
|
|
28
30
|
if (!sections.has(name)) errors.push(`Data page requires ${name}`);
|
|
29
31
|
const channels = new Set(source.clientChannels?.map(row => row.id));
|
|
30
32
|
for (const feature of features) if (feature.kind === 'motion.channels') {
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE-FORMAT OF19d1: a creature look drawn from a scene model library's baked rig. A look row whose recipe is
|
|
3
|
+
* `platform.rig` names the `world/scenes` models library (`parameters.library`) whose rigs carry the body, and optionally
|
|
4
|
+
* the rig body (`parameters.body`, else the species' kind). The rig brings its own skeleton, surfaces and clips, so the row
|
|
5
|
+
* names no material and its animation is the rig's own (`platform.rig`, no parameters). This replaces a page's
|
|
6
|
+
* `species.program` feature for drawing declared bodies (Sunscar Dunes' ray, strider and Matriarch).
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
exactOptional,
|
|
10
|
+
maxLength,
|
|
11
|
+
minLength,
|
|
12
|
+
parse,
|
|
13
|
+
pipe,
|
|
14
|
+
safeParse,
|
|
15
|
+
strictObject,
|
|
16
|
+
string,
|
|
17
|
+
} from 'valibot'
|
|
18
|
+
|
|
19
|
+
import { nativeRuntimeActorIds } from './nativeRuntimePlan.ts'
|
|
20
|
+
|
|
21
|
+
import type { GenericSchema } from 'valibot'
|
|
22
|
+
|
|
23
|
+
/** The look recipe, and its animation recipe, for a body drawn from a scene library's rig. */
|
|
24
|
+
const RIG_LOOK_RECIPE = 'platform.rig'
|
|
25
|
+
const ID_MIN = 1
|
|
26
|
+
const ID_MAX = 128
|
|
27
|
+
const NONE = 0
|
|
28
|
+
const rowId = pipe(string(), minLength(ID_MIN), maxLength(ID_MAX))
|
|
29
|
+
/** The look row's parameters: the library, and the rig body when it is not the species' kind. */
|
|
30
|
+
interface RigLookParameters {
|
|
31
|
+
readonly library: string
|
|
32
|
+
readonly body?: string
|
|
33
|
+
}
|
|
34
|
+
const RigLookParametersSchema: GenericSchema<RigLookParameters> = strictObject({
|
|
35
|
+
body: exactOptional(rowId),
|
|
36
|
+
library: rowId,
|
|
37
|
+
})
|
|
38
|
+
/** The fields of a look row these rules read. */
|
|
39
|
+
interface RigLookRow {
|
|
40
|
+
readonly id: string
|
|
41
|
+
readonly species: string
|
|
42
|
+
readonly recipe: string
|
|
43
|
+
readonly material: string | null
|
|
44
|
+
readonly parameters: Readonly<Record<string, unknown>>
|
|
45
|
+
readonly animation: {
|
|
46
|
+
readonly recipe: string
|
|
47
|
+
readonly parameters: Readonly<Record<string, unknown>>
|
|
48
|
+
readonly clipMap?: unknown
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** The fields of a shard these rules read. */
|
|
52
|
+
interface RigLookShard {
|
|
53
|
+
readonly rows: { readonly looks: readonly RigLookRow[] }
|
|
54
|
+
readonly creatures: {
|
|
55
|
+
readonly spawns: readonly { readonly species: string }[]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Whether a look plays its rig's own clips: the rig recipe, no parameters and no clip map. */
|
|
60
|
+
function ownClips(row: Readonly<RigLookRow>): boolean {
|
|
61
|
+
const { animation } = row
|
|
62
|
+
return (
|
|
63
|
+
animation.recipe === RIG_LOOK_RECIPE &&
|
|
64
|
+
Object.keys(animation.parameters).length === NONE &&
|
|
65
|
+
animation.clipMap === undefined
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The errors of one `platform.rig` look's own fields (none for another recipe whose animation is not the rig's). */
|
|
70
|
+
function rigLookRowRules(row: Readonly<RigLookRow>): readonly string[] {
|
|
71
|
+
if (row.recipe !== RIG_LOOK_RECIPE) {
|
|
72
|
+
return row.animation.recipe === RIG_LOOK_RECIPE
|
|
73
|
+
? [`Rig clips without a rig look: ${row.id}`]
|
|
74
|
+
: []
|
|
75
|
+
}
|
|
76
|
+
const errors: string[] = []
|
|
77
|
+
if (!safeParse(RigLookParametersSchema, row.parameters).success) {
|
|
78
|
+
errors.push(
|
|
79
|
+
`Rig look parameters are a library and an optional body: ${row.id}`,
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
if (row.material !== null) {
|
|
83
|
+
errors.push(`A rig look draws with its rig's surfaces: ${row.id}`)
|
|
84
|
+
}
|
|
85
|
+
if (!ownClips(row)) {
|
|
86
|
+
errors.push(`A rig look plays its rig's own clips: ${row.id}`)
|
|
87
|
+
}
|
|
88
|
+
return errors
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The parameters of a rig look that passed `rigLookRules`. */
|
|
92
|
+
function rigLookParameters(
|
|
93
|
+
row: Readonly<Pick<RigLookRow, 'parameters'>>,
|
|
94
|
+
): RigLookParameters {
|
|
95
|
+
return parse(RigLookParametersSchema, row.parameters)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Whether a value is a plain JSON object. */
|
|
99
|
+
function isObject(value: unknown): value is Readonly<Record<string, unknown>> {
|
|
100
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The ids of the `models` libraries a `world/scenes` section declares. */
|
|
104
|
+
function modelLibraries(scenes: unknown): ReadonlySet<string> {
|
|
105
|
+
const libraries: unknown = isObject(scenes) ? scenes['libraries'] : undefined
|
|
106
|
+
const rows: readonly unknown[] = Array.isArray(libraries) ? libraries : []
|
|
107
|
+
return new Set(
|
|
108
|
+
rows.flatMap((row: unknown): string[] =>
|
|
109
|
+
isObject(row) && row['kind'] === 'models' && typeof row['id'] === 'string'
|
|
110
|
+
? [row['id']]
|
|
111
|
+
: [],
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Every look's rig rules, and cross-section: every rig look names a `models` library of `world/scenes` (the rig body is
|
|
117
|
+
* the library file's, checked where the page loads it). */
|
|
118
|
+
function rigLookRules(
|
|
119
|
+
looks: readonly RigLookRow[],
|
|
120
|
+
sections: ReadonlyMap<string, unknown>,
|
|
121
|
+
): readonly string[] {
|
|
122
|
+
const rows = looks.flatMap((row: Readonly<RigLookRow>): readonly string[] =>
|
|
123
|
+
rigLookRowRules(row),
|
|
124
|
+
)
|
|
125
|
+
const rigged = looks.filter(
|
|
126
|
+
(row: Readonly<RigLookRow>): boolean => row.recipe === RIG_LOOK_RECIPE,
|
|
127
|
+
)
|
|
128
|
+
if (rigged.length === NONE) {
|
|
129
|
+
return rows
|
|
130
|
+
}
|
|
131
|
+
const models = modelLibraries(sections.get('world/scenes'))
|
|
132
|
+
const libraries = rigged.flatMap((row: Readonly<RigLookRow>): string[] => {
|
|
133
|
+
const { library } = row.parameters
|
|
134
|
+
return typeof library === 'string' && models.has(library)
|
|
135
|
+
? []
|
|
136
|
+
: [`Rig look ${row.id} names no world/scenes models library`]
|
|
137
|
+
})
|
|
138
|
+
return [...rows, ...libraries]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** OF19d1: a page whose plan keeper stands no body (`keeper` is its actor ids), and whose every declared spawn's species
|
|
142
|
+
* has a look row, draws its creatures as an ordinary upload does, so it needs no `species.program` feature. */
|
|
143
|
+
function declaredLooksDraw(
|
|
144
|
+
shard: Readonly<RigLookShard>,
|
|
145
|
+
keeper: readonly string[],
|
|
146
|
+
): boolean {
|
|
147
|
+
if (keeper.length > NONE) {
|
|
148
|
+
return false
|
|
149
|
+
}
|
|
150
|
+
const looked = new Set(
|
|
151
|
+
shard.rows.looks.map((row: Readonly<RigLookRow>): string => row.species),
|
|
152
|
+
)
|
|
153
|
+
return shard.creatures.spawns.every(
|
|
154
|
+
(spawn: Readonly<{ species: string }>): boolean =>
|
|
155
|
+
looked.has(spawn.species),
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Whether a data page draws its declared bodies from their looks: it has no `species.program` feature, its runtime plan's
|
|
160
|
+
* keeper (`plan`, the `sim/runtime-plan` section) stands no body, and every declared spawn's species has a look. */
|
|
161
|
+
function pageDrawsDeclaredLooks(
|
|
162
|
+
shard: Readonly<RigLookShard>,
|
|
163
|
+
plan: unknown,
|
|
164
|
+
features: readonly Readonly<{ kind: string }>[],
|
|
165
|
+
): boolean {
|
|
166
|
+
if (
|
|
167
|
+
plan === undefined ||
|
|
168
|
+
features.some(
|
|
169
|
+
(row: Readonly<{ kind: string }>): boolean =>
|
|
170
|
+
row.kind === 'species.program',
|
|
171
|
+
)
|
|
172
|
+
) {
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
return declaredLooksDraw(shard, nativeRuntimeActorIds(plan))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export {
|
|
179
|
+
RIG_LOOK_RECIPE,
|
|
180
|
+
RigLookParametersSchema,
|
|
181
|
+
declaredLooksDraw,
|
|
182
|
+
pageDrawsDeclaredLooks,
|
|
183
|
+
rigLookParameters,
|
|
184
|
+
rigLookRules,
|
|
185
|
+
}
|
|
186
|
+
export type { RigLookParameters, RigLookRow, RigLookShard }
|