@wildshard/shard-format 0.27.0 → 0.29.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 -1
- package/src/format/creature-layers.ts +39 -4
- package/src/format/creature-mount.ts +120 -0
- package/src/format/creature-projectile.ts +32 -0
- package/src/format/outputIndex.ts +3 -1
- package/src/format/primitives.ts +274 -0
- package/src/format/rows.ts +3 -3
- package/src/format/section-versions.ts +63 -0
- package/src/format/spawnCombat.ts +10 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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": {
|
|
@@ -269,6 +269,7 @@
|
|
|
269
269
|
"./practiceCourseRows": "./src/format/practiceCourseRows.ts",
|
|
270
270
|
"./preflight": "./src/format/preflight.ts",
|
|
271
271
|
"./presentation": "./src/format/presentation.ts",
|
|
272
|
+
"./primitives": "./src/format/primitives.ts",
|
|
272
273
|
"./shardfileAssets": "./src/format/shardfile-assets.ts",
|
|
273
274
|
"./shardfileValidation": "./src/format/shardfileValidation.ts",
|
|
274
275
|
"./shardfileStream": "./src/format/shardfile-stream.ts",
|
|
@@ -323,6 +324,7 @@
|
|
|
323
324
|
"./scriptActionsV2": "./src/format/scriptActionsV2.ts",
|
|
324
325
|
"./scriptAdmission": "./src/format/scriptAdmission.ts",
|
|
325
326
|
"./scriptAdmissionV2": "./src/format/scriptAdmissionV2.ts",
|
|
327
|
+
"./sectionVersions": "./src/format/section-versions.ts",
|
|
326
328
|
"./scriptContract": "./src/format/scriptContract.ts",
|
|
327
329
|
"./scriptFuelV2": "./src/format/scriptFuelV2.ts",
|
|
328
330
|
"./scriptGroupBankV2": "./src/format/scriptGroupBankV2.ts",
|
|
@@ -20,12 +20,17 @@ import {
|
|
|
20
20
|
union,
|
|
21
21
|
} from 'valibot'
|
|
22
22
|
|
|
23
|
+
import { CreatureProjectileSchema } from './creature-projectile.ts'
|
|
23
24
|
import { CreatureSocketNameSchema } from './creature-volumes.ts'
|
|
24
25
|
import { CreatureSkinClipNameSchema } from './skinData.ts'
|
|
26
|
+
import { StrikeTellKindSchema } from './spawnCombat.ts'
|
|
25
27
|
import { HuntTuningSchema } from './speciesPrograms.ts'
|
|
26
28
|
|
|
27
29
|
import type { CreatureBody } from './creature-body.ts'
|
|
30
|
+
import type { CreatureMount } from './creature-mount.ts'
|
|
31
|
+
import type { CreatureProjectile } from './creature-projectile.ts'
|
|
28
32
|
import type { CreatureSkinClipName } from './skinData.ts'
|
|
33
|
+
import type { StrikeTellKind } from './spawnCombat.ts'
|
|
29
34
|
import type { SpeciesData } from './speciesPrograms.ts'
|
|
30
35
|
import type { GenericSchema } from 'valibot'
|
|
31
36
|
|
|
@@ -84,6 +89,11 @@ interface CreatureAbility {
|
|
|
84
89
|
duration?: number
|
|
85
90
|
from?: string
|
|
86
91
|
clip?: CreatureSkinClipName
|
|
92
|
+
effect?: 'knockback'
|
|
93
|
+
/** Horizontal travel in metres on clear ground. */
|
|
94
|
+
strength?: number
|
|
95
|
+
tell?: StrikeTellKind
|
|
96
|
+
projectile?: CreatureProjectile
|
|
87
97
|
}
|
|
88
98
|
type CreatureAbilityInput = Omit<CreatureAbility, 'clip'> & { clip?: string }
|
|
89
99
|
interface CreaturePresentation {
|
|
@@ -103,6 +113,8 @@ interface CreatureLayers {
|
|
|
103
113
|
senses?: CreatureSenses
|
|
104
114
|
abilities?: CreatureAbility[]
|
|
105
115
|
presentation?: CreaturePresentation
|
|
116
|
+
/** CC40a: rideable by the riding primitive. */
|
|
117
|
+
mount?: CreatureMount
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
const ZERO = 0
|
|
@@ -112,6 +124,7 @@ const MAX_SOUND = 4096
|
|
|
112
124
|
const MAX_RADIUS = 500
|
|
113
125
|
const MAX_SPEED = 15
|
|
114
126
|
const MAX_TIME = 86_400
|
|
127
|
+
const MAX_KNOCKBACK_DISTANCE = 60
|
|
115
128
|
const MAX_AMOUNT = 10_000_000
|
|
116
129
|
const MAX_CALLS = 32
|
|
117
130
|
const MAX_TUNING_FIELDS = 64
|
|
@@ -124,6 +137,11 @@ const speed = pipe(scalar, minValue(ZERO), maxValue(MAX_SPEED))
|
|
|
124
137
|
const unit = pipe(scalar, minValue(ZERO), maxValue(ONE))
|
|
125
138
|
const time = pipe(scalar, minValue(ZERO), maxValue(MAX_TIME))
|
|
126
139
|
const amount = pipe(scalar, minValue(ZERO), maxValue(MAX_AMOUNT))
|
|
140
|
+
const knockbackDistance = pipe(
|
|
141
|
+
scalar,
|
|
142
|
+
minValue(ZERO),
|
|
143
|
+
maxValue(MAX_KNOCKBACK_DISTANCE),
|
|
144
|
+
)
|
|
127
145
|
const orderedRadius = pipe(
|
|
128
146
|
tuple([radius, radius]),
|
|
129
147
|
check<[number, number], 'Ordered creature ability range'>(
|
|
@@ -202,10 +220,7 @@ const CreatureSensesSchema: GenericSchema<CreatureSenses> = strictObject(
|
|
|
202
220
|
},
|
|
203
221
|
'Unknown creature sense',
|
|
204
222
|
)
|
|
205
|
-
const
|
|
206
|
-
CreatureAbilityInput,
|
|
207
|
-
CreatureAbility
|
|
208
|
-
> = strictObject({
|
|
223
|
+
const abilityRow = strictObject({
|
|
209
224
|
use: id,
|
|
210
225
|
range: union([radius, orderedRadius]),
|
|
211
226
|
cooldown: time,
|
|
@@ -217,7 +232,26 @@ const CreatureAbilitySchema: GenericSchema<
|
|
|
217
232
|
duration: exactOptional(time),
|
|
218
233
|
from: exactOptional(CreatureSocketNameSchema),
|
|
219
234
|
clip: exactOptional(CreatureSkinClipNameSchema),
|
|
235
|
+
effect: exactOptional(picklist(['knockback'])),
|
|
236
|
+
strength: exactOptional(knockbackDistance),
|
|
237
|
+
tell: exactOptional(StrikeTellKindSchema),
|
|
238
|
+
projectile: exactOptional(CreatureProjectileSchema),
|
|
220
239
|
})
|
|
240
|
+
const abilityEffectCheck = check<
|
|
241
|
+
CreatureAbility,
|
|
242
|
+
'Creature knockback effect and strength must be specified together'
|
|
243
|
+
>(
|
|
244
|
+
({
|
|
245
|
+
effect,
|
|
246
|
+
strength,
|
|
247
|
+
}: Readonly<Pick<CreatureAbility, 'effect' | 'strength'>>): boolean =>
|
|
248
|
+
(effect === undefined) === (strength === undefined),
|
|
249
|
+
'Creature knockback effect and strength must be specified together',
|
|
250
|
+
)
|
|
251
|
+
const CreatureAbilitySchema: GenericSchema<
|
|
252
|
+
CreatureAbilityInput,
|
|
253
|
+
CreatureAbility
|
|
254
|
+
> = pipe(abilityRow, abilityEffectCheck)
|
|
221
255
|
const callVariants = pipe(array(sound), maxLength(MAX_CALLS))
|
|
222
256
|
const CreaturePresentationSchema: GenericSchema<CreaturePresentation> =
|
|
223
257
|
strictObject({
|
|
@@ -254,4 +288,5 @@ export type {
|
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
export { CreatureBodySchema } from './creature-body.ts'
|
|
291
|
+
export { CreatureMountSchema, creatureMountRules } from './creature-mount.ts'
|
|
257
292
|
export type { CreatureBody } from './creature-body.ts'
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boolean,
|
|
3
|
+
check,
|
|
4
|
+
exactOptional,
|
|
5
|
+
finite,
|
|
6
|
+
maxValue,
|
|
7
|
+
minValue,
|
|
8
|
+
number,
|
|
9
|
+
pipe,
|
|
10
|
+
strictObject,
|
|
11
|
+
} from 'valibot'
|
|
12
|
+
|
|
13
|
+
import { CREATURE_SKELETONS } from './creature-skeletons.ts'
|
|
14
|
+
import { CreatureSocketNameSchema } from './creature-volumes.ts'
|
|
15
|
+
|
|
16
|
+
import type { CreatureSkeleton } from './creature-layers.ts'
|
|
17
|
+
import type { GenericSchema } from 'valibot'
|
|
18
|
+
|
|
19
|
+
/** The seat socket both kit skeletons name. */
|
|
20
|
+
const DEFAULT_SEAT = 'seat'
|
|
21
|
+
/** Metres per second: past a galloping horse with room for a fast flyer. */
|
|
22
|
+
const MAX_GAIT = 40
|
|
23
|
+
const ZERO = 0
|
|
24
|
+
const PREVIOUS = 1
|
|
25
|
+
|
|
26
|
+
/** Ground speeds in metres per second, slowest first; trot and canter are optional steps between. */
|
|
27
|
+
interface MountGaits {
|
|
28
|
+
walk: number
|
|
29
|
+
trot?: number
|
|
30
|
+
canter?: number
|
|
31
|
+
gallop: number
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ONE-FORMAT CC40a (Q27, Q-S3, Q-C7, Q-CC42): a `mount` row makes any creature rideable by the one riding primitive.
|
|
35
|
+
* `seat` names the socket the rider sits at (default `seat`), `fly` lets it take off on its species `flight` row.
|
|
36
|
+
*/
|
|
37
|
+
interface CreatureMount {
|
|
38
|
+
seat?: string
|
|
39
|
+
gaits: MountGaits
|
|
40
|
+
fly?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const gait = pipe(number(), finite(), minValue(ZERO), maxValue(MAX_GAIT))
|
|
44
|
+
const gaitsObject = strictObject(
|
|
45
|
+
{
|
|
46
|
+
walk: gait,
|
|
47
|
+
trot: exactOptional(gait),
|
|
48
|
+
canter: exactOptional(gait),
|
|
49
|
+
gallop: gait,
|
|
50
|
+
},
|
|
51
|
+
'Unknown mount gait',
|
|
52
|
+
)
|
|
53
|
+
function rising(gaits: Readonly<MountGaits>): boolean {
|
|
54
|
+
const steps = [gaits.walk, gaits.trot, gaits.canter, gaits.gallop].filter(
|
|
55
|
+
(step): step is number => step !== undefined,
|
|
56
|
+
)
|
|
57
|
+
return steps.every(
|
|
58
|
+
(step: number, at: number): boolean =>
|
|
59
|
+
at === ZERO || step > (steps[at - PREVIOUS] ?? step),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
const CreatureMountSchema: GenericSchema<CreatureMount> = strictObject(
|
|
63
|
+
{
|
|
64
|
+
seat: exactOptional(CreatureSocketNameSchema),
|
|
65
|
+
gaits: pipe(
|
|
66
|
+
gaitsObject,
|
|
67
|
+
check(rising, 'Mount gaits rise from walk to gallop'),
|
|
68
|
+
),
|
|
69
|
+
fly: exactOptional(boolean()),
|
|
70
|
+
},
|
|
71
|
+
'Unknown mount field',
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/** The parts of a species row the mount rules read. */
|
|
75
|
+
interface MountedSpecies {
|
|
76
|
+
readonly id: string
|
|
77
|
+
readonly mount?: { readonly seat?: string; readonly fly?: boolean }
|
|
78
|
+
readonly flight?: unknown
|
|
79
|
+
readonly body?: {
|
|
80
|
+
readonly skeleton?: CreatureSkeleton
|
|
81
|
+
readonly volumes?: readonly { readonly part: string }[]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function seatKnown(seat: string, body: MountedSpecies['body']): boolean {
|
|
86
|
+
const parts = (body?.volumes ?? []).map(
|
|
87
|
+
(volume: { readonly part: string }): string => volume.part,
|
|
88
|
+
)
|
|
89
|
+
if (parts.includes(seat)) {
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
// A GLB with its own rig names its sockets in its skin; admission checks the seat there.
|
|
93
|
+
return (
|
|
94
|
+
body?.skeleton === undefined ||
|
|
95
|
+
Object.hasOwn(CREATURE_SKELETONS[body.skeleton].sockets, seat)
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Each mount's references, as named refusals: a body to sit on, a seat it has, and a flight row to fly with. */
|
|
100
|
+
function creatureMountRules(species: readonly MountedSpecies[]): string[] {
|
|
101
|
+
return species.flatMap((row: MountedSpecies): string[] => {
|
|
102
|
+
const { mount, body, id } = row
|
|
103
|
+
if (mount === undefined) {
|
|
104
|
+
return []
|
|
105
|
+
}
|
|
106
|
+
const seat = mount.seat ?? DEFAULT_SEAT
|
|
107
|
+
return [
|
|
108
|
+
...(body === undefined ? [`Mount ${id} needs a body`] : []),
|
|
109
|
+
...(body !== undefined && !seatKnown(seat, body)
|
|
110
|
+
? [`Unknown mount seat ${seat} on ${id}`]
|
|
111
|
+
: []),
|
|
112
|
+
...(mount.fly === true && row.flight === undefined
|
|
113
|
+
? [`Flying mount ${id} needs a flight row`]
|
|
114
|
+
: []),
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type { CreatureMount, MountGaits }
|
|
120
|
+
export { CreatureMountSchema, DEFAULT_SEAT, creatureMountRules }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
finite,
|
|
3
|
+
gtValue,
|
|
4
|
+
minValue,
|
|
5
|
+
maxValue,
|
|
6
|
+
number,
|
|
7
|
+
pipe,
|
|
8
|
+
strictObject,
|
|
9
|
+
} from 'valibot'
|
|
10
|
+
|
|
11
|
+
import type { GenericSchema } from 'valibot'
|
|
12
|
+
|
|
13
|
+
interface CreatureProjectile {
|
|
14
|
+
/** Metres per second at launch. */
|
|
15
|
+
speed: number
|
|
16
|
+
/** Downward acceleration, metres per second squared. */
|
|
17
|
+
gravity: number
|
|
18
|
+
/** Sphere radius in metres. */
|
|
19
|
+
radius: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const zero = 0
|
|
23
|
+
const maxRadius = 500
|
|
24
|
+
const finiteNumber = pipe(number(), finite())
|
|
25
|
+
const positive = pipe(finiteNumber, gtValue(zero))
|
|
26
|
+
const gravity = pipe(finiteNumber, minValue(zero))
|
|
27
|
+
const radius = pipe(positive, maxValue(maxRadius))
|
|
28
|
+
const CreatureProjectileSchema: GenericSchema<CreatureProjectile> =
|
|
29
|
+
strictObject({ speed: positive, gravity, radius })
|
|
30
|
+
|
|
31
|
+
export { CreatureProjectileSchema }
|
|
32
|
+
export type { CreatureProjectile }
|
|
@@ -20,6 +20,7 @@ import type { ShardfileVersion } from './version.ts';
|
|
|
20
20
|
import { isJsonData, isJsonDataWithFileSchemas } from './json.ts';
|
|
21
21
|
import { clientOwnershipRules } from './clientOwnership.ts';
|
|
22
22
|
import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts';
|
|
23
|
+
import { sectionSchemaIssue } from './section-versions.ts';
|
|
23
24
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
24
25
|
|
|
25
26
|
const path = v.pipe(v.string(), v.maxLength(240), v.regex(/^(?:[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/u));
|
|
@@ -81,7 +82,8 @@ function parseOutputIndexRows(input: unknown): OutputIndex {
|
|
|
81
82
|
for (const entry of index.sections) {
|
|
82
83
|
if (names.has(entry.name) || entry.path !== `sections/${entry.name}.json`) throw new Error('Duplicate or mismatched section path');
|
|
83
84
|
names.add(entry.name);
|
|
84
|
-
|
|
85
|
+
const issue = sectionSchemaIssue(entry.name, entry.schema);
|
|
86
|
+
if (issue !== undefined) throw new Error(`Unknown platform section schema: ${issue}`);
|
|
85
87
|
}
|
|
86
88
|
const refs = new Set<string>(), logical = new Set<string>();
|
|
87
89
|
for (const entry of index.files) {
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ACCEPTED_SECTION_VERSIONS, FIRST_VERSION } from './section-versions.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ONE-FORMAT OF17a (J365 (6), J367 (5), Q-T22 option (b), Q-T27 (a)): no host list ships. A section switches a primitive
|
|
5
|
+
* on, and the server works out the list from the product's sections. The families and their hosts are the verdict
|
|
6
|
+
* table, meta `docs/plans/one-format/HOSTS.md` (OF16a), pending Jake's corrections (OF16b).
|
|
7
|
+
*
|
|
8
|
+
* `on` says what turns a family on: `always` (every product has it), a section path whose value is a non-empty array or
|
|
9
|
+
* object, or `later` while its row (`row`) has not given it a section yet. A family's version is its section's `@N`
|
|
10
|
+
* (`ACCEPTED_SECTION_VERSIONS`): changes are additive, and a removal follows SHARD-COMPAT's rollout.
|
|
11
|
+
*/
|
|
12
|
+
/** An empty array or object switches nothing on. */
|
|
13
|
+
const NONE = 0
|
|
14
|
+
|
|
15
|
+
interface PrimitiveSwitch {
|
|
16
|
+
readonly section: string
|
|
17
|
+
readonly path: readonly string[]
|
|
18
|
+
/** When set, the family is on only if some row of the list at `path` has this key. */
|
|
19
|
+
readonly having?: string
|
|
20
|
+
}
|
|
21
|
+
interface Primitive {
|
|
22
|
+
readonly name: string
|
|
23
|
+
/** The ONE-FORMAT row that builds it. */
|
|
24
|
+
readonly row: string
|
|
25
|
+
/** The server hosts and page features it replaces (HOSTS.md). A host split across two families sits in the first. */
|
|
26
|
+
readonly hosts: readonly string[]
|
|
27
|
+
readonly on: PrimitiveSwitch | 'always' | 'later'
|
|
28
|
+
}
|
|
29
|
+
/** One family the server switched on, at the version of the section that switched it; no `section` for `always`. */
|
|
30
|
+
interface DerivedPrimitive {
|
|
31
|
+
readonly name: string
|
|
32
|
+
readonly section?: string
|
|
33
|
+
readonly version: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const TABLE: readonly Primitive[] = [
|
|
37
|
+
{
|
|
38
|
+
name: 'collision',
|
|
39
|
+
row: 'OF41',
|
|
40
|
+
on: 'always',
|
|
41
|
+
hosts: ['collision', 'collision.pieces'],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'plumbing',
|
|
45
|
+
row: 'OF18',
|
|
46
|
+
on: 'always',
|
|
47
|
+
hosts: [
|
|
48
|
+
'commands',
|
|
49
|
+
'decisions',
|
|
50
|
+
'engine.creatures.update',
|
|
51
|
+
'strings.register',
|
|
52
|
+
'content.catalogue',
|
|
53
|
+
'debug.expose',
|
|
54
|
+
'audio.cues',
|
|
55
|
+
'audio.scene',
|
|
56
|
+
'player.enter',
|
|
57
|
+
'bag.finds',
|
|
58
|
+
'state.adventure',
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'population',
|
|
63
|
+
row: 'OF29',
|
|
64
|
+
on: 'later',
|
|
65
|
+
hosts: [
|
|
66
|
+
'population.roster',
|
|
67
|
+
'population.spawn-script',
|
|
68
|
+
'population.shelter',
|
|
69
|
+
'population.environment',
|
|
70
|
+
'population.mixed',
|
|
71
|
+
'population.poses',
|
|
72
|
+
'population.reactions',
|
|
73
|
+
'population.settle',
|
|
74
|
+
'population.homes',
|
|
75
|
+
'population.wildlife',
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'elites',
|
|
80
|
+
row: 'OF33',
|
|
81
|
+
on: 'later',
|
|
82
|
+
hosts: [
|
|
83
|
+
'population.elites',
|
|
84
|
+
'population.elites-ready',
|
|
85
|
+
'riding.elites',
|
|
86
|
+
'riding.elites-ready',
|
|
87
|
+
'elite.entry',
|
|
88
|
+
'elite.construct',
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'boss',
|
|
93
|
+
row: 'OF34',
|
|
94
|
+
on: 'later',
|
|
95
|
+
hosts: ['boss.ground', 'boss.spawned', 'boss.held'],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'boss.arena',
|
|
99
|
+
row: 'OF34',
|
|
100
|
+
on: 'later',
|
|
101
|
+
hosts: ['boss.arena', 'boss.open-arena'],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'riding',
|
|
105
|
+
row: 'CC40',
|
|
106
|
+
on: {
|
|
107
|
+
section: 'actors/species',
|
|
108
|
+
path: ['rows', 'species'],
|
|
109
|
+
having: 'mount',
|
|
110
|
+
},
|
|
111
|
+
hosts: [
|
|
112
|
+
'riding.mounted',
|
|
113
|
+
'riding.roster',
|
|
114
|
+
'riding.groups',
|
|
115
|
+
'riding.hunt',
|
|
116
|
+
'riding.trample',
|
|
117
|
+
'riding.environment',
|
|
118
|
+
'riding.taming',
|
|
119
|
+
'riding.session',
|
|
120
|
+
'taming.entry',
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'patrol',
|
|
125
|
+
row: 'OF37',
|
|
126
|
+
on: 'later',
|
|
127
|
+
hosts: ['encounter.patrol', 'timed.encounters'],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'held.melee',
|
|
131
|
+
row: 'OF38',
|
|
132
|
+
on: 'later',
|
|
133
|
+
hosts: [
|
|
134
|
+
'item.swept',
|
|
135
|
+
'held.melee',
|
|
136
|
+
'held.arms',
|
|
137
|
+
'held.claims',
|
|
138
|
+
'held.cosmetics',
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'held.ranged',
|
|
143
|
+
row: 'OF38',
|
|
144
|
+
on: 'later',
|
|
145
|
+
hosts: [
|
|
146
|
+
'item.ranged',
|
|
147
|
+
'combat.motion',
|
|
148
|
+
'ammunition',
|
|
149
|
+
'loadout',
|
|
150
|
+
'held.ranged-feel',
|
|
151
|
+
'held.ranged-page',
|
|
152
|
+
'combat.targets',
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'sky',
|
|
157
|
+
row: 'OF41',
|
|
158
|
+
on: { section: 'world/days', path: ['rows', 'days'] },
|
|
159
|
+
hosts: ['day.toon', 'day.keyed-sky', 'day.declared'],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'weather',
|
|
163
|
+
row: 'OF41',
|
|
164
|
+
on: { section: 'world/weather', path: ['rows', 'weather'] },
|
|
165
|
+
hosts: [
|
|
166
|
+
'weather.program',
|
|
167
|
+
'weather.native',
|
|
168
|
+
'weather.forest',
|
|
169
|
+
'weather.fields',
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'water.sea',
|
|
174
|
+
row: 'OF40',
|
|
175
|
+
on: 'later',
|
|
176
|
+
hosts: ['water.sea', 'world.water'],
|
|
177
|
+
},
|
|
178
|
+
{ name: 'water.field', row: 'OF40', on: 'later', hosts: ['water.field'] },
|
|
179
|
+
{ name: 'grapple', row: 'OF41', on: 'later', hosts: ['grapple'] },
|
|
180
|
+
{ name: 'portal', row: 'OF41', on: 'later', hosts: ['portal.ride'] },
|
|
181
|
+
]
|
|
182
|
+
const PRIMITIVES: readonly Primitive[] = Object.freeze(
|
|
183
|
+
TABLE.map((row): Primitive => Object.freeze(row)),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
/** Hosts HOSTS.md leaves out of the primitives: quest (Q-S5), opened as it is; Nalati's stealth entry (Q-S4). */
|
|
187
|
+
const OUT_OF_SCOPE_HOSTS: readonly string[] = Object.freeze([
|
|
188
|
+
'quest.body-scripts',
|
|
189
|
+
'quest.composition',
|
|
190
|
+
'quest.chapter',
|
|
191
|
+
'quest.kill-steps',
|
|
192
|
+
'stealth.entry',
|
|
193
|
+
])
|
|
194
|
+
|
|
195
|
+
const HOST_FAMILY: ReadonlyMap<string, string> = new Map(
|
|
196
|
+
PRIMITIVES.flatMap((row): (readonly [string, string])[] =>
|
|
197
|
+
row.hosts.map((host): readonly [string, string] => [host, row.name]),
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
/** The family a host joins, or `undefined` for a host outside the table. */
|
|
202
|
+
function primitiveOfHost(host: string): string | undefined {
|
|
203
|
+
return HOST_FAMILY.get(host)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function at(value: unknown, path: readonly string[]): unknown {
|
|
207
|
+
let here = value
|
|
208
|
+
for (const key of path) {
|
|
209
|
+
if (typeof here !== 'object' || here === null || Array.isArray(here)) {
|
|
210
|
+
return undefined
|
|
211
|
+
}
|
|
212
|
+
const next: unknown = Object.getOwnPropertyDescriptor(here, key)?.value
|
|
213
|
+
here = next
|
|
214
|
+
}
|
|
215
|
+
return here
|
|
216
|
+
}
|
|
217
|
+
function filled(value: unknown): boolean {
|
|
218
|
+
if (Array.isArray(value)) {
|
|
219
|
+
return value.length > NONE
|
|
220
|
+
}
|
|
221
|
+
return (
|
|
222
|
+
typeof value === 'object' &&
|
|
223
|
+
value !== null &&
|
|
224
|
+
Object.keys(value).length > NONE
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
function switchedOn(value: unknown, having: string | undefined): boolean {
|
|
228
|
+
if (having === undefined) {
|
|
229
|
+
return filled(value)
|
|
230
|
+
}
|
|
231
|
+
return (
|
|
232
|
+
Array.isArray(value) &&
|
|
233
|
+
value.some(
|
|
234
|
+
(row: unknown): boolean =>
|
|
235
|
+
typeof row === 'object' && row !== null && Object.hasOwn(row, having),
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
function newest(section: string): number {
|
|
240
|
+
return Math.max(...(ACCEPTED_SECTION_VERSIONS[section] ?? [FIRST_VERSION]))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The primitives a product's sections switch on, in table order: `sections` maps each section name to its admitted
|
|
245
|
+
* value. A family is on when its switch path holds a non-empty array or object. `versions` are the `@N` the index named
|
|
246
|
+
* (default: the newest this format reads).
|
|
247
|
+
*/
|
|
248
|
+
function derivePrimitives(
|
|
249
|
+
sections: ReadonlyMap<string, unknown>,
|
|
250
|
+
versions: ReadonlyMap<string, number> = new Map(),
|
|
251
|
+
): DerivedPrimitive[] {
|
|
252
|
+
return PRIMITIVES.flatMap((row): DerivedPrimitive[] => {
|
|
253
|
+
if (row.on === 'always') {
|
|
254
|
+
return [{ name: row.name, version: FIRST_VERSION }]
|
|
255
|
+
}
|
|
256
|
+
if (
|
|
257
|
+
row.on === 'later' ||
|
|
258
|
+
!switchedOn(at(sections.get(row.on.section), row.on.path), row.on.having)
|
|
259
|
+
) {
|
|
260
|
+
return []
|
|
261
|
+
}
|
|
262
|
+
const { section } = row.on
|
|
263
|
+
return [
|
|
264
|
+
{
|
|
265
|
+
name: row.name,
|
|
266
|
+
section,
|
|
267
|
+
version: versions.get(section) ?? newest(section),
|
|
268
|
+
},
|
|
269
|
+
]
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export type { DerivedPrimitive, Primitive, PrimitiveSwitch }
|
|
274
|
+
export { OUT_OF_SCOPE_HOSTS, PRIMITIVES, derivePrimitives, primitiveOfHost }
|
package/src/format/rows.ts
CHANGED
|
@@ -7,7 +7,7 @@ import * as v from 'valibot';
|
|
|
7
7
|
import { isJsonData } from './json.ts';
|
|
8
8
|
import { sketchReference } from './sketch.ts';
|
|
9
9
|
import { JournalRowSchema, journalRowRules } from './compendiumRows.ts';
|
|
10
|
-
import { CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
|
|
10
|
+
import { CreatureMountSchema, creatureMountRules, CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
|
|
11
11
|
import type { CreatureAbilityInput, CreatureLayers } from './creature-layers.ts';
|
|
12
12
|
import { creatureSizeRules } from './creature-sizes.ts';
|
|
13
13
|
import { SKIN_CLIPS_RECIPE, SkinClipMapSchema } from './skins.ts';
|
|
@@ -52,7 +52,7 @@ const species = v.strictObject({ id, kind: id, label: text, capExempt: v.exactOp
|
|
|
52
52
|
variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
|
|
53
53
|
type: v.exactOptional(CreatureTypeSchema), body: v.exactOptional(CreatureBodySchema),
|
|
54
54
|
temperament: v.exactOptional(CreatureTemperamentSchema), senses: v.exactOptional(CreatureSensesSchema),
|
|
55
|
-
abilities: v.exactOptional(abilities), presentation: v.exactOptional(CreaturePresentationSchema) });
|
|
55
|
+
abilities: v.exactOptional(abilities), presentation: v.exactOptional(CreaturePresentationSchema), mount: v.exactOptional(CreatureMountSchema) });
|
|
56
56
|
const parameter = v.union([finite, v.boolean(), text, v.pipe(v.array(finite), v.maxLength(16))]);
|
|
57
57
|
const animationParameters = v.record(id, parameter);
|
|
58
58
|
const lookAnimation = v.strictObject({
|
|
@@ -82,7 +82,7 @@ function rowRules(rows: ShardRows): string[] {
|
|
|
82
82
|
}
|
|
83
83
|
for (const d of rows.days) if (d.schedule[0]?.from !== 0 || d.schedule.at(-1)?.to !== 24 || d.schedule.some((s, i) => s.from >= s.to || (i > 0 && d.schedule[i - 1]?.to !== s.from))) errors.push('complete ordered day schedule');
|
|
84
84
|
const speciesIds = new Set(rows.species.map((s) => s.id));
|
|
85
|
-
errors.push(...strikeDebrisCatalogueRules(rows), ...creatureSizeRules(rows.species));
|
|
85
|
+
errors.push(...strikeDebrisCatalogueRules(rows), ...creatureSizeRules(rows.species), ...creatureMountRules(rows.species));
|
|
86
86
|
for (const s of rows.species) if (new Set(s.variants.map((r) => r.id)).size !== s.variants.length || s.variants.some((r) => r.scale[1] > 10)) errors.push('species variants');
|
|
87
87
|
const strikeIds = new Set<string>();
|
|
88
88
|
for (const strikeRow of rows.strikes) { strikeIds.add(strikeRow.id); }
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { OUTPUT_SECTIONS } from './outputFields.ts'
|
|
2
|
+
import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts'
|
|
3
|
+
|
|
4
|
+
/** The one version every section is at today. */
|
|
5
|
+
const FIRST_VERSION = 1
|
|
6
|
+
/** How much of a bad schema string a refusal quotes. */
|
|
7
|
+
const QUOTED_SCHEMA_CHARS = 120
|
|
8
|
+
const FIRST_CHAR = 0
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ONE-FORMAT OF17a, SHARD-COMPAT §3.3: the section versions this format reads. A section's version is the `@N` its index
|
|
12
|
+
* row already names (`schema: "wildshard:<name>@<N>"`), never a field in its body. Every section is at version 1 today;
|
|
13
|
+
* an additive change keeps `[1]`, a removal adds `@2` beside `@1` and drops `@1` only at SHARD-COMPAT's B release.
|
|
14
|
+
*/
|
|
15
|
+
const ACCEPTED_SECTION_VERSIONS: Readonly<Record<string, readonly number[]>> =
|
|
16
|
+
Object.freeze(
|
|
17
|
+
Object.fromEntries(
|
|
18
|
+
[
|
|
19
|
+
...OUTPUT_SECTIONS.map((row): string => row.name),
|
|
20
|
+
...Object.keys(PLATFORM_DATA_SECTIONS),
|
|
21
|
+
].map((name): [string, readonly number[]] => [
|
|
22
|
+
name,
|
|
23
|
+
Object.freeze([FIRST_VERSION]),
|
|
24
|
+
]),
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const SCHEMA = /^wildshard:(?<name>[^@]+)@(?<version>0|[1-9]\d{0,5})$/u
|
|
29
|
+
|
|
30
|
+
/** The version an index row's schema names, when it names its own section; `undefined` otherwise. */
|
|
31
|
+
function sectionSchemaVersion(
|
|
32
|
+
name: string,
|
|
33
|
+
schema: string,
|
|
34
|
+
): number | undefined {
|
|
35
|
+
const match = SCHEMA.exec(schema)
|
|
36
|
+
return match?.groups?.['name'] === name
|
|
37
|
+
? Number(match.groups['version'])
|
|
38
|
+
: undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Why an index row's section and schema are not ones this format reads, as one named line; `undefined` when they are. */
|
|
42
|
+
function sectionSchemaIssue(name: string, schema: string): string | undefined {
|
|
43
|
+
const accepted = Object.hasOwn(ACCEPTED_SECTION_VERSIONS, name)
|
|
44
|
+
? ACCEPTED_SECTION_VERSIONS[name]
|
|
45
|
+
: undefined
|
|
46
|
+
if (accepted === undefined) {
|
|
47
|
+
return `unknown platform section ${name}`
|
|
48
|
+
}
|
|
49
|
+
const version = sectionSchemaVersion(name, schema)
|
|
50
|
+
if (version === undefined) {
|
|
51
|
+
return `section ${name} names the schema ${schema.slice(FIRST_CHAR, QUOTED_SCHEMA_CHARS)}; expected wildshard:${name}@<version>`
|
|
52
|
+
}
|
|
53
|
+
return accepted.includes(version)
|
|
54
|
+
? undefined
|
|
55
|
+
: `section ${name} is at version ${String(version)}; this format reads ${accepted.join(', ')}`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
ACCEPTED_SECTION_VERSIONS,
|
|
60
|
+
FIRST_VERSION,
|
|
61
|
+
sectionSchemaIssue,
|
|
62
|
+
sectionSchemaVersion,
|
|
63
|
+
}
|
|
@@ -4,23 +4,28 @@ import { CreatureStrikeSchema } from './creatures.ts';
|
|
|
4
4
|
|
|
5
5
|
const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
|
|
6
6
|
const amount = v.pipe(v.number(), v.finite(), v.minValue(0), v.maxValue(60));
|
|
7
|
+
type StrikeTellKind = 'lane' | 'ring';
|
|
8
|
+
const StrikeTellKindSchema: v.GenericSchema<StrikeTellKind> = v.picklist(['lane', 'ring']);
|
|
7
9
|
/** V1 strike capabilities use the existing contact kernel. Effects and presentation edges are rows, never hooks. */
|
|
8
|
-
|
|
10
|
+
const SpawnCombatSchema: v.GenericSchema<SpawnCombatInput, SpawnCombat> = v.pipe(v.unknown(), v.check(isJsonData, 'plain JSON scripted strikes'), v.array(v.strictObject({ id, row: CreatureStrikeSchema,
|
|
9
11
|
trauma: v.pipe(v.number(), v.finite(), v.minValue(0), v.maxValue(1)), stun: amount,
|
|
10
|
-
tell: v.exactOptional(
|
|
12
|
+
tell: v.exactOptional(StrikeTellKindSchema), startCue: v.exactOptional(id), activeCue: v.exactOptional(id), doneCue: v.exactOptional(id),
|
|
11
13
|
})), v.maxLength(32), v.check(rows => new Set(rows.map(row => row.id)).size === rows.length
|
|
12
14
|
&& new Set(rows.map(row => row.row.id)).size === rows.length, 'unique scripted strikes'));
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
/** Admitted data contracts, independent of validator implementation metadata. */
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
type SpawnCombatInput = unknown;
|
|
19
|
+
type SpawnCombat = ({
|
|
18
20
|
id: string;
|
|
19
21
|
row: v.InferOutput<typeof CreatureStrikeSchema>;
|
|
20
22
|
trauma: number;
|
|
21
23
|
stun: number;
|
|
22
|
-
tell?:
|
|
24
|
+
tell?: StrikeTellKind;
|
|
23
25
|
startCue?: string;
|
|
24
26
|
activeCue?: string;
|
|
25
27
|
doneCue?: string;
|
|
26
28
|
})[];
|
|
29
|
+
|
|
30
|
+
export { SpawnCombatSchema, StrikeTellKindSchema };
|
|
31
|
+
export type { SpawnCombat, SpawnCombatInput, StrikeTellKind };
|