moved music_db pull to copyResourcesFromGame func and removed generateLatestMusicDBFile func + fixes

This commit is contained in:
vvo
2022-10-02 09:54:35 +08:00
parent 5cec9bc3a1
commit 5dfd1a348a
3 changed files with 195 additions and 201 deletions
-2
View File
@@ -18,7 +18,6 @@ import {
saveValgene,
} from './handlers/profiles';
import {
generateLatestMusicDBFile,
copyResourcesFromGame
} from './utils'
import {
@@ -45,7 +44,6 @@ export function register() {
R.Config('use_information' ,{ type: 'boolean', default: true, name:'Use Information', desc:'Enable the information section after entry.'});
R.Config('use_asphyxia_gameover',{ type: 'boolean', default: true, name:'Use Asphyxia Gameover', desc:'Enable the Asphyxia gameover message after ending the game.'})
R.WebUIEvent('generateLatestMusicDBFile', generateLatestMusicDBFile);
R.WebUIEvent('copyResourcesFromGame', copyResourcesFromGame);
R.WebUIEvent('updateProfile', updateProfile);
R.WebUIEvent('updateMix', updateMix);
+173 -175
View File
@@ -33,205 +33,203 @@ export function getRandomIntInclusive(min, max) {
}
export const copyResourcesFromGame = async (data: {}) => {
let mdbJson;
let mdbJsonFix = [];
let mdbJsonFixFinal;
let mdb = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/others/music_db.xml")
let prevAssetMdb = JSON.parse(U.DecodeString(await IO.ReadFile('webui/asset/json/music_db.json'), 'utf8'))
let newJsonSongs = [];
let newVersionSongs = [];
let resourceJsonData = JSON.parse(U.DecodeString(await IO.ReadFile('webui/asset/json/data.json'), 'utf8'))
let newNemsysData = []
let newAPCardData = []
let newSubBGData = []
let newBGMData = []
// Copying new nemsys files from gamedata
console.log("Copying new nemsys files from gamedata")
let nemsysFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/game_nemsys")
for await (const nemsys of nemsysFiles) {
let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/game_nemsys/" + nemsys.name)
if(!IO.Exists('webui/asset/nemsys/' + nemsys.name.substring(0, (nemsys.name.length - 4)) + ".png") && !IO.Exists('webui/asset/nemsys/' + nemsys.name.substring(0, (nemsys.name.length - 4)) + ".jpg")) {
IO.WriteFile('webui/asset/nemsys/' + nemsys.name, fileToWrite)
newNemsysData.push(nemsys.name)
} else {
console.log(nemsys.name + " exists")
}
// Get new music data from music_db.xml
let version = '';
let ea3Config = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/prop/ea3-config.xml")
let configJson = U.parseXML(U.DecodeString(ea3Config, "shift_jis"), false)
version = configJson['ea3']['soft']['ext']['@content'];
mdbJson = U.parseXML(U.DecodeString(mdb, "shift_jis"), false)
try {
mdbJson.mdb.music.forEach(musicValue => {
if(prevAssetMdb['mdb']['music'].find(item => parseInt(item['@id']) == parseInt(musicValue.info.label['@content'])) == undefined) {
console.log("New song added to json: " + musicValue.info.title_name['@content'] + " (" + musicValue.info.distribution_date['@content'] + ")")
newJsonSongs.push('[' + musicValue.info.distribution_date['@content'] + '] ' + musicValue.info.title_name['@content'])
}
if(parseInt(musicValue.info.distribution_date['@content'][0]) >= parseInt(version.substring(0,8))) {
console.log("Found new song for version " + version + ": " + musicValue.info.title_name['@content'] + " (" + musicValue.info.distribution_date['@content'] + ")");
newVersionSongs.push('[' + musicValue.info.distribution_date['@content'] + '] ' + musicValue.info.title_name['@content'])
}
mdbJsonFix.push({
'@id': musicValue['@attr'].id,
'info': {
'title_name': musicValue.info.title_name['@content'],
'version': {
'@__type': 'u8',
'#text': musicValue.info.version['@content'][0].toString()
},
'inf_ver': {
'@__type': 'u8',
'#text': musicValue.info.inf_ver['@content'][0].toString()
},
'distribution_date' : {
'#text': musicValue.info.distribution_date['@content'][0]
}
},
'difficulty': {
'novice': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.novice.difnum['@content'][0].toString()
}
},
'advanced': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.advanced.difnum['@content'][0].toString()
}
},
'exhaust': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.exhaust.difnum['@content'][0].toString()
}
},
'maximum': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.maximum != undefined ? musicValue.difficulty.maximum.difnum['@content'][0].toString() : '0'
}
},
'infinite': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.infinite != undefined ? musicValue.difficulty.infinite.difnum['@content'][0].toString() : '0'
}
}
}
});
})
} catch (err) {
console.log(err)
}
newNemsysData.forEach(fileName => {
if(parseInt(fileName.substring(7, 11))) {
resourceJsonData.nemsys.push({"value": parseInt(fileName.substring(7, 11)), "name": fileName + " (please rename)"})
}
})
// Copying new appeal card files from gamedata
console.log("Copying new appeal card files from gamedata")
let apCardFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/ap_card")
for await (const apCard of apCardFiles) {
let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/ap_card/" + apCard.name)
if(!IO.Exists('webui/asset/ap_card/' + apCard.name.substring(0, (apCard.name.length - 4)) + ".png") && !IO.Exists('webui/asset/ap_card/' + apCard.name.substring(0, (apCard.name.length - 4)) + ".jpg")) {
IO.WriteFile('webui/asset/ap_card/' + apCard.name, fileToWrite)
newAPCardData.push(apCard.name)
} else {
console.log(apCard.name + " exists")
try{
mdbJsonFixFinal = {
'mdb': {
'version': version,
'music': mdbJsonFix
}
};
IO.WriteFile('webui/asset/json/music_db.json', JSON.stringify(mdbJsonFixFinal));
if(!IO.Exists('webui/asset/json/music_db_' + version + '.json')){
IO.WriteFile('webui/asset/json/music_db_' + version + '.json', JSON.stringify(mdbJsonFixFinal));
}
} catch(err) {
console.log(err)
}
// Appeal card data registration to data.json not properly implemented yet, I don't quite understand how their IDs work
// newAPCardData.forEach(fileName => {
// if(parseInt(fileName.substring(6, 10))) {
// resourceJsonData.apCard.push({"value": parseInt(fileName.substring(6, 10)), "name": fileName + " (please rename)"})
// // Copying new nemsys files from gamedata
// console.log("Copying new nemsys files from gamedata")
// let nemsysFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/game_nemsys")
// for await (const nemsys of nemsysFiles) {
// let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/game_nemsys/" + nemsys.name)
// if(!IO.Exists('webui/asset/nemsys/' + nemsys.name.substring(0, (nemsys.name.length - 4)) + ".png") && !IO.Exists('webui/asset/nemsys/' + nemsys.name.substring(0, (nemsys.name.length - 4)) + ".jpg")) {
// IO.WriteFile('webui/asset/nemsys/' + nemsys.name, fileToWrite)
// newNemsysData.push(nemsys.name)
// } else {
// console.log(nemsys.name + " exists")
// }
// }
// newNemsysData.forEach(fileName => {
// if(parseInt(fileName.substring(7, 11))) {
// resourceJsonData.nemsys.push({"value": parseInt(fileName.substring(7, 11)), "name": fileName + " (please rename)"})
// }
// })
// Copying new subbg files from gamedata
console.log("Copying new subbg files from gamedata")
let subBGFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/submonitor_bg")
for await (const subbg of subBGFiles) {
if (subbg.name.substring(subbg.name.length-4, subbg.name.length).match(/(\.png|\.jpg)/g)) {
let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/submonitor_bg/" + subbg.name)
if(!IO.Exists('webui/asset/submonitor_bg/' + subbg.name.substring(0, (subbg.name.length - 4)) + ".png") && !IO.Exists('webui/asset/submonitor_bg/' + subbg.name.substring(0, (subbg.name.length - 4)) + ".jpg")) {
IO.WriteFile('webui/asset/submonitor_bg/' + subbg.name, fileToWrite)
newSubBGData.push(subbg.name)
} else {
console.log(subbg.name + " exists")
}
}
}
// // Copying new appeal card files from gamedata
// console.log("Copying new appeal card files from gamedata")
// let apCardFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/ap_card")
// for await (const apCard of apCardFiles) {
// let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/ap_card/" + apCard.name)
// if(!IO.Exists('webui/asset/ap_card/' + apCard.name.substring(0, (apCard.name.length - 4)) + ".png") && !IO.Exists('webui/asset/ap_card/' + apCard.name.substring(0, (apCard.name.length - 4)) + ".jpg")) {
// IO.WriteFile('webui/asset/ap_card/' + apCard.name, fileToWrite)
// newAPCardData.push(apCard.name)
// } else {
// console.log(apCard.name + " exists")
// }
// }
newSubBGData.forEach(fileName => {
if(parseInt(fileName.substring(6, 10))) {
resourceJsonData.subbg.push({"value": parseInt(fileName.substring(6, 10)), "name": fileName + " (please rename)"})
}
})
// // Appeal card data registration to data.json not properly implemented yet, I don't quite understand how their IDs work
// // newAPCardData.forEach(fileName => {
// // if(parseInt(fileName.substring(6, 10))) {
// // resourceJsonData.apCard.push({"value": parseInt(fileName.substring(6, 10)), "name": fileName + " (please rename)"})
// // }
// // })
// Copying new bgm files from gamedata
console.log("Copying new bgm files from gamedata")
let bgmFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/sound/custom")
for await (const bgm of bgmFiles) {
if (bgm.name.substring(bgm.name.length-4, bgm.name.length) == '.s3p') {
let folderName = bgm.name.match(/(custom|special)_([0-9]*)/g)[0]
if(folderName != '') {
let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/sound/custom/" + bgm.name)
if(!IO.Exists('webui/asset/audio/' + folderName)) {
IO.WriteFile('webui/asset/audio/' + folderName + '/' + bgm.name, fileToWrite)
newBGMData.push(bgm.name)
} else {
console.log(bgm.name + " exists")
}
}
}
}
// // Copying new subbg files from gamedata
// console.log("Copying new subbg files from gamedata")
// let subBGFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/submonitor_bg")
// for await (const subbg of subBGFiles) {
// if (subbg.name.substring(subbg.name.length-4, subbg.name.length).match(/(\.png|\.jpg)/g)) {
// let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/graphics/submonitor_bg/" + subbg.name)
// if(!IO.Exists('webui/asset/submonitor_bg/' + subbg.name.substring(0, (subbg.name.length - 4)) + ".png") && !IO.Exists('webui/asset/submonitor_bg/' + subbg.name.substring(0, (subbg.name.length - 4)) + ".jpg")) {
// IO.WriteFile('webui/asset/submonitor_bg/' + subbg.name, fileToWrite)
// newSubBGData.push(subbg.name)
// } else {
// console.log(subbg.name + " exists")
// }
// }
// }
newBGMData.forEach(fileName => {
let bgmId = fileName.match(/(?<=(custom|special)_)([0-9]*)/g)[0]
if(parseInt(bgmId)) {
resourceJsonData.bgm.push({"value": parseInt(bgmId), "name": fileName + " (please rename)"})
}
})
// newSubBGData.forEach(fileName => {
// if(parseInt(fileName.substring(6, 10))) {
// resourceJsonData.subbg.push({"value": parseInt(fileName.substring(6, 10)), "name": fileName + " (please rename)"})
// }
// })
// // Copying new bgm files from gamedata
// console.log("Copying new bgm files from gamedata")
// let bgmFiles = await IO.ReadDir(U.GetConfig('sdvx_eg_root_dir') + "/data/sound/custom")
// for await (const bgm of bgmFiles) {
// if (bgm.name.substring(bgm.name.length-4, bgm.name.length) == '.s3p') {
// let folderName = bgm.name.match(/(custom|special)_([0-9]*)/g)[0]
// if(folderName != '') {
// let fileToWrite = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/sound/custom/" + bgm.name)
// if(!IO.Exists('webui/asset/audio/' + folderName)) {
// IO.WriteFile('webui/asset/audio/' + folderName + '/' + bgm.name, fileToWrite)
// newBGMData.push(bgm.name)
// } else {
// console.log(bgm.name + " exists")
// }
// }
// }
// }
// newBGMData.forEach(fileName => {
// let bgmId = fileName.match(/(?<=(custom|special)_)([0-9]*)/g)[0]
// if(parseInt(bgmId)) {
// resourceJsonData.bgm.push({"value": parseInt(bgmId), "name": fileName + " (please rename)"})
// }
// })
await IO.WriteFile('webui/asset/json/data.json', JSON.stringify(resourceJsonData))
await IO.WriteFile('webui/asset/logs/copyResourcesFromGame.json', JSON.stringify({
nemsys: newNemsysData,
apCard: newAPCardData,
subbg: newSubBGData,
bgm: newBGMData
bgm: newBGMData,
versionSongs: newVersionSongs,
jsonSongs: newJsonSongs
}))
}
export const generateLatestMusicDBFile = async (data: {}) => {
var version = '';
IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/prop/ea3-config.xml").then(
function(value){
let configJson = U.parseXML(U.DecodeString(value, "shift_jis"), false)
version = configJson['ea3']['soft']['ext']['@content'];
},
function(error){
console.log(error)
return null;
}
);
var mdbJson;
var mdbJsonFix = [];
var mdbJsonFixFinal;
var mdb = await IO.ReadFile(U.GetConfig('sdvx_eg_root_dir') + "/data/others/music_db.xml").then(
function(value){
mdbJson = U.parseXML(U.DecodeString(value, "shift_jis"), false)
try {
mdbJson.mdb.music.forEach(musicValue => {
if(parseInt(musicValue.info.distribution_date['@content'][0]) >= parseInt(version.substring(0,8))) {
console.log("Found new song for version " + version + ": " + musicValue.info.title_name['@content'] + " (" + musicValue.info.distribution_date['@content'] + ")");
}
mdbJsonFix.push({
'@id': musicValue['@attr'].id,
'info': {
'title_name': musicValue.info.title_name['@content'],
'version': {
'@__type': 'u8',
'#text': musicValue.info.version['@content'][0].toString()
},
'inf_ver': {
'@__type': 'u8',
'#text': musicValue.info.inf_ver['@content'][0].toString()
},
'distribution_date' : {
'#text': musicValue.info.distribution_date['@content'][0]
}
},
'difficulty': {
'novice': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.novice.difnum['@content'][0].toString()
}
},
'advanced': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.advanced.difnum['@content'][0].toString()
}
},
'exhaust': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.exhaust.difnum['@content'][0].toString()
}
},
'maximum': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.maximum != undefined ? musicValue.difficulty.maximum.difnum['@content'][0].toString() : '0'
}
},
'infinite': {
'difnum': {
'@__type': 'u8',
'#text': musicValue.difficulty.infinite != undefined ? musicValue.difficulty.infinite.difnum['@content'][0].toString() : '0'
}
}
}
});
})
} catch (err) {
console.log(err)
}
// export const generateLatestMusicDBFile = async (data: {}) => {
try{
mdbJsonFixFinal = {
'mdb': {
'version': version,
'music': mdbJsonFix
}
};
IO.WriteFile('webui/asset/json/music_db.json', JSON.stringify(mdbJsonFixFinal));
if(!IO.Exists('webui/asset/json/music_db_' + version + '.json')){
IO.WriteFile('webui/asset/json/music_db_' + version + '.json', JSON.stringify(mdbJsonFixFinal));
}
} catch(err) {
console.log(err)
}
return mdbJsonFixFinal;
},
function(error){
console.log(error);
return null;
}
);
console.log(mdb.mdb.version)
return mdb;
}
// return mdbJsonFixFinal;
// }
+22 -24
View File
@@ -4,32 +4,14 @@
$(document).ready(async function() {
let sdvxDir = document.getElementById("sdvx-dir").innerText
$( "#updateResources" ).click(async function() {
answer = confirm("Clicking OK would mean that you have already updated the datecode in your ea3-config.xml file. Would you like to proceed?");
answer = confirm("Clicking OK would mean that you have already updated the datacode in your ea3-config.xml file. Would you like to proceed?");
if (answer == true) {
document.getElementById("logtextarea").textContent = ''
document.getElementById("logtextarea").textContent = 'Updating music_db.json file....\n'
await emit("generateLatestMusicDBFile").then(
function(response) {
$.getJSON( "static/asset/json/music_db.json", function( data ) {
document.getElementById("logtextarea").textContent += "New songs found in version " + data['mdb']['version'] + ": \n";
$.each( data['mdb']['music'], function( key, val ) {
if(parseInt(val.info.distribution_date['#text']) >= parseInt(data['mdb']['version'].substring(0,8))){
document.getElementById("logtextarea").textContent += val.info.distribution_date['#text'] + " - " + val.info.title_name + "\n";
}
});
document.getElementById("logtextarea").textContent += '\n\n'
});
},
function(error) {
document.getElementById("logtextarea").textContent += error + "\n";
document.getElementById("logtextarea").textContent += "Please check if 'Exceed Gear Data Directory' is configured properly." + "\n";
}
);
document.getElementById("logtextarea").textContent = 'Running....\n'
await emit("copyResourcesFromGame").then(
function(response){
$.getJSON( "static/asset/logs/copyResourcesFromGame.json", function( data ) {
if(data['nemsys']) {
if(data['nemsys'].length > 0) {
document.getElementById("logtextarea").textContent += 'New nemsys: \n'
$.each(data['nemsys'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
@@ -37,7 +19,7 @@ $(document).ready(async function() {
document.getElementById("logtextarea").textContent += '\n\n'
}
if(data['apCard']) {
if(data['apCard'].length > 0) {
document.getElementById("logtextarea").textContent += 'New appeal cards: \n'
$.each(data['apCard'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
@@ -45,7 +27,7 @@ $(document).ready(async function() {
document.getElementById("logtextarea").textContent += '\n\n'
}
if(data['subbg']) {
if(data['subbg'].length > 0) {
document.getElementById("logtextarea").textContent += 'New submonitor backgrounds: \n'
$.each(data['subbg'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
@@ -53,13 +35,29 @@ $(document).ready(async function() {
document.getElementById("logtextarea").textContent += '\n\n'
}
if(data['bgm']) {
if(data['bgm'].length > 0) {
document.getElementById("logtextarea").textContent += 'New bgm: \n'
$.each(data['bgm'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
})
document.getElementById("logtextarea").textContent += '\n\n'
}
if(data['versionSongs'].length > 0) {
document.getElementById("logtextarea").textContent += 'New songs in latest data: \n'
$.each(data['versionSongs'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
})
document.getElementById("logtextarea").textContent += '\n\n'
}
if(data['jsonSongs'].length > 0) {
document.getElementById("logtextarea").textContent += 'New songs added to mdb asset: \n'
$.each(data['jsonSongs'], function(key, val) {
document.getElementById("logtextarea").textContent += "- " + val + '\n'
})
document.getElementById("logtextarea").textContent += '\n\n'
}
})
},
function(error){