From 30cbe1db3b309a67cfef354ee95f1c508b587340 Mon Sep 17 00:00:00 2001 From: Bui Date: Sun, 26 Aug 2018 17:14:56 +0100 Subject: [PATCH] too many changes --- app.py | 48 +++++++++++++++++++++++++++++ index.html | 1 + src/css/animations.css | 58 +++++++++++++++++++++++++++++++++++ src/css/main.css | 8 +++++ src/css/songselect.css | 4 +-- src/js/assets.js | 3 +- src/js/game.js | 2 +- src/js/loader.js | 7 +++-- src/js/loadsong.js | 2 +- src/js/songselect.js | 68 ++++++++++++++++++++++++++++++++--------- src/js/view.js | 3 +- src/php/getsongs.php | 63 -------------------------------------- taiko.db | Bin 0 -> 24576 bytes 13 files changed, 180 insertions(+), 87 deletions(-) create mode 100644 app.py create mode 100644 src/css/animations.css delete mode 100644 src/php/getsongs.php create mode 100644 taiko.db diff --git a/app.py b/app.py new file mode 100644 index 0000000..7c93615 --- /dev/null +++ b/app.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python2 + +import sqlite3 +from flask import Flask, g, jsonify + +app = Flask(__name__) +DATABASE = 'taiko.db' + + +def get_db(): + db = getattr(g, '_database', None) + if db is None: + db = g._database = sqlite3.connect(DATABASE) + return db + + +def query_db(query, args=(), one=False): + cur = get_db().execute(query, args) + rv = cur.fetchall() + cur.close() + return (rv[0] if rv else None) if one else rv + + +@app.teardown_appcontext +def close_connection(exception): + db = getattr(g, '_database', None) + if db is not None: + db.close() + + +@app.route('/api/songs') +def route_api_songs(): + songs = query_db('select * from songs where enabled = 1') + songs_out = [] + for song in songs: + print song + songs_out.append( + {'id': song[0], 'title': song[1], 'title_en': song[2], 'stars': { + 'easy': song[3], 'normal': song[4], + 'hard': song[5], 'oni': song[6] + }} + ) + + return jsonify(songs_out) + + +if __name__ == '__main__': + app.run(port=34801) diff --git a/index.html b/index.html index babc551..6c7a8eb 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@ + diff --git a/src/css/animations.css b/src/css/animations.css new file mode 100644 index 0000000..82dce8a --- /dev/null +++ b/src/css/animations.css @@ -0,0 +1,58 @@ +@keyframes don-normal { +0%{background-position-y:0px} +6.35%{background-position-y:-184px} +7.94%{background-position-y:-368px} +9.52%{background-position-y:-552px} +11.11%{background-position-y:-736px} +12.7%{background-position-y:-920px} +14.29%{background-position-y:-1104px} +15.87%{background-position-y:-1104px} +17.46%{background-position-y:-920px} +19.05%{background-position-y:-736px} +20.63%{background-position-y:-552px} +22.22%{background-position-y:-368px} +23.81%{background-position-y:-184px} +25.4%{background-position-y:0px} +31.75%{background-position-y:-184px} +33.33%{background-position-y:-368px} +34.92%{background-position-y:-552px} +36.51%{background-position-y:-736px} +38.1%{background-position-y:-920px} +39.68%{background-position-y:-1104px} +41.27%{background-position-y:-1104px} +42.86%{background-position-y:-920px} +44.44%{background-position-y:-736px} +46.03%{background-position-y:-552px} +47.62%{background-position-y:-368px} +49.21%{background-position-y:-184px} +50.79%{background-position-y:0px} +57.14%{background-position-y:-184px} +58.73%{background-position-y:-368px} +60.32%{background-position-y:-552px} +61.9%{background-position-y:-736px} +63.49%{background-position-y:-920px} +65.08%{background-position-y:-1104px} +66.67%{background-position-y:-1104px} +68.25%{background-position-y:-920px} +69.84%{background-position-y:-1288px} +71.43%{background-position-y:-1472px} +73.02%{background-position-y:-1656px} +74.6%{background-position-y:-1840px} +76.19%{background-position-y:-2024px} +77.78%{background-position-y:-2024px} +79.37%{background-position-y:-2024px} +80.95%{background-position-y:-2024px} +82.54%{background-position-y:-1840px} +84.13%{background-position-y:-1656px} +85.71%{background-position-y:-1472px} +87.3%{background-position-y:-1288px} +88.89%{background-position-y:-2392px} +90.48%{background-position-y:-2208px} +92.06%{background-position-y:-2208px} +93.65%{background-position-y:-2392px} +95.24%{background-position-y:-2576px} +96.83%{background-position-y:-2760px} +98.41%{background-position-y:-2944px} +100%{background-position-y:-3128px} +} + diff --git a/src/css/main.css b/src/css/main.css index c74f834..320626d 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -63,6 +63,7 @@ html, body{ color: white; float: right; z-index: 1; + font-weight: 300; } .stroke-main:before { @@ -98,4 +99,11 @@ html, body{ .click-to-continue:before { width: 100%; +} + + +.don { + background-position-y: 0; + position: absolute; + top: 0px; } \ No newline at end of file diff --git a/src/css/songselect.css b/src/css/songselect.css index 817760d..1147e0d 100644 --- a/src/css/songselect.css +++ b/src/css/songselect.css @@ -50,7 +50,7 @@ ul li{ .song-title{ float: right; width: 45px; - padding: 10px 0px; + padding: 10px 2px; word-wrap: break-word; font-size: 22pt; color: white; @@ -65,7 +65,7 @@ ul li{ .song{ font-size: 14pt; - width: 45px; + width: 50px; margin-right:15px; height:100%; color: black; diff --git a/src/js/assets.js b/src/js/assets.js index 81445a0..165f654 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -26,7 +26,8 @@ var assets = { 'muzu_easy.png', 'muzu_normal.png', 'muzu_hard.png', - 'muzu_oni.png' + 'muzu_oni.png', + 'don_anim_normal.png' ), audio: new Array( diff --git a/src/js/game.js b/src/js/game.js index 844c2a2..2687a9e 100644 --- a/src/js/game.js +++ b/src/js/game.js @@ -194,7 +194,7 @@ function Game(controller, selectedSong, songData){ _fadeOutStarted=true; } } - + this.whenFadeoutMusic = function(){ if(_fadeOutStarted){ if(_musicFadeOut%8==0){ diff --git a/src/js/loader.js b/src/js/loader.js index 3dc7da8..a7c9ae1 100644 --- a/src/js/loader.js +++ b/src/js/loader.js @@ -26,6 +26,7 @@ function Loader(){ var id = name.substr(0, name.length-4); var audio = new Audio(); audio.src = '/assets/audio/'+name; + audio.muted = true; audio.load(); audio.onloadeddata = function(){ assets.sounds[id] = new Audio(); @@ -37,10 +38,10 @@ function Loader(){ $.ajax({ async:true, - type:"POST", - url:"/src/php/getsongs.php", + type:"GET", + url:"/api/songs", success:function(songs){ - assets.songs = $.parseJSON(songs); + assets.songs = songs; _this.assetLoaded(); }, error:function(){ diff --git a/src/js/loadsong.js b/src/js/loadsong.js index e46dc30..64834be 100644 --- a/src/js/loadsong.js +++ b/src/js/loadsong.js @@ -17,7 +17,7 @@ function loadSong(selectedSong){ $("#assets").append(""); var audio = new Audio(); - audio.src = '/songs/'+_selectedSong.folder+'/'+_selectedSong.title+'.mp3'; + audio.src = '/songs/'+_selectedSong.folder+'/main.mp3'; audio.load(); $("#music-bg").load(function(){ diff --git a/src/js/songselect.js b/src/js/songselect.js index 110a144..244649a 100644 --- a/src/js/songselect.js +++ b/src/js/songselect.js @@ -4,6 +4,35 @@ function SongSelect(){ var _songs; var _selectedSong = {title:'', folder:'', difficulty:''}; var _code=""; + var _preview; + var _preview_to; + + this.startPreview = function(id, first_open=true) { + 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; + + _preview.currentTime = 10.0; + _preview.loop = true; + _preview.volume = 0.5; + + _preview_to = setTimeout(function(){ + _preview.play(); + }, delay <= 1000 && first_open ? 1000 : no_delay); + } + }; + + this.endPreview = function() { + clearTimeout(_preview_to); + _preview.pause(); + }; this.run = function(){ @@ -15,6 +44,9 @@ function SongSelect(){ $("#song-container").show(); $(".difficulty").click(function(e){ + _this.endPreview(); + assets.sounds["diffsel"].pause(); + assets.sounds["diffsel"].currentTime = 0; assets.sounds["don"].play(); clearInterval(menuLoop); @@ -22,8 +54,8 @@ function SongSelect(){ _selectedSong.difficulty = difficultyElement.classList[1]+'.osu'; var parentID = $(this).parent().closest(".song").attr("id"); var songID = parseInt(parentID.substr(5, parentID.length-1)); - _selectedSong.title = $(this).parent().closest('.song').find('.song-title').html(); - _selectedSong.folder = songID+" "+_selectedSong.title; + _selectedSong.title = $(this).parent().closest('.song').data('title'); + _selectedSong.folder = songID; bgm.pause(); new loadSong(_selectedSong); @@ -41,6 +73,8 @@ function SongSelect(){ $(".song").click(function(e){ if (!$(e.target).parents('.difficulties').length) { if ($(".opened").length && $(".opened").attr('id') == $(this).attr('id')) { + _this.endPreview(); + bgm.play(); assets.sounds["cancel"].play(); $(".difficulty").hide(); $(".opened").removeClass("opened", 300); @@ -59,8 +93,9 @@ function SongSelect(){ return; } - + if(!$('.opened').length) { + _this.startPreview($(this).data('song-id')); assets.sounds["don"].play(); assets.sounds["song-select"].pause(); assets.sounds["song-select"].currentTime = 0; @@ -73,6 +108,8 @@ function SongSelect(){ $('.songsel-title').animate({left:0, opacity:"show"}, 400); }); } else { + _preview.pause(); + _this.startPreview($(this).data('song-id'), false); assets.sounds["ka"].play(); } }; @@ -98,15 +135,15 @@ function SongSelect(){ assets.sounds["song-select"].play(); }, 200); for(var i=0; i
"; + _code += "
"; for (var c=0; c=_nextBeat){ diff --git a/src/php/getsongs.php b/src/php/getsongs.php deleted file mode 100644 index a5435ef..0000000 --- a/src/php/getsongs.php +++ /dev/null @@ -1,63 +0,0 @@ - $data){ - $row_data = explode(':', $data); - if($row_data[0]=='OverallDifficulty'){ - $difficulty=intval($row_data[1]); - break; - } - } - - $file = array( - "songFile" => $songFile, - "difficulty" => $difficulty - ); - - array_push($files, $file); - } - - } - - $scale = array('easy.osu', 'normal.osu', 'hard.osu', 'oni.osu'); - usort($files, function ($a, $b) use ($scale) { - $pos_a = array_search($a['songFile'], $scale); - $pos_b = array_search($b['songFile'], $scale); - return $pos_a - $pos_b; - }); - - $song = array( - "songDir" => $songDir, - "files" => $files - ); - - array_push($songs, $song); - - } - - } - - echo json_encode($songs); - -?> \ No newline at end of file diff --git a/taiko.db b/taiko.db new file mode 100644 index 0000000000000000000000000000000000000000..0e76b0f5dd258a58679ca49de50e5c6293603026 GIT binary patch literal 24576 zcmeI(!E4h{90&0Cl6CS5UA#!H&*@>aLmb1Suqr{yx^C-I>%64t7B$c%E=id?c<3hn z0q)>&3_(1I7mo`5175v&?O_bO&Xb_Ow|1Qc89fL}{03fL^739@-iKcckK`>cmHfn$ z_rqx2P2>za&p2nZQZmK_rO{r}D4(S?Lg{4VCkJQbf?ehJa$|=~&+W6Z7rA}ov(Ydb zXSBd22tWV=5P$##AOHafK;R!1*j~PJ&aBn=(@f$vnqIuoqzOeM3O8dfaw0Eq*F9%7 zY_`?|C-63%;VWskDptX^q+PgKvSfXz8`tGTR@D8qx+s=y>$X*qt;j;vUMQC7{_|GZmeq1`scKD8!^BUTUR~JMU24>8*e`dypnFM`cy7Ga??e>@ zY6jIDD0=8drw^j)gn>U$fpAFdv`)Xz>?BQ@ewe1ociJ)WsspPl7X}aFSnURR#*fR! z(=z-;ebmh7`N}WR;>6xY%L`U}5!OE)83>bZl=Lr7sPLPjmXq`g`g-hm@l411vE!cz zBR?~0KB;l$=X-gu<~{B`p4&=7U!6NcMYS_MR5hK(IHUe4CaKFCCUyP$E>-lVp-)V;p0uX=z1Rwwb2tWV=5P$##AOL|B31oE6HBHxrQ1Ab_am0)x<5P+T zh@n6L0uX=z1Rwwb2tWV=5P$##QY$cVL9dBnRtks