gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js rhythm game editor load url mp3 bpm share "#/" shortcuts
- User
html css js rhythm game editor load url mp3 bpm share "#/" shortcuts
- Assistant
html css js rhythm game editor load url mp3 bpm share "#/" shortcuts
Sure! You want a simple rhythm game editor built with HTML, CSS, and JS that can:
#/ with encoded data)Here’s a minimal but functional example. It will:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rhythm Game Editor</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background: #222; color: #eee; display: flex; flex-direction: column; height: 100vh;}
header { padding: 1em; background: #333; }
main { flex: 1; display: flex; flex-direction: column; gap: 0.5em; padding: 1em; }
label { display: inline-block; margin-right: 0.5em; }
input[type="text"], input[type="number"] {
padding: 0.3em;
font-size: 1em;
background: #444;
border: none;
color: #eee;
border-radius: 3px;
width: 300px;
}
button {
background: #08f;
border: none;
color: white;
padding: 0.5em 1.2em;
border-radius: 3px;
cursor: pointer;
font-weight: bold;
}
button:hover { background: #06c; }
#timeline {
margin-top: 1em;
background: #111;
height: 120px;
position: relative;
border-radius: 6px;
user-select: none;
cursor: crosshair;
}
#timeline .beat {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background: #666;
}
#timeline .note {
position: absolute;
top: 20px;
width: 12px;
height: 80px;
background: #0f8;
border-radius: 3px;
cursor: pointer;
opacity: 0.9;
transition: background 0.3s;
}
#timeline .note.hover {
background: #0fc;
}
audio {
margin-top: 0.5em;
width: 100%;
}
#shortcuts {
font-size: 0.9em;
color: #ccc;
margin-top: 1em;
}
</style>
</head>
<body>
<header>
<h1>Rhythm Game Editor</h1>
</header>
<main>
<div>
<label for="url">MP3 URL:</label>
<input type="text" id="url" placeholder="Paste MP3 URL here" />
<button id="loadBtn">Load</button>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="number" id="bpm" min="30" max="300" step="1" value="120" />
</div>
<audio id="audio" controls></audio>
<div id="timeline" title="Click to add notes. Select note and press Delete to remove. Use Left/Right arrows to move note.">
</div>
<div id="shortcuts">
<p><b>Shortcuts:</b> Click timeline to add note. Select note by clicking. Delete = Remove note. Left/Right arrows = Move note.</p>
</div>
</main>
<script>
(() => {
const urlInput = document.getElementById('url');
const bpmInput = document.getElementById('bpm');
const audio = document.getElementById('audio');
const timeline = document.getElementById('timeline');
const loadBtn = document.getElementById('loadBtn');
// Internal state
let state = {
url: '',
bpm: 120,
notes: [], // notes are beat indices (integers)
};
let selectedNoteIndex = null;
// Constants
const timelineWidth = 800; // Will resize timeline to this px width for layout calculations.
timeline.style.width = timelineWidth + 'px';
// Helpers
function saveStateToHash() {
// Encode state as JSON base64 (URL safe)
const data = {
url: state.url,
bpm: state.bpm,
notes: state.notes,
};
const json = JSON.stringify(data);
const b64 = btoa(encodeURIComponent(json));
location.hash = '#/' + b64;
}
function loadStateFromHash() {
const hash = location.hash;
if (!hash.startsWith('#/')) return false;
try {
const b64 = hash.slice(2);
const json = decodeURIComponent(atob(b64));
const data = JSON.parse(json);
if (data.url && data.bpm && Array.isArray(data.notes)) {
state.url = data.url;
state.bpm = data.bpm;
state.notes = data.notes;
return true;
}
return false;
} catch(e) {
console.warn('Failed to parse state from URL:', e);
return false;
}
}
function bpmToMs(bpm) {
return 60000 / bpm;
}
function drawTimeline() {
timeline.innerHTML = '';
// Draw beat lines for 16 beats (4 measures 4/4)
const beatCount = 16;
for (let beat = 0; beat <= beatCount; beat++) {
const pos = (beat / beatCount) * timelineWidth;
const beatLine = document.createElement('div');
beatLine.className = 'beat';
beatLine.style.left = pos + 'px';
// Make every 4th beat line stronger
beatLine.style.backgroundColor = (beat % 4 === 0) ? '#aaa' : '#666';
beatLine.style.width = (beat % 4 === 0) ? '3px' : '1px';
timeline.appendChild(beatLine);
}
// Draw notes
state.notes.forEach((beatIndex, i) => {
const pos = (beatIndex / beatCount) * timelineWidth;
const note = document.createElement('div');
note.className = 'note';
note.style.left = (pos - 6) + 'px'; // centered 12px width
note.title = `Note at beat ${beatIndex + 1}`;
note.dataset.index = i;
if (selectedNoteIndex === i) {
note.style.backgroundColor = '#ff0';
note.classList.add('hover');
}
// Click selects this note
note.addEventListener('click', (e) => {
e.stopPropagation();
selectedNoteIndex = i;
drawTimeline();
});
timeline.appendChild(note);
});
}
function addNoteAtPosition(x) {
// Add note based on click X pos in timeline
const beatCount = 16;
const beat = Math.round((x / timelineWidth) * beatCount);
// Avoid duplicates at same beat
if (!state.notes.includes(beat)) {
state.notes.push(beat);
state.notes.sort((a,b) => a - b);
selectedNoteIndex = state.notes.indexOf(beat);
drawTimeline();
saveStateToHash();
}
}
function removeSelectedNote() {
if (selectedNoteIndex !== null && selectedNoteIndex >= 0 && selectedNoteIndex < state.notes.length) {
state.notes.splice(selectedNoteIndex, 1);
selectedNoteIndex = null;
drawTimeline();
saveStateToHash();
}
}
function moveSelectedNote(delta) {
if (selectedNoteIndex === null) return;
const beatCount = 16;
let newBeat = state.notes[selectedNoteIndex] + delta;
if (newBeat < 0) newBeat = 0;
if (newBeat > beatCount) newBeat = beatCount;
if (state.notes.includes(newBeat)) return; // don't overlap notes
state.notes[selectedNoteIndex] = newBeat;
state.notes.sort((a,b) => a - b);
selectedNoteIndex = state.notes.indexOf(newBeat);
drawTimeline();
saveStateToHash();
}
// Load MP3 URL and set Audio src
function loadAudio(url) {
audio.src = url;
audio.load();
}
// UI bind
loadBtn.addEventListener('click', () => {
const url = urlInput.value.trim();
if (!url) {
alert('Please enter an MP3 URL');
return;
}
state.url = url;
loadAudio(url);
saveStateToHash();
});
bpmInput.addEventListener('change', () => {
let val = parseInt(bpmInput.value);
if (isNaN(val) || val < 30) val = 30;
if (val > 300) val = 300;
bpmInput.value = val;
state.bpm = val;
saveStateToHash();
});
// Timeline click to add notes
timeline.addEventListener('click', (e) => {
const rect = timeline.getBoundingClientRect();
const x = e.clientX - rect.left;
addNoteAtPosition(x);
});
// Keyboard shortcuts
window.addEventListener('keydown', (e) => {
if (!document.activeElement || ['URL', 'NUMBER', 'INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return;
switch(e.key) {
case 'Delete':
case 'Backspace':
removeSelectedNote();
break;
case 'ArrowLeft':
moveSelectedNote(-1);
e.preventDefault();
break;
case 'ArrowRight':
moveSelectedNote(1);
e.preventDefault();
break;
default:
break;
}
});
// On load, try to load state from URL hash
if (loadStateFromHash()) {
urlInput.value = state.url;
bpmInput.value = state.bpm;
loadAudio(state.url);
}
drawTimeline();
})();
</script>
</body>
</html>
https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 (public URLs work)Example share link format:
https://yourpage/#/...
(The hash encodes the JSON state base64-encoded.)
This is a basic editor. You can expand it by:
Let me know if you want any of those features or help integrating with actual gameplay code!
Not yet included in a published release.