Repository navigation
Expand file tree
/
Copy pathavatarClips.ts
More file actions
101 lines (88 loc) · 2.91 KB
/
Copy pathavatarClips.ts
File metadata and controls
101 lines (88 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type { Section } from '../../hooks/useActiveSection'
export type PlayMode = 'loop' | 'once'
export interface ClipConfig {
src: string
mode: PlayMode
}
function once(src: string): ClipConfig {
return { src, mode: 'once' }
}
function shuffle<T>(items: readonly T[]): T[] {
const shuffled = [...items]
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
;[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]
}
return shuffled
}
// Draws items in shuffled batches so every clip in the pool plays before any repeats,
// and avoids repeating the same clip back-to-back across a batch boundary.
function createShuffleBag<T>(items: readonly T[]): () => T {
let bag: T[] = []
let previous: T | undefined
return () => {
if (bag.length === 0) {
bag = shuffle(items)
if (items.length > 1 && bag[0] === previous) {
;[bag[0], bag[1]] = [bag[1], bag[0]]
}
}
const value = bag.shift() as T
previous = value
return value
}
}
export const APP_LOADED_CLIP: ClipConfig = once('/wave_hello_3.mp4')
export const CHAT_SENT_CLIP: ClipConfig = once('/waving_gesture.mp4')
const IDLE_CLIPS: ClipConfig[] = [
once('/happy_idle.mp4'),
once('/walk_sway.mp4'),
once('/walk_swing_arms.mp4'),
once('/floating.mp4'),
]
const nextIdleClip = createShuffleBag(IDLE_CLIPS)
const NAV_CLIP_POOLS: Record<Section, ClipConfig[]> = {
about: ['catwalk_walk', 'standard_walk', 'walk_punch_kick_jump_walk', 'zombie_walk'].map(
(name) => once(`/${name}.mp4`),
),
experience: ['run', 'run_walk_jump_walk', 'running_jump', 'jump'].map((name) =>
once(`/${name}.mp4`),
),
projects: ['box_jump', 'jump_attack', 'boxing', 'jab_cross'].map((name) => once(`/${name}.mp4`)),
education: ['jump_rope', 'skipping', 'hip_hop_dancing', 'hip_hop_dancing2'].map((name) =>
once(`/${name}.mp4`),
),
achievements: ['joyful_jump_l', 'punching_bag', 'shoot_gun', 'flying_kick'].map((name) =>
once(`/${name}.mp4`),
),
contact: ['waving_gesture', 'wave_hello_3', 'happy_idle', 'walk_swing_arms'].map((name) =>
once(`/${name}.mp4`),
),
resume: ['standard_walk', 'walk_sway', 'happy_idle', 'floating'].map((name) =>
once(`/${name}.mp4`),
),
}
const navClipBags = Object.fromEntries(
(Object.keys(NAV_CLIP_POOLS) as Section[]).map((section) => [
section,
createShuffleBag(NAV_CLIP_POOLS[section]),
]),
) as Record<Section, () => ClipConfig>
const CHAT_RESPONSE_CLIPS: ClipConfig[] = [
'dab_dance',
'dance',
'dance001',
'dance002',
'shuffle_dance',
'hip_hop_dancing3',
].map((name) => once(`/${name}.mp4`))
const nextChatResponseClip = createShuffleBag(CHAT_RESPONSE_CLIPS)
export function getNextIdleClip(): ClipConfig {
return nextIdleClip()
}
export function getNavClip(section: Section): ClipConfig {
return navClipBags[section]()
}
export function getNextChatResponseClip(): ClipConfig {
return nextChatResponseClip()
}