From 67e418bc4d6755380c9f311a82326ec4665a8dfb Mon Sep 17 00:00:00 2001 From: Bui Date: Sun, 24 Nov 2019 23:51:58 +0000 Subject: [PATCH 1/5] SongSelect: Add maker identification requires maker_id(int) column in songs table, and a new "makers" table with maker_id(int), name(text), url(text) --- app.py | 6 +- public/src/js/songselect.js | 113 +++++++++++++++++++++++++++++++++++- public/src/js/strings.js | 20 +++++++ 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index e03643d..6a0adbe 100644 --- a/app.py +++ b/app.py @@ -107,7 +107,7 @@ def route_api_preview(): @app.route('/api/songs') @app.cache.cached(timeout=15) def route_api_songs(): - songs = query_db('select * from songs where enabled = 1') + songs = query_db('select s.*, m.name, m.url from songs s left join makers m on s.maker_id = m.maker_id where enabled = 1') raw_categories = query_db('select * from categories') categories = {} @@ -127,6 +127,7 @@ def route_api_songs(): category_out = categories[song[11]] if song[11] in categories else "" song_skin_out = song_skins[song[14]] if song[14] in song_skins else None + maker = {'name': song[18], 'url': song[19]} if song[17] else None songs_out.append({ 'id': song_id, @@ -142,7 +143,8 @@ def route_api_songs(): 'type': song_type, 'offset': song[13], 'song_skin': song_skin_out, - 'volume': song[16] + 'volume': song[16], + 'maker': maker }) return jsonify(songs_out) diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index d02c07f..ec33cc9 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -114,7 +114,8 @@ class SongSelect{ offset: song.offset, songSkin: song.song_skin || {}, music: song.music, - volume: song.volume + volume: song.volume, + maker: song.maker }) } this.songs.sort((a, b) => { @@ -431,6 +432,8 @@ class SongSelect{ this.toSongSelect() }else if(moveBy === 1){ this.toOptions(1) + }else if(moveBy === "maker" && this.songs[this.selectedSong].maker.url){ + window.open(this.songs[this.selectedSong].maker.url) }else if(moveBy === this.diffOptions.length + 4){ this.state.ura = !this.state.ura assets.sounds["se_ka"].play() @@ -518,6 +521,8 @@ class SongSelect{ if(this.state.locked === 0){ if(223 < x && x < 367 && 118 < y && y < 422){ return Math.floor((x - 223) / ((367 - 223) / 2)) + }else if(this.songs[this.selectedSong].maker && this.songs[this.selectedSong].maker.url && x > 230 && x < 485 && y > 432 && y < 519) { + return "maker" }else if(550 < x && x < 1050 && 95 < y && y < 524){ var moveBy = Math.floor((x - 550) / ((1050 - 550) / 5)) + this.diffOptions.length var currentSong = this.songs[this.selectedSong] @@ -1473,6 +1478,112 @@ class SongSelect{ }) }) } + + if(currentSong.maker){ + if (songSel) { + var _x = x + 38 + var _y = y + 10 + ctx.lineWidth = 5 + + var grd = ctx.createLinearGradient(_x, _y, _x, _y+50); + grd.addColorStop(0, '#fa251a'); + grd.addColorStop(1, '#ffdc33'); + + ctx.fillStyle = grd; + this.draw.roundedRect({ + ctx: ctx, + x: _x - 28, + y: _y, + w: 130, + h: 50, + radius: 24 + }) + ctx.fill() + ctx.stroke() + ctx.beginPath() + ctx.arc(_x, _y + 28, 20, 0, Math.PI * 2) + ctx.fill() + + this.draw.layeredText({ + ctx: ctx, + text: strings.creative.creative, + fontSize: strings.id == "en" ? 30 : 34, + fontFamily: this.font, + align: "center", + baseline: "middle", + x: _x + 38, + y: _y + (["ja", "en"].indexOf(strings.id) >= 0 ? 25 : 28), + width: 110 + }, [ + {outline: "#fff", letterBorder: 8}, + {fill: "#000"} + ]) + } else { + var _x = x + 62 + var _y = y + 380 + ctx.lineWidth = 5 + + var grd = ctx.createLinearGradient(_x, _y, _x, _y+50); + grd.addColorStop(0, '#fa251a'); + grd.addColorStop(1, '#ffdc33'); + + ctx.fillStyle = '#75E2EE'; + this.draw.roundedRect({ + ctx: ctx, + x: _x - 28, + y: _y, + w: 250, + h: 80, + radius: 15 + }) + ctx.fill() + ctx.stroke() + ctx.beginPath() + ctx.arc(_x, _y + 28, 20, 0, Math.PI * 2) + ctx.fill() + + this.draw.layeredText({ + ctx: ctx, + text: strings.creative.maker, + fontSize: 24, + fontFamily: this.font, + align: "left", + baseline: "middle", + x: _x - 15, + y: _y + 23 + }, [ + {outline: "#000", letterBorder: 8}, + {fill: "#fff"} + ]) + + this.draw.layeredText({ + ctx: ctx, + text: currentSong.maker.name, + fontSize: 28, + fontFamily: this.font, + align: "center", + baseline: "middle", + x: _x + 100, + y: _y + 56, + width: 210 + }, [ + {outline: "#fff", letterBorder: 8}, + {fill: "#000"} + ]) + + if(this.state.moveHover === "maker"){ + this.draw.highlight({ + ctx: ctx, + x: _x - 32, + y: _y - 3, + w: 250 + 7, + h: 80 + 7, + opacity: 0.8, + radius: 15 + }) + } + } + } if(!songSel && currentSong.stars[4]){ var fade = ((ms - this.state.screenMS) % 1200) / 1200 diff --git a/public/src/js/strings.js b/public/src/js/strings.js index eb77015..5bed612 100644 --- a/public/src/js/strings.js +++ b/public/src/js/strings.js @@ -137,6 +137,10 @@ failedTests: "このテストは失敗しました:", supportedBrowser: "%sなどのサポートされているブラウザを使用してください" } + this.creative = { + creative: '創作', + maker: 'メーカー' + } } function StringsEn(){ this.id = "en" @@ -277,6 +281,10 @@ function StringsEn(){ failedTests: "The following tests have failed:", supportedBrowser: "Please use a supported browser such as %s" } + this.creative = { + creative: 'Creative', + maker: 'Maker:' + } } function StringsCn(){ this.id = "cn" @@ -417,6 +425,10 @@ function StringsCn(){ failedTests: "The following tests have failed:", supportedBrowser: "Please use a supported browser such as %s" } + this.creative = { + creative: '创作', + maker: '制作者' + } } function StringsTw(){ this.id = "tw" @@ -557,6 +569,10 @@ function StringsTw(){ failedTests: "The following tests have failed:", supportedBrowser: "Please use a supported browser such as %s" } + this.creative = { + creative: '創作', + maker: '製作者' + } } function StringsKo(){ this.id = "ko" @@ -697,6 +713,10 @@ function StringsKo(){ failedTests: "The following tests have failed:", supportedBrowser: "Please use a supported browser such as %s" } + this.creative = { + creative: '창작', + maker: '만드는 사람' + } } var allStrings = { "ja": new StringsJa(), From 42f22a4f09825f5a22939e5737a2b204bf935695 Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 25 Nov 2019 00:58:07 +0000 Subject: [PATCH 2/5] allow anonymous makers --- app.py | 6 +++++- public/src/js/songselect.js | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 6a0adbe..b45f694 100644 --- a/app.py +++ b/app.py @@ -127,7 +127,11 @@ def route_api_songs(): category_out = categories[song[11]] if song[11] in categories else "" song_skin_out = song_skins[song[14]] if song[14] in song_skins else None - maker = {'name': song[18], 'url': song[19]} if song[17] else None + maker = None + if song[17] == 0: + maker = 0 + elif song[17] > 0: + maker = {'name': song[18], 'url': song[19], 'id': song[17]} songs_out.append({ 'id': song_id, diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index ec33cc9..642f4e5 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -5,7 +5,7 @@ class SongSelect{ loader.changePage("songselect", false) this.canvas = document.getElementById("song-sel-canvas") this.ctx = this.canvas.getContext("2d") - + this.songSkin = { "selected": { background: "#ffdb2c", @@ -432,7 +432,7 @@ class SongSelect{ this.toSongSelect() }else if(moveBy === 1){ this.toOptions(1) - }else if(moveBy === "maker" && this.songs[this.selectedSong].maker.url){ + }else if(moveBy === "maker"){ window.open(this.songs[this.selectedSong].maker.url) }else if(moveBy === this.diffOptions.length + 4){ this.state.ura = !this.state.ura @@ -521,7 +521,7 @@ class SongSelect{ if(this.state.locked === 0){ if(223 < x && x < 367 && 118 < y && y < 422){ return Math.floor((x - 223) / ((367 - 223) / 2)) - }else if(this.songs[this.selectedSong].maker && this.songs[this.selectedSong].maker.url && x > 230 && x < 485 && y > 432 && y < 519) { + }else if(this.songs[this.selectedSong].maker && this.songs[this.selectedSong].maker.id > 0 && this.songs[this.selectedSong].maker.url && x > 230 && x < 485 && y > 432 && y < 519) { return "maker" }else if(550 < x && x < 1050 && 95 < y && y < 524){ var moveBy = Math.floor((x - 550) / ((1050 - 550) / 5)) + this.diffOptions.length @@ -1479,7 +1479,7 @@ class SongSelect{ }) } - if(currentSong.maker){ + if(currentSong.maker !== null){ if (songSel) { var _x = x + 38 var _y = y + 10 @@ -1518,7 +1518,7 @@ class SongSelect{ {outline: "#fff", letterBorder: 8}, {fill: "#000"} ]) - } else { + } else if(currentSong.maker && currentSong.maker.id > 0){ var _x = x + 62 var _y = y + 380 ctx.lineWidth = 5 From 8cc1b940e1746856283c306945473ec3d89e8ded Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 25 Nov 2019 01:04:59 +0000 Subject: [PATCH 3/5] read maker from local tja --- public/src/js/importsongs.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/src/js/importsongs.js b/public/src/js/importsongs.js index a0b059c..6fb7ea1 100644 --- a/public/src/js/importsongs.js +++ b/public/src/js/importsongs.js @@ -231,6 +231,9 @@ if(meta.taikowebskin){ songObj.song_skin = this.getSkin(dir, meta.taikowebskin) } + if(meta.maker){ + songObj.maker = {name: meta.maker, id: 1} + } for(var id in allStrings){ var songTitle = songObj.title var ura = "" From 0ac923d2455bd8840eb019414e9cb5c675e52a79 Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 25 Nov 2019 01:24:06 +0000 Subject: [PATCH 4/5] check existence of maker_id --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index b45f694..11c4b44 100644 --- a/app.py +++ b/app.py @@ -130,7 +130,7 @@ def route_api_songs(): maker = None if song[17] == 0: maker = 0 - elif song[17] > 0: + elif song[17] and song[17] > 0: maker = {'name': song[18], 'url': song[19], 'id': song[17]} songs_out.append({ From 30bc2b10028bbcba8a7633fdf7e2be725ee9700b Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 25 Nov 2019 01:44:40 +0000 Subject: [PATCH 5/5] handle invalid maker ids --- public/src/js/songselect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index 642f4e5..70c6bd1 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -1518,7 +1518,7 @@ class SongSelect{ {outline: "#fff", letterBorder: 8}, {fill: "#000"} ]) - } else if(currentSong.maker && currentSong.maker.id > 0){ + } else if(currentSong.maker && currentSong.maker.id > 0 && currentSong.maker.name){ var _x = x + 62 var _y = y + 380 ctx.lineWidth = 5