-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
508 lines (447 loc) · 23.9 KB
/
Copy pathindex.html
File metadata and controls
508 lines (447 loc) · 23.9 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>MelodyMaster Pro v2.0 | @墨点星痕</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;900&display=swap" rel="stylesheet">
<style>
:root {
--navy: #1A365D; --gold: #D4AF37; --bg: #0f172a; --card: #1e293b; --text: #f1f5f9;
--success: #00ff88; --danger: #ff4444; --accent: #6366f1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); margin: 0; min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden; }
/* 导航与头部 */
header { background: var(--navy); padding: 0.8rem 1.5rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--gold); position: sticky; top:0; z-index:100; }
.user-pill { background: rgba(212,175,55,0.1); border: 1px solid var(--gold); padding: 5px 12px; border-radius: 20px; font-size: 0.8rem; color: var(--gold); cursor: pointer; font-weight: bold; }
/* 设置栏 */
.settings-bar { background: #1e293b; padding: 10px; display: flex; justify-content: center; gap: 10px; border-bottom: 1px solid #334155; }
.toggle-btn { background: #0f172a; border: 1px solid var(--gold); color: var(--gold); padding: 5px 10px; border-radius: 5px; font-size: 0.75rem; cursor: pointer; }
.toggle-btn.active { background: var(--gold); color: var(--navy); font-weight: bold; }
.container { max-width: 1000px; margin: 0 auto; width: 100%; padding: 1rem; flex: 1; }
/* 登录模态框 */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.95); z-index: 2000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.login-card { background: var(--card); padding: 2rem; border-radius: 20px; border: 2px solid var(--gold); width: 90%; max-width: 400px; text-align: center; }
.login-card input { width: 100%; padding: 15px; border-radius: 10px; border: none; margin: 1.5rem 0; font-size: 1.1rem; background: #0f172a; color: white; text-align: center; border: 1px solid #334155; }
/* 大厅卡片 */
.matrix-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; margin-top: 1rem; }
.level-card { background: var(--card); border-radius: 15px; padding: 1.2rem; border: 1px solid rgba(255,255,255,0.05); }
.level-card h3 { margin: 0 0 15px 0; font-size: 1rem; color: var(--gold); border-left: 3px solid var(--gold); padding-left: 10px; }
/* 游戏区域 */
.stave-box { background: white; border-radius: 15px; height: 260px; position: relative; border: 5px solid var(--navy); touch-action: none; overflow: hidden; }
.stave-line { stroke: #000; stroke-width: 2.5; }
.guide-line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4; opacity: 0.5; pointer-events: none; }
.ghost-note { fill: rgba(99, 102, 241, 0.3); stroke: var(--accent); stroke-width: 2; }
/* 按钮 */
.btn { background: var(--navy); color: white; border: 2px solid var(--gold); padding: 1rem; border-radius: 12px; font-weight: 900; font-size: 1.1rem; cursor: pointer; }
.btn:active { transform: scale(0.95); opacity: 0.8; }
.btn-confirm { background: var(--accent); border-color: white; width: 100%; margin-top: 15px; display: none; padding: 1.2rem; }
/* 纠错反馈 */
#global-click-layer { position: fixed; inset: 0; z-index: 999; background: rgba(0,0,0,0.4); display: none; align-items: flex-end; justify-content: center; padding-bottom: 80px; }
.hint-bar { background: #fff; color: #000; padding: 15px 40px; border-radius: 50px; font-weight: 900; border: 4px solid var(--navy); }
.panel { background: rgba(0,0,0,0.2); border-radius: 12px; padding: 1.2rem; margin-top: 1.5rem; border: 1px solid #334155; }
.error-chip { display: inline-block; background: #000; padding: 6px 12px; border-radius: 8px; margin: 5px; font-size: 0.8rem; border: 1px solid var(--danger); }
footer { background: #000; color: #555; text-align: center; padding: 1.5rem; font-size: 0.75rem; }
.hidden { display: none !important; }
.correct-note { fill: var(--success); stroke: #000; stroke-width: 2; }
.wrong-note { fill: var(--danger); stroke: #000; stroke-width: 2; }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
.confirm-anim { animation: pulse 1s infinite; }
</style>
</head>
<body>
<div id="login-modal" class="modal-overlay hidden">
<div class="login-card">
<h2 style="color:var(--gold); margin:0;">识别身份</h2>
<input type="text" id="user-input" placeholder="输入你的大名..." maxlength="10">
<div id="user-history-list" style="text-align:left; margin-bottom:1.5rem; max-height: 150px; overflow-y: auto;"></div>
<button onclick="UserSystem.login()" class="btn" style="width:100%;">开始练习</button>
</div>
</div>
<header>
<div style="display:flex; align-items:center; gap:10px;">
<div style="background:var(--gold); color:var(--navy); font-weight:900; padding:4px 8px; border-radius:5px;">MM</div>
<div style="font-weight:900; letter-spacing:1px;">MelodyMaster <span style="font-weight:100; font-size:0.7rem;">PRO v2.0</span></div>
</div>
<div id="user-display" class="user-pill" onclick="UserSystem.showLogin()">载入中...</div>
</header>
<!-- 全局设置选项 -->
<div class="settings-bar">
<span style="font-size: 0.75rem; color: #94a3b8; align-self: center;">显示模式:</span>
<button class="toggle-btn active" id="mode-name" onclick="Config.setMode('name')">音名 (CDE)</button>
<button class="toggle-btn" id="mode-sol" onclick="Config.setMode('sol')">唱名 (DoReMi)</button>
<button class="toggle-btn" id="mode-both" onclick="Config.setMode('both')">混合显示</button>
</div>
<div id="global-click-layer" onclick="Game.nextQuestion()">
<div class="hint-bar">点击屏幕任意处继续 →</div>
</div>
<div id="lobby-view" class="container">
<h2 style="margin:0 0 1rem 0; font-size:1.2rem; color:var(--gold);">🎯 训练维度 (每组20题)</h2>
<div id="level-matrix" class="matrix-grid"></div>
<div class="panel">
<h3 style="margin:0 0 10px 0; font-size:0.9rem; color:var(--danger);">❌ 高频弱项</h3>
<div id="error-list">暂无错题。</div>
</div>
</div>
<div id="game-view" class="container hidden">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:1rem;">
<button onclick="Game.exit()" class="btn" style="padding: 5px 15px; font-size: 0.9rem;">退出</button>
<div id="timer-display" style="font-family:monospace; color:var(--gold); font-size:1.4rem; font-weight:900;">0.00s</div>
<div id="game-progress" style="font-weight:bold; color:var(--accent);">0 / 20</div>
</div>
<div id="instruction" style="text-align:center; font-weight:900; font-size:1.2rem; color:var(--gold); margin-bottom:15px; background:rgba(212,175,55,0.1); padding:12px; border-radius:10px; min-height: 3rem; display: flex; align-items: center; justify-content: center;">...</div>
<div class="stave-box" id="stave-click-area">
<svg id="svg-main" viewBox="0 0 400 240" width="100%" height="100%">
<g id="stave-lines">
<line x1="10" y1="80" x2="390" y2="80" class="stave-line" />
<line x1="10" y1="100" x2="390" y2="100" class="stave-line" />
<line x1="10" y1="120" x2="390" y2="120" class="stave-line" />
<line x1="10" y1="140" x2="390" y2="140" class="stave-line" />
<line x1="10" y1="160" x2="390" y2="160" class="stave-line" />
</g>
<text id="clef-render" x="20" y="152" font-size="80" fill="#000" font-family="serif" font-weight="bold">𝄞</text>
<line id="guide-line" x1="0" y1="-100" x2="400" y2="-100" class="guide-line" />
<g id="ledger-layer"></g>
<g id="note-layer"></g>
<ellipse id="ghost-note" cx="-100" cy="-100" rx="11" ry="8" class="ghost-note" />
<g id="status-icons"></g>
</svg>
</div>
<!-- 标位模式专用的确认按钮 -->
<button id="confirm-btn" class="btn btn-confirm" onclick="Game.confirmPlacement()">确 定 位 置</button>
<div id="input-zone" style="display:grid; grid-template-columns:repeat(7, 1fr); gap:8px; margin-top:1.5rem;">
<!-- 按钮由JS动态生成 -->
</div>
<div id="game-feedback" style="margin-top:1rem; text-align:center; font-weight:bold; min-height: 1.5rem;"></div>
</div>
<footer>
COPYRIGHT © 2026 墨点星痕 | 专业音乐识谱训练终极版
</footer>
<script>
/** 0. 全局配置 **/
const Config = {
displayMode: 'name', // 'name', 'sol', 'both'
solfegeMap: { 'C': 'Do', 'D': 'Re', 'E': 'Mi', 'F': 'Fa', 'G': 'Sol', 'A': 'La', 'B': 'Si' },
setMode(m) {
this.displayMode = m;
document.querySelectorAll('.toggle-btn').forEach(b => b.classList.remove('active'));
document.getElementById('mode-' + m).classList.add('active');
if(!document.getElementById('game-view').classList.contains('hidden')) {
Game.renderInputButtons();
Game.renderInstruction();
}
},
formatNote(noteId) {
const name = noteId[0];
const oct = noteId.slice(1);
const sol = this.solfegeMap[name];
if(this.displayMode === 'sol') return sol + oct;
if(this.displayMode === 'both') return `${name}(${sol})${oct}`;
return noteId;
},
formatBase(name) {
if(this.displayMode === 'sol') return this.solfegeMap[name];
if(this.displayMode === 'both') return `${name}\n<small>${this.solfegeMap[name]}</small>`;
return name;
}
};
/** 1. 用户系统 **/
const UserSystem = {
key: 'MelodyMaster_V2_DB',
db: JSON.parse(localStorage.getItem('MelodyMaster_V2_DB') || '{"users":{}, "current":null}'),
init() {
if (!this.db.current) this.showLogin();
else this.applyUser(this.db.current);
this.renderLobby();
},
showLogin() {
document.getElementById('login-modal').classList.remove('hidden');
const list = document.getElementById('user-history-list');
list.innerHTML = '';
Object.keys(this.db.users).forEach(u => {
const d = document.createElement('div');
d.style = "padding:12px; background:rgba(255,255,255,0.05); border-radius:8px; margin-bottom:8px; cursor:pointer; border:1px solid #334155";
d.innerHTML = `👤 ${u}`;
d.onclick = () => { document.getElementById('user-input').value = u; };
list.appendChild(d);
});
},
login() {
const name = document.getElementById('user-input').value.trim();
if(!name) return;
if(!this.db.users[name]) this.db.users[name] = { history: {}, errors: {} };
this.db.current = name;
this.save();
location.reload();
},
applyUser(name) {
document.getElementById('user-display').innerText = `学习者: ${name}`;
document.getElementById('login-modal').classList.add('hidden');
},
save() { localStorage.setItem(this.key, JSON.stringify(this.db)); },
renderLobby() {
const user = this.db.users[this.db.current];
if(!user) return;
const grid = document.getElementById('level-matrix');
grid.innerHTML = '';
Game.levels.forEach(l => {
const sKey = `${l.id}_identify`, pKey = `${l.id}_place`;
const s = user.history[sKey], p = user.history[pKey];
const div = document.createElement('div');
div.className = 'level-card';
div.innerHTML = `
<h3>${l.title}</h3>
<div style="display:grid; grid-template-columns:1fr 1fr; gap:8px;">
<button class="btn" style="padding:10px; font-size:0.8rem;" onclick="Game.start('${l.id}','identify')">识谱训练<br><small>${s?s.speed+'s':'NEW'}</small></button>
<button class="btn" style="padding:10px; font-size:0.8rem;" onclick="Game.start('${l.id}','place')">标位训练<br><small>${p?p.speed+'s':'NEW'}</small></button>
</div>
`;
grid.appendChild(div);
});
const errList = document.getElementById('error-list');
const sorted = Object.entries(user.errors).sort((a,b)=>b[1]-a[1]).slice(0,12);
errList.innerHTML = sorted.length ? sorted.map(x=>`<span class="error-chip">${Config.formatNote(x[0])} <b>×${x[1]}</b></span>`).join('') : "记录完美,继续保持!";
}
};
/** 2. 乐理引擎 **/
const Music = {
pitches: ['C','D','E','F','G','A','B'],
getY(noteId, clef) {
const name = noteId[0], octave = parseInt(noteId.slice(1));
const abs = octave * 7 + this.pitches.indexOf(name);
const center = (clef === 'treble') ? (4*7+6) : (3*7+1); // Treble B4(34), Bass D3(22)
return 120 + (center - abs) * 10;
},
getNote(y, clef) {
const center = (clef === 'treble') ? (4*7+6) : (3*7+1);
const abs = center - Math.round((y - 120) / 10);
return this.pitches[((abs%7)+7)%7] + Math.floor(abs/7);
}
};
/** 3. 游戏核心 **/
const Game = {
levels: [
{ id: 't1', title: '高音基础 (E4-F5)', clef: 'treble', range: ['E4', 'F5'] },
{ id: 't2', title: '高音全域 (C4-C6)', clef: 'treble', range: ['C4', 'C6'] },
{ id: 'b1', title: '低音基础 (G2-A3)', clef: 'bass', range: ['G2', 'A3'] },
{ id: 'b2', title: '低音全域 (C2-E4)', clef: 'bass', range: ['C2', 'E4'] },
{ id: 'm1', title: '混合挑战 (大谱表全域)', clef: 'mixed', range: ['C2', 'C6'] }
],
state: { isWaiting: false, startTime: 0, timer: null, selectedNote: null },
start(lid, mode) {
const l = this.levels.find(x => x.id === lid);
this.state = {
lid, mode,
configClef: l.clef,
range: l.range,
idx: 0,
correct: 0,
timeTotal: 0,
sessionErrors: [],
isWaiting: false,
selectedNote: null
};
document.getElementById('lobby-view').classList.add('hidden');
document.getElementById('game-view').classList.remove('hidden');
document.getElementById('input-zone').classList.toggle('hidden', mode === 'place');
document.getElementById('confirm-btn').style.display = (mode === 'place' ? 'block' : 'none');
this.renderInputButtons();
this.nextQuestion();
},
renderInputButtons() {
const zone = document.getElementById('input-zone');
zone.innerHTML = '';
Music.pitches.forEach(p => {
const b = document.createElement('button');
b.className = 'btn';
b.innerHTML = Config.formatBase(p);
b.onclick = () => this.handleInput(p);
zone.appendChild(b);
});
},
nextQuestion() {
if(this.state.idx >= 20) return this.end();
this.state.isWaiting = false;
this.state.selectedNote = null;
document.getElementById('global-click-layer').style.display = 'none';
document.getElementById('note-layer').innerHTML = '';
document.getElementById('ledger-layer').innerHTML = '';
document.getElementById('status-icons').innerHTML = '';
document.getElementById('confirm-btn').classList.remove('confirm-anim');
document.getElementById('ghost-note').setAttribute("cx", "-100");
// 确定当前题目谱号
if(this.state.configClef === 'mixed') {
this.state.currentClef = Math.random() > 0.5 ? 'treble' : 'bass';
// 根据谱号限制抽题范围,避免低音谱号抽到太高的音
if(this.state.currentClef === 'treble') this.state.currentRange = ['C4', 'C6'];
else this.state.currentRange = ['C2', 'E4'];
} else {
this.state.currentClef = this.state.configClef;
this.state.currentRange = this.state.range;
}
// 抽题逻辑
const pool = this.getPool(this.state.currentRange);
this.state.currNote = pool[Math.floor(Math.random()*pool.length)];
this.renderClef();
this.renderInstruction();
if(this.state.mode === 'identify') {
this.drawNote(this.state.currNote, 'standard');
}
document.getElementById('game-progress').textContent = `${this.state.idx + 1} / 20`;
this.state.startTime = performance.now();
this.startTimer();
},
renderClef() {
const el = document.getElementById('clef-render');
if(this.state.currentClef === 'treble') {
el.textContent = '𝄞'; el.setAttribute("y", "152");
} else {
el.textContent = '𝄢'; el.setAttribute("y", "110");
}
},
renderInstruction() {
const ins = document.getElementById('instruction');
if(this.state.mode === 'identify') {
ins.innerHTML = "请辨认该音符名称";
} else {
ins.innerHTML = `请标出位置: <b style="color:var(--gold); font-size:1.6rem; margin-left:10px;">${Config.formatNote(this.state.currNote)}</b>`;
}
},
drawNote(noteId, type, x = 200) {
const y = Music.getY(noteId, this.state.currentClef);
const g = document.getElementById('note-layer');
const elp = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
elp.setAttribute("cx", x); elp.setAttribute("cy", y);
elp.setAttribute("rx", "12"); elp.setAttribute("ry", "9");
elp.setAttribute("class", type === 'correct' ? 'correct-note' : (type === 'wrong' ? 'wrong-note' : ''));
elp.setAttribute("fill", type === 'standard' ? '#000' : '');
elp.setAttribute("transform", `rotate(-15, ${x}, ${y})`);
g.appendChild(elp);
// 动态补加线
const ledgerG = document.getElementById('ledger-layer');
if (y <= 70 || y >= 170) {
const isUp = y <= 70;
const startY = isUp ? 60 : 180;
const count = Math.ceil(Math.abs(y - (isUp ? 70 : 170)) / 20);
for(let i=0; i<count; i++) {
const ly = startY + (isUp ? -i*20 : i*20);
const l = document.createElementNS("http://www.w3.org/2000/svg", "line");
l.setAttribute("x1", x-25); l.setAttribute("x2", x+25);
l.setAttribute("y1", ly); l.setAttribute("y2", ly);
l.setAttribute("stroke", "#000"); l.setAttribute("stroke-width", "2.5");
ledgerG.appendChild(l);
}
}
},
// 标位模式点击确认
confirmPlacement() {
if(this.state.isWaiting || !this.state.selectedNote) return;
this.handleInput(this.state.selectedNote);
},
handleInput(val) {
if(this.state.isWaiting) return;
clearInterval(this.state.timer);
this.state.isWaiting = true;
const elapsed = (performance.now() - this.state.startTime) / 1000;
const isCorrect = (this.state.mode === 'identify') ? (val === this.state.currNote[0]) : (val === this.state.currNote);
const fb = document.getElementById('game-feedback');
if(isCorrect) {
this.state.correct++; this.state.timeTotal += elapsed;
fb.innerHTML = `<span style="color:var(--success)">太棒了! +1</span>`;
this.drawIcon("O", "var(--success)");
setTimeout(() => this.nextQuestion(), 600);
} else {
this.state.sessionErrors.push(this.state.currNote);
fb.innerHTML = `<span style="color:var(--danger)">答错了哦</span>`;
this.drawIcon("X", "var(--danger)");
this.showCorrection(val);
}
this.state.idx++;
},
drawIcon(txt, color) {
const t = document.createElementNS("http://www.w3.org/2000/svg", "text");
t.setAttribute("x", "340"); t.setAttribute("y", "70");
t.setAttribute("font-size", "60"); t.setAttribute("fill", color);
t.setAttribute("font-weight", "900"); t.textContent = txt;
document.getElementById('status-icons').appendChild(t);
},
showCorrection(wrongVal) {
document.getElementById('note-layer').innerHTML = '';
if(this.state.mode === 'place') {
this.drawNote(wrongVal, 'wrong', 160);
this.drawNote(this.state.currNote, 'correct', 240);
document.getElementById('instruction').innerHTML = `解析: <span style="color:var(--danger)">左侧为你选</span> | <span style="color:var(--success)">右侧为正确</span>`;
} else {
this.drawNote(this.state.currNote, 'correct', 200);
document.getElementById('instruction').innerHTML = `正确答案: <b style="color:var(--success)">${Config.formatNote(this.state.currNote)}</b>`;
}
document.getElementById('global-click-layer').style.display = 'flex';
},
startTimer() {
const el = document.getElementById('timer-display');
clearInterval(this.state.timer);
this.state.timer = setInterval(() => {
const n = (performance.now() - this.state.startTime) / 1000;
el.textContent = n.toFixed(2) + 's';
}, 60);
},
getPool(range) {
const p = Music.pitches;
const v = n => parseInt(n[1])*7 + p.indexOf(n[0]);
const min = v(range[0]), max = v(range[1]);
let r = [];
for(let i=min; i<=max; i++) r.push(p[((i%7)+7)%7] + Math.floor(i/7));
return r;
},
end() {
const acc = (this.state.correct / 20) * 100;
const speed = (this.state.timeTotal / (this.state.correct || 1)).toFixed(2);
const user = UserSystem.db.users[UserSystem.db.current];
const key = `${this.state.lid}_${this.state.mode}`;
if(!user.history[key] || acc >= user.history[key].score) {
user.history[key] = { score: acc, speed };
}
this.state.sessionErrors.forEach(n => user.errors[n] = (user.errors[n] || 0) + 1);
UserSystem.save();
alert(`训练完成!\n正确率: ${acc}%\n平均用时: ${speed}s`);
this.exit();
},
exit() {
clearInterval(this.state.timer);
document.getElementById('game-view').classList.add('hidden');
document.getElementById('lobby-view').classList.remove('hidden');
UserSystem.renderLobby();
}
};
/** 4. 交互控制 **/
const svgArea = document.getElementById('stave-click-area');
// 手机/鼠标点击五线谱
svgArea.addEventListener('pointerdown', (e) => {
if(Game.state.isWaiting || Game.state.mode !== 'place') return;
const r = svgArea.getBoundingClientRect();
const y = (e.clientY - r.top) * (240 / r.height);
const snapY = Math.round(y/10)*10;
// 更新辅助线和重影音符
document.getElementById('guide-line').setAttribute("y1", snapY);
document.getElementById('guide-line').setAttribute("y2", snapY);
const note = Music.getNote(snapY, Game.state.currentClef);
Game.state.selectedNote = note;
const g = document.getElementById('ghost-note');
g.setAttribute("cy", snapY); g.setAttribute("cx", "200");
// 激活确认按钮动画
document.getElementById('confirm-btn').classList.add('confirm-anim');
});
// 辅助线跟随移动
svgArea.addEventListener('pointermove', (e) => {
if(Game.state.isWaiting) return;
const r = svgArea.getBoundingClientRect();
const y = (e.clientY - r.top) * (240 / r.height);
const snapY = Math.round(y/10)*10;
document.getElementById('guide-line').setAttribute("y1", snapY);
document.getElementById('guide-line').setAttribute("y2", snapY);
});
window.onload = () => UserSystem.init();
</script>
</body>
</html>