mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-03-21 17:34:46 -05:00
Use newer API for Custom MDB, Fix profile bug.
This commit is contained in:
parent
5d52767f0a
commit
8db9d98b2b
3
gitadora@asphyxia/data/.gitignore
vendored
3
gitadora@asphyxia/data/.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
mdb_ex.xml
|
||||
mdb_mt.xml
|
||||
mdb_ex.b64
|
||||
mdb_mt.b64
|
||||
mdb_mt.b64
|
||||
custom_mdb.xml
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,32 @@
|
|||
import { getVersion } from "../utils";
|
||||
import { processData as ExchainMusic } from "../data/Exchain"
|
||||
import { processData as MatixxMusic } from "../data/Matixx"
|
||||
import { readXML } from "../data/helper";
|
||||
import * as path from "path";
|
||||
import { CommonMusicDataField, readJSONOrXML, readXML } from "../data/helper";
|
||||
|
||||
export const playableMusic: EPR = async (info, data, send) => {
|
||||
const version = getVersion(info);
|
||||
|
||||
let musicList: any[] = [];
|
||||
let music: CommonMusicDataField[] = [];
|
||||
try {
|
||||
if (U.GetConfig("enable_custom_mdb")) {
|
||||
const data = await readXML(path.normalize(U.GetConfig("custom_mdb_path")))
|
||||
const data = await readXML('data/custom_mdb.xml')
|
||||
const mdb = $(data).elements("mdb.mdb_data");
|
||||
|
||||
|
||||
for (const m of mdb) {
|
||||
const d = m.numbers("xg_diff_list");
|
||||
const contain = m.numbers("contain_stat");
|
||||
const gf = contain[0];
|
||||
const dm = contain[1];
|
||||
|
||||
|
||||
if (gf == 0 && dm == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
let type = gf;
|
||||
if (gf == 0) {
|
||||
type = dm;
|
||||
}
|
||||
|
||||
musicList.push({
|
||||
|
||||
music.push({
|
||||
id: K.ITEM('s32', m.number("music_id")),
|
||||
cont_gf: K.ITEM('bool', gf == 0 ? 0 : 1),
|
||||
cont_dm: K.ITEM('bool', dm == 0 ? 0 : 1),
|
||||
|
|
@ -56,15 +54,16 @@ export const playableMusic: EPR = async (info, data, send) => {
|
|||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
send.deny();
|
||||
console.error(e.stack);
|
||||
console.error("Fallback: Using default MDB method.")
|
||||
music = [];
|
||||
}
|
||||
|
||||
if (musicList.length == 0) {
|
||||
if (music.length == 0) {
|
||||
if (version == 'exchain') {
|
||||
musicList = _.get(await ExchainMusic(), 'music', []);
|
||||
music = _.get(await ExchainMusic(), 'music', []);
|
||||
} else {
|
||||
musicList = _.get(await MatixxMusic(), 'music', []);
|
||||
music = _.get(await MatixxMusic(), 'music', []);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,11 +73,8 @@ export const playableMusic: EPR = async (info, data, send) => {
|
|||
major: K.ITEM('s32', 1),
|
||||
minor: K.ITEM('s32', 1),
|
||||
},
|
||||
musicinfo: {
|
||||
'@attr': {
|
||||
nr: musicList.length,
|
||||
},
|
||||
'music': musicList,
|
||||
},
|
||||
musicinfo: K.ATTR({ nr: `${music.length}` }, {
|
||||
music,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
|
@ -713,16 +713,28 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999
|
|||
}
|
||||
}
|
||||
|
||||
const defaultScores = (game: 'gf' | 'dm'): Scores => {
|
||||
return {
|
||||
collection: 'scores',
|
||||
version,
|
||||
pluginVer: PLUGIN_VER,
|
||||
game,
|
||||
scores: {}
|
||||
}
|
||||
};
|
||||
|
||||
const gf = { game: 'gf', version };
|
||||
const dm = { game: 'dm', version };
|
||||
|
||||
await DB.Upsert(refid, { collection: 'playerinfo', version }, defaultInfo)
|
||||
await DB.Upsert(refid, { collection: 'profile', ...gf }, defaultProfile('gf'))
|
||||
await DB.Upsert(refid, { collection: 'profile', ...dm }, defaultProfile('dm'))
|
||||
await DB.Upsert(refid, { collection: 'record', ...gf }, defaultRecord('gf'))
|
||||
await DB.Upsert(refid, { collection: 'record', ...dm }, defaultRecord('dm'))
|
||||
await DB.Upsert(refid, { collection: 'extra', ...gf }, defaultExtra('gf'))
|
||||
await DB.Upsert(refid, { collection: 'extra', ...dm }, defaultExtra('dm'))
|
||||
await DB.Upsert(refid, { collection: 'playerinfo', version }, defaultInfo);
|
||||
await DB.Upsert(refid, { collection: 'profile', ...gf }, defaultProfile('gf'));
|
||||
await DB.Upsert(refid, { collection: 'profile', ...dm }, defaultProfile('dm'));
|
||||
await DB.Upsert(refid, { collection: 'record', ...gf }, defaultRecord('gf'));
|
||||
await DB.Upsert(refid, { collection: 'record', ...dm }, defaultRecord('dm'));
|
||||
await DB.Upsert(refid, { collection: 'extra', ...gf }, defaultExtra('gf'));
|
||||
await DB.Upsert(refid, { collection: 'extra', ...dm }, defaultExtra('dm'));
|
||||
await DB.Upsert(refid, { collection: 'scores', ...gf }, defaultScores('gf'));
|
||||
await DB.Upsert(refid, { collection: 'scores', ...dm }, defaultScores('dm'));
|
||||
|
||||
return defaultInfo
|
||||
}
|
||||
|
|
@ -868,6 +880,7 @@ export const savePlayer: EPR = async (info, data, send) => {
|
|||
await DB.Upsert(refid, { collection: 'extra', game, version }, extra)
|
||||
|
||||
const stages = $(data).elements('player.stage');
|
||||
const scores = (await getScore(refid, version, game)).scores;
|
||||
for (const stage of stages) {
|
||||
const mid = stage.number('musicid', -1);
|
||||
const seq = stage.number('seq', -1);
|
||||
|
|
@ -885,41 +898,31 @@ export const savePlayer: EPR = async (info, data, send) => {
|
|||
const meter = stage.bigint('meter', BigInt(0));
|
||||
const prog = stage.number('meter_prog', 0);
|
||||
|
||||
|
||||
const score = (await getScore(refid, version, game)
|
||||
|| {
|
||||
collection: 'scores',
|
||||
game,
|
||||
version,
|
||||
pluginVer: PLUGIN_VER,
|
||||
scores: {}
|
||||
}).scores;
|
||||
|
||||
if(!score[mid]) {
|
||||
score[mid] = {
|
||||
update: [0,0],
|
||||
if(!scores[mid]) {
|
||||
scores[mid] = {
|
||||
update: [0, 0],
|
||||
diffs: {}
|
||||
}
|
||||
}
|
||||
|
||||
if (newSkill > score.update[1]) {
|
||||
score.update[0] = seq;
|
||||
score.update[1] = newSkill;
|
||||
if (newSkill > scores[mid].update[1]) {
|
||||
scores[mid].update[0] = seq;
|
||||
scores[mid].update[1] = newSkill;
|
||||
}
|
||||
|
||||
score.diffs[seq] = {
|
||||
perc: Math.max(_.get(score.diffs[seq], 'perc', 0), perc),
|
||||
rank: Math.max(_.get(score.diffs[seq], 'rank', 0), rank),
|
||||
scores[mid].diffs[seq] = {
|
||||
perc: Math.max(_.get(scores[mid].diffs[seq], 'perc', 0), perc),
|
||||
rank: Math.max(_.get(scores[mid].diffs[seq], 'rank', 0), rank),
|
||||
meter: meter.toString(),
|
||||
prog: Math.max(_.get(score.diffs[seq], 'prog', 0), prog),
|
||||
clear: _.get(score.diffs[seq], 'clear') || clear,
|
||||
fc: _.get(score.diffs[seq], 'fc') || fc,
|
||||
ex: _.get(score.diffs[seq], 'ex') || ex,
|
||||
prog: Math.max(_.get(scores[mid].diffs[seq], 'prog', 0), prog),
|
||||
clear: _.get(scores[mid].diffs[seq], 'clear') || clear,
|
||||
fc: _.get(scores[mid].diffs[seq], 'fc') || fc,
|
||||
ex: _.get(scores[mid].diffs[seq], 'ex') || ex,
|
||||
};
|
||||
|
||||
await saveScore(refid, version, game, score);
|
||||
}
|
||||
|
||||
await saveScore(refid, version, game, scores);
|
||||
|
||||
await send.object({
|
||||
player: K.ATTR({ no: `${no}` }, {
|
||||
skill: { rank: K.ITEM('s32', 1), total_nr: K.ITEM('s32', 1) },
|
||||
|
|
@ -962,12 +965,18 @@ async function getRecord(refid: string, version: string, game: 'gf' | 'dm') {
|
|||
})
|
||||
}
|
||||
|
||||
async function getScore(refid: string, version: string, game: 'gf' | 'dm') {
|
||||
return await DB.FindOne<Scores>(refid, {
|
||||
async function getScore(refid: string, version: string, game: 'gf' | 'dm'): Promise<Scores> {
|
||||
return (await DB.FindOne<Scores>(refid, {
|
||||
collection: 'scores',
|
||||
version: version,
|
||||
game: game
|
||||
})
|
||||
})) || {
|
||||
collection: 'scores',
|
||||
version: version,
|
||||
pluginVer: PLUGIN_VER,
|
||||
game: game,
|
||||
scores: {}
|
||||
}
|
||||
}
|
||||
|
||||
async function saveScore(refid: string, version: string, game: 'gf' | 'dm', scores: Scores['scores']) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,13 @@ import { gameInfoGet, shopInfoRegist } from "./handlers/info";
|
|||
import { playableMusic } from "./handlers/MusicList"
|
||||
import { getPlayer, check, regist, savePlayer } from "./handlers/profiles";
|
||||
import { updatePlayerInfo } from "./handlers/webui";
|
||||
import { isRequiredVersion } from "./utils";
|
||||
|
||||
export function register() {
|
||||
if(!isRequiredVersion(1, 20)) {
|
||||
console.error("You need newer version of Core. v1.20 or newer required.")
|
||||
}
|
||||
|
||||
R.GameCode('M32');
|
||||
|
||||
R.Config("enable_custom_mdb", {
|
||||
|
|
@ -13,11 +18,10 @@ export function register() {
|
|||
default: false,
|
||||
})
|
||||
|
||||
R.Config("custom_mdb_path", {
|
||||
name: "Custom MDB PATH",
|
||||
desc: "You need to enable Custom MDB option first. USE ABSOLUTE PATH !!",
|
||||
type: "string",
|
||||
default: "",
|
||||
R.DataFile("data/custom_mdb.xml", {
|
||||
accept: ".xml",
|
||||
name: "Custom MDB",
|
||||
desc: "You need to enable Custom MDB option first."
|
||||
})
|
||||
|
||||
R.WebUIEvent('updatePlayerInfo', updatePlayerInfo);
|
||||
|
|
|
|||
|
|
@ -10,3 +10,10 @@ export const getVersion = (info: EamuseInfo) => {
|
|||
const moduleName: string = info.module;
|
||||
return moduleName.match(/([^_]*)_(.*)/)[1];
|
||||
};
|
||||
|
||||
export function isRequiredVersion(major: number, minor: number) {
|
||||
// version value exposed since Core v1.19
|
||||
const core_major = typeof CORE_VERSION_MAJOR === "number" ? CORE_VERSION_MAJOR : 1
|
||||
const core_minor = typeof CORE_VERSION_MINOR === "number" ? CORE_VERSION_MINOR : 18
|
||||
return core_major >= major && core_minor >= minor
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user