@jjlmoya/utils-tabletop 1.3.0 → 1.5.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 +1 -1
- package/src/category/TabletopCategorySEO.astro +2 -7
- package/src/category/i18n/en.ts +4 -4
- package/src/category/i18n/ru.ts +2 -2
- package/src/category/i18n/zh.ts +8 -8
- package/src/category/index.ts +2 -1
- package/src/entries.ts +14 -1
- package/src/index.ts +1 -0
- package/src/pages/[locale]/[slug].astro +7 -6
- package/src/tests/locale_completeness.test.ts +1 -1
- package/src/tests/no_em_dash.test.ts +47 -0
- package/src/tests/seo_length.test.ts +1 -0
- package/src/tests/title_quality.test.ts +1 -1
- package/src/tests/tool_validation.test.ts +1 -1
- package/src/tool/board-game-timer/modules/ColorHelper.ts +2 -2
- package/src/tool/board-game-timer/modules/DuelViewManager.ts +4 -4
- package/src/tool/board-game-timer/modules/GameRunner.ts +1 -1
- package/src/tool/board-game-timer/modules/MultiplayerViewManager.ts +2 -2
- package/src/tool/board-game-timer/modules/SetupPanelManager.ts +1 -1
- package/src/tool/board-game-timer/modules/TimerEngine.ts +1 -1
- package/src/tool/board-game-timer/types.ts +1 -1
- package/src/tool/decision-wheel/audio.ts +78 -0
- package/src/tool/decision-wheel/bibliography.astro +16 -0
- package/src/tool/decision-wheel/bibliography.ts +8 -0
- package/src/tool/decision-wheel/client.ts +226 -0
- package/src/tool/decision-wheel/component.astro +48 -0
- package/src/tool/decision-wheel/components/SegmentEditor.astro +22 -0
- package/src/tool/decision-wheel/components/SpinHistory.astro +17 -0
- package/src/tool/decision-wheel/components/SpinResult.astro +13 -0
- package/src/tool/decision-wheel/components/WheelCanvas.astro +23 -0
- package/src/tool/decision-wheel/decision-wheel.css +632 -0
- package/src/tool/decision-wheel/drawing.ts +144 -0
- package/src/tool/decision-wheel/entry.ts +48 -0
- package/src/tool/decision-wheel/i18n/de.ts +97 -0
- package/src/tool/decision-wheel/i18n/en.ts +251 -0
- package/src/tool/decision-wheel/i18n/es.ts +93 -0
- package/src/tool/decision-wheel/i18n/fr.ts +93 -0
- package/src/tool/decision-wheel/i18n/id.ts +93 -0
- package/src/tool/decision-wheel/i18n/it.ts +93 -0
- package/src/tool/decision-wheel/i18n/ja.ts +93 -0
- package/src/tool/decision-wheel/i18n/ko.ts +93 -0
- package/src/tool/decision-wheel/i18n/nl.ts +93 -0
- package/src/tool/decision-wheel/i18n/pl.ts +93 -0
- package/src/tool/decision-wheel/i18n/pt.ts +93 -0
- package/src/tool/decision-wheel/i18n/ru.ts +75 -0
- package/src/tool/decision-wheel/i18n/sv.ts +93 -0
- package/src/tool/decision-wheel/i18n/tr.ts +93 -0
- package/src/tool/decision-wheel/i18n/zh.ts +93 -0
- package/src/tool/decision-wheel/index.ts +9 -0
- package/src/tool/decision-wheel/logic.test.ts +163 -0
- package/src/tool/decision-wheel/logic.ts +145 -0
- package/src/tool/decision-wheel/seo.astro +16 -0
- package/src/tool/decision-wheel/types.ts +14 -0
- package/src/tool/decision-wheel/ui.ts +121 -0
- package/src/tool/dice-roller-simulator/client.ts +2 -2
- package/src/tool/dice-roller-simulator/i18n/ru.ts +8 -8
- package/src/tool/dice-roller-simulator/modules/history.ts +1 -1
- package/src/tool/fantasy-runes-translator/bibliography.astro +16 -0
- package/src/tool/fantasy-runes-translator/bibliography.ts +16 -0
- package/src/tool/fantasy-runes-translator/client.ts +205 -0
- package/src/tool/fantasy-runes-translator/component.astro +95 -0
- package/src/tool/fantasy-runes-translator/entry.ts +56 -0
- package/src/tool/fantasy-runes-translator/fantasy-runes-translator.css +712 -0
- package/src/tool/fantasy-runes-translator/i18n/de.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/en.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/es.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/fr.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/id.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/it.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/ja.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/ko.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/nl.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/pl.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/pt.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/ru.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/sv.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/tr.ts +139 -0
- package/src/tool/fantasy-runes-translator/i18n/zh.ts +139 -0
- package/src/tool/fantasy-runes-translator/index.ts +9 -0
- package/src/tool/fantasy-runes-translator/logic.ts +174 -0
- package/src/tool/fantasy-runes-translator/seo.astro +16 -0
- package/src/tool/fantasy-runes-translator/types.ts +26 -0
- package/src/tool/first-player-selector/bibliography.astro +16 -0
- package/src/tool/first-player-selector/bibliography.ts +12 -0
- package/src/tool/first-player-selector/client.ts +197 -0
- package/src/tool/first-player-selector/component.astro +77 -0
- package/src/tool/first-player-selector/entry.ts +42 -0
- package/src/tool/first-player-selector/first-player-selector.css +303 -0
- package/src/tool/first-player-selector/i18n/de.ts +226 -0
- package/src/tool/first-player-selector/i18n/en.ts +226 -0
- package/src/tool/first-player-selector/i18n/es.ts +226 -0
- package/src/tool/first-player-selector/i18n/fr.ts +227 -0
- package/src/tool/first-player-selector/i18n/id.ts +226 -0
- package/src/tool/first-player-selector/i18n/it.ts +227 -0
- package/src/tool/first-player-selector/i18n/ja.ts +227 -0
- package/src/tool/first-player-selector/i18n/ko.ts +227 -0
- package/src/tool/first-player-selector/i18n/nl.ts +226 -0
- package/src/tool/first-player-selector/i18n/pl.ts +227 -0
- package/src/tool/first-player-selector/i18n/pt.ts +226 -0
- package/src/tool/first-player-selector/i18n/ru.ts +227 -0
- package/src/tool/first-player-selector/i18n/sv.ts +226 -0
- package/src/tool/first-player-selector/i18n/tr.ts +226 -0
- package/src/tool/first-player-selector/i18n/zh.ts +227 -0
- package/src/tool/first-player-selector/index.ts +9 -0
- package/src/tool/first-player-selector/modules/AnimationEffects.ts +256 -0
- package/src/tool/first-player-selector/modules/SelectionEngine.ts +249 -0
- package/src/tool/first-player-selector/modules/SoundEffects.ts +87 -0
- package/src/tool/first-player-selector/modules/TouchTracker.ts +148 -0
- package/src/tool/first-player-selector/seo.astro +16 -0
- package/src/tool/first-player-selector/types.ts +21 -0
- package/src/tool/rpg-initiative-tracker/bibliography.astro +16 -0
- package/src/tool/rpg-initiative-tracker/bibliography.ts +12 -0
- package/src/tool/rpg-initiative-tracker/client.ts +201 -0
- package/src/tool/rpg-initiative-tracker/component.astro +23 -0
- package/src/tool/rpg-initiative-tracker/components/AddForm.astro +49 -0
- package/src/tool/rpg-initiative-tracker/components/CombatantList.astro +16 -0
- package/src/tool/rpg-initiative-tracker/components/TurnControls.astro +28 -0
- package/src/tool/rpg-initiative-tracker/entry.ts +50 -0
- package/src/tool/rpg-initiative-tracker/i18n/de.ts +266 -0
- package/src/tool/rpg-initiative-tracker/i18n/en.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/es.ts +264 -0
- package/src/tool/rpg-initiative-tracker/i18n/fr.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/id.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/it.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/ja.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/ko.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/nl.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/pl.ts +264 -0
- package/src/tool/rpg-initiative-tracker/i18n/pt.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/ru.ts +264 -0
- package/src/tool/rpg-initiative-tracker/i18n/sv.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/tr.ts +263 -0
- package/src/tool/rpg-initiative-tracker/i18n/zh.ts +263 -0
- package/src/tool/rpg-initiative-tracker/index.ts +9 -0
- package/src/tool/rpg-initiative-tracker/logic.test.ts +121 -0
- package/src/tool/rpg-initiative-tracker/logic.ts +122 -0
- package/src/tool/rpg-initiative-tracker/rpg-initiative-tracker.css +617 -0
- package/src/tool/rpg-initiative-tracker/seo.astro +16 -0
- package/src/tool/rpg-initiative-tracker/types.ts +15 -0
- package/src/tool/score-tracker/bibliography.astro +16 -0
- package/src/tool/score-tracker/bibliography.ts +12 -0
- package/src/tool/score-tracker/client.ts +248 -0
- package/src/tool/score-tracker/component.astro +34 -0
- package/src/tool/score-tracker/components/Leaderboard.astro +19 -0
- package/src/tool/score-tracker/components/PlayerSetup.astro +32 -0
- package/src/tool/score-tracker/components/RoundScoring.astro +22 -0
- package/src/tool/score-tracker/components/ScoreHistory.astro +25 -0
- package/src/tool/score-tracker/entry.ts +57 -0
- package/src/tool/score-tracker/i18n/de.ts +278 -0
- package/src/tool/score-tracker/i18n/en.ts +278 -0
- package/src/tool/score-tracker/i18n/es.ts +251 -0
- package/src/tool/score-tracker/i18n/fr.ts +278 -0
- package/src/tool/score-tracker/i18n/id.ts +278 -0
- package/src/tool/score-tracker/i18n/it.ts +278 -0
- package/src/tool/score-tracker/i18n/ja.ts +278 -0
- package/src/tool/score-tracker/i18n/ko.ts +278 -0
- package/src/tool/score-tracker/i18n/nl.ts +278 -0
- package/src/tool/score-tracker/i18n/pl.ts +278 -0
- package/src/tool/score-tracker/i18n/pt.ts +278 -0
- package/src/tool/score-tracker/i18n/ru.ts +278 -0
- package/src/tool/score-tracker/i18n/sv.ts +278 -0
- package/src/tool/score-tracker/i18n/tr.ts +278 -0
- package/src/tool/score-tracker/i18n/zh.ts +278 -0
- package/src/tool/score-tracker/index.ts +9 -0
- package/src/tool/score-tracker/logic.test.ts +83 -0
- package/src/tool/score-tracker/logic.ts +122 -0
- package/src/tool/score-tracker/score-tracker.css +1029 -0
- package/src/tool/score-tracker/seo.astro +16 -0
- package/src/tool/score-tracker/types.ts +17 -0
- package/src/tools.ts +10 -0
- package/src/types.ts +1 -2
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type { ContactPoint, SelectionState, SelectorMode } from '../types';
|
|
2
|
+
|
|
3
|
+
export class SelectionEngine {
|
|
4
|
+
private mode: SelectorMode = 'finger';
|
|
5
|
+
private state: SelectionState = 'idle';
|
|
6
|
+
private contacts: ContactPoint[] = [];
|
|
7
|
+
private winner: ContactPoint | null = null;
|
|
8
|
+
|
|
9
|
+
private countdownTimer = 0;
|
|
10
|
+
private readonly countdownDuration = 2000;
|
|
11
|
+
|
|
12
|
+
private wheelAngle = 0;
|
|
13
|
+
private wheelSpeed = 0;
|
|
14
|
+
private isSpinning = false;
|
|
15
|
+
private prevContactsCount = 0;
|
|
16
|
+
|
|
17
|
+
private onStateChange: (state: SelectionState) => void;
|
|
18
|
+
private onTick: () => void;
|
|
19
|
+
private onWinnerChosen: (winner: ContactPoint) => void;
|
|
20
|
+
private onCountdownStart: () => void;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
onStateChange: (state: SelectionState) => void,
|
|
24
|
+
onTick: () => void,
|
|
25
|
+
onWinnerChosen: (winner: ContactPoint) => void,
|
|
26
|
+
onCountdownStart: () => void
|
|
27
|
+
) {
|
|
28
|
+
this.onStateChange = onStateChange;
|
|
29
|
+
this.onTick = onTick;
|
|
30
|
+
this.onWinnerChosen = onWinnerChosen;
|
|
31
|
+
this.onCountdownStart = onCountdownStart;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public setMode(mode: SelectorMode): void {
|
|
35
|
+
this.mode = mode;
|
|
36
|
+
this.reset();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public setContacts(contacts: ContactPoint[]): void {
|
|
40
|
+
const prevCount = this.prevContactsCount;
|
|
41
|
+
this.prevContactsCount = contacts.length;
|
|
42
|
+
this.contacts = contacts;
|
|
43
|
+
|
|
44
|
+
if (this.mode === 'finger') {
|
|
45
|
+
this.handleFingerContacts(contacts, prevCount);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private handleFingerContacts(contacts: ContactPoint[], prevCount: number): void {
|
|
50
|
+
if (this.state === 'celebration') {
|
|
51
|
+
this.handleCelebrationContacts(contacts, prevCount);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.handleActiveContacts(contacts, prevCount);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private handleCelebrationContacts(contacts: ContactPoint[], prevCount: number): void {
|
|
58
|
+
if (contacts.length === 0) {
|
|
59
|
+
this.reset();
|
|
60
|
+
} else if (contacts.length > prevCount) {
|
|
61
|
+
this.restartCountdown(contacts);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private handleActiveContacts(contacts: ContactPoint[], prevCount: number): void {
|
|
66
|
+
if (contacts.length < 2) {
|
|
67
|
+
if (this.state !== 'idle') {
|
|
68
|
+
this.setState('idle');
|
|
69
|
+
this.countdownTimer = 0;
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.state === 'countdown' && contacts.length !== prevCount) {
|
|
75
|
+
this.countdownTimer = 0;
|
|
76
|
+
this.onCountdownStart();
|
|
77
|
+
} else if (this.state === 'idle') {
|
|
78
|
+
this.startCountdown();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private restartCountdown(contacts: ContactPoint[]): void {
|
|
83
|
+
this.reset();
|
|
84
|
+
this.contacts = contacts;
|
|
85
|
+
this.prevContactsCount = contacts.length;
|
|
86
|
+
this.setState('countdown');
|
|
87
|
+
this.countdownTimer = 0;
|
|
88
|
+
this.onCountdownStart();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private startCountdown(): void {
|
|
92
|
+
this.setState('countdown');
|
|
93
|
+
this.countdownTimer = 0;
|
|
94
|
+
this.onCountdownStart();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public startWheelSelection(): void {
|
|
98
|
+
if (this.mode !== 'wheel' || this.contacts.length < 2 || this.isSpinning) return;
|
|
99
|
+
this.winner = null;
|
|
100
|
+
this.contacts.forEach((c) => (c.isWinner = false));
|
|
101
|
+
this.setState('selecting');
|
|
102
|
+
this.isSpinning = true;
|
|
103
|
+
this.wheelSpeed = 0.3 + Math.random() * 0.2;
|
|
104
|
+
this.onCountdownStart();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public update(dt: number): void {
|
|
108
|
+
if (this.mode === 'finger') {
|
|
109
|
+
this.updateFinger(dt);
|
|
110
|
+
} else if (this.mode === 'wheel') {
|
|
111
|
+
this.updateWheel(dt);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private updateFinger(dt: number): void {
|
|
116
|
+
if (this.state !== 'countdown') return;
|
|
117
|
+
|
|
118
|
+
const prevSec = Math.floor(this.countdownTimer / 500);
|
|
119
|
+
this.countdownTimer += dt;
|
|
120
|
+
const currSec = Math.floor(this.countdownTimer / 500);
|
|
121
|
+
|
|
122
|
+
if (currSec > prevSec && this.countdownTimer < this.countdownDuration) {
|
|
123
|
+
this.onTick();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (this.countdownTimer >= this.countdownDuration) {
|
|
127
|
+
this.chooseFingerWinner();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private updateWheel(dt: number): void {
|
|
132
|
+
if (this.state !== 'selecting' || !this.isSpinning) return;
|
|
133
|
+
|
|
134
|
+
this.wheelAngle += this.wheelSpeed * (dt / 16.666);
|
|
135
|
+
this.wheelSpeed *= Math.pow(0.97, dt / 16.666);
|
|
136
|
+
|
|
137
|
+
if (this.wheelSpeed < 0.002) {
|
|
138
|
+
this.isSpinning = false;
|
|
139
|
+
this.wheelSpeed = 0;
|
|
140
|
+
this.chooseWheelWinner();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public reset(): void {
|
|
145
|
+
this.state = 'idle';
|
|
146
|
+
this.winner = null;
|
|
147
|
+
this.contacts.forEach((c) => (c.isWinner = false));
|
|
148
|
+
this.countdownTimer = 0;
|
|
149
|
+
this.wheelAngle = 0;
|
|
150
|
+
this.wheelSpeed = 0;
|
|
151
|
+
this.isSpinning = false;
|
|
152
|
+
this.prevContactsCount = 0;
|
|
153
|
+
this.onStateChange(this.state);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public getState(): SelectionState {
|
|
157
|
+
return this.state;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getCountdownProgress(): number {
|
|
161
|
+
return Math.min(1, this.countdownTimer / this.countdownDuration);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public getWheelAngle(): number {
|
|
165
|
+
return this.wheelAngle;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public getWinner(): ContactPoint | null {
|
|
169
|
+
return this.winner;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private setState(state: SelectionState): void {
|
|
173
|
+
this.state = state;
|
|
174
|
+
this.onStateChange(state);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private chooseFingerWinner(): void {
|
|
178
|
+
if (this.contacts.length < 2) {
|
|
179
|
+
this.reset();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const winnerIndex = Math.floor(Math.random() * this.contacts.length);
|
|
184
|
+
const winContact = this.contacts[winnerIndex]!;
|
|
185
|
+
winContact.isWinner = true;
|
|
186
|
+
this.winner = winContact;
|
|
187
|
+
this.setState('celebration');
|
|
188
|
+
this.onWinnerChosen(winContact);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private chooseWheelWinner(): void {
|
|
192
|
+
if (this.contacts.length === 0) {
|
|
193
|
+
this.reset();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const angle = this.normalizeAngle(this.wheelAngle);
|
|
198
|
+
const pointerAngle = 3 * Math.PI / 2;
|
|
199
|
+
const centroid = this.getCentroid();
|
|
200
|
+
|
|
201
|
+
const closestContact = this.findClosestContact(angle, pointerAngle, centroid);
|
|
202
|
+
|
|
203
|
+
closestContact.isWinner = true;
|
|
204
|
+
this.winner = closestContact;
|
|
205
|
+
this.setState('celebration');
|
|
206
|
+
this.onWinnerChosen(closestContact);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private normalizeAngle(a: number): number {
|
|
210
|
+
return ((a % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private findClosestContact(angle: number, pointerAngle: number, centroid: { x: number; y: number }): ContactPoint {
|
|
214
|
+
let closestContact = this.contacts[0]!;
|
|
215
|
+
let minDiff = Infinity;
|
|
216
|
+
|
|
217
|
+
this.contacts.forEach((c) => {
|
|
218
|
+
const dx = c.x - centroid.x;
|
|
219
|
+
const dy = c.y - centroid.y;
|
|
220
|
+
let contactAngle = Math.atan2(dy, dx);
|
|
221
|
+
contactAngle = ((contactAngle + angle) % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
|
|
222
|
+
|
|
223
|
+
let diff = Math.abs(contactAngle - pointerAngle);
|
|
224
|
+
if (diff > Math.PI) {
|
|
225
|
+
diff = 2 * Math.PI - diff;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (diff < minDiff) {
|
|
229
|
+
minDiff = diff;
|
|
230
|
+
closestContact = c;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return closestContact;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public getCentroid(): { x: number; y: number } {
|
|
238
|
+
if (this.contacts.length === 0) {
|
|
239
|
+
return { x: 0, y: 0 };
|
|
240
|
+
}
|
|
241
|
+
let sumX = 0;
|
|
242
|
+
let sumY = 0;
|
|
243
|
+
this.contacts.forEach((c) => {
|
|
244
|
+
sumX += c.x;
|
|
245
|
+
sumY += c.y;
|
|
246
|
+
});
|
|
247
|
+
return { x: sumX / this.contacts.length, y: sumY / this.contacts.length };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export class SoundEffects {
|
|
2
|
+
private ctx: AudioContext | null = null;
|
|
3
|
+
private isMuted = false;
|
|
4
|
+
|
|
5
|
+
public setMute(muted: boolean): void {
|
|
6
|
+
this.isMuted = muted;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
private initCtx(): void {
|
|
10
|
+
if (!this.ctx) {
|
|
11
|
+
this.ctx = new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)();
|
|
12
|
+
}
|
|
13
|
+
if (this.ctx.state === 'suspended') {
|
|
14
|
+
this.ctx.resume();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public playTick(): void {
|
|
19
|
+
if (this.isMuted) return;
|
|
20
|
+
this.initCtx();
|
|
21
|
+
if (!this.ctx) return;
|
|
22
|
+
|
|
23
|
+
const osc = this.ctx.createOscillator();
|
|
24
|
+
const gain = this.ctx.createGain();
|
|
25
|
+
|
|
26
|
+
osc.connect(gain);
|
|
27
|
+
gain.connect(this.ctx.destination);
|
|
28
|
+
|
|
29
|
+
osc.frequency.setValueAtTime(800, this.ctx.currentTime);
|
|
30
|
+
gain.gain.setValueAtTime(0.1, this.ctx.currentTime);
|
|
31
|
+
gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + 0.05);
|
|
32
|
+
|
|
33
|
+
osc.start();
|
|
34
|
+
osc.stop(this.ctx.currentTime + 0.05);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public playCountdown(): void {
|
|
38
|
+
if (this.isMuted) return;
|
|
39
|
+
this.initCtx();
|
|
40
|
+
if (!this.ctx) return;
|
|
41
|
+
|
|
42
|
+
const osc = this.ctx.createOscillator();
|
|
43
|
+
const gain = this.ctx.createGain();
|
|
44
|
+
|
|
45
|
+
osc.connect(gain);
|
|
46
|
+
gain.connect(this.ctx.destination);
|
|
47
|
+
|
|
48
|
+
osc.type = 'triangle';
|
|
49
|
+
osc.frequency.setValueAtTime(200, this.ctx.currentTime);
|
|
50
|
+
osc.frequency.exponentialRampToValueAtTime(600, this.ctx.currentTime + 1.5);
|
|
51
|
+
|
|
52
|
+
gain.gain.setValueAtTime(0.01, this.ctx.currentTime);
|
|
53
|
+
gain.gain.linearRampToValueAtTime(0.15, this.ctx.currentTime + 1.2);
|
|
54
|
+
gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + 1.5);
|
|
55
|
+
|
|
56
|
+
osc.start();
|
|
57
|
+
osc.stop(this.ctx.currentTime + 1.5);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public playWinner(): void {
|
|
61
|
+
if (this.isMuted) return;
|
|
62
|
+
this.initCtx();
|
|
63
|
+
if (!this.ctx) return;
|
|
64
|
+
|
|
65
|
+
const now = this.ctx.currentTime;
|
|
66
|
+
const notes = [261.63, 329.63, 392.00, 523.25];
|
|
67
|
+
|
|
68
|
+
notes.forEach((freq, index) => {
|
|
69
|
+
if (!this.ctx) return;
|
|
70
|
+
const osc = this.ctx.createOscillator();
|
|
71
|
+
const gain = this.ctx.createGain();
|
|
72
|
+
|
|
73
|
+
osc.connect(gain);
|
|
74
|
+
gain.connect(this.ctx.destination);
|
|
75
|
+
|
|
76
|
+
osc.type = 'sine';
|
|
77
|
+
osc.frequency.setValueAtTime(freq, now + index * 0.1);
|
|
78
|
+
|
|
79
|
+
gain.gain.setValueAtTime(0.001, now + index * 0.1);
|
|
80
|
+
gain.gain.exponentialRampToValueAtTime(0.2, now + index * 0.1 + 0.02);
|
|
81
|
+
gain.gain.exponentialRampToValueAtTime(0.001, now + index * 0.1 + 0.6);
|
|
82
|
+
|
|
83
|
+
osc.start(now + index * 0.1);
|
|
84
|
+
osc.stop(now + index * 0.1 + 0.6);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ContactPoint, SelectorMode } from '../types';
|
|
2
|
+
|
|
3
|
+
export class TouchTracker {
|
|
4
|
+
private canvas: HTMLCanvasElement;
|
|
5
|
+
private mode: SelectorMode = 'finger';
|
|
6
|
+
private contacts: ContactPoint[] = [];
|
|
7
|
+
private onContactsChange: (contacts: ContactPoint[]) => void;
|
|
8
|
+
|
|
9
|
+
private colors = [
|
|
10
|
+
'#E11D48',
|
|
11
|
+
'#2563EB',
|
|
12
|
+
'#16A34A',
|
|
13
|
+
'#D97706',
|
|
14
|
+
'#7C3AED',
|
|
15
|
+
'#0891B2',
|
|
16
|
+
'#DB2777',
|
|
17
|
+
'#EA580C',
|
|
18
|
+
'#4F46E5',
|
|
19
|
+
'#65A30D'
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
constructor(canvas: HTMLCanvasElement, onContactsChange: (contacts: ContactPoint[]) => void) {
|
|
23
|
+
this.canvas = canvas;
|
|
24
|
+
this.onContactsChange = onContactsChange;
|
|
25
|
+
this.initEvents();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public setMode(mode: SelectorMode): void {
|
|
29
|
+
this.mode = mode;
|
|
30
|
+
this.contacts = [];
|
|
31
|
+
this.onContactsChange(this.contacts);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public getContacts(): ContactPoint[] {
|
|
35
|
+
return this.contacts;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public clear(): void {
|
|
39
|
+
this.contacts = [];
|
|
40
|
+
this.onContactsChange(this.contacts);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public setContacts(contacts: ContactPoint[]): void {
|
|
44
|
+
this.contacts = contacts;
|
|
45
|
+
this.onContactsChange(this.contacts);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private initEvents(): void {
|
|
49
|
+
this.canvas.addEventListener('touchstart', (e) => this.handleTouchStart(e), { passive: false });
|
|
50
|
+
this.canvas.addEventListener('touchmove', (e) => this.handleTouchMove(e), { passive: false });
|
|
51
|
+
this.canvas.addEventListener('touchend', (e) => this.handleTouchEnd(e));
|
|
52
|
+
this.canvas.addEventListener('touchcancel', (e) => this.handleTouchEnd(e));
|
|
53
|
+
this.canvas.addEventListener('mousedown', (e) => this.handleMouseDown(e));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private handleTouchStart(e: TouchEvent): void {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
if (this.mode !== 'finger') return;
|
|
59
|
+
|
|
60
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
61
|
+
const activeIds = new Set<string>();
|
|
62
|
+
|
|
63
|
+
for (let i = 0; i < e.touches.length; i++) {
|
|
64
|
+
const touch = e.touches[i]!;
|
|
65
|
+
const id = `touch-${touch.identifier}`;
|
|
66
|
+
activeIds.add(id);
|
|
67
|
+
|
|
68
|
+
const x = touch.clientX - rect.left;
|
|
69
|
+
const y = touch.clientY - rect.top;
|
|
70
|
+
|
|
71
|
+
const existingIndex = this.contacts.findIndex((c) => c.id === id);
|
|
72
|
+
if (existingIndex > -1) {
|
|
73
|
+
this.contacts[existingIndex]!.x = x;
|
|
74
|
+
this.contacts[existingIndex]!.y = y;
|
|
75
|
+
} else {
|
|
76
|
+
const color = this.getNextColor();
|
|
77
|
+
this.contacts.push({ id, x, y, color });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.contacts = this.contacts.filter((c) => c.id.startsWith('sim-') || activeIds.has(c.id));
|
|
82
|
+
this.onContactsChange(this.contacts);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private handleTouchMove(e: TouchEvent): void {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
if (this.mode !== 'finger') return;
|
|
88
|
+
|
|
89
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
90
|
+
for (let i = 0; i < e.touches.length; i++) {
|
|
91
|
+
const touch = e.touches[i]!;
|
|
92
|
+
const id = `touch-${touch.identifier}`;
|
|
93
|
+
const contact = this.contacts.find((c) => c.id === id);
|
|
94
|
+
if (contact) {
|
|
95
|
+
contact.x = touch.clientX - rect.left;
|
|
96
|
+
contact.y = touch.clientY - rect.top;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.onContactsChange(this.contacts);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private handleTouchEnd(e: TouchEvent): void {
|
|
104
|
+
if (this.mode !== 'finger') return;
|
|
105
|
+
|
|
106
|
+
const activeIds = new Set<string>();
|
|
107
|
+
for (let i = 0; i < e.touches.length; i++) {
|
|
108
|
+
activeIds.add(`touch-${e.touches[i]!.identifier}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.contacts = this.contacts.filter((c) => c.id.startsWith('sim-') || activeIds.has(c.id));
|
|
112
|
+
this.onContactsChange(this.contacts);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private handleMouseDown(e: MouseEvent): void {
|
|
116
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
117
|
+
const x = e.clientX - rect.left;
|
|
118
|
+
const y = e.clientY - rect.top;
|
|
119
|
+
|
|
120
|
+
const existingIndex = this.contacts.findIndex((c) => {
|
|
121
|
+
const dx = c.x - x;
|
|
122
|
+
const dy = c.y - y;
|
|
123
|
+
return Math.sqrt(dx * dx + dy * dy) < 30;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (existingIndex > -1) {
|
|
127
|
+
this.contacts.splice(existingIndex, 1);
|
|
128
|
+
this.onContactsChange(this.contacts);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.contacts.length >= 10) return;
|
|
133
|
+
|
|
134
|
+
const id = this.mode === 'finger' ? `sim-${Date.now()}` : `pin-${Date.now()}`;
|
|
135
|
+
const color = this.getNextColor();
|
|
136
|
+
this.contacts.push({ id, x, y, color });
|
|
137
|
+
this.onContactsChange(this.contacts);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private getNextColor(): string {
|
|
141
|
+
const usedColors = this.contacts.map((c) => c.color);
|
|
142
|
+
const available = this.colors.filter((c) => !usedColors.includes(c));
|
|
143
|
+
if (available.length > 0) {
|
|
144
|
+
return available[0];
|
|
145
|
+
}
|
|
146
|
+
return this.colors[this.contacts.length % this.colors.length];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { SEORenderer } from '@jjlmoya/utils-shared';
|
|
3
|
+
import { firstPlayerSelector } from './index';
|
|
4
|
+
import type { KnownLocale } from '../../types';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
locale?: KnownLocale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { locale = 'en' } = Astro.props;
|
|
11
|
+
const loader = firstPlayerSelector.i18n[locale] || firstPlayerSelector.i18n.en;
|
|
12
|
+
const content = await loader?.();
|
|
13
|
+
if (!content) return null;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
{content.seo?.length > 0 && <SEORenderer content={{ locale, sections: content.seo }} />}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type SelectorMode = 'finger' | 'wheel';
|
|
2
|
+
|
|
3
|
+
export type SelectionState = 'idle' | 'waiting' | 'countdown' | 'selecting' | 'celebration';
|
|
4
|
+
|
|
5
|
+
export interface ContactPoint {
|
|
6
|
+
id: string;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
color: string;
|
|
10
|
+
isWinner?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Particle {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
vx: number;
|
|
17
|
+
vy: number;
|
|
18
|
+
radius: number;
|
|
19
|
+
color: string;
|
|
20
|
+
alpha: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { Bibliography as SharedBibliography } from '@jjlmoya/utils-shared';
|
|
3
|
+
import { initiativeTracker } from './index';
|
|
4
|
+
import type { KnownLocale } from '../../types';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
locale?: KnownLocale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { locale = 'en' } = Astro.props as Props;
|
|
11
|
+
const loader = initiativeTracker.i18n[locale] || initiativeTracker.i18n.en;
|
|
12
|
+
const content = await loader?.();
|
|
13
|
+
if (!content) return null;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
{content && <SharedBibliography links={content.bibliography} />}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BibliographyEntry } from '../../types';
|
|
2
|
+
|
|
3
|
+
export const bibliography: BibliographyEntry[] = [
|
|
4
|
+
{
|
|
5
|
+
name: 'Dungeons & Dragons Basic Rules',
|
|
6
|
+
url: 'https://media.wizards.com/2018/dnd/downloads/DnD_BasicRules_2018.pdf',
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'Pathfinder Initiative Rules',
|
|
10
|
+
url: 'https://2e.aonprd.com/Rules.aspx?ID=2539',
|
|
11
|
+
},
|
|
12
|
+
];
|