mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-09-22 22:27:56 +03:00
GITADORA PlayerBoard Customization Update
This commit is contained in:
@@ -13,7 +13,7 @@ import Logger from "../utils/logger"
|
||||
import { isAsphyxiaDebugMode, isRivalEnabled, isSharedSongScoresEnabled } from "../utils/index";
|
||||
import { SecretMusicEntry } from "../models/secretmusicentry";
|
||||
import { CheckPlayerResponse, getCheckPlayerResponse } from "../models/Responses/checkplayerresponse";
|
||||
import { getPlayerStickerResponse, PlayerStickerResponse } from "../models/Responses/playerstickerresponse";
|
||||
import { getPlayerBoardResponse } from "../models/Responses/playerstickerresponse";
|
||||
import { getSecretMusicResponse, SecretMusicResponse } from "../models/Responses/secretmusicresponse";
|
||||
import { getSaveProfileResponse } from "../models/Responses/saveprofileresponse";
|
||||
import { getDefaultBattleDataResponse } from "../models/Responses/battledataresponse";
|
||||
@@ -292,14 +292,12 @@ export const getPlayer: EPR = async (info, data, send) => {
|
||||
}));
|
||||
}
|
||||
|
||||
const sticker: PlayerStickerResponse[] = getPlayerStickerResponse(name.card);
|
||||
const playerboard = getPlayerBoardResponse(name);
|
||||
const playinfo: PlayerPlayInfoResponse = getPlayerPlayInfoResponse(profile);
|
||||
|
||||
const playerData: any = {
|
||||
playerboard: {
|
||||
index: K.ITEM('s32', 1),
|
||||
is_active: K.ITEM('bool', _.isArray(name.card) ? 1 : 0),
|
||||
sticker,
|
||||
...playerboard,
|
||||
},
|
||||
player_info: {
|
||||
// The initial profile is player type 0. Each follow-up rival profile is
|
||||
|
||||
@@ -15,7 +15,7 @@ import Logger from "../utils/logger"
|
||||
import { isAsphyxiaDebugMode, isSharedSongScoresEnabled } from "../utils/index";
|
||||
import { SecretMusicEntry } from "../models/secretmusicentry";
|
||||
import { CheckPlayerResponse, getCheckPlayerResponse } from "../models/Responses/checkplayerresponse";
|
||||
import { getPlayerStickerResponse, PlayerStickerResponse } from "../models/Responses/playerstickerresponse";
|
||||
import { getPlayerBoardResponse } from "../models/Responses/playerstickerresponse";
|
||||
import { getSecretMusicResponse, SecretMusicResponse } from "../models/Responses/secretmusicresponse";
|
||||
import { getSaveProfileResponse } from "../models/Responses/saveprofileresponse";
|
||||
import { getDefaultBattleDataResponse } from "../models/Responses/battledataresponse";
|
||||
@@ -181,14 +181,12 @@ export const getPlayer: EPR = async (info, data, send) => {
|
||||
}));
|
||||
}
|
||||
|
||||
const sticker: PlayerStickerResponse[] = getPlayerStickerResponse(name.card);
|
||||
const playerboard = getPlayerBoardResponse(name);
|
||||
const playinfo: PlayerPlayInfoResponse = getPlayerPlayInfoResponse(profile);
|
||||
|
||||
const playerData: any = {
|
||||
playerboard: {
|
||||
index: K.ITEM('s32', 1),
|
||||
is_active: K.ITEM('bool', _.isArray(name.card) ? 1 : 0),
|
||||
sticker,
|
||||
...playerboard,
|
||||
},
|
||||
player_info: {
|
||||
player_type: K.ITEM('s8', 0),
|
||||
|
||||
@@ -6,6 +6,7 @@ export const updatePlayerInfo = async (data: {
|
||||
version: string;
|
||||
name?: string;
|
||||
title?: string;
|
||||
playerboard?: string | PlayerInfo['playerboard'];
|
||||
}) => {
|
||||
if (data.refid == null) return;
|
||||
|
||||
@@ -21,6 +22,11 @@ export const updatePlayerInfo = async (data: {
|
||||
update.title = data.title;
|
||||
}
|
||||
|
||||
if (data.playerboard !== undefined) {
|
||||
const playerboard = parsePlayerBoard(data.playerboard);
|
||||
if (playerboard) update.playerboard = playerboard;
|
||||
}
|
||||
|
||||
await DB.Update<PlayerInfo>(
|
||||
data.refid,
|
||||
{ collection: 'playerinfo', version: data.version },
|
||||
@@ -28,6 +34,61 @@ export const updatePlayerInfo = async (data: {
|
||||
);
|
||||
};
|
||||
|
||||
/** Parse and normalize the JSON editor payload before persisting it. */
|
||||
function parsePlayerBoard(input: string | PlayerInfo['playerboard']): PlayerInfo['playerboard'] | null {
|
||||
let value: any = input;
|
||||
if (typeof input === 'string') {
|
||||
try {
|
||||
value = input.trim() ? JSON.parse(input) : {};
|
||||
} catch (error) {
|
||||
console.warn('[gitadora] Ignoring invalid playerboard JSON:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
||||
|
||||
const numberOr = (candidate: unknown, fallback: number) => {
|
||||
const parsed = typeof candidate === 'number' ? candidate : Number(candidate);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
};
|
||||
const boolOr = (candidate: unknown, fallback: boolean) => {
|
||||
if (candidate === undefined || candidate === null || candidate === '') return fallback;
|
||||
if (typeof candidate === 'boolean') return candidate;
|
||||
if (candidate === 1 || candidate === '1' || candidate === 'true') return true;
|
||||
if (candidate === 0 || candidate === '0' || candidate === 'false') return false;
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const stickers = Array.isArray(value.sticker) ? value.sticker : [];
|
||||
const normalizedStickers = stickers.slice(0, 10).reduce((result: any[], sticker: any) => {
|
||||
if (!sticker || typeof sticker !== 'object') return result;
|
||||
const position = Array.isArray(sticker.position) ? sticker.position : [];
|
||||
const scale = Array.isArray(sticker.scale) ? sticker.scale : [];
|
||||
const id = numberOr(sticker.id, NaN);
|
||||
const posX = numberOr(sticker.pos_x ?? position[0], NaN);
|
||||
const posY = numberOr(sticker.pos_y ?? position[1], NaN);
|
||||
const scaleX = numberOr(sticker.scale_x ?? scale[0], NaN);
|
||||
const scaleY = numberOr(sticker.scale_y ?? scale[1], NaN);
|
||||
const rotate = numberOr(sticker.rotate ?? sticker.rotation, NaN);
|
||||
if (![id, posX, posY, scaleX, scaleY, rotate].every(Number.isFinite)) return result;
|
||||
result.push({
|
||||
id: Math.trunc(id),
|
||||
pos_x: posX,
|
||||
pos_y: posY,
|
||||
scale_x: scaleX,
|
||||
scale_y: scaleY,
|
||||
rotate,
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
index: Math.trunc(numberOr(value.index, 1)),
|
||||
is_active: boolOr(value.is_active, false),
|
||||
sticker: normalizedStickers,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the rival list for one game/version pair.
|
||||
*
|
||||
@@ -48,12 +109,13 @@ export const updateRival = async (data: {
|
||||
|
||||
const requestedRefids = [data.rival1, data.rival2, data.rival3, data.rival4, data.rival5];
|
||||
const seenRefids = new Set<string>();
|
||||
const rivalSlots = requestedRefids.flatMap((input, index) => {
|
||||
const rivalSlots = requestedRefids.reduce((result: Array<{ rivalRefid: string; slot: number }>, input, index) => {
|
||||
const rivalRefid = input?.trim();
|
||||
if (!rivalRefid || rivalRefid === data.refid || seenRefids.has(rivalRefid)) return [];
|
||||
if (!rivalRefid || rivalRefid === data.refid || seenRefids.has(rivalRefid)) return result;
|
||||
seenRefids.add(rivalRefid);
|
||||
return [{ rivalRefid, slot: index + 1 }];
|
||||
});
|
||||
result.push({ rivalRefid, slot: index + 1 });
|
||||
return result;
|
||||
}, [] as Array<{ rivalRefid: string; slot: number }>);
|
||||
|
||||
// Store only players that have a profile in the same game version. This keeps
|
||||
// the later game response from referencing a player whose DID/profile is absent.
|
||||
@@ -82,3 +144,15 @@ export const updateRival = async (data: {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user