Use newer API for Custom MDB, Fix profile bug.

This commit is contained in:
DitFranXX
2020-12-11 17:48:27 +09:00
parent 5d52767f0a
commit 8db9d98b2b
8 changed files with 117 additions and 77 deletions

View File

@@ -1,4 +1,5 @@
mdb_ex.xml
mdb_mt.xml
mdb_ex.b64
mdb_mt.b64
mdb_mt.b64
custom_mdb.xml

View File

@@ -1,15 +1,14 @@
import * as path from "path";
import { readJSON, readXML } from './helper';
import { CommonMusicData, readJSONOrXML, readXML } from './helper';
export async function processData() {
const { music } = await readJSON(path.resolve(__dirname, './mdb_ex.json'))
const { music } = await readJSONOrXML('data/mdb_ex.json', 'data/mdb_ex.xml', processRawData)
return {
music,
};
}
export async function processRawData() {
const data = await readXML(path.resolve(__dirname, './mdb_ex.xml'))
export async function processRawData(path: string): Promise<CommonMusicData> {
const data = await readXML(path)
const mdb = $(data).elements("mdb.mdb_data");
const music: any[] = [];
for (const m of mdb) {

View File

@@ -1,15 +1,14 @@
import * as path from "path";
import { readJSON, readXML } from './helper';
import { CommonMusicData, readJSONOrXML, readXML } from './helper';
export async function processData() {
const { music } = await readJSON(path.resolve(__dirname, './mdb_ex.json'))
const { music } = await readJSONOrXML('data/mdb_mt.json', 'data/mdb_mt.xml', processRawData)
return {
music,
};
}
export async function processRawData() {
const data = await readXML(path.resolve(__dirname, './mdb_mt.xml'))
export async function processRawData(path: string): Promise<CommonMusicData> {
const data = await readXML(path)
const mdb = $(data).elements("mdb.mdb_data");
const music: any[] = [];
for (const m of mdb) {

View File

@@ -1,11 +1,36 @@
export interface CommonMusicDataField {
id: KITEM<"s32">;
cont_gf: KITEM<"bool">;
cont_dm: KITEM<"bool">;
is_secret: KITEM<"bool">;
is_hot: KITEM<"bool">;
data_ver: KITEM<"s32">;
diff: KARRAY<"u16">;
}
export interface CommonMusicData {
music: CommonMusicDataField[]
}
export async function readXML(path: string) {
const xml = await IO.ReadFile(path, 'utf-8');
const json = U.parseXML(xml, false)
return json
const xml = await IO.ReadFile(path, 'utf-8');
const json = U.parseXML(xml, false)
return json
}
export async function readJSON(path: string) {
const str = await IO.ReadFile(path, 'utf-8');
const json = JSON.parse(str)
const str = await IO.ReadFile(path, 'utf-8');
const json = JSON.parse(str)
return json
}
export async function readJSONOrXML(jsonPath: string, xmlPath: string, processHandler: (path: string) => Promise<CommonMusicData>): Promise<CommonMusicData> {
if (!IO.Exists(jsonPath)) {
const data = await processHandler(xmlPath)
await IO.WriteFile(jsonPath, JSON.stringify(data))
return data
} else {
const json = JSON.parse(await IO.ReadFile(jsonPath, 'utf-8'))
return json
}
}