more BGMusic updates

- update getCategoryList to return obj
- 2 custom categories
- improved classic support
- only tell client to refresh playlist if the playlist has changed
- move reset defaults for bgmusic due to autosubmit onleave on category page
- rearrange songs: move Lufia Fortress near Lufia Map
This commit is contained in:
zefie
2021-11-09 18:32:58 -05:00
parent 2251aad735
commit a76c31a9c8
39 changed files with 315 additions and 43 deletions

View File

@@ -3,6 +3,9 @@ var minisrv_service_file = true;
var WTVBGMusic = require("./WTVBGMusic.js");
var wtvbgm = new WTVBGMusic(minisrv_config, ssid_sessions[socket.ssid])
var catsListed = 0;
var categories = wtvbgm.getCategoryList();
var divide = Math.round(categories.length / 2, 0);
headers = `200 OK
Connection: Keep-Alive
@@ -51,7 +54,7 @@ Background music styles
</td><td colspan="3">
<table cellspacing="0" cellpadding="0">
<tbody><tr>
<td absheight="80" valign="center">
${(categories.length > 14) ? '<td absheight="50" valign="center">' : '<td absheight="80" valign="center">'}
<font size="+2" color="E7CE4A"><blackface><shadow>
Background music styles
</shadow></blackface></font></td></tr><tr><td>
@@ -67,14 +70,10 @@ Choose a style name to see the songs for that style.
<form action="/validate-bg-song-category">
<input type="hidden" autosubmit="onLeave">
`;
var catsListed = 0;
var categories = wtvbgm.getCategoryList();
var numCats = categories.length;
var divide = Math.round(numCats / 2, 0);
Object.keys(categories).forEach(function (k) {
var pubcat = parseInt(k) + 1;
var songsInCat = wtvbgm.getCategorySongList(pubcat);
var catID = categories[k].id;
var songsInCat = wtvbgm.getCategorySongList(catID);
if (songsInCat.length > 0) {
if (catsListed == divide) {
data += `</td ><td width="20">
@@ -83,9 +82,9 @@ Object.keys(categories).forEach(function (k) {
data += `<table>
<tbody><tr>
<td valign="top">
<input type="checkbox" name="enableCategory" value=${pubcat}${(wtvbgm.isCategoryEnabled(pubcat)) ? ' checked="checked"' : ''}>
<input type="checkbox" name="enableCategory" value=${catID}${(wtvbgm.isCategoryEnabled(catID)) ? ' checked="checked"' : ''}>
</td><td valign="bottom">
<a href="wtv-setup:/set-bg?category=${pubcat}">${categories[k]}</a><br>
<a href="wtv-setup:/set-bg?category=${catID}">${categories[k].name}</a><br>
</td></tr></tbody></table>`;
catsListed++;
}
@@ -114,16 +113,10 @@ data += `
</td></tr><tr>
<td>
</td><td colspan="3" valign="top" align="right">
<table><tc><td>
<form action="wtv-setup:/reset-musicobj">
<font size="-1" color="#E7CE4A"><shadow>
<input type="SUBMIT" borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Reset to Defaults" name="Reset" usestyle="" width="203">
</shadow></font></form></td><td>
<form action="wtv-setup:/sound">
<font size="-1" color="#E7CE4A"><shadow>
<input type="SUBMIT" borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Done" name="Done" usestyle="" width="103">
</shadow></font></form>
</td></tc></table>
</td><td>
</td></tr></tbody></table>
</display></display></body></html>`;

View File

@@ -1,6 +1,6 @@
var music_obj = {};
ssid_sessions[socket.ssid].setSessionData("wtv-bgmusic", Object.assign({}, music_obj));
ssid_sessions[socket.ssid].setSessionData("wtv-bgmusic", music_obj);
ssid_sessions[socket.ssid].saveSessionData();
headers = `300 OK
Location: wtv-setup:/choose-bg-songs`;
Location: wtv-setup:/choose-bg-songs
wtv-backgroundmusic-load-playlist: wtv-setup:/get-playlist`;

View File

@@ -53,7 +53,7 @@ ${categoryName}
</td><td colspan="3">
<table cellspacing="0" cellpadding="0">
<tbody><tr>
<td absheight="80" valign="center">
${(musicList.length > 14) ? '<td absheight="50" valign="center">' : '<td absheight="80" valign="center">'}
<font size="+2" color="E7CE4A"><blackface><shadow>
${categoryName}
</shadow></blackface></font></td></tr><tr><td>
@@ -71,8 +71,7 @@ Choose the songs that you'd like to include.
<input type="hidden" autosubmit="onLeave">
`;
var songsListed = 0;
var numSongs = musicList.length;
var divide = Math.round(numSongs / 2, 0);
var divide = Math.round(musicList.length / 2, 0);
Object.keys(musicList).forEach(function (k) {
if (songsListed == divide) {
data += `</td ><td width="20">
@@ -82,9 +81,12 @@ Choose the songs that you'd like to include.
<tbody><tr>
<td valign="top">
<input type="checkbox" name="enableSong" value=${musicList[k]['id']}${(wtvbgm.isSongEnabled(musicList[k]['id'])) ? ' checked="checked"' : ''}>
</td><td valign="bottom">
<a href=${musicList[k]['url']}?wtv-title=${escape(musicList[k]['title'])}>${musicList[k]['title']}</a>
</td><td valign="bottom">`;
if (musicList[k]['title'].length > 12 && musicList[k]['title'].length < 18) data += `<font size="-1">`;
if (musicList[k]['title'].length > 18) data += `<font size="-2">`;
data += `<a href=${musicList[k]['url']}?wtv-title=${escape(musicList[k]['title'])}>${musicList[k]['title']}</a>
</td></tr></tbody></table>`;
if (musicList[k]['title'].length > 12) data += `</font>`;
songsListed++;
});

View File

@@ -81,7 +81,7 @@ for ${ssid_sessions[socket.ssid].getSessionData("subscriber_username") || "You"}
<TR>
<td>
<font size="-1">
<td WIDTH=150 HEIGHT=244 VALIGN=top ALIGN=left>
<td WIDTH=160 HEIGHT=244 VALIGN=top ALIGN=left>
<br><font size="-1"><blackface>
<img src="ROMCache/BulletArrow.gif" width=6 height=13 valign=absmiddle><spacer type=block width=6 height=1>
<a href="wtv-setup:/mail">Mail/Discuss</a><BR>

View File

@@ -111,7 +111,11 @@ action="client:SetSetupValue" selected &wtv-muzac-on;${canDoMuzac ? '' : 'disabl
<TD>
<TD COLSPAN=3 VALIGN=top ALIGN=right>
<FONT COLOR="#E7CE4A" SIZE=-1><SHADOW>
<INPUT name="chooseMusicStyles" value="Choose Music Styles" WIDTH=195 action="wtv-setup:/choose-bg-songs"
<INPUT name="resetMusicStyles" value="Reset Defaults" WIDTH=145 action="wtv-setup:/reset-musicobj"
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" USESTYLE WIDTH=103>
<spacer type=block WIDTH=4 HEIGHT=1>
<INPUT name="chooseMusicStyles" value="Choose Music" WIDTH=145 action="wtv-setup:/choose-bg-songs"
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" USESTYLE WIDTH=103>
<spacer type=block WIDTH=4 HEIGHT=1>
<INPUT name="Done" value="Done" WIDTH=103

View File

@@ -1,10 +1,11 @@
if (request_headers.query && ssid_sessions[socket.ssid]) {
if (request_headers.request_url.indexOf('?') >= 0) {
var category = (request_headers.query.category) ? request_headers.query.category : null;
var WTVBGMusic = require("./WTVBGMusic.js");
var wtvbgm = new WTVBGMusic(minisrv_config, ssid_sessions[socket.ssid])
var music_obj = wtvbgm.getMusicObj();
var old_music_obj = Object.assign({}, music_obj);
if (category == null) music_obj.enableCategories = [];
else {
@@ -15,13 +16,13 @@ if (request_headers.query && ssid_sessions[socket.ssid]) {
if (wtvbgm.getSongCategory(parseInt(music_obj.enableSongs[k])) == parseInt(category)) toRemove.push(k);
});
toRemove.forEach(function (v) {
music_obj.enableSongs.splice(v,1,"");
music_obj.enableSongs.splice(v, 1, "");
});
var newEnableSongs = music_obj.enableSongs.filter(value => Object.keys(value).length !== 0);
music_obj.enableSongs = newEnableSongs;
}
}
var qraw = request_headers.request_url.split('?')[1];
var qraw = request_headers.request_url.split('?')[1];
if (qraw.length > 0) {
qraw = qraw.split("&");
for (let i = 0; i < qraw.length; i++) {
@@ -29,18 +30,26 @@ if (request_headers.query && ssid_sessions[socket.ssid]) {
if (qraw_split.length == 2) {
var k = qraw_split[0];
if (k == "enableCategory") music_obj['enableCategories'].push(unescape(qraw[i].split("=")[1].replace(/\+/g, "%20")));
if (k == "enableSong") music_obj['enableSongs'].push(unescape(qraw[i].split("=")[1].replace(/\+/g, "%20")));
if (k == "enableSong") music_obj['enableSongs'].push(unescape(qraw[i].split("=")[1].replace(/\+/g, "%20")));
}
}
}
}
music_obj.enableCategories = [...new Set(music_obj.enableCategories)];
music_obj.enableSongs = [...new Set(music_obj.enableSongs)];
ssid_sessions[socket.ssid].setSessionData("wtv-bgmusic", Object.assign({}, music_obj));
ssid_sessions[socket.ssid].saveSessionData();
headers = `200 OK
music_obj.enableCategories = [...new Set(music_obj.enableCategories.filter(value => Object.keys(value).length !== 0))];
music_obj.enableSongs = [...new Set(music_obj.enableSongs.filter(value => Object.keys(value).length !== 0))];
music_obj = Object.assign({}, music_obj)
if ((Object.keys(music_obj.enableCategories).length != Object.keys(old_music_obj.enableCategories).length) || (Object.keys(music_obj.enableSongs).length != Object.keys(old_music_obj.enableSongs).length)) {
// something changed
ssid_sessions[socket.ssid].setSessionData("wtv-bgmusic", music_obj);
ssid_sessions[socket.ssid].saveSessionData();
headers = `200 OK
Content-type: text/html
wtv-backgroundmusic-load-playlist: wtv-setup:/get-playlist`;
} else {
// nothing changed
headers = `200 OK
Content-type: text/html`;
}
} else {
var outdata = doErrorPage();
headers = outdata[0];