@wildshard/kit 0.0.0-stage → 0.4.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.
Files changed (129) hide show
  1. package/GUIDE.md +221 -0
  2. package/content/abilities/bite.json +24 -0
  3. package/content/abilities/charge.json +25 -0
  4. package/content/abilities/claw.json +24 -0
  5. package/content/abilities/slam.json +24 -0
  6. package/content/abilities/swing.json +25 -0
  7. package/content/animated/bear/pbr/black-blaze.glb +0 -0
  8. package/content/animated/bear/pbr/black-blaze.json +1 -0
  9. package/content/animated/bear/pbr/black-old.glb +0 -0
  10. package/content/animated/bear/pbr/black-old.json +1 -0
  11. package/content/animated/bear/pbr/black.glb +0 -0
  12. package/content/animated/bear/pbr/black.json +1 -0
  13. package/content/animated/bear/pbr/brown-old.glb +0 -0
  14. package/content/animated/bear/pbr/brown-old.json +1 -0
  15. package/content/animated/bear/pbr/brown.glb +0 -0
  16. package/content/animated/bear/pbr/brown.json +1 -0
  17. package/content/animated/bear/toon/black-blaze.glb +0 -0
  18. package/content/animated/bear/toon/black-blaze.json +1 -0
  19. package/content/animated/bear/toon/black-old.glb +0 -0
  20. package/content/animated/bear/toon/black-old.json +1 -0
  21. package/content/animated/bear/toon/black.glb +0 -0
  22. package/content/animated/bear/toon/black.json +1 -0
  23. package/content/animated/bear/toon/brown-old.glb +0 -0
  24. package/content/animated/bear/toon/brown-old.json +1 -0
  25. package/content/animated/bear/toon/brown.glb +0 -0
  26. package/content/animated/bear/toon/brown.json +1 -0
  27. package/content/animated/boar/pbr/big.glb +0 -0
  28. package/content/animated/boar/pbr/big.json +1 -0
  29. package/content/animated/boar/pbr/black.glb +0 -0
  30. package/content/animated/boar/pbr/black.json +1 -0
  31. package/content/animated/boar/pbr/boar.glb +0 -0
  32. package/content/animated/boar/pbr/boar.json +1 -0
  33. package/content/animated/boar/pbr/ironhide.glb +0 -0
  34. package/content/animated/boar/pbr/ironhide.json +1 -0
  35. package/content/animated/boar/pbr/scarback.glb +0 -0
  36. package/content/animated/boar/pbr/scarback.json +1 -0
  37. package/content/animated/boar/pbr/sow.glb +0 -0
  38. package/content/animated/boar/pbr/sow.json +1 -0
  39. package/content/animated/boar/toon/big.glb +0 -0
  40. package/content/animated/boar/toon/big.json +1 -0
  41. package/content/animated/boar/toon/black.glb +0 -0
  42. package/content/animated/boar/toon/black.json +1 -0
  43. package/content/animated/boar/toon/boar.glb +0 -0
  44. package/content/animated/boar/toon/boar.json +1 -0
  45. package/content/animated/boar/toon/ironhide.glb +0 -0
  46. package/content/animated/boar/toon/ironhide.json +1 -0
  47. package/content/animated/boar/toon/scarback.glb +0 -0
  48. package/content/animated/boar/toon/scarback.json +1 -0
  49. package/content/animated/boar/toon/sow.glb +0 -0
  50. package/content/animated/boar/toon/sow.json +1 -0
  51. package/content/animated/catalogue.json +1 -0
  52. package/content/bodies/biped.json +5 -0
  53. package/content/bodies/quadruped.json +5 -0
  54. package/content/clips/quadruped.json +1 -0
  55. package/content/creatures/bear/look.json +199 -0
  56. package/content/creatures/bear/pbr/black-blaze.glb +0 -0
  57. package/content/creatures/bear/pbr/black-old.glb +0 -0
  58. package/content/creatures/bear/pbr/black.glb +0 -0
  59. package/content/creatures/bear/pbr/brown-old.glb +0 -0
  60. package/content/creatures/bear/pbr/brown.glb +0 -0
  61. package/content/creatures/bear/toon/black-blaze.glb +0 -0
  62. package/content/creatures/bear/toon/black-old.glb +0 -0
  63. package/content/creatures/bear/toon/black.glb +0 -0
  64. package/content/creatures/bear/toon/brown-old.glb +0 -0
  65. package/content/creatures/bear/toon/brown.glb +0 -0
  66. package/content/creatures/bear.json +257 -0
  67. package/content/creatures/boar/look.json +184 -0
  68. package/content/creatures/boar/pbr/big.glb +0 -0
  69. package/content/creatures/boar/pbr/black.glb +0 -0
  70. package/content/creatures/boar/pbr/boar.glb +0 -0
  71. package/content/creatures/boar/pbr/ironhide.glb +0 -0
  72. package/content/creatures/boar/pbr/scarback.glb +0 -0
  73. package/content/creatures/boar/pbr/sow.glb +0 -0
  74. package/content/creatures/boar/toon/big.glb +0 -0
  75. package/content/creatures/boar/toon/black.glb +0 -0
  76. package/content/creatures/boar/toon/boar.glb +0 -0
  77. package/content/creatures/boar/toon/ironhide.glb +0 -0
  78. package/content/creatures/boar/toon/scarback.glb +0 -0
  79. package/content/creatures/boar/toon/sow.glb +0 -0
  80. package/content/creatures/boar.json +275 -0
  81. package/content/creatures/bodies.json +4754 -0
  82. package/content/harvest-items.json +98 -0
  83. package/content/harvest.json +31 -0
  84. package/content/journal-icons/antlers.png +0 -0
  85. package/content/journal-icons/bear.png +0 -0
  86. package/content/journal-icons/boar.png +0 -0
  87. package/content/journal-icons/deer.png +0 -0
  88. package/content/journal-icons/elk.png +0 -0
  89. package/content/journal-icons/ghost.png +0 -0
  90. package/content/journal-icons/ironhide.png +0 -0
  91. package/content/journal-icons.json +9 -0
  92. package/content/shared/pickupCatalogue.json +1008 -0
  93. package/content/shared/starterBow.json +21 -0
  94. package/content/species/bear.json +144 -0
  95. package/content/species/boar.json +147 -0
  96. package/content/sword-debris.json +7 -0
  97. package/content/temperaments.json +519 -0
  98. package/content/tuning/bear.json +43 -0
  99. package/content/tuning/boar.json +32 -0
  100. package/content/tuning/deer.json +32 -0
  101. package/content/tuning/pursue.json +12 -0
  102. package/package.json +63 -3
  103. package/src/abilities.ts +85 -0
  104. package/src/body.ts +25 -0
  105. package/src/clips.ts +139 -0
  106. package/src/creatures.ts +76 -0
  107. package/src/geometry/arms.ts +725 -0
  108. package/src/geometry/bear.ts +521 -0
  109. package/src/geometry/boar.ts +604 -0
  110. package/src/geometry/bowProfile.ts +34 -0
  111. package/src/geometry/export.ts +101 -0
  112. package/src/geometry/meleeProfile.ts +261 -0
  113. package/src/geometry/nativeInteractionFacts.ts +7 -0
  114. package/src/geometry/nativeLooks.ts +54 -0
  115. package/src/geometry/riderArms.ts +215 -0
  116. package/src/geometry/sharedSpecs.ts +26 -0
  117. package/src/geometry/species.ts +768 -0
  118. package/src/geometry/specimenCatalogue.ts +80 -0
  119. package/src/geometry/starterCombat.ts +194 -0
  120. package/src/geometry/starterGlyphs.ts +12 -0
  121. package/src/geometry/starterMeleeProfile.ts +134 -0
  122. package/src/geometry/starterMoves.ts +172 -0
  123. package/src/index.ts +26 -0
  124. package/src/legacyCombat.ts +25 -0
  125. package/src/legacyHarvest.ts +104 -0
  126. package/src/legacyJournalIcons.ts +10 -0
  127. package/src/legacySpecies.ts +127 -0
  128. package/src/temperament.ts +97 -0
  129. package/README.md +0 -3
@@ -0,0 +1,85 @@
1
+ import {
2
+ CreatureAbilitySchema,
3
+ type CreatureAbility,
4
+ } from '@wildshard/shard-format/creatureLayers'
5
+ import { RowsSchema, type StrikeRows } from '@wildshard/shard-format/rows'
6
+ import { parse, strictObject, type GenericSchema } from 'valibot'
7
+
8
+ import bite from '../content/abilities/bite.json' with { type: 'json' }
9
+ import charge from '../content/abilities/charge.json' with { type: 'json' }
10
+ import claw from '../content/abilities/claw.json' with { type: 'json' }
11
+ import slam from '../content/abilities/slam.json' with { type: 'json' }
12
+ import swing from '../content/abilities/swing.json' with { type: 'json' }
13
+
14
+ interface AbilityTemplate {
15
+ ability: CreatureAbility
16
+ strike: StrikeRows
17
+ }
18
+ interface AbilityOptions {
19
+ readonly id?: string
20
+ readonly damage?: number
21
+ readonly range?: number
22
+ readonly cooldown?: number
23
+ readonly weight?: number
24
+ readonly hpBelow?: number
25
+ }
26
+ type AbilityName = 'bite' | 'claw' | 'swing' | 'charge' | 'slam'
27
+ type AbilityHelper = (options?: Readonly<AbilityOptions>) => AbilityTemplate
28
+ const plain = { bite, claw, swing, charge, slam }
29
+ const ROW_ENTRIES = 2
30
+ const ARRAY_SCHEMA = 0
31
+ const StrikeSchema =
32
+ RowsSchema.pipe[ROW_ENTRIES].entries.strikes.pipe[ARRAY_SCHEMA].item
33
+ const TemplateSchema: GenericSchema<AbilityTemplate> = strictObject({
34
+ ability: CreatureAbilitySchema,
35
+ strike: StrikeSchema,
36
+ })
37
+
38
+ function strikeOverrides(
39
+ options: Readonly<AbilityOptions>,
40
+ ): Partial<StrikeRows> {
41
+ return {
42
+ ...(options.id === undefined ? {} : { id: options.id }),
43
+ ...(options.damage === undefined ? {} : { damage: options.damage }),
44
+ ...(options.range === undefined ? {} : { range: options.range }),
45
+ ...(options.cooldown === undefined ? {} : { cooldown: options.cooldown }),
46
+ ...(options.weight === undefined ? {} : { weight: options.weight }),
47
+ }
48
+ }
49
+ function abilityOverrides(
50
+ options: Readonly<AbilityOptions>,
51
+ ): Partial<CreatureAbility> {
52
+ return {
53
+ ...(options.id === undefined ? {} : { use: options.id }),
54
+ ...(options.range === undefined ? {} : { range: options.range }),
55
+ ...(options.cooldown === undefined ? {} : { cooldown: options.cooldown }),
56
+ ...(options.weight === undefined ? {} : { weight: options.weight }),
57
+ ...(options.hpBelow === undefined ? {} : { hpBelow: options.hpBelow }),
58
+ }
59
+ }
60
+ /** Helpers return the strike row and its priority-list reference together. */
61
+ function ability(
62
+ name: AbilityName,
63
+ options: Readonly<AbilityOptions> = {},
64
+ ): AbilityTemplate {
65
+ const row = parse(TemplateSchema, plain[name])
66
+ return parse(TemplateSchema, {
67
+ ability: { ...row.ability, ...abilityOverrides(options) },
68
+ strike: { ...row.strike, ...strikeOverrides(options) },
69
+ })
70
+ }
71
+ const abilities: Readonly<Record<AbilityName, AbilityHelper>> = {
72
+ bite: (options?: Readonly<AbilityOptions>): AbilityTemplate =>
73
+ ability('bite', options),
74
+ claw: (options?: Readonly<AbilityOptions>): AbilityTemplate =>
75
+ ability('claw', options),
76
+ swing: (options?: Readonly<AbilityOptions>): AbilityTemplate =>
77
+ ability('swing', options),
78
+ charge: (options?: Readonly<AbilityOptions>): AbilityTemplate =>
79
+ ability('charge', options),
80
+ slam: (options?: Readonly<AbilityOptions>): AbilityTemplate =>
81
+ ability('slam', options),
82
+ }
83
+
84
+ export { abilities }
85
+ export type { AbilityOptions, AbilityTemplate, AbilityHelper, AbilityName }
package/src/body.ts ADDED
@@ -0,0 +1,25 @@
1
+ import {
2
+ CreatureBodySchema,
3
+ type CreatureBody,
4
+ type CreatureSize,
5
+ } from '@wildshard/shard-format/creatureLayers'
6
+ import { parse } from 'valibot'
7
+
8
+ import bipedBody from '../content/bodies/biped.json' with { type: 'json' }
9
+ import quadrupedBody from '../content/bodies/quadruped.json' with { type: 'json' }
10
+
11
+ interface BodyOptions {
12
+ readonly look: string
13
+ readonly size?: CreatureSize
14
+ readonly scale?: number
15
+ }
16
+
17
+ function quadruped(options: Readonly<BodyOptions>): CreatureBody {
18
+ return parse(CreatureBodySchema, { ...quadrupedBody, ...options })
19
+ }
20
+ function biped(options: Readonly<BodyOptions>): CreatureBody {
21
+ return parse(CreatureBodySchema, { ...bipedBody, ...options })
22
+ }
23
+
24
+ export { quadruped, biped }
25
+ export type { BodyOptions }
package/src/clips.ts ADDED
@@ -0,0 +1,139 @@
1
+ import {
2
+ SkinClipNameSchema,
3
+ SkinBindingSchema,
4
+ type SkinBinding,
5
+ } from '@wildshard/shard-format/skinData'
6
+ import {
7
+ AnimationClip,
8
+ QuaternionKeyframeTrack,
9
+ VectorKeyframeTrack,
10
+ } from 'three'
11
+ import * as v from 'valibot'
12
+
13
+ import content from '../content/clips/quadruped.json' with { type: 'json' }
14
+
15
+ import type { BoneDef } from './geometry/species.ts'
16
+
17
+ const finite = v.pipe(v.number(), v.finite())
18
+ const name = v.pipe(
19
+ v.string(),
20
+ v.regex(/^[A-Za-z][A-Za-z0-9_.-]*$/u),
21
+ v.maxLength(64),
22
+ )
23
+ const vector = v.tuple([finite, finite, finite])
24
+ const pack = v.parse(
25
+ v.strictObject({
26
+ version: v.literal(1),
27
+ source: v.strictObject({
28
+ repo: v.string(),
29
+ revision: v.string(),
30
+ glb: v.string(),
31
+ skin: v.string(),
32
+ }),
33
+ bones: v.pipe(
34
+ v.array(
35
+ v.strictObject({
36
+ name,
37
+ parent: v.nullable(name),
38
+ position: vector,
39
+ rotation: v.tuple([finite, finite, finite, finite]),
40
+ scale: vector,
41
+ }),
42
+ ),
43
+ v.minLength(1),
44
+ v.maxLength(64),
45
+ ),
46
+ clips: v.pipe(
47
+ v.array(
48
+ v.strictObject({
49
+ name: SkinClipNameSchema,
50
+ tracks: v.pipe(
51
+ v.array(
52
+ v.strictObject({
53
+ bone: name,
54
+ property: v.picklist(['position', 'quaternion', 'scale']),
55
+ times: v.pipe(
56
+ v.array(finite),
57
+ v.minLength(2),
58
+ v.maxLength(4097),
59
+ ),
60
+ values: v.pipe(v.array(finite), v.maxLength(16388)),
61
+ }),
62
+ ),
63
+ v.maxLength(192),
64
+ ),
65
+ }),
66
+ ),
67
+ v.minLength(1),
68
+ v.maxLength(32),
69
+ ),
70
+ binding: SkinBindingSchema,
71
+ }),
72
+ content,
73
+ )
74
+
75
+ /** Existing quadruped clips, translated from their source rest offsets to the supplied named bones. */
76
+ export function quadrupedClips(bones: readonly BoneDef[]): AnimationClip[] {
77
+ const targets = new Map(bones.map(bone => [bone.name, bone]))
78
+ if (targets.size !== bones.length)
79
+ throw new Error('Quadruped clip target has duplicate bones')
80
+ const offsets = new Map<string, readonly number[]>()
81
+ for (const source of pack.bones) {
82
+ const target = targets.get(source.name)
83
+ if (target === undefined || target.parent !== source.parent)
84
+ throw new Error(`Quadruped clips need chain ${source.name}`)
85
+ const parent =
86
+ target.parent === null ? undefined : targets.get(target.parent)
87
+ if (target.parent !== null && parent === undefined)
88
+ throw new Error(`Quadruped clips need parent ${target.parent}`)
89
+ if (
90
+ source.rotation.some((value, axis) => value !== [0, 0, 0, 1][axis]) ||
91
+ source.scale.some(value => value !== 1)
92
+ )
93
+ throw new Error('Quadruped clip source has a transformed rest pose')
94
+ offsets.set(
95
+ source.name,
96
+ target.pos.map(
97
+ (value, axis) =>
98
+ value - (parent?.pos[axis] ?? 0) - (source.position[axis] ?? 0),
99
+ ),
100
+ )
101
+ }
102
+ return pack.clips.map(
103
+ clip =>
104
+ new AnimationClip(
105
+ clip.name,
106
+ -1,
107
+ clip.tracks.map(track => {
108
+ const offset = offsets.get(track.bone),
109
+ width = track.property === 'quaternion' ? 4 : 3
110
+ if (
111
+ offset === undefined ||
112
+ track.values.length !== track.times.length * width ||
113
+ track.times[0] !== 0 ||
114
+ track.times.some(
115
+ (time, index) =>
116
+ index > 0 && time <= (track.times[index - 1] ?? 0),
117
+ ) ||
118
+ (track.times.at(-1) ?? Infinity) > 60
119
+ )
120
+ throw new Error(`Invalid quadruped clip ${clip.name}/${track.bone}`)
121
+ const values =
122
+ track.property === 'position'
123
+ ? track.values.map(
124
+ (value, index) => value + (offset[index % 3] ?? 0),
125
+ )
126
+ : track.values
127
+ const path = `${track.bone}.${track.property}`
128
+ return track.property === 'quaternion'
129
+ ? new QuaternionKeyframeTrack(path, track.times, values)
130
+ : new VectorKeyframeTrack(path, track.times, values)
131
+ }),
132
+ ),
133
+ )
134
+ }
135
+
136
+ /** Fresh plain binding and existing periodic pose tables for a skin on this named quadruped chain. */
137
+ export function quadrupedBinding(skin: string): SkinBinding {
138
+ return v.parse(SkinBindingSchema, { ...structuredClone(pack.binding), skin })
139
+ }
@@ -0,0 +1,76 @@
1
+ import {
2
+ parseRows,
3
+ type SpeciesRow,
4
+ type StrikeRows,
5
+ } from '@wildshard/shard-format/rows'
6
+
7
+ import bear from '../content/creatures/bear.json' with { type: 'json' }
8
+ import boar from '../content/creatures/boar.json' with { type: 'json' }
9
+ import { legacyHarvestItems } from './legacyHarvest.ts'
10
+
11
+ import type { ShardItems } from '@wildshard/shard-format/items'
12
+
13
+ type CommonCreatureKind = 'boar' | 'bear'
14
+ interface CreatureOptions {
15
+ readonly id: string
16
+ readonly look: string
17
+ readonly strike?: string
18
+ }
19
+ interface CreatureContent {
20
+ species: SpeciesRow
21
+ strikes: StrikeRows[]
22
+ items: NonNullable<ShardItems['catalogue']>
23
+ }
24
+ const plain = { boar, bear }
25
+
26
+ /** Copy shipped gameplay layers; the caller supplies its own species and look ids. */
27
+ function commonCreature(
28
+ kind: CommonCreatureKind,
29
+ options: Readonly<CreatureOptions>,
30
+ ): CreatureContent {
31
+ const content = plain[kind]
32
+ const strikeId = options.strike ?? `${options.id}.charge`
33
+ const rows = parseRows({
34
+ strikes: content.strikes.map(strike => {
35
+ const row = structuredClone(strike)
36
+ row.id = strikeId
37
+ return row
38
+ }),
39
+ weather: [],
40
+ days: [],
41
+ compendiums: [],
42
+ loot: [],
43
+ species: [
44
+ {
45
+ ...content.species,
46
+ id: options.id,
47
+ body: { ...content.species.body, look: options.look },
48
+ abilities: content.species.abilities.map(ability => {
49
+ const row = structuredClone(ability)
50
+ row.use = strikeId
51
+ return row
52
+ }),
53
+ },
54
+ ],
55
+ looks: [
56
+ {
57
+ id: options.look,
58
+ species: options.id,
59
+ recipe: 'platform.skin',
60
+ material: null,
61
+ parameters: {},
62
+ animation: { recipe: 'platform.clips', parameters: {} },
63
+ },
64
+ ],
65
+ })
66
+ const [species] = rows.species
67
+ if (species === undefined) throw new Error('Missing kit creature row')
68
+ return {
69
+ species,
70
+ strikes: rows.strikes,
71
+ items: legacyHarvestItems((species.harvest ?? []).map(row => row.item)),
72
+ }
73
+ }
74
+
75
+ export { commonCreature }
76
+ export type { CommonCreatureKind, CreatureOptions, CreatureContent }