var OSU_FILES = []; const global = new Dispatcher(); function _removeFile(id) { //TODO: Remove from bars too let elem = document.getElementById(id); const file_id = elem.dataset.index; elem.remove(); if(file_id!==undefined && OSU_FILES[file_id]) { const osu = OSU_FILES[file_id]; OSU_FILES[file_id] = null; global.signal("FILE_REMOVE", {id: file_id, osu: osu}); } } const READ_WHOLE_BUFFER = true; function _readfile(event) { var input = event.target; if(READ_WHOLE_BUFFER) { var reader = new FileReader(); reader.onload = () => { var osu = new OsuFile(); osu.LoadString(reader.result).then(result => { console.log("Read version "+osu.version); if(osu.okay()) { //Push to read osu files OSU_FILES.push(osu); global.signal("FILE_ADD", {id: OSU_FILES.length-1, osu: osu}); } else { var er = osu.errors; console.log("Parsing .osu file failed: "+JSON.stringify(er)); //TODO: Signal error } }); }; reader.readAsText(input.files[0]); } else { var nav = new LineNavigator(input.files[0]); } } var SIDEBAR_VIEWING = null; function get_aggregate() { return OSU_FILES.where(x=> x)[0]; } function clear_sidebar() { for(const elem of document.getElementsByClassName("metadata")) { elem.innerText=""; removeClass(elem, "meta-dupe"); } } function populate_sidebar(osu) { const meta = (id, value_name, transform) => { transform = transform || ((value) => value); const elem = document.getElementById("meta-"+id); const value = transform(path(osu, value_name)); elem.innerText = value; if(OSU_FILES.where(x=> x && transform(path(x, value_name)) == value).length != OSU_FILES.where(x=> x).length) { //Is a not-dupe. addClass(elem, "meta-dupe"); } else removeClass(elem, "meta-dupe"); }; if(!osu) { if(OSU_FILES.where(x=> x).length<1) clear_sidebar(); else { //Is aggregate. populate_sidebar(get_aggregate()); SIDEBAR_VIEWING = null; } } else { //Is single //General meta("audio-filename", "data.General.AudioFilename"); meta("audio-lead-in", "data.General.AudioLeadIn"); meta("preview-time", "data.General.PreviewTime"); meta("countdown", "data.General.Countdown"); meta("sample-set", "data.General.SampleSet"); meta("stacking", "data.General.StackLeniency"); meta("mode", "data.General.Mode"); meta("letterbox", "data.General.LetterboxInBreaks"); meta("widescreen", "data.General.WidescreenStoryboard"); //Metadata meta("title", "data.Metadata.TitleUnicode"); meta("title-ascii", "data.Metadata.Title"); meta("artist", "data.Metadata.ArtistUnicode"); meta("artist-ascii", "data.Metadata.Artist"); meta("mapper", "data.Metadata.Creator"); meta("difficulty", "data.Metadata.Version"); meta("source", "data.Metadata.Source"); meta("tags", "data.Metadata.Tags", tags=> tags.join(", ")); meta("beatmap-id", "data.Metadata.BeatmapID"); meta("beatmap-set-id", "data.Metadata.BeatmapSetID"); //Diff meta("diff-hp", "data.Difficulty.HPDrainRate"); meta("diff-cs", "data.Difficulty.CircleSize"); meta("diff-od", "data.Difficulty.OverallDifficulty"); meta("diff-ar", "data.Difficulty.ApproachRate"); meta("diff-sv", "data.Difficulty.SliderMultiplier"); meta("diff-tr", "data.Difficulty.SliderTickRate"); //Background meta("background", "spec.Background"); SIDEBAR_VIEWING = osu; } } function repopulate_sidebar(get_sel) { if(get_sel) { const elem = document.getElementById("meta-selector"); if(elem.selectedIndex==0) populate_sidebar(); else populate_sidebar(OSU_FILES[elem.value]); } else populate_sidebar(SIDEBAR_VIEWING); } function _onload() { // --- Set up collapsers --- // const collapsers = document.getElementsByClassName('collapse'); for(const elem of collapsers) { elem.addEventListener('click', function() { let block; if(this.dataset.collapse) { block = document.getElementById(this.dataset.collapse); } else block = this.parentElement.nextSibling.nextSibling; if(block.style.display === "none") { removeClass(this, "collapsed"); block.style.display = ""; } else { addClass(this, "collapsed"); block.style.display = "none"; } }, false); } // --- End collapsers --- // // --- Selector change -- // const metadataSelector = document.getElementById('meta-selector'); metadataSelector.addEventListener("change", function(event) { if(this.selectedIndex==0) { populate_sidebar(); } else { const osu = OSU_FILES[this.value]; if(osu) { populate_sidebar(osu); } } }); } const OSUFILE_DOM_PRE = "O_file"; function setWarn(elem, on, str) { if(!elem) return; if(on) { addClass(elem, "warning"); elem.setAttribute("title", "Warning"+ (str?": "+str:"")); } else if(hasClass(elem,"warning")) { removeClass(elem, "warning"); elem.removeAttribute("title"); } } /// --- HOOKS --- /// //Create DOM elem for file. global.hook("FILE_ADD", function(arg) { const id = arg.id; const osu = arg.osu; //A new file has been added. //