-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
519 lines (470 loc) · 15.6 KB
/
Copy pathtypes.ts
File metadata and controls
519 lines (470 loc) · 15.6 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
export type CategoryGroup = 'A' | 'B' | 'C';
/**
* Tile-Status für jede Kachel (LearningUnit)
*
* State-Übergänge:
* - locked → gold_unlocked: Wenn Standard-Quiz einmal perfekt abgeschlossen wurde (keine Fehler, keine Hints)
* - gold_unlocked → bounty_cleared: Wenn alle 3 Bounty-Aufgaben in einem Durchlauf korrekt beantwortet wurden
*
* Hinweis: Der Status kann aus User-State berechnet werden:
* - locked: Unit nicht in perfectStandardQuizUnits
* - gold_unlocked: Unit in perfectStandardQuizUnits, aber nicht in perfectBountyUnits
* - bounty_cleared: Unit in perfectBountyUnits
*/
export type TileStatus = 'locked' | 'gold_unlocked' | 'bounty_cleared';
export type ValidatorType =
| 'keywords'
| 'boolean'
| 'numeric'
| 'numericTolerance'
| 'coordinatePair'
| 'equation';
export interface InputValidatorConfig {
type: ValidatorType;
keywordsAny?: string[];
keywordsAll?: string[];
requireNegation?: boolean;
acceptedNumbers?: number[];
numericAnswer?: number;
tolerance?: number;
booleanExpected?: 'true' | 'false';
coordinateAnswer?: { x: number; y: number };
coordinateTolerance?: number;
equationPatterns?: string[];
}
export interface SvgLineSpec {
x1: number;
y1: number;
x2: number;
y2: number;
stroke?: string;
strokeWidth?: number;
dashed?: boolean;
}
export interface SvgArcSpec {
path: string;
fill?: string;
opacity?: number;
stroke?: string;
strokeWidth?: number;
strokeDasharray?: string;
}
export interface SvgLabelSpec {
text: string;
x: number;
y: number;
color?: string;
fontSize?: number;
anchor?: 'start' | 'middle' | 'end';
}
export type SupportVisualElement =
| ({ type: 'line' } & SvgLineSpec)
| ({ type: 'path' } & Omit<SvgArcSpec, 'path'> & { d: string })
| ({
type: 'text';
text: string;
x: number;
y: number;
color?: string;
fontSize?: number;
anchor?: 'start' | 'middle' | 'end';
});
export interface SupportVisual {
viewBox?: string;
elements: SupportVisualElement[];
caption?: string;
}
export interface AngleData {
path: string;
correctAngle: number;
baseLine?: SvgLineSpec;
wallLine?: SvgLineSpec;
helperLines?: SvgLineSpec[];
angleArcs?: SvgArcSpec[];
referenceLabels?: SvgLabelSpec[];
}
export interface MultiInputField {
id: string;
label: string;
placeholder?: string;
options?: string[]; // Optional: renders a dropdown instead of free text
validator: InputValidatorConfig;
}
export interface Task {
id: string;
question: string;
type:
| 'choice'
| 'input'
| 'boolean'
| 'shorttext'
| 'visualChoice'
| 'wager'
| 'dragDrop'
| 'angleMeasure'
| 'sliderTransform'
| 'areaDecomposition'
| 'multiAngleThrow';
options?: string[];
correctAnswer: number | string;
explanation: string;
placeholder?: string;
visualData?: any;
wagerOptions?: number[];
dragDropData?: {
shapes: Array<{ id: string; path: string; shapeType: string; label?: string }>;
categories: Array<{ id: string; label: string; accepts: string[] }>;
};
angleData?: AngleData;
sliderData?: { basePath: string; shapeType: string; minK: number; maxK: number; correctK: number };
decompositionData?: { complexPath: string; parts: Array<{ path: string; label: string; area?: number }> };
multiAngleThrowData?: { targetAngle: number; maxAngles: number; startCost: number; hitReward: number; tolerance?: number };
validator?: InputValidatorConfig;
multiInputFields?: MultiInputField[];
difficultyLevel?: 'Mittel' | 'Schwer';
context?: string;
given?: string[];
asked?: string[];
instructions?: string;
supportVisual?: SupportVisual;
}
/**
* Voraufgabe: Spielerische, visuelle Aufgabe als Vorbereitung für das Standard-Quiz
*
* Diese Aufgaben sind leichter und sollen das Konzept spielerisch einführen.
* Sie werden VOR dem Standard-Quiz angeboten, um den Lernenden auf das Thema vorzubereiten.
*
* @property uiType - Definiert, welche UI-Komponente verwendet wird (z.B. 'dragDrop', 'visualChoice', 'interactive')
* @property meta - Zusätzliche Metadaten für die UI-Komponente (z.B. SVG-Pfade, Konfiguration)
*/
export interface PreTask {
id: string;
title: string;
description: string;
uiType: 'dragDrop' | 'visualChoice' | 'interactive' | 'angleMeasure' | 'sliderTransform' | 'areaDecomposition';
meta: any; // Flexible Metadaten je nach uiType (z.B. visualData, dragDropData, etc.)
correctAnswer: number | string | Record<string, string | string[]>; // Kann auch ein Objekt für komplexe Antworten sein
explanation: string;
}
/**
* Bounty-Aufgabe: Klassische Prüfungsaufgabe (schwer, sehr klassisch)
*
* Diese Aufgaben sind die "Final Boss" Aufgaben für den Bounty-Modus.
* Es gibt genau 3 Bounty-Aufgaben pro Tile, die alle in einem Durchlauf korrekt
* beantwortet werden müssen, um den Status "bounty_cleared" zu erreichen.
*
* Hinweis: Diese Aufgaben sind deterministisch und nicht zufällig generiert,
* da sie klassische Prüfungsaufgaben repräsentieren sollen.
*/
export interface BountyTask extends Task {
// Erbt alle Eigenschaften von Task
// Zusätzlich können hier spezifische Bounty-Metadaten hinzugefügt werden
difficultyLevel: 'Mittel' | 'Schwer'; // Klassische Prüfungsaufgaben sind tendenziell schwerer
}
export interface TermDefinition {
term: string;
definition: string;
visual?: string; // SVG path or instruction
}
export interface LearningUnit {
id: string;
group: CategoryGroup;
category: 'Basics' | 'Konstruktion' | 'Berechnung' | 'Transformation' | 'Koordinaten' | 'Modellierung';
title: string;
description: string;
detailedInfo: string;
examples: string[];
/**
* Standard-Quiz: Die Hauptaufgaben für diese Kachel
* Diese werden beim normalen Quest-Durchlauf verwendet.
* Ein perfekter Durchlauf (keine Fehler, keine Hints) führt zu gold_unlocked Status.
*/
tasks: Task[];
/**
* Voraufgaben: Spielerische, visuelle Aufgaben als Vorbereitung
* Diese werden VOR dem Standard-Quiz angeboten, um das Konzept spielerisch einzuführen.
* Sie sind optional und dienen der Vorbereitung, nicht der Bewertung.
*/
preTasks?: PreTask[];
/**
* Bounty-Aufgaben: 3 klassische Prüfungsaufgaben
* Diese werden im Bounty-Modus verwendet (nach gold_unlocked Status).
* Alle 3 müssen in einem Durchlauf korrekt beantwortet werden, um bounty_cleared zu erreichen.
*
* Hinweis: Diese Aufgaben sind deterministisch (nicht zufällig generiert),
* da sie klassische Prüfungsaufgaben repräsentieren sollen.
*/
bountyTasks?: BountyTask[];
difficulty: 'Einfach' | 'Mittel' | 'Schwer';
coinsReward: number; // Standard Reward für Abschluss (immer)
bounty: number; // Extra Reward für Perfect Run (100-500)
definitionId?: string;
keywords: string[];
}
export interface GeometryDefinition {
id: string;
groupId: CategoryGroup;
title: string;
description: string;
formula: string;
terms: TermDefinition[];
visual: string;
}
export interface ShopItem {
id: string;
name: string;
type: 'avatar' | 'effect' | 'feature' | 'voucher' | 'calculator' | 'prize' | 'tool' | 'formelsammlung' | 'calc_gadget' | 'persona' | 'skin';
cost: number;
value: string;
icon?: string; // New: Display symbol separate from logic value
description: string;
rarity?: 'common' | 'rare' | 'epic' | 'legendary';
}
export interface AIMessage {
role: 'user' | 'assistant';
content: string;
costCoins?: number;
}
export interface User {
id: string;
username: string;
login_name?: string; // Einzigartiger Login-Name (mind. 4 Zeichen, zum Einloggen ohne Passwort)
/** QA account: infinite coins, all content unlocked (login_name master_dev) */
isMasterDev?: boolean;
avatar: string;
coins: number;
totalEarned: number;
/**
* Units, die mindestens einmal abgeschlossen wurden (mit oder ohne Fehler)
* Wird verwendet für Fortschrittsanzeige und Entsperrung weiterer Units.
*/
completedUnits: string[];
/**
* Units, die mit Bounty (perfekt) abgeschlossen wurden
*
* DEPRECATED: Verwende stattdessen perfectBountyUnits für Klarheit.
* Wird beibehalten für Rückwärtskompatibilität.
*
* State-Übergang: Unit wird hier hinzugefügt, wenn:
* - Standard-Quiz perfekt abgeschlossen wurde (keine Fehler, keine Hints)
* - UND alle 3 Bounty-Aufgaben in einem Durchlauf korrekt beantwortet wurden
*/
masteredUnits: string[];
/**
* Units, bei denen das Standard-Quiz perfekt abgeschlossen wurde
*
* "Perfekt" bedeutet:
* - Keine Fehler während des gesamten Quiz-Durchlaufs
* - Keine Hints verwendet (wenn noCheatSheet aktiviert war)
*
* State-Übergang: Unit wird hier hinzugefügt, wenn:
* - handleQuestComplete mit isPerfectRun=true aufgerufen wird
* - UND es war ein Standard-Quiz (nicht Bounty-Modus)
*
* Dies führt zum Status gold_unlocked für die entsprechende Tile.
*/
perfectStandardQuizUnits?: string[];
/**
* Units, bei denen alle Bounty-Aufgaben perfekt abgeschlossen wurden
*
* "Perfekt" bedeutet:
* - Alle 3 Bounty-Aufgaben wurden in einem Durchlauf korrekt beantwortet
* - Keine Fehler während des Bounty-Durchlaufs
* - Keine Hints verwendet (wenn noCheatSheet aktiviert war)
*
* State-Übergang: Unit wird hier hinzugefügt, wenn:
* - handleQuestComplete mit isPerfectRun=true aufgerufen wird
* - UND es war ein Bounty-Modus (alle 3 bountyTasks wurden korrekt beantwortet)
*
* Dies führt zum Status bounty_cleared für die entsprechende Tile.
*
* Hinweis: Eine Unit kann sowohl in perfectStandardQuizUnits als auch in
* perfectBountyUnits sein, wenn beide Modi perfekt abgeschlossen wurden.
*/
perfectBountyUnits?: string[];
/**
* Coin-Tracking pro Frage: Speichert, für welche Fragen bereits Coins vergeben wurden
*
* Struktur: { [questionKey]: string[] }
* - questionKey: Eindeutige Identifikation der Frage (z.B. "u1-standard-0" oder "u1-bounty-task-123")
* - string[]: Array von Modus-Strings, für die bereits Coins vergeben wurden
* - "standard": Standard-Modus (kein Hardmode)
* - "hardmode": Hardmode (timed + noCheatSheet)
* - "preTask": Voraufgabe
* - "bounty": Bounty-Aufgabe
*
* Logik:
* - Jede Frage kann nur einmal pro Modus Coins geben
* - Hardmode kann zusätzliche Coins geben, auch wenn Standard bereits Coins gegeben hat
* - Beispiel: Frage wurde im Standard-Modus richtig beantwortet → Coins gegeben, "standard" hinzugefügt
* → Später im Hardmode wieder richtig → Coins gegeben, "hardmode" hinzugefügt
* → Nochmal im Hardmode richtig → Keine Coins (bereits "hardmode" vorhanden)
*/
questionCoins?: Record<string, string[]>;
/**
* Summe der bereits verdienten Quest-Coins pro Unit (für Cap-Logik)
*/
questCoinsEarnedByUnit?: Record<string, number>;
/**
* Merker, ob eine Bounty-Belohnung bereits ausgezahlt wurde
*/
bountyPayoutClaimed?: Record<string, boolean>;
unlockedItems: string[];
activeEffects: string[];
calculatorSkin: string; // The active calculator design
xp: number;
// Neue Tools & Features
unlockedTools?: string[]; // ['formel_rechner', 'schritt_loeser']
calculatorGadgets?: string[]; // ['potenz', 'parabel', 'wurzel']
formelsammlungSkin?: string; // 'base', 'neon', 'klassik', 'minimal', 'interaktiv'
preClearedUnits?: string[]; // Units mit abgeschlossenen PreTasks
solvedQuestionIds?: string[]; // IDs gelöster Fragen (Anti-Farming)
}
export interface ChatMessage {
id: string;
userId: string;
username: string;
text: string;
timestamp: number;
avatar: string;
type?: 'chat' | 'system';
}
export interface BattleRequest {
id: string;
challengerId: string;
opponentId: string;
opponentName: string;
opponentAvatar: string;
unitId: string;
unitTitle: string;
wager: number;
status: 'pending' | 'active' | 'completed';
result?: {
winnerId: string;
challengerScore: number;
opponentScore: number;
};
}
export interface BattleScenario {
id: string;
title: string;
tagline: string;
description: string;
unitId: string;
unitTitle: string;
stake: number;
rounds: number;
icon: string;
difficulty: 'Einfach' | 'Mittel' | 'Schwer';
modifiers: string[];
tags: string[];
}
export type BattleStatus = 'pending' | 'running' | 'finished';
export interface BattleRecord {
id: string;
scenarioId?: string | null;
challengerId: string;
opponentId?: string | null;
unitId: string;
unitTitle?: string | null;
stake: number;
roundCount: number;
taskIds?: string[];
taskBundle?: Task[];
status: BattleStatus;
metadata?: Record<string, any> | null;
createdAt?: string;
acceptedAt?: string | null;
finishedAt?: string | null;
winnerId?: string | null;
resultReason?: string | null;
challengerScore?: number;
opponentScore?: number;
challengerTimeMs?: number;
opponentTimeMs?: number;
challengerSummary?: any;
opponentSummary?: any;
}
export interface BattleSummaryPayload {
correctCount: number;
totalTasks: number;
percentage: number;
solveTimeMs: number;
isPerfectRun?: boolean;
detail?: any;
}
export interface LogEntry {
timestamp: number;
action: string;
details: string;
userId: string;
}
export type ToastType = 'success' | 'error' | 'info';
export interface ToastMessage {
id: string;
type: ToastType;
message: string;
}
/**
* Berechnet den Tile-Status für eine LearningUnit basierend auf dem User-State
*
* State-Übergänge:
*
* 1. locked → gold_unlocked:
* - Trigger: Standard-Quiz wurde perfekt abgeschlossen (keine Fehler, keine Hints)
* - Aktion: Unit-ID wird zu user.perfectStandardQuizUnits hinzugefügt
* - Code: handleQuestComplete(isPerfectRun=true) für Standard-Quiz
*
* 2. gold_unlocked → bounty_cleared:
* - Trigger: Alle 3 Bounty-Aufgaben wurden in einem Durchlauf korrekt beantwortet
* - Aktion: Unit-ID wird zu user.perfectBountyUnits hinzugefügt
* - Code: handleQuestComplete(isPerfectRun=true) für Bounty-Modus
*
* @param unitId - Die ID der LearningUnit
* @param user - Der User-Objekt mit perfectStandardQuizUnits und perfectBountyUnits
* @returns Der aktuelle Tile-Status
*
* @example
* ```typescript
* const status = getTileStatus('u1', user);
* // Returns: 'locked' | 'gold_unlocked' | 'bounty_cleared'
* ```
*/
export function getTileStatus(unitId: string, user: User): TileStatus {
if (user.isMasterDev || (user.login_name && user.login_name.toLowerCase() === 'master_dev')) {
return 'bounty_cleared';
}
const perfectStandard = user.perfectStandardQuizUnits?.includes(unitId) ?? false;
const perfectBounty = user.perfectBountyUnits?.includes(unitId) ?? false;
// Rückwärtskompatibilität: Falls perfectBountyUnits nicht existiert,
// prüfe masteredUnits (alte Implementierung)
const hasBounty = perfectBounty || (user.perfectBountyUnits === undefined && user.masteredUnits?.includes(unitId));
if (hasBounty) {
return 'bounty_cleared';
}
if (perfectStandard) {
return 'gold_unlocked';
}
return 'locked';
}
/**
* Prüft, ob eine Unit den Status "gold_unlocked" oder höher hat
*
* @param unitId - Die ID der LearningUnit
* @param user - Der User-Objekt
* @returns true, wenn die Unit mindestens gold_unlocked ist
*/
export function isGoldUnlocked(unitId: string, user: User): boolean {
const status = getTileStatus(unitId, user);
return status === 'gold_unlocked' || status === 'bounty_cleared';
}
/**
* Prüft, ob eine Unit den Status "bounty_cleared" hat
*
* @param unitId - Die ID der LearningUnit
* @param user - Der User-Objekt
* @returns true, wenn die Unit bounty_cleared ist
*/
export function isBountyCleared(unitId: string, user: User): boolean {
return getTileStatus(unitId, user) === 'bounty_cleared';
}