@moonwitness/ui 7.3.1 → 9.0.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/CHANGELOG.md +16 -0
- package/package.json +2 -3
- package/scripts/consumer-smoke.mjs +0 -45
- package/scripts/generate-icons.mjs +0 -110
- package/scripts/generate-token-artifacts.mjs +0 -90
- package/scripts/icon-svg-to-jsx.mjs +0 -249
- package/scripts/verification-diagnostics.mjs +0 -40
- package/scripts/verify-package.mjs +0 -412
- package/src/cartoon/anime-avatar.tsx +0 -628
- package/src/cartoon/anime-stage.tsx +0 -458
- package/src/cartoon/index.tsx +0 -542
- package/src/cartoon.tsx +0 -645
- package/src/characters.ts +0 -625
- package/src/components/accordion.tsx +0 -77
- package/src/components/alert.tsx +0 -139
- package/src/components/appearance-menu.tsx +0 -181
- package/src/components/artwork-frame.tsx +0 -49
- package/src/components/audio.tsx +0 -97
- package/src/components/avatar.tsx +0 -75
- package/src/components/badge.tsx +0 -94
- package/src/components/brand-mark.tsx +0 -73
- package/src/components/breadcrumbs.tsx +0 -98
- package/src/components/button.tsx +0 -340
- package/src/components/card.tsx +0 -171
- package/src/components/character-badge.tsx +0 -58
- package/src/components/character-preview.tsx +0 -104
- package/src/components/character-stage.tsx +0 -225
- package/src/components/chart.tsx +0 -481
- package/src/components/checkbox.tsx +0 -64
- package/src/components/comic-panel.tsx +0 -301
- package/src/components/comic-theater.tsx +0 -170
- package/src/components/command.tsx +0 -189
- package/src/components/confirm-dialog.tsx +0 -129
- package/src/components/copy-button.tsx +0 -62
- package/src/components/date-picker.tsx +0 -126
- package/src/components/dialog.tsx +0 -164
- package/src/components/dna-icon.tsx +0 -77
- package/src/components/dropdown-menu.tsx +0 -87
- package/src/components/effects.tsx +0 -1021
- package/src/components/empty-state.tsx +0 -93
- package/src/components/epistemic-branch-panel.tsx +0 -101
- package/src/components/error-state.tsx +0 -137
- package/src/components/field.tsx +0 -96
- package/src/components/filter-facet-bar.tsx +0 -91
- package/src/components/inbox-popover.tsx +0 -146
- package/src/components/input.tsx +0 -25
- package/src/components/kanban-board.tsx +0 -190
- package/src/components/label.tsx +0 -19
- package/src/components/layered-scene.tsx +0 -555
- package/src/components/log-console.tsx +0 -261
- package/src/components/metric-tile.tsx +0 -99
- package/src/components/mode-picker.tsx +0 -149
- package/src/components/motion-timeline.tsx +0 -848
- package/src/components/number-input.tsx +0 -104
- package/src/components/page-header.tsx +0 -123
- package/src/components/pagination.tsx +0 -83
- package/src/components/panel.tsx +0 -121
- package/src/components/paper-note.tsx +0 -77
- package/src/components/popover.tsx +0 -72
- package/src/components/progress.tsx +0 -127
- package/src/components/quest-card.tsx +0 -319
- package/src/components/radio-group.tsx +0 -50
- package/src/components/riot-sticker.tsx +0 -151
- package/src/components/scene-particles.tsx +0 -196
- package/src/components/scene-transitions.tsx +0 -130
- package/src/components/section-ribbon.tsx +0 -94
- package/src/components/select-field.tsx +0 -27
- package/src/components/select.tsx +0 -81
- package/src/components/separator.tsx +0 -58
- package/src/components/sheet.tsx +0 -96
- package/src/components/skeleton.tsx +0 -35
- package/src/components/sketch-annotation.tsx +0 -87
- package/src/components/smart-button-box.tsx +0 -114
- package/src/components/speech-bubble.tsx +0 -116
- package/src/components/spinner.tsx +0 -69
- package/src/components/sprite-player.tsx +0 -412
- package/src/components/status-bar.tsx +0 -63
- package/src/components/status-pill.tsx +0 -68
- package/src/components/switch.tsx +0 -76
- package/src/components/table.tsx +0 -163
- package/src/components/tabs.tsx +0 -101
- package/src/components/tag-input.tsx +0 -170
- package/src/components/textarea.tsx +0 -25
- package/src/components/toast.tsx +0 -14
- package/src/components/toolbar.tsx +0 -39
- package/src/components/tooltip.tsx +0 -49
- package/src/components/update-banner.tsx +0 -220
- package/src/components/xv-primitives.tsx +0 -256
- package/src/css-exports.ts +0 -142
- package/src/dna.tsx +0 -137
- package/src/game/boss-hud.tsx +0 -384
- package/src/game/index.tsx +0 -886
- package/src/game/tactical.tsx +0 -245
- package/src/game.tsx +0 -770
- package/src/icons/activity.tsx +0 -38
- package/src/icons/add.tsx +0 -38
- package/src/icons/addon.tsx +0 -37
- package/src/icons/anime-anger.tsx +0 -37
- package/src/icons/anime-shock.tsx +0 -37
- package/src/icons/anime-sparkle.tsx +0 -38
- package/src/icons/anime-sweatdrop.tsx +0 -38
- package/src/icons/archive.tsx +0 -37
- package/src/icons/arrow-left.tsx +0 -37
- package/src/icons/arrow-right.tsx +0 -37
- package/src/icons/attachment.tsx +0 -38
- package/src/icons/bank.tsx +0 -37
- package/src/icons/bolt.tsx +0 -37
- package/src/icons/book-open.tsx +0 -37
- package/src/icons/bookmark.tsx +0 -37
- package/src/icons/boss-skull.tsx +0 -40
- package/src/icons/calendar-clock.tsx +0 -40
- package/src/icons/calendar.tsx +0 -38
- package/src/icons/check-circle.tsx +0 -38
- package/src/icons/check-square.tsx +0 -38
- package/src/icons/check.tsx +0 -37
- package/src/icons/chevron-right.tsx +0 -37
- package/src/icons/chevrons-left.tsx +0 -37
- package/src/icons/chevrons-right.tsx +0 -37
- package/src/icons/clapperboard.tsx +0 -38
- package/src/icons/clock.tsx +0 -38
- package/src/icons/close.tsx +0 -37
- package/src/icons/code.tsx +0 -37
- package/src/icons/columns.tsx +0 -38
- package/src/icons/combo-flame.tsx +0 -38
- package/src/icons/company.tsx +0 -38
- package/src/icons/credit-card.tsx +0 -38
- package/src/icons/critical-star.tsx +0 -37
- package/src/icons/currency.tsx +0 -38
- package/src/icons/delete.tsx +0 -37
- package/src/icons/document.tsx +0 -38
- package/src/icons/download.tsx +0 -37
- package/src/icons/dpad.tsx +0 -38
- package/src/icons/edit.tsx +0 -38
- package/src/icons/element-fire.tsx +0 -37
- package/src/icons/element-ice.tsx +0 -38
- package/src/icons/element-solar.tsx +0 -38
- package/src/icons/element-void.tsx +0 -38
- package/src/icons/element-volt.tsx +0 -38
- package/src/icons/element-wind.tsx +0 -37
- package/src/icons/error.tsx +0 -38
- package/src/icons/external-link.tsx +0 -38
- package/src/icons/field.tsx +0 -38
- package/src/icons/file-spreadsheet.tsx +0 -38
- package/src/icons/filter.tsx +0 -37
- package/src/icons/gacha-ticket.tsx +0 -38
- package/src/icons/gamepad.tsx +0 -40
- package/src/icons/globe.tsx +0 -38
- package/src/icons/grid.tsx +0 -40
- package/src/icons/hash.tsx +0 -37
- package/src/icons/heart-hp.tsx +0 -38
- package/src/icons/history.tsx +0 -37
- package/src/icons/home.tsx +0 -37
- package/src/icons/image.tsx +0 -39
- package/src/icons/impact-slash.tsx +0 -38
- package/src/icons/inbox.tsx +0 -38
- package/src/icons/index.ts +0 -120
- package/src/icons/info.tsx +0 -38
- package/src/icons/jobs.tsx +0 -38
- package/src/icons/katana.tsx +0 -38
- package/src/icons/key.tsx +0 -38
- package/src/icons/keyboard.tsx +0 -38
- package/src/icons/keyframe-diamond.tsx +0 -38
- package/src/icons/knowledge.tsx +0 -38
- package/src/icons/language.tsx +0 -39
- package/src/icons/lock.tsx +0 -38
- package/src/icons/logout.tsx +0 -37
- package/src/icons/loot-chest.tsx +0 -39
- package/src/icons/mail.tsx +0 -38
- package/src/icons/mana-crystal.tsx +0 -38
- package/src/icons/map-pin.tsx +0 -38
- package/src/icons/mecha-helm.tsx +0 -38
- package/src/icons/menu.tsx +0 -37
- package/src/icons/message.tsx +0 -38
- package/src/icons/model.tsx +0 -38
- package/src/icons/moon.tsx +0 -37
- package/src/icons/notification.tsx +0 -38
- package/src/icons/partner.tsx +0 -41
- package/src/icons/pause.tsx +0 -37
- package/src/icons/phone.tsx +0 -37
- package/src/icons/play.tsx +0 -37
- package/src/icons/potion-flask.tsx +0 -40
- package/src/icons/quest-scroll.tsx +0 -39
- package/src/icons/radar-ping.tsx +0 -40
- package/src/icons/refresh.tsx +0 -38
- package/src/icons/relation.tsx +0 -40
- package/src/icons/save.tsx +0 -38
- package/src/icons/search.tsx +0 -38
- package/src/icons/security.tsx +0 -38
- package/src/icons/send.tsx +0 -38
- package/src/icons/settings.tsx +0 -39
- package/src/icons/shield-crest.tsx +0 -38
- package/src/icons/shuriken.tsx +0 -38
- package/src/icons/signal-off.tsx +0 -37
- package/src/icons/signal.tsx +0 -37
- package/src/icons/skill-node.tsx +0 -40
- package/src/icons/smartphone.tsx +0 -38
- package/src/icons/sort-ascending.tsx +0 -37
- package/src/icons/sort-descending.tsx +0 -37
- package/src/icons/sort.tsx +0 -37
- package/src/icons/sparkle.tsx +0 -38
- package/src/icons/speech-burst.tsx +0 -37
- package/src/icons/story.tsx +0 -37
- package/src/icons/sun.tsx +0 -38
- package/src/icons/tag.tsx +0 -38
- package/src/icons/team.tsx +0 -40
- package/src/icons/trophy-crown.tsx +0 -39
- package/src/icons/upload.tsx +0 -37
- package/src/icons/user.tsx +0 -38
- package/src/icons/users.tsx +0 -39
- package/src/icons/visibility-off.tsx +0 -38
- package/src/icons/visibility.tsx +0 -38
- package/src/icons/volume-off.tsx +0 -37
- package/src/icons/volume.tsx +0 -37
- package/src/icons/warning.tsx +0 -38
- package/src/icons/workflow.tsx +0 -40
- package/src/icons.tsx +0 -965
- package/src/index.ts +0 -89
- package/src/lib/asset-registry.ts +0 -534
- package/src/lib/audio-runtime.ts +0 -314
- package/src/lib/character-adapter.ts +0 -370
- package/src/lib/character-registry.ts +0 -2368
- package/src/lib/cn.ts +0 -6
- package/src/lib/compose-refs.ts +0 -16
- package/src/lib/sanitize-url.ts +0 -51
- package/src/lib/scene-camera.ts +0 -483
- package/src/lib/scene-playback.ts +0 -622
- package/src/lib/scene-soundscape.ts +0 -151
- package/src/lib/scene-test-harness.ts +0 -200
- package/src/lib/scene-timeline.ts +0 -398
- package/src/lib/use-animation-visibility.ts +0 -45
- package/src/lib/use-modal-focus.ts +0 -270
- package/src/lib/use-reduced-motion.ts +0 -37
- package/src/motion/easing-presets.ts +0 -262
- package/src/motion/index.tsx +0 -894
- package/src/motion/physics.ts +0 -259
- package/src/motion/timeline-math.ts +0 -358
- package/src/motion.tsx +0 -639
- package/src/pixelfx-boundary.ts +0 -188
- package/src/pixelfx-registry.ts +0 -1190
- package/src/pixelfx-types.d.ts +0 -73
- package/src/pixelfx.tsx +0 -1022
- package/src/provider.tsx +0 -63
- package/src/skin-catalog.ts +0 -306
- package/src/skin-tokens.ts +0 -425
- package/src/ssr/init-script.ts +0 -281
- package/src/ssr/resolve-skin.ts +0 -217
- package/src/ssr/theme-mismatch-dev.ts +0 -181
- package/src/templates/battle-arena.tsx +0 -688
- package/src/templates/index.tsx +0 -314
- package/src/templates.tsx +0 -225
- package/src/themes/dna-presets.ts +0 -119
- package/src/themes/index.ts +0 -56
- package/src/themes/provider.tsx +0 -183
- package/src/themes/types.ts +0 -111
- package/src/themes.ts +0 -9
- package/src/token-exporter.ts +0 -12
- package/src/token-exporters.ts +0 -343
- package/src/token-seeds.ts +0 -335
- package/src/token-snapshot.ts +0 -179
- package/src/utils.ts +0 -58
package/src/game/index.tsx
DELETED
|
@@ -1,886 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
forwardRef,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
type ComponentPropsWithoutRef,
|
|
11
|
-
type CSSProperties,
|
|
12
|
-
type ReactNode,
|
|
13
|
-
} from "react";
|
|
14
|
-
import { cn } from "../lib/cn.js";
|
|
15
|
-
import { getCharacterById } from "../lib/character-registry.js";
|
|
16
|
-
import { AnimeCharacterSvg } from "../cartoon/anime-avatar.js";
|
|
17
|
-
import { clampUnit, useMotion } from "../motion/index.js";
|
|
18
|
-
export {
|
|
19
|
-
AchievementBadge,
|
|
20
|
-
QuestCard,
|
|
21
|
-
RewardPanel,
|
|
22
|
-
type AchievementBadgeProps,
|
|
23
|
-
type QuestCardProps,
|
|
24
|
-
type QuestStatus,
|
|
25
|
-
type RewardBadgeEntry,
|
|
26
|
-
type RewardPanelProps,
|
|
27
|
-
} from "../components/quest-card.js";
|
|
28
|
-
export {
|
|
29
|
-
AchievementToast,
|
|
30
|
-
BossHealthBar,
|
|
31
|
-
LootRevealCard,
|
|
32
|
-
TurnOrderStrip,
|
|
33
|
-
type AchievementToastProps,
|
|
34
|
-
type BossHealthBarProps,
|
|
35
|
-
type LootRarity,
|
|
36
|
-
type LootRevealCardProps,
|
|
37
|
-
type TurnOrderEntry,
|
|
38
|
-
type TurnOrderStripProps,
|
|
39
|
-
} from "./boss-hud.js";
|
|
40
|
-
export {
|
|
41
|
-
SkillTreeGraph,
|
|
42
|
-
TacticalRadar,
|
|
43
|
-
type RadarBlip,
|
|
44
|
-
type SkillNodeState,
|
|
45
|
-
type SkillTreeGraphProps,
|
|
46
|
-
type SkillTreeNode,
|
|
47
|
-
type TacticalRadarProps,
|
|
48
|
-
} from "./tactical.js";
|
|
49
|
-
|
|
50
|
-
export type StatGaugeTone = "hp" | "mp" | "xp" | "shield" | "stamina";
|
|
51
|
-
export type StatGaugeVariant = "straight" | "arcade-skew" | "segmented";
|
|
52
|
-
|
|
53
|
-
export type StatGaugeProps = ComponentPropsWithoutRef<"div"> & {
|
|
54
|
-
label: string;
|
|
55
|
-
value: number;
|
|
56
|
-
max: number;
|
|
57
|
-
tone?: StatGaugeTone;
|
|
58
|
-
variant?: StatGaugeVariant;
|
|
59
|
-
segments?: number;
|
|
60
|
-
lowThreshold?: number;
|
|
61
|
-
showNumbers?: boolean;
|
|
62
|
-
trailDelayMs?: number;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const StatGauge = forwardRef<HTMLDivElement, StatGaugeProps>(
|
|
66
|
-
function StatGauge(
|
|
67
|
-
{
|
|
68
|
-
label,
|
|
69
|
-
value,
|
|
70
|
-
max,
|
|
71
|
-
tone = "hp",
|
|
72
|
-
variant = "straight",
|
|
73
|
-
segments = 10,
|
|
74
|
-
lowThreshold = 0.25,
|
|
75
|
-
showNumbers = true,
|
|
76
|
-
trailDelayMs = 260,
|
|
77
|
-
className,
|
|
78
|
-
...props
|
|
79
|
-
},
|
|
80
|
-
ref,
|
|
81
|
-
) {
|
|
82
|
-
const { reducedMotion } = useMotion();
|
|
83
|
-
const safeMax = Math.max(1, max);
|
|
84
|
-
const clamped = Math.min(safeMax, Math.max(0, value));
|
|
85
|
-
const ratio = clampUnit(clamped / safeMax);
|
|
86
|
-
const [trailRatio, setTrailRatio] = useState(ratio);
|
|
87
|
-
const [hitFlash, setHitFlash] = useState(false);
|
|
88
|
-
const prevRef = useRef(clamped);
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
const prev = prevRef.current;
|
|
92
|
-
prevRef.current = clamped;
|
|
93
|
-
if (clamped < prev && !reducedMotion) {
|
|
94
|
-
setHitFlash(true);
|
|
95
|
-
const flashTimer = window.setTimeout(() => setHitFlash(false), 180);
|
|
96
|
-
const trailTimer = window.setTimeout(
|
|
97
|
-
() => setTrailRatio(ratio),
|
|
98
|
-
trailDelayMs,
|
|
99
|
-
);
|
|
100
|
-
return () => {
|
|
101
|
-
window.clearTimeout(flashTimer);
|
|
102
|
-
window.clearTimeout(trailTimer);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
setTrailRatio(ratio);
|
|
106
|
-
return undefined;
|
|
107
|
-
}, [clamped, ratio, reducedMotion, trailDelayMs]);
|
|
108
|
-
|
|
109
|
-
const isCritical = ratio > 0 && ratio <= lowThreshold;
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<div
|
|
113
|
-
ref={ref}
|
|
114
|
-
data-slot="stat-gauge"
|
|
115
|
-
data-tone={tone}
|
|
116
|
-
data-variant={variant}
|
|
117
|
-
data-critical={isCritical ? "true" : "false"}
|
|
118
|
-
data-hit={hitFlash ? "true" : "false"}
|
|
119
|
-
data-reduced-motion={reducedMotion ? "true" : "false"}
|
|
120
|
-
className={cn("mw-ui-game-gauge", className)}
|
|
121
|
-
{...props}
|
|
122
|
-
>
|
|
123
|
-
<div className="mw-ui-game-gauge-header">
|
|
124
|
-
<span className="mw-ui-game-gauge-label">{label}</span>
|
|
125
|
-
{showNumbers ? (
|
|
126
|
-
<span className="mw-ui-game-gauge-numbers">
|
|
127
|
-
{Math.round(clamped)} / {Math.round(safeMax)}
|
|
128
|
-
</span>
|
|
129
|
-
) : null}
|
|
130
|
-
</div>
|
|
131
|
-
<div
|
|
132
|
-
role="progressbar"
|
|
133
|
-
aria-label={label}
|
|
134
|
-
aria-valuemin={0}
|
|
135
|
-
aria-valuemax={safeMax}
|
|
136
|
-
aria-valuenow={Math.round(clamped)}
|
|
137
|
-
className="mw-ui-game-gauge-track"
|
|
138
|
-
>
|
|
139
|
-
<div
|
|
140
|
-
className="mw-ui-game-gauge-trail"
|
|
141
|
-
style={{ width: `${Math.round(trailRatio * 1000) / 10}%` }}
|
|
142
|
-
/>
|
|
143
|
-
<div
|
|
144
|
-
className="mw-ui-game-gauge-fill"
|
|
145
|
-
style={{ width: `${Math.round(ratio * 1000) / 10}%` }}
|
|
146
|
-
/>
|
|
147
|
-
{variant === "segmented" ? (
|
|
148
|
-
<div className="mw-ui-game-gauge-segments" aria-hidden="true">
|
|
149
|
-
{Array.from({ length: Math.max(2, segments) }).map((_, idx) => (
|
|
150
|
-
<span key={idx} className="mw-ui-game-gauge-segment" />
|
|
151
|
-
))}
|
|
152
|
-
</div>
|
|
153
|
-
) : null}
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
);
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
StatGauge.displayName = "StatGauge";
|
|
160
|
-
|
|
161
|
-
export interface DialogueChoice {
|
|
162
|
-
readonly id: string;
|
|
163
|
-
readonly label: string;
|
|
164
|
-
readonly hint?: string;
|
|
165
|
-
readonly disabled?: boolean;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export type DialogueBoxProps = ComponentPropsWithoutRef<"section"> & {
|
|
169
|
-
characterId?: string;
|
|
170
|
-
speaker?: string;
|
|
171
|
-
roleTitle?: string;
|
|
172
|
-
text: string;
|
|
173
|
-
portrait?: ReactNode;
|
|
174
|
-
charsPerSec?: number;
|
|
175
|
-
instant?: boolean;
|
|
176
|
-
choices?: readonly DialogueChoice[];
|
|
177
|
-
onChoiceSelect?: (choice: DialogueChoice) => void;
|
|
178
|
-
onAdvance?: () => void;
|
|
179
|
-
onTypingProgress?: (visibleChars: number, isTyping: boolean) => void;
|
|
180
|
-
advanceLabel?: string;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export const DialogueBox = forwardRef<HTMLElement, DialogueBoxProps>(
|
|
184
|
-
function DialogueBox(
|
|
185
|
-
{
|
|
186
|
-
characterId,
|
|
187
|
-
speaker,
|
|
188
|
-
roleTitle,
|
|
189
|
-
text,
|
|
190
|
-
portrait,
|
|
191
|
-
charsPerSec = 42,
|
|
192
|
-
instant = false,
|
|
193
|
-
choices,
|
|
194
|
-
onChoiceSelect,
|
|
195
|
-
onAdvance,
|
|
196
|
-
onTypingProgress,
|
|
197
|
-
advanceLabel = "Continue",
|
|
198
|
-
className,
|
|
199
|
-
...props
|
|
200
|
-
},
|
|
201
|
-
ref,
|
|
202
|
-
) {
|
|
203
|
-
const { reducedMotion, triggerSfx } = useMotion();
|
|
204
|
-
const profile = getCharacterById(characterId);
|
|
205
|
-
const resolvedSpeaker = speaker ?? profile?.name ?? "Speaker";
|
|
206
|
-
const resolvedRole = roleTitle ?? profile?.title;
|
|
207
|
-
const skipTyping = instant || reducedMotion || charsPerSec <= 0;
|
|
208
|
-
const [visibleChars, setVisibleChars] = useState(
|
|
209
|
-
skipTyping ? text.length : 0,
|
|
210
|
-
);
|
|
211
|
-
const [autoMode, setAutoMode] = useState(false);
|
|
212
|
-
|
|
213
|
-
const isTyping = visibleChars < text.length;
|
|
214
|
-
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
setVisibleChars(skipTyping ? text.length : 0);
|
|
217
|
-
}, [text, skipTyping]);
|
|
218
|
-
|
|
219
|
-
useEffect(() => {
|
|
220
|
-
onTypingProgress?.(visibleChars, visibleChars < text.length);
|
|
221
|
-
}, [visibleChars, text.length, onTypingProgress]);
|
|
222
|
-
|
|
223
|
-
useEffect(() => {
|
|
224
|
-
if (!isTyping) return;
|
|
225
|
-
const stepMs = Math.max(12, Math.round(1000 / Math.max(1, charsPerSec)));
|
|
226
|
-
const timer = window.setTimeout(() => {
|
|
227
|
-
setVisibleChars((prev) => {
|
|
228
|
-
const next = Math.min(text.length, prev + 1);
|
|
229
|
-
if (next % 3 === 0)
|
|
230
|
-
triggerSfx("dialogue-blip", profile?.voicePitch ?? 1);
|
|
231
|
-
return next;
|
|
232
|
-
});
|
|
233
|
-
}, stepMs);
|
|
234
|
-
return () => window.clearTimeout(timer);
|
|
235
|
-
}, [
|
|
236
|
-
isTyping,
|
|
237
|
-
visibleChars,
|
|
238
|
-
text.length,
|
|
239
|
-
charsPerSec,
|
|
240
|
-
profile?.voicePitch,
|
|
241
|
-
triggerSfx,
|
|
242
|
-
]);
|
|
243
|
-
|
|
244
|
-
useEffect(() => {
|
|
245
|
-
if (
|
|
246
|
-
!autoMode ||
|
|
247
|
-
isTyping ||
|
|
248
|
-
!onAdvance ||
|
|
249
|
-
(choices && choices.length > 0)
|
|
250
|
-
)
|
|
251
|
-
return;
|
|
252
|
-
const timer = window.setTimeout(() => onAdvance(), 1400);
|
|
253
|
-
return () => window.clearTimeout(timer);
|
|
254
|
-
}, [autoMode, isTyping, onAdvance, choices]);
|
|
255
|
-
|
|
256
|
-
const handlePrimaryAction = useCallback(() => {
|
|
257
|
-
if (isTyping) {
|
|
258
|
-
setVisibleChars(text.length);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
triggerSfx("click-soft");
|
|
262
|
-
onAdvance?.();
|
|
263
|
-
}, [isTyping, text.length, onAdvance, triggerSfx]);
|
|
264
|
-
|
|
265
|
-
const resolvedPortrait =
|
|
266
|
-
portrait ??
|
|
267
|
-
(characterId ? (
|
|
268
|
-
<AnimeCharacterSvg
|
|
269
|
-
characterId={characterId}
|
|
270
|
-
mood={profile?.defaultMood ?? "neutral"}
|
|
271
|
-
phoneme={isTyping ? "wide" : "closed"}
|
|
272
|
-
/>
|
|
273
|
-
) : null);
|
|
274
|
-
|
|
275
|
-
return (
|
|
276
|
-
<section
|
|
277
|
-
ref={ref}
|
|
278
|
-
aria-label={`Dialogue from ${resolvedSpeaker}`}
|
|
279
|
-
data-slot="dialogue-box"
|
|
280
|
-
data-typing={isTyping ? "true" : "false"}
|
|
281
|
-
className={cn("mw-ui-game-dialogue", className)}
|
|
282
|
-
{...props}
|
|
283
|
-
>
|
|
284
|
-
{resolvedPortrait ? (
|
|
285
|
-
<div className="mw-ui-game-dialogue-portrait">{resolvedPortrait}</div>
|
|
286
|
-
) : null}
|
|
287
|
-
<div className="mw-ui-game-dialogue-body">
|
|
288
|
-
<div className="mw-ui-game-dialogue-head">
|
|
289
|
-
<div className="mw-ui-game-dialogue-speaker-wrap">
|
|
290
|
-
<span className="mw-ui-game-dialogue-speaker">
|
|
291
|
-
{resolvedSpeaker}
|
|
292
|
-
</span>
|
|
293
|
-
{resolvedRole ? (
|
|
294
|
-
<span className="mw-ui-game-dialogue-role">{resolvedRole}</span>
|
|
295
|
-
) : null}
|
|
296
|
-
</div>
|
|
297
|
-
<div className="mw-ui-game-dialogue-controls">
|
|
298
|
-
<button
|
|
299
|
-
type="button"
|
|
300
|
-
className="mw-ui-game-mini-btn"
|
|
301
|
-
aria-pressed={autoMode}
|
|
302
|
-
onClick={() => setAutoMode((prev) => !prev)}
|
|
303
|
-
>
|
|
304
|
-
Auto {autoMode ? "ON" : "OFF"}
|
|
305
|
-
</button>
|
|
306
|
-
{isTyping ? (
|
|
307
|
-
<button
|
|
308
|
-
type="button"
|
|
309
|
-
className="mw-ui-game-mini-btn"
|
|
310
|
-
onClick={() => setVisibleChars(text.length)}
|
|
311
|
-
>
|
|
312
|
-
Skip
|
|
313
|
-
</button>
|
|
314
|
-
) : null}
|
|
315
|
-
</div>
|
|
316
|
-
</div>
|
|
317
|
-
|
|
318
|
-
<p className="mw-ui-game-dialogue-text" aria-live="polite">
|
|
319
|
-
{text.slice(0, visibleChars)}
|
|
320
|
-
{isTyping ? (
|
|
321
|
-
<span aria-hidden="true" className="mw-ui-game-dialogue-caret" />
|
|
322
|
-
) : null}
|
|
323
|
-
</p>
|
|
324
|
-
|
|
325
|
-
{!isTyping && choices && choices.length > 0 ? (
|
|
326
|
-
<div
|
|
327
|
-
className="mw-ui-game-dialogue-choices"
|
|
328
|
-
role="group"
|
|
329
|
-
aria-label="Dialogue choices"
|
|
330
|
-
>
|
|
331
|
-
{choices.map((choice, idx) => (
|
|
332
|
-
<button
|
|
333
|
-
key={choice.id}
|
|
334
|
-
type="button"
|
|
335
|
-
disabled={choice.disabled}
|
|
336
|
-
className="mw-ui-game-choice-btn"
|
|
337
|
-
onClick={() => {
|
|
338
|
-
triggerSfx("toggle-pop");
|
|
339
|
-
onChoiceSelect?.(choice);
|
|
340
|
-
}}
|
|
341
|
-
>
|
|
342
|
-
<span className="mw-ui-game-choice-index">{idx + 1}</span>
|
|
343
|
-
<span>{choice.label}</span>
|
|
344
|
-
{choice.hint ? (
|
|
345
|
-
<small className="mw-ui-game-choice-hint">
|
|
346
|
-
{choice.hint}
|
|
347
|
-
</small>
|
|
348
|
-
) : null}
|
|
349
|
-
</button>
|
|
350
|
-
))}
|
|
351
|
-
</div>
|
|
352
|
-
) : onAdvance ? (
|
|
353
|
-
<div className="mw-ui-game-dialogue-footer">
|
|
354
|
-
<button
|
|
355
|
-
type="button"
|
|
356
|
-
className="mw-ui-game-advance-btn"
|
|
357
|
-
onClick={handlePrimaryAction}
|
|
358
|
-
>
|
|
359
|
-
<span>{isTyping ? "Reveal" : advanceLabel}</span>
|
|
360
|
-
<span aria-hidden="true" className="mw-ui-game-advance-arrow">
|
|
361
|
-
▸
|
|
362
|
-
</span>
|
|
363
|
-
</button>
|
|
364
|
-
</div>
|
|
365
|
-
) : null}
|
|
366
|
-
</div>
|
|
367
|
-
</section>
|
|
368
|
-
);
|
|
369
|
-
},
|
|
370
|
-
);
|
|
371
|
-
DialogueBox.displayName = "DialogueBox";
|
|
372
|
-
|
|
373
|
-
export interface CombatTextEvent {
|
|
374
|
-
readonly id: string | number;
|
|
375
|
-
readonly text: string;
|
|
376
|
-
readonly tone?: "damage" | "crit" | "heal" | "status";
|
|
377
|
-
readonly xPercent?: number;
|
|
378
|
-
readonly yPercent?: number;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export type FloatingCombatTextProps = ComponentPropsWithoutRef<"div"> & {
|
|
382
|
-
events: readonly CombatTextEvent[];
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
export const FloatingCombatText = forwardRef<
|
|
386
|
-
HTMLDivElement,
|
|
387
|
-
FloatingCombatTextProps
|
|
388
|
-
>(function FloatingCombatText({ events, className, ...props }, ref) {
|
|
389
|
-
const { reducedMotion } = useMotion();
|
|
390
|
-
return (
|
|
391
|
-
<div
|
|
392
|
-
ref={ref}
|
|
393
|
-
aria-live="polite"
|
|
394
|
-
data-slot="floating-combat-text"
|
|
395
|
-
data-reduced-motion={reducedMotion ? "true" : "false"}
|
|
396
|
-
className={cn("mw-ui-game-combat-layer", className)}
|
|
397
|
-
{...props}
|
|
398
|
-
>
|
|
399
|
-
{events.map((evt) => (
|
|
400
|
-
<span
|
|
401
|
-
key={evt.id}
|
|
402
|
-
data-tone={evt.tone ?? "damage"}
|
|
403
|
-
className="mw-ui-game-combat-pop"
|
|
404
|
-
style={
|
|
405
|
-
{
|
|
406
|
-
left: `${evt.xPercent ?? 50}%`,
|
|
407
|
-
top: `${evt.yPercent ?? 40}%`,
|
|
408
|
-
} as CSSProperties
|
|
409
|
-
}
|
|
410
|
-
>
|
|
411
|
-
{evt.text}
|
|
412
|
-
</span>
|
|
413
|
-
))}
|
|
414
|
-
</div>
|
|
415
|
-
);
|
|
416
|
-
});
|
|
417
|
-
FloatingCombatText.displayName = "FloatingCombatText";
|
|
418
|
-
|
|
419
|
-
export type ItemRarity = "common" | "rare" | "epic" | "legendary";
|
|
420
|
-
|
|
421
|
-
export interface HotbarSlotItem {
|
|
422
|
-
readonly id: string;
|
|
423
|
-
readonly label: string;
|
|
424
|
-
readonly hotkey?: string;
|
|
425
|
-
readonly icon?: ReactNode;
|
|
426
|
-
readonly count?: number;
|
|
427
|
-
readonly rarity?: ItemRarity;
|
|
428
|
-
readonly cooldownProgress?: number; // 0 = ready, 1 = just triggered
|
|
429
|
-
readonly cooldownSeconds?: number;
|
|
430
|
-
readonly active?: boolean;
|
|
431
|
-
readonly disabled?: boolean;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
export type InventoryGridProps = ComponentPropsWithoutRef<"div"> & {
|
|
435
|
-
items: readonly HotbarSlotItem[];
|
|
436
|
-
columns?: number;
|
|
437
|
-
onActivate?: (item: HotbarSlotItem) => void;
|
|
438
|
-
ariaLabel?: string;
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
export const InventoryGrid = forwardRef<HTMLDivElement, InventoryGridProps>(
|
|
442
|
-
function InventoryGrid(
|
|
443
|
-
{
|
|
444
|
-
items,
|
|
445
|
-
columns = 4,
|
|
446
|
-
onActivate,
|
|
447
|
-
ariaLabel = "Inventory slots",
|
|
448
|
-
className,
|
|
449
|
-
style,
|
|
450
|
-
...props
|
|
451
|
-
},
|
|
452
|
-
ref,
|
|
453
|
-
) {
|
|
454
|
-
const { triggerSfx } = useMotion();
|
|
455
|
-
return (
|
|
456
|
-
<div
|
|
457
|
-
ref={ref}
|
|
458
|
-
role="group"
|
|
459
|
-
aria-label={ariaLabel}
|
|
460
|
-
data-slot="inventory-grid"
|
|
461
|
-
className={cn("mw-ui-game-inventory", className)}
|
|
462
|
-
style={
|
|
463
|
-
{
|
|
464
|
-
...style,
|
|
465
|
-
"--mw-grid-cols": String(Math.max(1, columns)),
|
|
466
|
-
} as CSSProperties
|
|
467
|
-
}
|
|
468
|
-
{...props}
|
|
469
|
-
>
|
|
470
|
-
{items.map((item) => {
|
|
471
|
-
const cooling = (item.cooldownProgress ?? 0) > 0;
|
|
472
|
-
const pct = Math.round(clampUnit(item.cooldownProgress ?? 0) * 100);
|
|
473
|
-
return (
|
|
474
|
-
<button
|
|
475
|
-
key={item.id}
|
|
476
|
-
type="button"
|
|
477
|
-
disabled={item.disabled || cooling}
|
|
478
|
-
data-rarity={item.rarity ?? "common"}
|
|
479
|
-
data-active={item.active ? "true" : "false"}
|
|
480
|
-
data-cooling={cooling ? "true" : "false"}
|
|
481
|
-
aria-label={`${item.label}${item.hotkey ? ` (Key ${item.hotkey})` : ""}${
|
|
482
|
-
cooling && item.cooldownSeconds
|
|
483
|
-
? `, ${item.cooldownSeconds.toFixed(1)}s cooldown`
|
|
484
|
-
: ""
|
|
485
|
-
}`}
|
|
486
|
-
className="mw-ui-game-slot"
|
|
487
|
-
onClick={() => {
|
|
488
|
-
triggerSfx("click-soft");
|
|
489
|
-
onActivate?.(item);
|
|
490
|
-
}}
|
|
491
|
-
>
|
|
492
|
-
{item.hotkey ? (
|
|
493
|
-
<span className="mw-ui-game-slot-key">{item.hotkey}</span>
|
|
494
|
-
) : null}
|
|
495
|
-
<span className="mw-ui-game-slot-icon" aria-hidden="true">
|
|
496
|
-
{item.icon ?? item.label.slice(0, 2).toUpperCase()}
|
|
497
|
-
</span>
|
|
498
|
-
<span className="mw-ui-game-slot-label">{item.label}</span>
|
|
499
|
-
{typeof item.count === "number" ? (
|
|
500
|
-
<span className="mw-ui-game-slot-count">×{item.count}</span>
|
|
501
|
-
) : null}
|
|
502
|
-
{cooling ? (
|
|
503
|
-
<span
|
|
504
|
-
aria-hidden="true"
|
|
505
|
-
className="mw-ui-game-slot-cooldown"
|
|
506
|
-
style={{ height: `${pct}%` }}
|
|
507
|
-
>
|
|
508
|
-
{item.cooldownSeconds
|
|
509
|
-
? `${item.cooldownSeconds.toFixed(1)}s`
|
|
510
|
-
: null}
|
|
511
|
-
</span>
|
|
512
|
-
) : null}
|
|
513
|
-
</button>
|
|
514
|
-
);
|
|
515
|
-
})}
|
|
516
|
-
</div>
|
|
517
|
-
);
|
|
518
|
-
},
|
|
519
|
-
);
|
|
520
|
-
InventoryGrid.displayName = "InventoryGrid";
|
|
521
|
-
|
|
522
|
-
export const ActionHotbar = forwardRef<HTMLDivElement, InventoryGridProps>(
|
|
523
|
-
function ActionHotbar(
|
|
524
|
-
{ items, columns, ariaLabel = "Action hotbar", className, ...props },
|
|
525
|
-
ref,
|
|
526
|
-
) {
|
|
527
|
-
return (
|
|
528
|
-
<InventoryGrid
|
|
529
|
-
ref={ref}
|
|
530
|
-
items={items}
|
|
531
|
-
columns={columns ?? items.length}
|
|
532
|
-
ariaLabel={ariaLabel}
|
|
533
|
-
className={cn("mw-ui-game-hotbar", className)}
|
|
534
|
-
{...props}
|
|
535
|
-
/>
|
|
536
|
-
);
|
|
537
|
-
},
|
|
538
|
-
);
|
|
539
|
-
ActionHotbar.displayName = "ActionHotbar";
|
|
540
|
-
|
|
541
|
-
export type ComboCounterProps = ComponentPropsWithoutRef<"div"> & {
|
|
542
|
-
count: number;
|
|
543
|
-
label?: string;
|
|
544
|
-
decayProgress?: number; // 0..1 remaining time
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
export function resolveComboTier(
|
|
548
|
-
count: number,
|
|
549
|
-
): "C" | "B" | "A" | "S" | "SS" | "SSS" {
|
|
550
|
-
if (count >= 25) return "SSS";
|
|
551
|
-
if (count >= 16) return "SS";
|
|
552
|
-
if (count >= 10) return "S";
|
|
553
|
-
if (count >= 6) return "A";
|
|
554
|
-
if (count >= 3) return "B";
|
|
555
|
-
return "C";
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export const ComboCounter = forwardRef<HTMLDivElement, ComboCounterProps>(
|
|
559
|
-
function ComboCounter(
|
|
560
|
-
{ count, label = "CHAIN", decayProgress = 1, className, ...props },
|
|
561
|
-
ref,
|
|
562
|
-
) {
|
|
563
|
-
const tier = resolveComboTier(count);
|
|
564
|
-
return (
|
|
565
|
-
<div
|
|
566
|
-
ref={ref}
|
|
567
|
-
role="status"
|
|
568
|
-
aria-live="polite"
|
|
569
|
-
data-slot="combo-counter"
|
|
570
|
-
data-tier={tier}
|
|
571
|
-
data-active={count > 0 ? "true" : "false"}
|
|
572
|
-
className={cn("mw-ui-game-combo", className)}
|
|
573
|
-
{...props}
|
|
574
|
-
>
|
|
575
|
-
<div className="mw-ui-game-combo-top">
|
|
576
|
-
<span className="mw-ui-game-combo-tier">{tier}</span>
|
|
577
|
-
<span key={count} className="mw-ui-game-combo-count">
|
|
578
|
-
×{count}
|
|
579
|
-
</span>
|
|
580
|
-
<span className="mw-ui-game-combo-label">{label}</span>
|
|
581
|
-
</div>
|
|
582
|
-
<div className="mw-ui-game-combo-bar" aria-hidden="true">
|
|
583
|
-
<div
|
|
584
|
-
className="mw-ui-game-combo-fill"
|
|
585
|
-
style={{ width: `${Math.round(clampUnit(decayProgress) * 100)}%` }}
|
|
586
|
-
/>
|
|
587
|
-
</div>
|
|
588
|
-
</div>
|
|
589
|
-
);
|
|
590
|
-
},
|
|
591
|
-
);
|
|
592
|
-
ComboCounter.displayName = "ComboCounter";
|
|
593
|
-
|
|
594
|
-
export interface RadialMenuOption {
|
|
595
|
-
readonly id: string;
|
|
596
|
-
readonly label: string;
|
|
597
|
-
readonly badge?: string;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
export type RadialMenuProps = Omit<
|
|
601
|
-
ComponentPropsWithoutRef<"div">,
|
|
602
|
-
"onSelect"
|
|
603
|
-
> & {
|
|
604
|
-
options: readonly RadialMenuOption[];
|
|
605
|
-
activeId?: string;
|
|
606
|
-
onSelect?: (option: RadialMenuOption) => void;
|
|
607
|
-
centerLabel?: string;
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
export const RadialMenu = forwardRef<HTMLDivElement, RadialMenuProps>(
|
|
611
|
-
function RadialMenu(
|
|
612
|
-
{ options, activeId, onSelect, centerLabel = "ACT", className, ...props },
|
|
613
|
-
ref,
|
|
614
|
-
) {
|
|
615
|
-
const { triggerSfx } = useMotion();
|
|
616
|
-
const radius = 64;
|
|
617
|
-
return (
|
|
618
|
-
<div
|
|
619
|
-
ref={ref}
|
|
620
|
-
role="group"
|
|
621
|
-
aria-label="Radial quick actions"
|
|
622
|
-
data-slot="radial-menu"
|
|
623
|
-
className={cn("mw-ui-game-radial", className)}
|
|
624
|
-
{...props}
|
|
625
|
-
>
|
|
626
|
-
<span className="mw-ui-game-radial-center">{centerLabel}</span>
|
|
627
|
-
{options.map((opt, idx) => {
|
|
628
|
-
const angle =
|
|
629
|
-
(idx / Math.max(1, options.length)) * Math.PI * 2 - Math.PI / 2;
|
|
630
|
-
const x = Math.round(Math.cos(angle) * radius);
|
|
631
|
-
const y = Math.round(Math.sin(angle) * radius);
|
|
632
|
-
const isSelected = activeId === opt.id;
|
|
633
|
-
return (
|
|
634
|
-
<button
|
|
635
|
-
key={opt.id}
|
|
636
|
-
type="button"
|
|
637
|
-
aria-pressed={isSelected}
|
|
638
|
-
data-active={isSelected ? "true" : "false"}
|
|
639
|
-
className="mw-ui-game-radial-btn"
|
|
640
|
-
style={{ transform: `translate(${x}px, ${y}px)` }}
|
|
641
|
-
onClick={() => {
|
|
642
|
-
triggerSfx("toggle-pop");
|
|
643
|
-
onSelect?.(opt);
|
|
644
|
-
}}
|
|
645
|
-
>
|
|
646
|
-
<span>{opt.label}</span>
|
|
647
|
-
{opt.badge ? <small>{opt.badge}</small> : null}
|
|
648
|
-
</button>
|
|
649
|
-
);
|
|
650
|
-
})}
|
|
651
|
-
</div>
|
|
652
|
-
);
|
|
653
|
-
},
|
|
654
|
-
);
|
|
655
|
-
RadialMenu.displayName = "RadialMenu";
|
|
656
|
-
|
|
657
|
-
export type InputPromptPlatform = "keyboard" | "xbox" | "playstation";
|
|
658
|
-
|
|
659
|
-
export type InputPromptBadgeProps = ComponentPropsWithoutRef<"kbd"> & {
|
|
660
|
-
input: string;
|
|
661
|
-
platform?: InputPromptPlatform;
|
|
662
|
-
actionLabel?: string;
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
export const InputPromptBadge = forwardRef<HTMLElement, InputPromptBadgeProps>(
|
|
666
|
-
function InputPromptBadge(
|
|
667
|
-
{ input, platform = "keyboard", actionLabel, className, ...props },
|
|
668
|
-
ref,
|
|
669
|
-
) {
|
|
670
|
-
return (
|
|
671
|
-
<kbd
|
|
672
|
-
ref={ref}
|
|
673
|
-
data-slot="input-prompt-badge"
|
|
674
|
-
data-platform={platform}
|
|
675
|
-
className={cn("mw-ui-game-prompt", className)}
|
|
676
|
-
{...props}
|
|
677
|
-
>
|
|
678
|
-
<span className="mw-ui-game-prompt-key">{input}</span>
|
|
679
|
-
{actionLabel ? (
|
|
680
|
-
<span className="mw-ui-game-prompt-action">{actionLabel}</span>
|
|
681
|
-
) : null}
|
|
682
|
-
</kbd>
|
|
683
|
-
);
|
|
684
|
-
},
|
|
685
|
-
);
|
|
686
|
-
InputPromptBadge.displayName = "InputPromptBadge";
|
|
687
|
-
|
|
688
|
-
export interface GamepadNavOptions {
|
|
689
|
-
readonly itemCount: number;
|
|
690
|
-
readonly initialIndex?: number;
|
|
691
|
-
readonly enabled?: boolean;
|
|
692
|
-
readonly onConfirm?: (index: number) => void;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
export function useGamepadNavigation({
|
|
696
|
-
itemCount,
|
|
697
|
-
initialIndex = 0,
|
|
698
|
-
enabled = true,
|
|
699
|
-
onConfirm,
|
|
700
|
-
}: GamepadNavOptions) {
|
|
701
|
-
const [activeIndex, setActiveIndex] = useState(
|
|
702
|
-
itemCount > 0 ? Math.min(itemCount - 1, Math.max(0, initialIndex)) : 0,
|
|
703
|
-
);
|
|
704
|
-
|
|
705
|
-
const move = useCallback(
|
|
706
|
-
(delta: number) => {
|
|
707
|
-
if (itemCount <= 0) return;
|
|
708
|
-
setActiveIndex((prev) => (prev + delta + itemCount) % itemCount);
|
|
709
|
-
},
|
|
710
|
-
[itemCount],
|
|
711
|
-
);
|
|
712
|
-
|
|
713
|
-
const handleKeyDown = useCallback(
|
|
714
|
-
(event: { key: string; preventDefault?: () => void }) => {
|
|
715
|
-
if (!enabled || itemCount <= 0) return;
|
|
716
|
-
if (
|
|
717
|
-
event.key === "ArrowDown" ||
|
|
718
|
-
event.key === "ArrowRight" ||
|
|
719
|
-
event.key === "s" ||
|
|
720
|
-
event.key === "d"
|
|
721
|
-
) {
|
|
722
|
-
event.preventDefault?.();
|
|
723
|
-
move(1);
|
|
724
|
-
} else if (
|
|
725
|
-
event.key === "ArrowUp" ||
|
|
726
|
-
event.key === "ArrowLeft" ||
|
|
727
|
-
event.key === "w" ||
|
|
728
|
-
event.key === "a"
|
|
729
|
-
) {
|
|
730
|
-
event.preventDefault?.();
|
|
731
|
-
move(-1);
|
|
732
|
-
} else if (event.key === "Enter" || event.key === " ") {
|
|
733
|
-
event.preventDefault?.();
|
|
734
|
-
onConfirm?.(activeIndex);
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
[enabled, itemCount, move, onConfirm, activeIndex],
|
|
738
|
-
);
|
|
739
|
-
|
|
740
|
-
return useMemo(
|
|
741
|
-
() => ({ activeIndex, setActiveIndex, move, handleKeyDown }),
|
|
742
|
-
[activeIndex, move, handleKeyDown],
|
|
743
|
-
);
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
export type GameTitleScreenProps = ComponentPropsWithoutRef<"section"> & {
|
|
747
|
-
title: string;
|
|
748
|
-
subtitle?: string;
|
|
749
|
-
menuItems: readonly { readonly id: string; readonly label: string }[];
|
|
750
|
-
onSelectItem: (id: string) => void;
|
|
751
|
-
footerPrompt?: string;
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
export const GameTitleScreen = forwardRef<HTMLElement, GameTitleScreenProps>(
|
|
755
|
-
function GameTitleScreen(
|
|
756
|
-
{
|
|
757
|
-
title,
|
|
758
|
-
subtitle,
|
|
759
|
-
menuItems,
|
|
760
|
-
onSelectItem,
|
|
761
|
-
footerPrompt = "PRESS ENTER OR CLICK TO START",
|
|
762
|
-
className,
|
|
763
|
-
...props
|
|
764
|
-
},
|
|
765
|
-
ref,
|
|
766
|
-
) {
|
|
767
|
-
const { triggerSfx } = useMotion();
|
|
768
|
-
const nav = useGamepadNavigation({
|
|
769
|
-
itemCount: menuItems.length,
|
|
770
|
-
onConfirm: (idx) => {
|
|
771
|
-
const item = menuItems[idx];
|
|
772
|
-
if (item) {
|
|
773
|
-
triggerSfx("level-up");
|
|
774
|
-
onSelectItem(item.id);
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
return (
|
|
780
|
-
<section
|
|
781
|
-
ref={ref}
|
|
782
|
-
tabIndex={0}
|
|
783
|
-
onKeyDown={nav.handleKeyDown}
|
|
784
|
-
data-slot="game-title-screen"
|
|
785
|
-
className={cn("mw-ui-game-title-screen", className)}
|
|
786
|
-
{...props}
|
|
787
|
-
>
|
|
788
|
-
<div className="mw-ui-game-title-head">
|
|
789
|
-
<h3 className="mw-ui-game-title-heading">{title}</h3>
|
|
790
|
-
{subtitle ? <p className="mw-ui-game-title-sub">{subtitle}</p> : null}
|
|
791
|
-
</div>
|
|
792
|
-
<div
|
|
793
|
-
className="mw-ui-game-title-menu"
|
|
794
|
-
role="menu"
|
|
795
|
-
aria-label={`${title} menu`}
|
|
796
|
-
>
|
|
797
|
-
{menuItems.map((item, idx) => (
|
|
798
|
-
<button
|
|
799
|
-
key={item.id}
|
|
800
|
-
type="button"
|
|
801
|
-
role="menuitem"
|
|
802
|
-
data-active={nav.activeIndex === idx ? "true" : "false"}
|
|
803
|
-
className="mw-ui-game-title-btn"
|
|
804
|
-
onMouseEnter={() => nav.setActiveIndex(idx)}
|
|
805
|
-
onClick={() => {
|
|
806
|
-
nav.setActiveIndex(idx);
|
|
807
|
-
triggerSfx("level-up");
|
|
808
|
-
onSelectItem(item.id);
|
|
809
|
-
}}
|
|
810
|
-
>
|
|
811
|
-
<span aria-hidden="true" className="mw-ui-game-title-cursor">
|
|
812
|
-
▶
|
|
813
|
-
</span>
|
|
814
|
-
<span>{item.label}</span>
|
|
815
|
-
</button>
|
|
816
|
-
))}
|
|
817
|
-
</div>
|
|
818
|
-
<p className="mw-ui-game-title-footer">{footerPrompt}</p>
|
|
819
|
-
</section>
|
|
820
|
-
);
|
|
821
|
-
},
|
|
822
|
-
);
|
|
823
|
-
GameTitleScreen.displayName = "GameTitleScreen";
|
|
824
|
-
|
|
825
|
-
export type PauseMenuOverlayProps = ComponentPropsWithoutRef<"div"> & {
|
|
826
|
-
open: boolean;
|
|
827
|
-
title?: string;
|
|
828
|
-
onResume: () => void;
|
|
829
|
-
onRestart?: () => void;
|
|
830
|
-
children?: ReactNode;
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
export const PauseMenuOverlay = forwardRef<
|
|
834
|
-
HTMLDivElement,
|
|
835
|
-
PauseMenuOverlayProps
|
|
836
|
-
>(function PauseMenuOverlay(
|
|
837
|
-
{
|
|
838
|
-
open,
|
|
839
|
-
title = "PAUSED",
|
|
840
|
-
onResume,
|
|
841
|
-
onRestart,
|
|
842
|
-
children,
|
|
843
|
-
className,
|
|
844
|
-
...props
|
|
845
|
-
},
|
|
846
|
-
ref,
|
|
847
|
-
) {
|
|
848
|
-
if (!open) return null;
|
|
849
|
-
return (
|
|
850
|
-
<div
|
|
851
|
-
ref={ref}
|
|
852
|
-
role="dialog"
|
|
853
|
-
aria-modal="true"
|
|
854
|
-
aria-label={title}
|
|
855
|
-
data-slot="pause-menu-overlay"
|
|
856
|
-
className={cn("mw-ui-game-pause", className)}
|
|
857
|
-
{...props}
|
|
858
|
-
>
|
|
859
|
-
<div className="mw-ui-game-pause-card">
|
|
860
|
-
<h4 className="mw-ui-game-pause-title">{title}</h4>
|
|
861
|
-
{children}
|
|
862
|
-
<div className="mw-ui-game-pause-actions">
|
|
863
|
-
<button
|
|
864
|
-
type="button"
|
|
865
|
-
className="mw-ui-button"
|
|
866
|
-
data-variant="default"
|
|
867
|
-
onClick={onResume}
|
|
868
|
-
>
|
|
869
|
-
Resume
|
|
870
|
-
</button>
|
|
871
|
-
{onRestart ? (
|
|
872
|
-
<button
|
|
873
|
-
type="button"
|
|
874
|
-
className="mw-ui-button"
|
|
875
|
-
data-variant="outline"
|
|
876
|
-
onClick={onRestart}
|
|
877
|
-
>
|
|
878
|
-
Restart
|
|
879
|
-
</button>
|
|
880
|
-
) : null}
|
|
881
|
-
</div>
|
|
882
|
-
</div>
|
|
883
|
-
</div>
|
|
884
|
-
);
|
|
885
|
-
});
|
|
886
|
-
PauseMenuOverlay.displayName = "PauseMenuOverlay";
|