2015-07-17 16:22:46 +08:00
|
|
|
function SongSelect(){
|
|
|
|
|
|
|
|
var _this=this;
|
|
|
|
var _songs;
|
|
|
|
var _selectedSong = {title:'', folder:'', difficulty:''};
|
2018-08-27 00:14:56 +08:00
|
|
|
var _preview;
|
|
|
|
var _preview_to;
|
2018-09-06 00:46:26 +08:00
|
|
|
var _diffNames={
|
|
|
|
easy:"かんたん",
|
|
|
|
normal:"ふつう",
|
|
|
|
hard:"むずかしい",
|
|
|
|
oni:"おに"
|
|
|
|
}
|
2018-08-27 00:14:56 +08:00
|
|
|
|
2018-08-27 20:28:30 +08:00
|
|
|
this.startPreview = function(id, prvtime, first_open=true) {
|
2018-08-27 00:14:56 +08:00
|
|
|
var start = Date.now();
|
|
|
|
setTimeout(function(){
|
|
|
|
bgm.pause();
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
_preview = new Audio('/songs/' + id + '/main.mp3');
|
|
|
|
_preview.onloadeddata = function() {
|
|
|
|
var end = Date.now();
|
|
|
|
var delay = end - start;
|
|
|
|
var no_delay = first_open ? 0 : 300;
|
|
|
|
|
2018-08-27 20:28:30 +08:00
|
|
|
_preview.currentTime = prvtime/1000;
|
2018-08-27 00:14:56 +08:00
|
|
|
_preview.volume = 0.5;
|
2018-08-27 09:09:04 +08:00
|
|
|
|
|
|
|
_preview.addEventListener('ended', function(){
|
2018-08-27 20:28:30 +08:00
|
|
|
this.currentTime = prvtime/1000;
|
2018-08-27 09:09:04 +08:00
|
|
|
this.play();
|
|
|
|
}, false);
|
2018-08-27 00:14:56 +08:00
|
|
|
|
|
|
|
_preview_to = setTimeout(function(){
|
|
|
|
_preview.play();
|
|
|
|
}, delay <= 1000 && first_open ? 1000 : no_delay);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.endPreview = function() {
|
|
|
|
clearTimeout(_preview_to);
|
2018-09-03 00:11:09 +08:00
|
|
|
if (_preview) {
|
|
|
|
_preview.pause();
|
|
|
|
};
|
2018-08-27 00:14:56 +08:00
|
|
|
};
|
2015-07-17 16:22:46 +08:00
|
|
|
|
|
|
|
this.run = function(){
|
|
|
|
|
|
|
|
_this.createCode();
|
|
|
|
_this.display();
|
|
|
|
$(window).resize(_this.display);
|
|
|
|
|
|
|
|
var menuLoop = setInterval(_this.refresh, 20);
|
|
|
|
$("#song-container").show();
|
2018-09-03 00:11:09 +08:00
|
|
|
|
|
|
|
$('#songsel-help').click(function(){
|
|
|
|
bgm.pause();
|
|
|
|
_this.endPreview();
|
|
|
|
assets.sounds['don'].playAsset();
|
|
|
|
|
|
|
|
new Tutorial();
|
|
|
|
});
|
2015-07-17 16:22:46 +08:00
|
|
|
|
|
|
|
$(".difficulty").click(function(e){
|
2018-08-27 00:14:56 +08:00
|
|
|
_this.endPreview();
|
|
|
|
assets.sounds["diffsel"].pause();
|
|
|
|
assets.sounds["diffsel"].currentTime = 0;
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["don"].playAsset();
|
2018-08-06 19:04:02 +08:00
|
|
|
|
2015-07-17 16:22:46 +08:00
|
|
|
clearInterval(menuLoop);
|
|
|
|
var difficultyElement = (e.target.className=="stars" || e.target.className=="diffname") ? e.target.parentElement : e.target;
|
|
|
|
_selectedSong.difficulty = difficultyElement.classList[1]+'.osu';
|
|
|
|
var parentID = $(this).parent().closest(".song").attr("id");
|
|
|
|
var songID = parseInt(parentID.substr(5, parentID.length-1));
|
2018-08-27 00:14:56 +08:00
|
|
|
_selectedSong.title = $(this).parent().closest('.song').data('title');
|
|
|
|
_selectedSong.folder = songID;
|
2018-08-06 22:12:08 +08:00
|
|
|
|
2018-08-23 06:51:16 +08:00
|
|
|
bgm.pause();
|
2018-08-28 07:56:31 +08:00
|
|
|
new loadSong(_selectedSong, e.shiftKey);
|
2015-07-17 16:22:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".song").hover(function(){
|
|
|
|
if(!$(this).hasClass("opened"))
|
|
|
|
$(this).css("background", "rgba(255, 233, 125, 0.90)");
|
|
|
|
},
|
|
|
|
function(){
|
|
|
|
if(!$(this).hasClass("opened"))
|
|
|
|
$(this).css("background", "rgba(255, 220, 47, 0.90)");
|
|
|
|
});
|
|
|
|
|
2018-08-06 22:12:08 +08:00
|
|
|
$(".song").click(function(e){
|
2018-08-06 19:04:02 +08:00
|
|
|
if (!$(e.target).parents('.difficulties').length) {
|
2018-08-06 22:12:08 +08:00
|
|
|
if ($(".opened").length && $(".opened").attr('id') == $(this).attr('id')) {
|
2018-08-27 00:14:56 +08:00
|
|
|
_this.endPreview();
|
|
|
|
bgm.play();
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["cancel"].playAsset();
|
2018-08-06 22:12:08 +08:00
|
|
|
$(".difficulty").hide();
|
|
|
|
$(".opened").removeClass("opened", 300);
|
|
|
|
|
|
|
|
assets.sounds["diffsel"].pause();
|
|
|
|
assets.sounds["diffsel"].currentTime = 0;
|
|
|
|
setTimeout(function(){
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["song-select"].playAsset();
|
2018-08-06 22:12:08 +08:00
|
|
|
}, 300);
|
|
|
|
|
|
|
|
$('.songsel-title').fadeOut(200, function(){
|
|
|
|
$('.songsel-title').attr('alt', '曲をえらぶ').html('曲をえらぶ').css('left', -300);
|
|
|
|
$('.songsel-title').animate({left:0, opacity:"show"}, 400);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2018-08-07 23:27:10 +08:00
|
|
|
|
2018-08-27 00:14:56 +08:00
|
|
|
|
2018-08-06 20:41:56 +08:00
|
|
|
if(!$('.opened').length) {
|
2018-09-09 12:11:05 +08:00
|
|
|
_this.startPreview($(this).data('song-id'), $(this).data('preview'));
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["don"].playAsset();
|
2018-08-06 22:12:08 +08:00
|
|
|
assets.sounds["song-select"].pause();
|
|
|
|
assets.sounds["song-select"].currentTime = 0;
|
2018-08-06 20:41:56 +08:00
|
|
|
setTimeout(function(){
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["diffsel"].playAsset();
|
2018-08-06 20:41:56 +08:00
|
|
|
}, 300);
|
|
|
|
|
|
|
|
$('.songsel-title').fadeOut(200, function(){
|
|
|
|
$('.songsel-title').attr('alt', 'むずかしさをえらぶ').html('むずかしさをえらぶ').css('left', -300);
|
|
|
|
$('.songsel-title').animate({left:0, opacity:"show"}, 400);
|
|
|
|
});
|
2018-08-07 23:27:10 +08:00
|
|
|
} else {
|
2018-08-27 00:14:56 +08:00
|
|
|
_preview.pause();
|
2018-09-09 12:11:05 +08:00
|
|
|
_this.startPreview($(this).data('song-id'), $(this).data('preview'), false);
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["ka"].playAsset();
|
2018-08-06 20:41:56 +08:00
|
|
|
}
|
2018-08-06 19:04:02 +08:00
|
|
|
};
|
|
|
|
|
2015-07-17 16:22:46 +08:00
|
|
|
$(".difficulty").hide();
|
|
|
|
$(".opened").removeClass("opened", 300);
|
|
|
|
$(this).addClass("opened", 300, "linear", function(){
|
|
|
|
$(this).find(".difficulty").show();
|
|
|
|
$(this).css("background", "rgba(255, 220, 47, 0.90)");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2018-08-06 18:13:01 +08:00
|
|
|
|
2018-08-23 06:51:16 +08:00
|
|
|
this.createCode = function(){
|
|
|
|
bgm = new BufferedLoop(
|
|
|
|
{url: '/assets/audio/bgm_songsel.ogg', duration: 1.442},
|
|
|
|
{url: '/assets/audio/bgm_songsel_loop.ogg', duration: 2.064}
|
|
|
|
);
|
|
|
|
bgm.play();
|
2018-09-09 12:11:05 +08:00
|
|
|
|
2018-08-06 22:12:08 +08:00
|
|
|
setTimeout(function(){
|
2018-08-29 13:55:16 +08:00
|
|
|
assets.sounds["song-select"].playAsset();
|
2018-08-06 22:12:08 +08:00
|
|
|
}, 200);
|
2018-09-09 12:11:05 +08:00
|
|
|
|
|
|
|
var songElements = [0]
|
|
|
|
|
2015-07-17 16:22:46 +08:00
|
|
|
for(var i=0; i<assets.songs.length; i++){
|
2018-09-09 12:11:05 +08:00
|
|
|
|
2018-08-27 00:14:56 +08:00
|
|
|
var song = assets.songs[i];
|
|
|
|
var songTitle = song.title;
|
2018-08-28 00:58:55 +08:00
|
|
|
var skipChars = [];
|
2018-09-09 12:11:05 +08:00
|
|
|
var charElements = [0]
|
|
|
|
var diffElements = [0]
|
2015-07-17 16:22:46 +08:00
|
|
|
|
2018-08-23 22:40:45 +08:00
|
|
|
for (var c=0; c<songTitle.length; c++) {
|
2018-08-28 00:58:55 +08:00
|
|
|
if (skipChars.indexOf(c) > -1) {
|
|
|
|
continue;
|
|
|
|
};
|
2018-09-09 12:11:05 +08:00
|
|
|
|
|
|
|
var ch = songTitle.charAt(c) == " " ? "\xa0" : songTitle.charAt(c);
|
|
|
|
|
2018-08-28 00:58:55 +08:00
|
|
|
var isApos = false;
|
2018-09-09 12:11:05 +08:00
|
|
|
if (songTitle.charAt(c+1) == "'") {
|
|
|
|
ch = ch + "'";
|
2018-08-28 00:58:55 +08:00
|
|
|
skipChars.push(c+1);
|
|
|
|
isApos = true;
|
|
|
|
};
|
2018-09-09 12:11:05 +08:00
|
|
|
|
|
|
|
var cl = ch == "\xa0" ? "song-title-char song-title-space" : "song-title-char";
|
|
|
|
cl = isApos ? cl + " song-title-apos" : cl;
|
|
|
|
|
|
|
|
charElements.push(
|
|
|
|
["span", {
|
|
|
|
class: cl,
|
|
|
|
alt: ch
|
|
|
|
}, ch]
|
|
|
|
)
|
2018-08-23 22:40:45 +08:00
|
|
|
};
|
2015-07-17 16:22:46 +08:00
|
|
|
|
2018-09-06 00:46:26 +08:00
|
|
|
for(var diff in _diffNames){
|
2018-08-27 00:14:56 +08:00
|
|
|
var diffName = diff;
|
2018-09-09 12:11:05 +08:00
|
|
|
var diffLevel = song.stars[diff];
|
2018-08-27 00:14:56 +08:00
|
|
|
if (!diffLevel) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-17 16:22:46 +08:00
|
|
|
|
2018-09-09 12:11:05 +08:00
|
|
|
var starsDisplay = [0]
|
2015-07-17 16:22:46 +08:00
|
|
|
for(var x=1; x<=diffLevel; x++){
|
2018-09-09 12:11:05 +08:00
|
|
|
starsDisplay.push("\u2605")
|
|
|
|
starsDisplay.push(["br"])
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:46:26 +08:00
|
|
|
var diffTxt=_diffNames[diffName]
|
2018-09-09 12:11:05 +08:00
|
|
|
|
|
|
|
diffElements.push(
|
|
|
|
["li", {
|
|
|
|
class: "difficulty " + diffName
|
|
|
|
},
|
|
|
|
["span", {
|
|
|
|
class: "diffname"
|
|
|
|
}, diffTxt],
|
|
|
|
["span", {
|
|
|
|
class: "stars"
|
|
|
|
}, starsDisplay]
|
|
|
|
]
|
|
|
|
)
|
2015-07-17 16:22:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-09 12:11:05 +08:00
|
|
|
songElements.push(
|
|
|
|
["div", {
|
|
|
|
id: "song-" + song.id,
|
|
|
|
class: "song",
|
|
|
|
"data-title": songTitle,
|
|
|
|
"data-song-id": song.id,
|
|
|
|
"data-preview": song.preview
|
|
|
|
},
|
|
|
|
["div", {
|
|
|
|
class: /^[\x00-\xFF]*$/.test(songTitle) ? "song-title alpha-title" : "song-title"
|
|
|
|
}, charElements],
|
|
|
|
["ul", {
|
|
|
|
class: "difficulties"
|
|
|
|
}, diffElements]
|
|
|
|
]
|
|
|
|
)
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
|
|
|
|
2018-09-09 12:11:05 +08:00
|
|
|
element(
|
|
|
|
document.getElementById("song-container"),
|
|
|
|
songElements
|
|
|
|
)
|
2018-08-23 19:58:48 +08:00
|
|
|
$('.difficulty').hide();
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.display = function(){
|
|
|
|
}
|
|
|
|
|
|
|
|
this.refresh = function(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#screen").load("/src/views/songselect.html", _this.run);
|
|
|
|
|
|
|
|
}
|