It sounds like you want to create a rhythm game editor using HTML, CSS, and JavaScript. The editor should support the following features:
html
<!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: #111; color: #eee;
display: flex; flex-direction: column; align-items: center; min-height: 100vh;
}
header {
margin: 1rem;
}
#controls {
display: flex; gap: 1rem; margin-bottom: 1rem;
align-items:center;
}
#notes {
display: flex;
overflow-x: auto;
border: 1px solid #555;
height: 80px;
width: 90vw;
background: #222;
position: relative;
user-select:none;
}
.bar {
border-left: 1px solid #666;
height: 100%;
width: 4rem;
display: flex;
flex-wrap: wrap;
}
.note {
flex: 1 0 20%;
border: 1px solid #333;
cursor: pointer;
display: flex;
align-items:center;
justify-content:center;
color: #ccc;
font-size: 0.8rem;
}
.note.hit {
background: #0f0;
color: black;
}
.note.combo {
background: orange;
color: black;
}
#audio-player {
margin-top: 1rem;
width: 90vw;
}
#shortcuts {
margin-top: 1rem;
font-size: 0.9rem;
background: #222;
border: 1px solid #444;
padding: 0.5rem 1rem;
border-radius: 6px;
}
button {
background:#333;color:#eee;border:none;padding:0.3rem 0.7rem;
border-radius:4px;cursor:pointer;
}
button:hover {
background:#555;
}
</style>
</head>
<body>
<header><h1>Rhythm Game Editor</h1></header>
<div id="controls">
<input id="mp3-url" type="text" placeholder="MP3 URL" size="50" />
<input id="bpm" type="number" min="30" max="300" step="1" value="120" style="width:70px"/>
<button id="load">Load</button>
<button id="share">Share map URL</button>
</div>
<div id="notes"></div>
<audio id="audio-player" controls></audio>
<div id="shortcuts">
<b>Shortcuts:</b>
<ul>
<li>Click note to toggle hit</li>
<li>Delete key - Remove last note</li>
<li>Arrow Left/Right - Navigate bars</li>
<li>Space - Play/Pause audio</li>
</ul>
</div>
<script>
(() => {
const mp3Input = document.getElementById('mp3-url');
const bpmInput = document.getElementById('bpm');
const loadBtn = document.getElementById('load');
const shareBtn = document.getElementById('share');
const notesContainer = document.getElementById('notes');
const audio = document.getElementById('audio-player');
/*
* We'll represent the map internally as:
* map = {
* bpm: number,
* bars: [
* [bool, bool, bool, bool, bool] <- 5 notes per bar
* ]
* }
*/
const NOTES_PER_BAR = 5; // 5 notes fit into each bar for now
// Editor state
let map = { bpm: 120, bars: [] };
let currentBarIndex = 0;
// Try to load from hash params
function parseHash() {
try {
const hash = location.hash;
if (!hash.startsWith('#/')) return false;
// format: #/bpm,barsEncoded,mp3encoded
// e.g. #/120,YnJV,https%3A%2F%2Fexample.com%2Faudio.mp3
const parts = decodeURIComponent(hash.slice(2)).split(',');
if(parts.length < 3) return false;
const bpmCandidate = parseInt(parts[0], 10);
if (isNaN(bpmCandidate) || bpmCandidate < 30 || bpmCandidate > 300) return false;
const barsEncoded = parts[1];
const mp3url = parts.slice(2).join(',');
// Decode bars: simple base64 or custom codec to bool arrays
// We encode each bar as a single base32 char representing 5 bits
// '0' or '1' bits per note (1 = hit, 0 = none)
// To keep simple, decode bars from string of base32 chars
// Base32 alphabet for 5 bits
const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
function decodeBarChar(c) {
const idx = BASE32.indexOf(c.toUpperCase());
if(idx === -1) return 0;
return idx;
}
function decodeBars(str) {
return [...str].map(c => {
const bits = decodeBarChar(c);
let bar = [];
for (let i=NOTES_PER_BAR-1; i>=0; i--) {
bar.unshift(!!(bits & (1<<i)));
}
return bar;
});
}
const bars = decodeBars(barsEncoded);
if (!bars.length) return false;
map = { bpm: bpmCandidate, bars, mp3: mp3url };
currentBarIndex = 0;
mp3Input.value = mp3url;
bpmInput.value = bpmCandidate;
audio.src = mp3url;
renderNotes();
return true;
} catch(e) {
console.warn('Failed to parse hash', e);
return false;
}
}
// Serialize bars into base32 string
function encodeBars(bars) {
const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
return bars.map(bar => {
let bits = 0;
for(let i=0; i<NOTES_PER_BAR; i++) {
if(bar[i]) bits |= (1 << (NOTES_PER_BAR - 1 - i));
}
return BASE32[bits] || 'A';
}).join('');
}
// Share current map in URL hash
function updateHash() {
if(!map.bars.length) return;
let barsEncoded = encodeBars(map.bars);
let urlPart = [
map.bpm,
barsEncoded,
encodeURIComponent(audio.src || mp3Input.value)
].join(',');
history.replaceState(null,null,'#/' + urlPart);
}
// Render notes for the entire map
// To keep performance ok, we'll render all bars since keyboard left/right can scroll
function renderNotes() {
notesContainer.innerHTML = '';
for(let b=0; b<map.bars.length; b++) {
const barDiv = document.createElement('div');
barDiv.classList.add('bar');
barDiv.dataset.barIndex = b;
const bar = map.bars[b];
for(let i=0; i<NOTES_PER_BAR; i++) {
const noteDiv = document.createElement('div');
noteDiv.classList.add('note');
if(bar[i]) noteDiv.classList.add('hit');
noteDiv.title = `Bar ${b+1}, Note ${i+1}`;
noteDiv.dataset.barIndex = b;
noteDiv.dataset.noteIndex = i;
noteDiv.textContent = i+1;
barDiv.appendChild(noteDiv);
}
notesContainer.appendChild(barDiv);
}
}
// Toggle note hit status
function toggleNote(barIndex, noteIndex) {
if (!map.bars[barIndex]) return;
map.bars[barIndex][noteIndex] = !map.bars[barIndex][noteIndex];
renderNotes();
updateHash();
}
// Delete last note (last "hit" note in the map)
function deleteLastNote() {
for(let b=map.bars.length - 1; b>=0; b--){
for(let n=NOTES_PER_BAR-1; n>=0; n--){
if(map.bars[b][n]){
map.bars[b][n] = false;
renderNotes();
updateHash();
return;
}
}
}
}
// Keyboard shortcuts handler
function onKeyDown(e) {
if(e.target.tagName === 'INPUT') return; // ignore inputs
switch(e.key) {
case 'ArrowLeft':
if(currentBarIndex > 0){
currentBarIndex--;
scrollToBar(currentBarIndex);
}
e.preventDefault();
break;
case 'ArrowRight':
if(currentBarIndex < map.bars.length - 1){
currentBarIndex++;
scrollToBar(currentBarIndex);
}
e.preventDefault();
break;
case 'Delete':
deleteLastNote();
e.preventDefault();
break;
case ' ':
if(audio.paused) audio.play(); else audio.pause();
e.preventDefault();
break;
default:
break;
}
}
function scrollToBar(index){
const barDivs = notesContainer.querySelectorAll('.bar');
if(index >= 0 && index < barDivs.length){
let barDiv = barDivs[index];
barDiv.scrollIntoView({behavior:'smooth', inline:'center'});
}
}
// Load from inputs
function loadMap() {
let url = mp3Input.value.trim();
let bpm = parseInt(bpmInput.value, 10);
if(!url || isNaN(bpm) || bpm < 30 || bpm > 300) {
alert('Please enter a valid MP3 URL and BPM (30-300)');
return;
}
audio.src = url;
map = { bpm, bars: [] };
currentBarIndex = 0;
// Add 8 empty bars by default
for(let i=0; i<8; i++) {
map.bars.push(new Array(NOTES_PER_BAR).fill(false));
}
renderNotes();
updateHash();
}
// Click handler for toggling notes
notesContainer.addEventListener('click', e => {
if(!e.target.classList.contains('note')) return;
const barIndex = Number(e.target.dataset.barIndex);
const noteIndex = Number(e.target.dataset.noteIndex);
toggleNote(barIndex, noteIndex);
});
loadBtn.addEventListener('click', loadMap);
shareBtn.addEventListener('click', () => {
updateHash();
prompt('Share this URL:', location.href);
});
window.addEventListener('keydown', onKeyDown);
// On load, try to parse hash or set defaults
if(!parseHash()){
mp3Input.value = '';
bpmInput.value = 120;
}
})();
</script>
</body>
</html>
If you'd like me to help adding any of those extra features or polish styling, just ask!