mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-12-04 19:20:29 -06:00
Merge pull request #98 from duxing0626/main
Updated WebUI and PlayerBoards Editor
This commit is contained in:
@@ -61,6 +61,17 @@ Scores are stored under `version: "shared"` but are automatically applied to the
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
v1.5.5
|
||||
----------------
|
||||
* A version played for the first time now inherits the player's name/title from another version
|
||||
* WebUI: profile page grouped into per-version tabs (User Detail / Playerboard, Profile and Rivals per game)
|
||||
* WebUI: leaderboards grouped into per-version tabs, then per game
|
||||
* WebUI: forms save in place without reloading, so the selected tab is kept
|
||||
* Playerboard editor reworked to match the official customize page: stickers snap to the fixed 3x5 grid in two sizes,
|
||||
with a visual preview (drag snaps to the grid), move / rotate / size / layer buttons and 10 sticker slots.
|
||||
Boards saved by earlier editors are still sent to the game unchanged and are snapped to the grid when opened in the editor.
|
||||
* Sticker catalog (data/trbitems.json) replaced with the cabinet-derived list (Sheet / Sticker / Seasonal / Special)
|
||||
|
||||
v1.5.0
|
||||
----------------
|
||||
* Added(more like bugfix lol) support for GALAXY WAVE DELTA
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/// <reference lib="es2020.bigint" />
|
||||
|
||||
import { getDefaultPlayerInfo, PlayerInfo } from "../models/playerinfo";
|
||||
import { findInheritablePlayerInfo, getDefaultPlayerInfo, PlayerInfo } from "../models/playerinfo";
|
||||
import { PlayerRanking } from "../models/playerranking";
|
||||
import { getDefaultProfile, Profile } from "../models/profile";
|
||||
import { getDefaultRecord, Record } from "../models/record";
|
||||
@@ -626,6 +626,12 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999
|
||||
|
||||
const defaultInfo: PlayerInfo = getDefaultPlayerInfo(version, id)
|
||||
|
||||
const inherited = await findInheritablePlayerInfo(refid);
|
||||
if (inherited) {
|
||||
defaultInfo.name = inherited.name || defaultInfo.name;
|
||||
defaultInfo.title = inherited.title || defaultInfo.title;
|
||||
}
|
||||
|
||||
const gf = { game: 'gf', version };
|
||||
const dm = { game: 'dm', version };
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference lib="es2020.bigint" />
|
||||
|
||||
import { getDefaultPlayerInfo, PlayerInfo } from "../models/playerinfo";
|
||||
import { findInheritablePlayerInfo, getDefaultPlayerInfo, PlayerInfo } from "../models/playerinfo";
|
||||
import { PlayerRanking } from "../models/playerranking";
|
||||
import { getDefaultProfile, Profile } from "../models/profile";
|
||||
import { getDefaultRecord, Record } from "../models/record";
|
||||
@@ -506,6 +506,12 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999
|
||||
|
||||
const defaultInfo: PlayerInfo = getDefaultPlayerInfo(version, id)
|
||||
|
||||
const inherited = await findInheritablePlayerInfo(refid);
|
||||
if (inherited) {
|
||||
defaultInfo.name = inherited.name || defaultInfo.name;
|
||||
defaultInfo.title = inherited.title || defaultInfo.title;
|
||||
}
|
||||
|
||||
const gf = { game: 'gf', version };
|
||||
const dm = { game: 'dm', version };
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { PlayerInfo } from "../models/playerinfo"
|
||||
import { isValidPickerBoard, pickerToPlayerBoard } from "../models/playerboard"
|
||||
import { Rival } from "../models/rival"
|
||||
import Logger from "../utils/logger"
|
||||
|
||||
const logger = new Logger("webui")
|
||||
|
||||
export const updatePlayerInfo = async (data: {
|
||||
refid: string;
|
||||
version: string;
|
||||
name?: string;
|
||||
title?: string;
|
||||
playerboard?: string | PlayerInfo['playerboard'];
|
||||
}) => {
|
||||
if (data.refid == null) return;
|
||||
|
||||
@@ -22,11 +25,6 @@ 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 },
|
||||
@@ -34,60 +32,36 @@ 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;
|
||||
}
|
||||
// The playerboard is edited only through the WebUI board editor (the game client displays the
|
||||
// board but never sends edits back). The editor submits grid/size presets, which are converted
|
||||
// to coordinates here so stored boards always stay on the official 3x5 grid.
|
||||
export const updatePlayerBoard = async (data: {
|
||||
refid: string;
|
||||
version: string;
|
||||
board?: string;
|
||||
}) => {
|
||||
if (data.refid == null || !data.version) return;
|
||||
if (data.board == null || data.board.trim().length === 0) return;
|
||||
|
||||
let parsed: any;
|
||||
try {
|
||||
parsed = JSON.parse(data.board);
|
||||
} catch (e) {
|
||||
logger.error(`Failed to parse player board JSON for refid ${data.refid}: ${e}`);
|
||||
return;
|
||||
}
|
||||
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;
|
||||
};
|
||||
if (!isValidPickerBoard(parsed)) {
|
||||
logger.error(`Rejected invalid player board for refid ${data.refid}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const stickers = Array.isArray(value.sticker) ? value.sticker : [];
|
||||
const normalizedStickers = stickers.slice(0, 11).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,
|
||||
};
|
||||
}
|
||||
await DB.Update<PlayerInfo>(
|
||||
data.refid,
|
||||
{ collection: 'playerinfo', version: data.version },
|
||||
{ $set: { playerboard: pickerToPlayerBoard(parsed) } }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace the rival list for one game/version pair.
|
||||
@@ -144,15 +118,3 @@ export const updateRival = async (data: {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { gameInfoGet, shopInfoRegist } from "./handlers/info";
|
||||
import { playableMusic } from "./handlers/MusicList"
|
||||
import { getPlayer, check, regist, savePlayers } from "./handlers/profiles";
|
||||
import { updatePlayerInfo, updateRival } from "./handlers/webui";
|
||||
import { updatePlayerInfo, updatePlayerBoard, updateRival } from "./handlers/webui";
|
||||
import { isAsphyxiaDebugMode, isRequiredCoreVersion } from "./utils";
|
||||
import Logger from "./utils/logger";
|
||||
|
||||
@@ -75,6 +75,7 @@ export function register() {
|
||||
})
|
||||
|
||||
R.WebUIEvent('updatePlayerInfo', updatePlayerInfo);
|
||||
R.WebUIEvent('updatePlayerBoard', updatePlayerBoard);
|
||||
R.WebUIEvent('updateRival', updateRival);
|
||||
|
||||
const MultiRoute = (method: string, handler: EPR | boolean) => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { getBoardStickers } from "../playerboard";
|
||||
|
||||
export interface PlayerStickerResponse {
|
||||
id: KITEM<'s32'>,
|
||||
pos_x: KITEM<'float'> ,
|
||||
@@ -59,23 +61,14 @@ export function getPlayerStickerResponse(playerCard : any[]) : PlayerStickerResp
|
||||
return stickers
|
||||
}
|
||||
|
||||
/** Build the playerboard response, with a safe fallback for old playerinfo documents. */
|
||||
/** Build the playerboard response from any stored board shape (see models/playerboard.ts). */
|
||||
export function getPlayerBoardResponse(playerInfo: any): PlayerBoardConfig {
|
||||
const configured = playerInfo?.playerboard;
|
||||
const legacyCard = playerInfo?.card;
|
||||
const stickers = getPlayerStickerResponse(
|
||||
_.isArray(configured?.sticker) ? configured.sticker : legacyCard
|
||||
);
|
||||
const index = finiteNumber(configured?.index, 0);
|
||||
const activeValue = configured?.is_active;
|
||||
const isActive = activeValue === undefined
|
||||
? _.isArray(legacyCard)
|
||||
: Boolean(activeValue === true || activeValue === 1 || activeValue === '1' || activeValue === 'true');
|
||||
const { stickers, isActive } = getBoardStickers(playerInfo);
|
||||
const index = finiteNumber(playerInfo?.playerboard?.index, 1);
|
||||
|
||||
return {
|
||||
index: K.ITEM('s32', Math.trunc(index)),
|
||||
is_active: K.ITEM('bool', isActive ? 1 : 0),
|
||||
sticker: stickers,
|
||||
sticker: getPlayerStickerResponse(stickers),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
167
gitadora@asphyxia/models/playerboard.ts
Normal file
167
gitadora@asphyxia/models/playerboard.ts
Normal file
@@ -0,0 +1,167 @@
|
||||
import { PlayerInfo } from "./playerinfo";
|
||||
|
||||
/**
|
||||
* Fixed-grid playerboard layout, matching the official e-amusement customize page:
|
||||
* stickers snap to a 3x5 position grid and come in two sizes.
|
||||
*
|
||||
* The whole grid is confirmed on a real cabinet: [160, 235] is the center anchor (a
|
||||
* full-board background image lines up exactly with the board panel there), and each grid
|
||||
* step — in both the 3-wide column direction and the 5-tall row direction — is a uniform 96px
|
||||
* from the center.
|
||||
*
|
||||
* Size 1 is the 1.0x baseline. Size 2 was confirmed to change the sticker on a cabinet; 0.6x
|
||||
* (smaller) is the value that suits normal sticker use.
|
||||
*
|
||||
* Rotation is NOT verified yet: the unit sent in `rotate` (degrees assumed) and the step the
|
||||
* official page uses (ROTATE_STEP) are guesses. Change ROTATE_STEP here and in
|
||||
* webui/profile_player_info.pug together if a cabinet shows otherwise.
|
||||
*/
|
||||
export const CENTER_X = 160;
|
||||
export const CENTER_Y = 235;
|
||||
export const GRID_STEP = 96;
|
||||
export const GRID_COLUMNS = 3;
|
||||
export const GRID_ROWS = 5;
|
||||
const COLUMN_OFFSETS = [CENTER_X - GRID_STEP, CENTER_X, CENTER_X + GRID_STEP];
|
||||
const ROW_OFFSETS = [CENTER_Y - 2 * GRID_STEP, CENTER_Y - GRID_STEP, CENTER_Y, CENTER_Y + GRID_STEP, CENTER_Y + 2 * GRID_STEP];
|
||||
const SIZE_SCALE: Record<number, number> = { 1: 1, 2: 0.6 };
|
||||
|
||||
export const MIN_POSITION = 1;
|
||||
export const MAX_POSITION = GRID_COLUMNS * GRID_ROWS; // 15
|
||||
export const DEFAULT_POSITION = 8; // center
|
||||
export const MIN_SIZE = 1;
|
||||
export const MAX_SIZE = 2;
|
||||
export const DEFAULT_SIZE = 1;
|
||||
export const MAX_STICKER_SLOTS = 10;
|
||||
export const ROTATE_STEP = 45;
|
||||
|
||||
/** What the WebUI editor submits. */
|
||||
export interface PickerBoard {
|
||||
sheet: number | null;
|
||||
stickers: PickerSticker[];
|
||||
}
|
||||
|
||||
export interface PickerSticker {
|
||||
id: number;
|
||||
position: number; // 1-15, row-major from the top-left
|
||||
size: number; // 1-2
|
||||
rotate: number; // multiple of ROTATE_STEP, normalized to [0, 360)
|
||||
/**
|
||||
* 0-based UI slot index (0..MAX_STICKER_SLOTS-1). Stored alongside the sticker so that
|
||||
* leaving an earlier slot empty doesn't shift later stickers forward on the next load.
|
||||
*/
|
||||
slot: number;
|
||||
}
|
||||
|
||||
type StoredBoard = NonNullable<PlayerInfo['playerboard']>;
|
||||
type StoredSticker = StoredBoard['sticker'][number];
|
||||
|
||||
export function positionToOffset(position: number): [number, number] {
|
||||
const clamped = Math.min(MAX_POSITION, Math.max(MIN_POSITION, Math.round(position)));
|
||||
const row = Math.floor((clamped - 1) / GRID_COLUMNS);
|
||||
const col = (clamped - 1) % GRID_COLUMNS;
|
||||
return [COLUMN_OFFSETS[col], ROW_OFFSETS[row]];
|
||||
}
|
||||
|
||||
export function sizeToScale(size: number): number {
|
||||
return SIZE_SCALE[size] ?? SIZE_SCALE[DEFAULT_SIZE];
|
||||
}
|
||||
|
||||
export function normalizeRotate(rotate: number): number {
|
||||
const snapped = Math.round(rotate / ROTATE_STEP) * ROTATE_STEP;
|
||||
return ((snapped % 360) + 360) % 360;
|
||||
}
|
||||
|
||||
function isIntegerInRange(value: any, min: number, max: number): boolean {
|
||||
return Number.isInteger(value) && value >= min && value <= max;
|
||||
}
|
||||
|
||||
/** Strict validation of the WebUI payload; anything off-grid is rejected rather than guessed. */
|
||||
export function isValidPickerBoard(value: any): value is PickerBoard {
|
||||
if (value == null || typeof value !== 'object') return false;
|
||||
if (value.sheet !== null && !Number.isInteger(value.sheet)) return false;
|
||||
if (!Array.isArray(value.stickers) || value.stickers.length > MAX_STICKER_SLOTS) return false;
|
||||
|
||||
const slots = new Set<number>();
|
||||
for (const item of value.stickers) {
|
||||
if (
|
||||
item == null ||
|
||||
!Number.isInteger(item.id) || item.id < 0 ||
|
||||
!isIntegerInRange(item.position, MIN_POSITION, MAX_POSITION) ||
|
||||
!isIntegerInRange(item.size, MIN_SIZE, MAX_SIZE) ||
|
||||
!Number.isFinite(item.rotate) ||
|
||||
!isIntegerInRange(item.slot, 0, MAX_STICKER_SLOTS - 1) ||
|
||||
slots.has(item.slot)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
slots.add(item.slot);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Converts the editor's grid/size presets into the stored, wire-shaped playerboard. */
|
||||
export function pickerToPlayerBoard(picker: PickerBoard): StoredBoard {
|
||||
const sticker: StoredSticker[] = [...picker.stickers]
|
||||
.sort((a, b) => a.slot - b.slot)
|
||||
.map(item => {
|
||||
const [x, y] = positionToOffset(item.position);
|
||||
const scale = sizeToScale(item.size);
|
||||
return {
|
||||
id: item.id,
|
||||
pos_x: x,
|
||||
pos_y: y,
|
||||
scale_x: scale,
|
||||
scale_y: scale,
|
||||
rotate: normalizeRotate(item.rotate),
|
||||
slot: item.slot,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
index: 1,
|
||||
is_active: picker.sheet != null || sticker.length > 0,
|
||||
sheet: picker.sheet,
|
||||
sticker,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The wire protocol has no separate field for the background — it is just another sticker.
|
||||
* Confirmed on a real cabinet: a Sheet-kind item placed at the center anchor with scale 1
|
||||
* fills the whole board. It is sent first so stickers layer on top of it.
|
||||
*/
|
||||
export function sheetToSticker(sheetId: number): StoredSticker {
|
||||
return {
|
||||
id: sheetId,
|
||||
pos_x: CENTER_X,
|
||||
pos_y: CENTER_Y,
|
||||
scale_x: 1,
|
||||
scale_y: 1,
|
||||
rotate: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves every stored shape into the ordered sticker list sent to the game:
|
||||
* - current editor: `playerboard.sheet` + grid stickers
|
||||
* - older free-placement editor: `playerboard.sticker` as-is (sticker[0] is the background)
|
||||
* - legacy documents: `sheet` + `card`
|
||||
*/
|
||||
export function getBoardStickers(playerInfo: Partial<PlayerInfo> | null | undefined): {
|
||||
stickers: any[];
|
||||
isActive: boolean;
|
||||
} {
|
||||
const board = playerInfo?.playerboard;
|
||||
if (board && Array.isArray(board.sticker)) {
|
||||
const stickers = board.sheet != null ? [sheetToSticker(board.sheet), ...board.sticker] : board.sticker;
|
||||
const isActive = board.is_active === undefined ? stickers.length > 0 : Boolean(board.is_active);
|
||||
return { stickers, isActive };
|
||||
}
|
||||
|
||||
const legacyCard = Array.isArray(playerInfo?.card) ? playerInfo.card : [];
|
||||
const stickers = [
|
||||
...(playerInfo?.sheet != null ? [sheetToSticker(playerInfo.sheet)] : []),
|
||||
...legacyCard,
|
||||
];
|
||||
return { stickers, isActive: stickers.length > 0 };
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import { PLUGIN_VER } from "../const";
|
||||
|
||||
const DEFAULT_NAME = 'ASPHYXIA-CORE USER';
|
||||
const DEFAULT_TITLE = 'Please edit on WebUI';
|
||||
|
||||
export interface PlayerInfo {
|
||||
collection: 'playerinfo',
|
||||
|
||||
@@ -10,23 +13,31 @@ export interface PlayerInfo {
|
||||
name: string;
|
||||
title: string;
|
||||
|
||||
/** Legacy (pre-playerboard) sticker list. Still read when `playerboard` is absent. */
|
||||
card?: {
|
||||
id: number;
|
||||
position: number[];
|
||||
scale: number[];
|
||||
rotation: number;
|
||||
/** 0-based WebUI slot index. Not sent to the game. */
|
||||
slot?: number;
|
||||
}[];
|
||||
|
||||
/** Legacy background sheet id that accompanied `card`. */
|
||||
sheet?: number;
|
||||
|
||||
/**
|
||||
* Playerboard data returned by gametop.get.
|
||||
* Playerboard data returned by gametop.get, stored wire-shaped.
|
||||
*
|
||||
* `card` is kept for backwards compatibility with older documents. New
|
||||
* edits should use this wire-shaped representation so every playerboard
|
||||
* field can be changed from the WebUI.
|
||||
* Written by the WebUI editor (see models/playerboard.ts): stickers sit on the
|
||||
* fixed 3x5 grid in one of two sizes, the background is kept separately in
|
||||
* `sheet` and sent first. Documents without `sheet` were written by the older
|
||||
* free-placement editor, where sticker[0] is the background.
|
||||
*/
|
||||
playerboard?: {
|
||||
index: number;
|
||||
is_active: boolean;
|
||||
sheet?: number | null;
|
||||
sticker: {
|
||||
id: number;
|
||||
pos_x: number;
|
||||
@@ -34,6 +45,8 @@ export interface PlayerInfo {
|
||||
scale_x: number;
|
||||
scale_y: number;
|
||||
rotate: number;
|
||||
/** 0-based WebUI slot index. Not sent to the game. */
|
||||
slot?: number;
|
||||
}[];
|
||||
};
|
||||
}
|
||||
@@ -44,7 +57,26 @@ export function getDefaultPlayerInfo(version: string, id: number) : PlayerInfo {
|
||||
pluginVer: PLUGIN_VER,
|
||||
id,
|
||||
version,
|
||||
name: 'ASPHYXIA-CORE USER',
|
||||
title: 'Please edit on WebUI',
|
||||
name: DEFAULT_NAME,
|
||||
title: DEFAULT_TITLE,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a playerinfo document from any other version for this refid, so a version
|
||||
* played for the first time can inherit the player's existing name/title instead
|
||||
* of resetting to the default. Prefers a version where the name/title were already
|
||||
* customized over one still sitting on the default placeholder values.
|
||||
*/
|
||||
export async function findInheritablePlayerInfo(refid: string): Promise<PlayerInfo | null> {
|
||||
const infos = await DB.Find<PlayerInfo>(refid, { collection: 'playerinfo' });
|
||||
if (!infos || infos.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Older builds used empty strings as the placeholder, so treat those as defaults too.
|
||||
const isDefaultName = (name?: string) => !name || name === DEFAULT_NAME;
|
||||
const isDefaultTitle = (title?: string) => !title || title === DEFAULT_TITLE;
|
||||
const customized = infos.find(info => !isDefaultName(info.name) || !isDefaultTitle(info.title));
|
||||
return customized ?? infos[0];
|
||||
}
|
||||
|
||||
243
gitadora@asphyxia/webui/css/webui_util.css
Normal file
243
gitadora@asphyxia/webui/css/webui_util.css
Normal file
@@ -0,0 +1,243 @@
|
||||
#tab-content, .tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#tab-content.is-active, .tab-content.is-active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
tr#tab-content.is-active, tr.tab-content.is-active {
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
#tabs li.disabled a {
|
||||
background-color: #c0c0c0;
|
||||
border-color: #c0c0c0;
|
||||
color: #7f7f7f;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#form-pagination ul.pagination-list {
|
||||
margin: 0!important;
|
||||
}
|
||||
.pagination-link, .pagination-next, .pagination-previous {
|
||||
border-color: transparent;
|
||||
transition: .2s linear;
|
||||
}
|
||||
.pagination-next, .pagination-previous {
|
||||
color: #209CEE;
|
||||
}
|
||||
.pagination-next:not([disabled]):hover, .pagination-previous:not([disabled]):hover {
|
||||
color: #118fe4;
|
||||
}
|
||||
/* Set all link color to Asphyxia CORE blue */
|
||||
::selection {
|
||||
color: white;
|
||||
background-color: #209CEE;
|
||||
}
|
||||
a {
|
||||
color: #209CEE;
|
||||
}
|
||||
.tabs.is-toggle li.is-active a {
|
||||
background-color: #209CEE;
|
||||
border-color: #209CEE;
|
||||
}
|
||||
.tabs li.is-active a {
|
||||
color: #209CEE;
|
||||
border-color: #209CEE;
|
||||
}
|
||||
.pagination-link.is-current {
|
||||
background-color: #209CEE;
|
||||
border-color: #209CEE;
|
||||
cursor: default;
|
||||
}
|
||||
.select:not(.is-multiple):not(.is-loading):after {
|
||||
border-color: #209CEE;
|
||||
}
|
||||
.select select:active, .select select:focus {
|
||||
border-color: #209CEE;
|
||||
}
|
||||
.button.is-link {
|
||||
background-color: #209CEE;
|
||||
}
|
||||
.button.is-link.is-active, .button.is-link:active, .button.is-link.is-hovered, .button.is-link:hover {
|
||||
background-color: #118fe4;
|
||||
}
|
||||
.input:active, .input:focus {
|
||||
border-color: #209CEE;
|
||||
}
|
||||
.table tr.is-selected {
|
||||
background-color: #209CEE;
|
||||
}
|
||||
|
||||
#card-content.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
#card-content {
|
||||
display: block;
|
||||
}
|
||||
.marquee-label {
|
||||
display: inline-block;
|
||||
}
|
||||
.marquee-label-container {
|
||||
overflow-x: hidden;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* from Bulma */
|
||||
.button.is-danger.is-light {
|
||||
background-color: #feecf0;
|
||||
color: #cc0f35;
|
||||
}
|
||||
.button.is-link.is-light {
|
||||
background-color: #edf8ff;
|
||||
color: #209CEE;
|
||||
}
|
||||
.button.is-danger.is-light.is-hovered, .button.is-danger.is-light:hover {
|
||||
background-color: #fde0e6;
|
||||
color: #cc0f35;
|
||||
}
|
||||
.button.is-link.is-light.is-hovered, .button.is-link.is-light:hover {
|
||||
background-color: #e0f1fc;
|
||||
color: #209CEE;
|
||||
}
|
||||
.tag.is-link.is-light {
|
||||
background-color: #edf8ff;
|
||||
color: #0D7DC6;
|
||||
}
|
||||
.tag.is-link.is-light:hover {
|
||||
background-color: #209CEE;
|
||||
color: white;
|
||||
}
|
||||
.tag.is-delete:hover {
|
||||
background-color: #FF3860!important;
|
||||
color: white;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
.pagination {
|
||||
flex-wrap: nowrap;
|
||||
justify-content: left;
|
||||
}
|
||||
}
|
||||
.pagination-list {
|
||||
flex-wrap: nowrap;
|
||||
list-style: none!important;
|
||||
margin-top: 0.25em!important;
|
||||
margin-bottom: 0.25em!important;
|
||||
}
|
||||
|
||||
.content li + li {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.one-quarter#forwide, .one-third#forwide {
|
||||
display: block;
|
||||
min-width: 100px;
|
||||
}
|
||||
.one-quarter#fornarrow, .one-third#fornarrow {
|
||||
display: none;
|
||||
min-width: 50px;
|
||||
}
|
||||
@media only screen and (max-width: 1023px) {
|
||||
.one-quarter#forwide {
|
||||
display: none;
|
||||
}
|
||||
.one-quarter#fornarrow {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 700px) {
|
||||
.one-third#forwide {
|
||||
display: none;
|
||||
}
|
||||
.one-third#fornarrow {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@keyframes notification-fadeout {
|
||||
0% {
|
||||
opacity: 1;
|
||||
display: block;
|
||||
}
|
||||
80% {
|
||||
opacity: 1;
|
||||
display: block;
|
||||
}
|
||||
99.99% {
|
||||
opacity: 0;
|
||||
display: block;
|
||||
}
|
||||
100% {
|
||||
opacity: 0;
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.notification {
|
||||
animation: notification-fadeout 8s forwards;
|
||||
animation-play-state: paused;
|
||||
}
|
||||
.notification:hover {
|
||||
animation-play-state: paused;
|
||||
}
|
||||
.modal {
|
||||
padding-bottom: 13px;
|
||||
}
|
||||
@media screen and (max-width:1024px) {
|
||||
.modal {
|
||||
transition: padding-left .2s ease-in-out 50ms;
|
||||
}
|
||||
}
|
||||
@media screen and (min-width:1023px) {
|
||||
.modal {
|
||||
padding-left: 256px;
|
||||
transition: padding-left .2s ease-in-out 50ms;
|
||||
}
|
||||
}
|
||||
.tag {
|
||||
transition: linear .2s;
|
||||
}
|
||||
.tags .tag:not(:last-child) {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.modal table tr {
|
||||
border: solid #dbdbdb;
|
||||
border-width: 0 0 1px;
|
||||
}
|
||||
.modal table tbody tr:last-child {
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
.hidden-wrapper {
|
||||
overflow: hidden;
|
||||
}
|
||||
.hidden-x-wrapper {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.hidden-y-wrapper {
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.scrolling-wrapper {
|
||||
overflow: auto;
|
||||
}
|
||||
.scrolling-x-wrapper {
|
||||
overflow-x: auto;
|
||||
}
|
||||
.scrolling-y-wrapper {
|
||||
overflow-y: auto;
|
||||
}
|
||||
a.pagination-previous {
|
||||
overflow: hidden;
|
||||
}
|
||||
a.pagination-next {
|
||||
overflow: hidden;
|
||||
}
|
||||
.button.checkbox, .button.checkbox .checkmark {
|
||||
transition: linear .2s;
|
||||
}
|
||||
30
gitadora@asphyxia/webui/js/ajax-form.js
Normal file
30
gitadora@asphyxia/webui/js/ajax-form.js
Normal file
@@ -0,0 +1,30 @@
|
||||
(function () {
|
||||
// Generic "submit without navigating" helper. A normal <form method="post" action="/emit/...">
|
||||
// does a full-page POST navigation, which resets our own client-side tab state (see
|
||||
// PLAYERBOARD_DEV_NOTES.md §8) back to defaults — e.g. saving on a non-first version tab makes
|
||||
// the page appear to jump back to a different tab afterwards, looking like the save was lost.
|
||||
// Any form tagged class="ajax-form" gets submitted via fetch() instead, with an optional
|
||||
// [data-role="form-status"] element inside it updated with the result.
|
||||
function bindAjaxForm(form) {
|
||||
if (form.dataset.ajaxBound === "1") return;
|
||||
form.dataset.ajaxBound = "1";
|
||||
|
||||
const statusEl = form.querySelector('[data-role="form-status"]');
|
||||
form.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
if (statusEl) statusEl.textContent = "Saving…";
|
||||
const body = new URLSearchParams(new FormData(form));
|
||||
fetch(form.action, { method: "POST", body })
|
||||
.then(res => {
|
||||
if (statusEl) statusEl.textContent = res.ok ? "Saved." : `Save failed (HTTP ${res.status}).`;
|
||||
})
|
||||
.catch(err => {
|
||||
if (statusEl) statusEl.textContent = "Save failed: " + err;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll("form.ajax-form").forEach(bindAjaxForm);
|
||||
});
|
||||
})();
|
||||
618
gitadora@asphyxia/webui/js/webui_util.js
Normal file
618
gitadora@asphyxia/webui/js/webui_util.js
Normal file
@@ -0,0 +1,618 @@
|
||||
function initializePaginatedContent() {
|
||||
let containers = document.querySelectorAll(".paginated-container")
|
||||
|
||||
for (let container of containers) {
|
||||
let pageSizeInput = container.querySelector("input.page-size")
|
||||
let paginations = container.querySelectorAll(".pagination")
|
||||
let contents = container.querySelectorAll(".paginated-content")
|
||||
let group = container.getAttribute("pagination-group")
|
||||
let flags = { isFirst: true }
|
||||
let refreshEllipsis = (param) => {
|
||||
if (flags.isFirst) return
|
||||
let maxWidth = container.offsetWidth / 2
|
||||
for (let pagination of paginations) {
|
||||
let buttons = pagination.querySelector("ul.pagination-list")
|
||||
if (buttons.childElementCount == 0) return
|
||||
let show = (index) => buttons.querySelector("li[tab-index=\"" + index + "\"]").style.display = "block"
|
||||
let hide = (index) => buttons.querySelector("li[tab-index=\"" + index + "\"]").style.display = "none"
|
||||
let previousButton = pagination.querySelector("a.pagination-previous")
|
||||
let nextButton = pagination.querySelector("a.pagination-next")
|
||||
let leftEllipsis = buttons.querySelector("li.ellipsis-left")
|
||||
let rightEllipsis = buttons.querySelector("li.ellipsis-right")
|
||||
let width = buttons.firstChild.offsetWidth.toString()
|
||||
leftEllipsis.style.width = width + "px"
|
||||
rightEllipsis.style.width = width + "px"
|
||||
let count = buttons.childElementCount - 2
|
||||
let maxButtonCount = Math.max((buttons.firstChild.offsetWidth == 0) ? 5 : Math.trunc(maxWidth / buttons.firstChild.offsetWidth), 5)
|
||||
let current = (param instanceof HTMLElement) ? param : buttons.querySelector("li.is-active")
|
||||
let index = parseInt((current == null) ? 0 : current.getAttribute("tab-index"))
|
||||
if (index == 0) previousButton.setAttribute("disabled", "")
|
||||
else previousButton.removeAttribute("disabled")
|
||||
if (index == (count - 1)) nextButton.setAttribute("disabled", "")
|
||||
else nextButton.removeAttribute("disabled")
|
||||
if (count <= maxButtonCount) {
|
||||
for (let i = 0; i < count; i++) buttons.querySelector("li[tab-index=\"" + i + "\"]").style.display = "block"
|
||||
leftEllipsis.style.display = "none"
|
||||
rightEllipsis.style.display = "none"
|
||||
} else {
|
||||
maxButtonCount = Math.trunc((maxButtonCount - 1) / 2) * 2 + 1
|
||||
let maxSurroundingButtonCount = (maxButtonCount - 5) / 2
|
||||
let maxNoEllipsisIndex = maxButtonCount - 2 - maxSurroundingButtonCount - 1
|
||||
|
||||
if (index <= maxNoEllipsisIndex) {
|
||||
for (let i = 0; i <= (maxNoEllipsisIndex + maxSurroundingButtonCount); i++) show(i)
|
||||
for (let i = (maxNoEllipsisIndex + maxSurroundingButtonCount) + 1; i < count - 1; i++) hide(i)
|
||||
show(count - 1)
|
||||
leftEllipsis.style.display = "none"
|
||||
rightEllipsis.style.display = "block"
|
||||
} else if (index >= (count - maxNoEllipsisIndex - 1)) {
|
||||
for (let i = 1; i < (count - maxNoEllipsisIndex - maxSurroundingButtonCount - 1); i++) hide(i)
|
||||
for (let i = (count - maxNoEllipsisIndex - maxSurroundingButtonCount - 1); i < count; i++) show(i)
|
||||
show(0)
|
||||
leftEllipsis.style.display = "block"
|
||||
rightEllipsis.style.display = "none"
|
||||
} else {
|
||||
for (let i = 1; i < (index - maxSurroundingButtonCount); i++) hide(i)
|
||||
for (let i = (index - maxSurroundingButtonCount); i <= (index + maxSurroundingButtonCount); i++) show(i)
|
||||
for (let i = (index + maxSurroundingButtonCount) + 1; i < count - 1; i++) hide(i)
|
||||
show(0)
|
||||
show(count - 1)
|
||||
leftEllipsis.style.display = "block"
|
||||
rightEllipsis.style.display = "block"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let refresh = () => {
|
||||
if ((pageSizeInput == null) || (parseInt(pageSizeInput.value) <= 0)) {
|
||||
for (let pagination of paginations) pagination.style.display = "none"
|
||||
return
|
||||
}
|
||||
let pageSize = parseInt(pageSizeInput.value)
|
||||
let pageCount = Math.ceil(contents.length / pageSize)
|
||||
if (!flags.isFirst && (flags.pageSize == pageSize) && (flags.pageCount == pageCount)) return
|
||||
for (let pagination of paginations) {
|
||||
let buttons = pagination.querySelector("ul.pagination-list")
|
||||
buttons.innerHTML = ""
|
||||
buttons.id = "tabs"
|
||||
}
|
||||
for (let i = 0; i < pageCount; i++) {
|
||||
for (let j = i * pageSize; j < (i + 1) * pageSize; j++) {
|
||||
if (contents[j] == null) break
|
||||
contents[j].classList.add("tab-content")
|
||||
contents[j].setAttribute("tab-group", group)
|
||||
contents[j].setAttribute("tab-index", i)
|
||||
if ((i == 0) && (flags.isFirst || (flags.pageCount != pageCount))) contents[j].classList.add("is-active")
|
||||
if (j == ((i + 1) * pageSize - 1)) for (let td of contents[j].querySelectorAll("td")) td.style.borderBottom = "0"
|
||||
}
|
||||
if (pageCount > 1) for (let pagination of paginations) {
|
||||
let buttons = pagination.querySelector("ul.pagination-list")
|
||||
let a = document.createElement("a")
|
||||
a.classList.add("pagination-link")
|
||||
a.innerText = i + 1
|
||||
let li = document.createElement("li")
|
||||
li.appendChild(a)
|
||||
if ((i == 0) && (flags.isFirst || (flags.pageCount != pageCount))) {
|
||||
li.classList.add("is-active")
|
||||
a.classList.add("is-current")
|
||||
}
|
||||
li.setAttribute("tab-group", group)
|
||||
li.setAttribute("tab-index", i)
|
||||
buttons.appendChild(li)
|
||||
li.addEventListener("click", () => {
|
||||
refreshEllipsis(li)
|
||||
})
|
||||
}
|
||||
}
|
||||
if (pageCount > 1) for (let pagination of paginations) {
|
||||
pagination.style.display = "flex"
|
||||
let buttons = pagination.querySelector("ul.pagination-list")
|
||||
let leftEllipsis = document.createElement("li")
|
||||
leftEllipsis.style.display = "none"
|
||||
leftEllipsis.classList.add("ellipsis-left", "ignore")
|
||||
leftEllipsis.innerHTML = "<span class=\"pagination-ellipsis\">…</span>"
|
||||
let rightEllipsis = document.createElement("li")
|
||||
rightEllipsis.style.display = "none"
|
||||
rightEllipsis.classList.add("ellipsis-right", "ignore")
|
||||
rightEllipsis.innerHTML = "<span class=\"pagination-ellipsis\">…</span>"
|
||||
buttons.firstChild.after(leftEllipsis)
|
||||
buttons.lastChild.before(rightEllipsis)
|
||||
|
||||
let previousButton = pagination.querySelector("a.pagination-previous")
|
||||
let nextButton = pagination.querySelector("a.pagination-next")
|
||||
previousButton.addEventListener("click", () => {
|
||||
let current = buttons.querySelector("li.is-active")
|
||||
let index = parseInt(current.getAttribute("tab-index"))
|
||||
if (index <= 0) return
|
||||
let prev = buttons.querySelector("li[tab-index=\"" + (index - 1) + "\"]")
|
||||
prev.dispatchEvent(new Event("click"))
|
||||
})
|
||||
nextButton.addEventListener("click", () => {
|
||||
let current = buttons.querySelector("li.is-active")
|
||||
let index = parseInt(current.getAttribute("tab-index"))
|
||||
if (index >= (buttons.childElementCount - 3)) return // includes left & right ellipsis
|
||||
let next = buttons.querySelector("li[tab-index=\"" + (index + 1) + "\"]")
|
||||
next.dispatchEvent(new Event("click"))
|
||||
})
|
||||
} else for (let pagination of paginations) pagination.style.display = "none"
|
||||
flags.pageCount = pageCount
|
||||
flags.pageSize = pageSize
|
||||
flags.isFirst = false
|
||||
}
|
||||
refresh()
|
||||
pageSizeInput.addEventListener("change", refresh)
|
||||
let o = new ResizeObserver(refreshEllipsis)
|
||||
o.observe(container)
|
||||
}
|
||||
}
|
||||
|
||||
function initializeTabs() {
|
||||
let tabs = document.querySelectorAll("#tabs li")
|
||||
let tabContents = document.querySelectorAll("#tab-content, .tab-content")
|
||||
let updateActiveTab = (tabGroup, tabIndex) => {
|
||||
for (let t of tabs) if (t && (t.getAttribute("tab-group") == tabGroup)) {
|
||||
if (t.getAttribute("tab-index") != tabIndex) {
|
||||
t.classList.remove("is-active")
|
||||
for (let a of t.querySelectorAll("a")) a.classList.remove("is-current")
|
||||
} else {
|
||||
t.classList.add("is-active")
|
||||
for (let a of t.querySelectorAll("a")) a.classList.add("is-current")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let updateActiveContent = (tabGroup, tabIndex) => {
|
||||
for (let item of tabContents) {
|
||||
let group = item.getAttribute("tab-group")
|
||||
let index = item.getAttribute("tab-index")
|
||||
if (item && (group == tabGroup)) item.classList.remove("is-active")
|
||||
if ((index == tabIndex) && (group == tabGroup)) item.classList.add("is-active")
|
||||
}
|
||||
}
|
||||
for (let t of tabs) {
|
||||
if (!t.classList.contains("disabled") && !t.classList.contains("ignore")) t.addEventListener("click", () => {
|
||||
let group = t.getAttribute("tab-group")
|
||||
let index = t.getAttribute("tab-index")
|
||||
updateActiveTab(group, index)
|
||||
updateActiveContent(group, index)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initializeToggles() {
|
||||
let toggles = document.querySelectorAll(".card-header .card-toggle")
|
||||
let contents = document.querySelectorAll(".card-content")
|
||||
|
||||
for (let t of toggles) {
|
||||
let card = t.getAttribute("card")
|
||||
if (card == null) continue
|
||||
let cc = []
|
||||
for (let c of contents) if (c.getAttribute("card") == card) cc.push(c)
|
||||
t.style.transition = "0.2s linear"
|
||||
t.addEventListener("click", (e) => {
|
||||
if (e.currentTarget.style.transform == "rotate(180deg)") {
|
||||
e.currentTarget.style.transform = ""
|
||||
for (let c of cc) c.classList.remove("is-hidden")
|
||||
} else {
|
||||
e.currentTarget.style.transform = "rotate(180deg)"
|
||||
for (let c of cc) c.classList.add("is-hidden")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initializeModals() {
|
||||
let modaltriggers = $(".modal-trigger")
|
||||
for (let t of modaltriggers) {
|
||||
let m = t.querySelector(".modal")
|
||||
let c = m.querySelectorAll("#close")
|
||||
t.addEventListener("click", (e) => { m.style.display = "flex" })
|
||||
for (let v of c) v.addEventListener("click", (e) => {
|
||||
m.style.display = "none"
|
||||
e.stopPropagation()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFormSelects() {
|
||||
let formSelects = document.querySelectorAll("#form-select")
|
||||
for (let s of formSelects) {
|
||||
let input = s.querySelector("input#form-select-input")
|
||||
let select = s.querySelector("select#form-select-select")
|
||||
let options = select.querySelectorAll("option")
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
let o = options[i]
|
||||
let value = (o.getAttribute("value") == null) ? i : o.getAttribute("value")
|
||||
let enabled = (o.getAttribute("disabled") == null) ? true : false
|
||||
if (value == input.value) select.selectedIndex = i
|
||||
if (!enabled) o.style.display = "none"
|
||||
}
|
||||
select.addEventListener("change", () => {
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
let o = options[i]
|
||||
if (o.selected) {
|
||||
input.value = (o.getAttribute("value") == null) ? i : o.getAttribute("value")
|
||||
input.dispatchEvent(new Event("change"))
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFormPaginations() {
|
||||
let formPags = document.querySelectorAll("#form-pagination")
|
||||
for (let p of formPags) {
|
||||
let input = p.querySelector("input#form-pagination-input")
|
||||
let options = p.querySelectorAll("ul.pagination-list li a.pagination-link")
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
let o = options[i]
|
||||
let value = (o.getAttribute("value") == null) ? i : o.getAttribute("value")
|
||||
if (value == input.value) {
|
||||
if (!o.classList.contains("is-current")) o.classList.add("is-current")
|
||||
} else o.classList.remove("is-current")
|
||||
o.addEventListener("click", () => {
|
||||
for (let i = 0; i < options.length; i++) options[i].classList.remove("is-current")
|
||||
if (!o.classList.contains("is-current")) o.classList.add("is-current")
|
||||
input.value = (o.getAttribute("value") == null) ? i : o.getAttribute("value")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFormValidation() {
|
||||
let forms = document.querySelectorAll("form#validatable")
|
||||
for (let f of forms) {
|
||||
let validatableFields = f.querySelectorAll(".field#validatable")
|
||||
let validatableButtons = f.querySelectorAll("button#validatable")
|
||||
|
||||
let getParams = (input) => {
|
||||
return {
|
||||
minLength: input.getAttribute("min-length"),
|
||||
maxLength: input.getAttribute("max-length"),
|
||||
recommendedLength: input.getAttribute("recommended-length"),
|
||||
minPattern: input.getAttribute("min-pattern"),
|
||||
recommendedPattern: input.getAttribute("recommended-pattern"),
|
||||
isNumeric: (input.getAttribute("numeric") != null) ? true : false
|
||||
}
|
||||
}
|
||||
let isValid = (value, params) => {
|
||||
let t = value.trim()
|
||||
if (params.minLength != null) if (t.length < parseInt(params.minLength)) return false
|
||||
if (params.maxLength != null) if (t.length > parseInt(params.maxLength)) return false
|
||||
if (params.minPattern != null) if (!(new RegExp(params.minPattern).test(t))) return false
|
||||
if (params.isNumeric == true) if (parseInt(t).toString() != t) return false
|
||||
return true
|
||||
}
|
||||
|
||||
let isFormValid = () => {
|
||||
for (let field of validatableFields) for (let i of field.querySelectorAll("input#validatable")) if (!isValid(i.value, getParams(i))) return false
|
||||
return true
|
||||
}
|
||||
|
||||
for (let field of validatableFields) {
|
||||
let inputs = field.querySelectorAll("input#validatable")
|
||||
let tips = field.querySelectorAll(".help")
|
||||
for (let i of inputs) i.addEventListener("change", () => {
|
||||
let params = getParams(i)
|
||||
// inputs
|
||||
if (isValid(i.value, params)) {
|
||||
i.classList.remove("is-danger")
|
||||
for (let t of tips) t.classList.remove("is-danger")
|
||||
} else if (!i.classList.contains("is-danger")) {
|
||||
i.classList.add("is-danger")
|
||||
for (let t of tips) t.classList.add("is-danger")
|
||||
}
|
||||
// buttons
|
||||
if (isFormValid()) {
|
||||
for (let b of validatableButtons) b.removeAttribute("disabled")
|
||||
} else {
|
||||
for (let b of validatableButtons) if (b.getAttribute("disabled") == null) b.setAttribute("disabled", "")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFormCollections() {
|
||||
let collections = document.querySelectorAll("#form-collection")
|
||||
for (let c of collections) {
|
||||
let maxLength = parseInt(c.getAttribute("max-length"))
|
||||
let fallbackValue = JSON.parse(c.getAttribute("fallback"))
|
||||
let input = c.querySelector("#form-collection-input")
|
||||
let tags = c.querySelectorAll("#form-collection-tag")
|
||||
let modButton = c.querySelector("#form-collection-modify")
|
||||
let modTable = c.querySelector("table#multi-select")
|
||||
let modInput = modTable.querySelector("input#multi-select-input")
|
||||
let modTitle = modTable.querySelector("input#multi-select-title")
|
||||
let deleteButtonClickEventListener = (tag) => () => {
|
||||
let tvalue = JSON.parse(tag.getAttribute("value"))
|
||||
let value = JSON.parse(input.value)
|
||||
value.splice(value.indexOf(tvalue), 1)
|
||||
if (fallbackValue != null) value.push(fallbackValue)
|
||||
input.value = JSON.stringify(value)
|
||||
modInput.value = input.value
|
||||
modInput.dispatchEvent(new Event("change"))
|
||||
tag.remove()
|
||||
}
|
||||
|
||||
for (let t of tags) {
|
||||
let d = t.querySelector(".delete, .is-delete")
|
||||
d.addEventListener("click", deleteButtonClickEventListener(t))
|
||||
}
|
||||
modInput.value = input.value
|
||||
modInput.setAttribute("max-length", maxLength)
|
||||
modInput.setAttribute("fallback", JSON.stringify(fallbackValue))
|
||||
modInput.addEventListener("change", () => {
|
||||
let fallbackValue = JSON.parse(c.getAttribute("fallback"))
|
||||
let oldValue = JSON.parse(input.value)
|
||||
let newValue = JSON.parse(modInput.value)
|
||||
let tags = c.querySelectorAll("#form-collection-tag")
|
||||
for (let o of oldValue) if (!newValue.includes(o) && (o != fallbackValue)) {
|
||||
for (let t of tags) if (JSON.parse(t.getAttribute("value")) == o) t.remove()
|
||||
}
|
||||
for (let n = 0; n < newValue.length; n++) if (!oldValue.includes(newValue[n]) && (newValue[n] != fallbackValue)) {
|
||||
let tag = document.createElement("div")
|
||||
tag.classList.add("control")
|
||||
tag.id = "form-collection-tag"
|
||||
tag.setAttribute("value", newValue[n])
|
||||
tag.innerHTML = "<span class=\"tags has-addons\"><span class=\"tag is-link is-light\" id=\"form-collection-tag-title\">" + JSON.parse(modTitle.value)[n] + "</span><a class=\"tag is-delete\" /></span>"
|
||||
tag.querySelector("a.is-delete").addEventListener("click", deleteButtonClickEventListener(tag))
|
||||
modButton.before(tag)
|
||||
}
|
||||
input.value = modInput.value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initializeMultiSelectTables() {
|
||||
let tables = document.querySelectorAll("table#multi-select")
|
||||
for (let table of tables) {
|
||||
let valueInput = table.querySelector("input#multi-select-input")
|
||||
let titleInput = table.querySelector("input#multi-select-title")
|
||||
let trimValues = (values, fallback) => {
|
||||
while (values.includes(fallback)) values.splice(values.indexOf(fallback), 1)
|
||||
return values
|
||||
}
|
||||
let fillValues = (values, fallback) => {
|
||||
let maxLength = (valueInput.getAttribute("max-length") == null) ? -1 : parseInt(valueInput.getAttribute("max-length"))
|
||||
while (values.length < maxLength) values.push(fallback)
|
||||
return values
|
||||
}
|
||||
let lines = table.querySelectorAll("tbody tr")
|
||||
let refresh = () => {
|
||||
let fallbackValue = JSON.parse(valueInput.getAttribute("fallback"))
|
||||
let value = trimValues(JSON.parse(valueInput.value), fallbackValue)
|
||||
let title = []
|
||||
for (let l of lines) {
|
||||
let lvalue = JSON.parse(l.getAttribute("multi-select-value"))
|
||||
if (value.includes(lvalue)) {
|
||||
if (!l.classList.contains("is-selected")) l.classList.add("is-selected")
|
||||
title[value.indexOf(lvalue)] = l.getAttribute("multi-select-title")
|
||||
l.style.fontWeight = "bold"
|
||||
} else {
|
||||
l.classList.remove("is-selected")
|
||||
l.style.fontWeight = ""
|
||||
}
|
||||
}
|
||||
titleInput.value = JSON.stringify(title)
|
||||
}
|
||||
|
||||
for (let l of lines) {
|
||||
l.onclick = () => {
|
||||
let fallbackValue = JSON.parse(valueInput.getAttribute("fallback"))
|
||||
let maxLength = (valueInput.getAttribute("max-length") == null) ? -1 : parseInt(valueInput.getAttribute("max-length"))
|
||||
let value = trimValues(JSON.parse(valueInput.value), fallbackValue)
|
||||
let lvalue = JSON.parse(l.getAttribute("multi-select-value"))
|
||||
if (value.includes(lvalue)) value.splice(value.indexOf(lvalue), 1)
|
||||
else if (maxLength >= 0) {
|
||||
if (value.length < maxLength) value.push(lvalue)
|
||||
else alert("Cannot add more items, items are up to " + maxLength + ".")
|
||||
} else value.push(lvalue)
|
||||
valueInput.value = JSON.stringify(fillValues(value, fallbackValue))
|
||||
refresh()
|
||||
valueInput.dispatchEvent(new Event("change"))
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
valueInput.addEventListener("change", refresh)
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFormNumerics() {
|
||||
let numerics = document.querySelectorAll("#form-numeric")
|
||||
for (let n of numerics) {
|
||||
let add = n.querySelector("#form-numeric-add")
|
||||
let sub = n.querySelector("#form-numeric-sub")
|
||||
let inputs = n.querySelectorAll("#form-numeric-input")
|
||||
add.addEventListener("click", (e) => {
|
||||
for (let i of inputs) {
|
||||
let maxValue = parseFloat(i.getAttribute("max-value"))
|
||||
let step = parseFloat(i.getAttribute("step"))
|
||||
|
||||
let digitCount = (i.getAttribute("digit-count") == null) ? -1 : parseInt(i.getAttribute("digit-count"))
|
||||
let value = (parseFloat(i.value) * 10 + step * 10) / 10
|
||||
if (value * Math.sign(step) <= maxValue * Math.sign(step)) i.value = (digitCount >= 0) ? value.toFixed(digitCount) : value
|
||||
}
|
||||
e.stopPropagation()
|
||||
})
|
||||
sub.addEventListener("click", (e) => {
|
||||
for (let i of inputs) {
|
||||
let minValue = parseFloat(i.getAttribute("min-value"))
|
||||
let step = parseFloat(i.getAttribute("step"))
|
||||
let digitCount = (i.getAttribute("digit-count") == null) ? -1 : parseInt(i.getAttribute("digit-count"))
|
||||
let value = (parseFloat(i.value) * 10 - step * 10) / 10
|
||||
if (value * Math.sign(step) >= minValue * Math.sign(step)) i.value = (digitCount >= 0) ? value.toFixed(digitCount) : value
|
||||
}
|
||||
e.stopPropagation()
|
||||
})
|
||||
for (let i of inputs) {
|
||||
let digitCount = (i.getAttribute("digit-count") == null) ? -1 : parseInt(i.getAttribute("digit-count"))
|
||||
let value = parseFloat(i.value)
|
||||
i.value = (digitCount >= 0) ? value.toFixed(digitCount) : value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeUploader() {
|
||||
let uploaders = document.querySelectorAll("div#uploader")
|
||||
for (let uploader of uploaders) {
|
||||
let input = uploader.querySelector("input#uploader-input")
|
||||
let text = uploader.querySelector("input#uploader-text")
|
||||
let placeholder = uploader.querySelector("#uploader-placeholder")
|
||||
let remove = uploader.querySelector("#uploader-delete")
|
||||
let reader = new FileReader()
|
||||
input.addEventListener("change", () => {
|
||||
if (input.files.length > 0) {
|
||||
remove.style.display = "block"
|
||||
placeholder.innerText = input.files[0].name
|
||||
reader.readAsText(input.files[0])
|
||||
reader.onload = () => text.value = reader.result
|
||||
} else {
|
||||
placeholder.innerText = ""
|
||||
remove.style.display = "none"
|
||||
text.value = null
|
||||
}
|
||||
})
|
||||
remove.addEventListener("click", (e) => {
|
||||
e.stopPropagation()
|
||||
input.value = null
|
||||
input.dispatchEvent(new Event("change"))
|
||||
})
|
||||
|
||||
remove.style.display = "none"
|
||||
}
|
||||
}
|
||||
|
||||
function checkImg() {
|
||||
let imgs = document.querySelectorAll("#exist-or-not")
|
||||
for (let img of imgs) {
|
||||
let general = img.querySelector("img#general")
|
||||
let specified = img.querySelector("img#specified")
|
||||
|
||||
if (specified.width == 0) specified.style.display = "none"
|
||||
else general.style.display = "none"
|
||||
}
|
||||
}
|
||||
|
||||
function initializeMarqueeLabels() {
|
||||
let marqueeContainers = document.querySelectorAll(".marquee-label-container")
|
||||
for (let c of marqueeContainers) {
|
||||
let marquees = c.querySelectorAll(".marquee-label")
|
||||
for (let marquee of marquees) {
|
||||
if (marquee.closest(".marquee-label-container") != c) continue
|
||||
let refresh = () => {
|
||||
let lpad = parseInt(window.getComputedStyle(c, null).getPropertyValue("padding-left"))
|
||||
if (lpad == NaN) lpad = 0
|
||||
let rpad = parseInt(window.getComputedStyle(c, null).getPropertyValue("padding-right"))
|
||||
if (rpad == NaN) rpad = 20
|
||||
let hpad = lpad + rpad
|
||||
let speed = marquee.getAttribute("speed")
|
||||
if (speed == null) speed = 1
|
||||
let stopingTime = 0.5
|
||||
let duration = (20 * (marquee.offsetWidth - c.offsetWidth + hpad)) / speed + 2 * stopingTime
|
||||
if ((marquee.offsetWidth > 0) && (marquee.offsetWidth > c.offsetWidth - hpad)) {
|
||||
marquee.animate([
|
||||
{ transform: "translateX(0)", offset: 0 },
|
||||
{ transform: "translateX(0)", easing: "cubic-bezier(0.67, 0, 0.33, 1)", offset: stopingTime / duration },
|
||||
{ transform: "translateX(" + (c.offsetWidth - marquee.offsetWidth - hpad) + "px)", easing: "cubic-bezier(0.67, 0, 0.33, 1)", offset: 1 - stopingTime / duration },
|
||||
{ transform: "translateX(" + (c.offsetWidth - marquee.offsetWidth - hpad) + "px)", offset: 1 }
|
||||
], { duration: (20 * (marquee.offsetWidth - c.offsetWidth) + 1000) / speed, direction: "alternate-reverse", iterations: Infinity })
|
||||
} else marquee.style.animation = "none"
|
||||
}
|
||||
let o = new ResizeObserver(refresh)
|
||||
o.observe(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeNotificatioAnimation() {
|
||||
let notifications = document.querySelectorAll(".notification.temporary")
|
||||
for (let n of notifications) {
|
||||
let remove = n.querySelector(".delete")
|
||||
let startSubmitter = n.querySelector("form.start")
|
||||
let startPath = startSubmitter.getAttribute("action")
|
||||
let startRequest = new XMLHttpRequest()
|
||||
startRequest.open("POST", startPath, true)
|
||||
startRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
|
||||
|
||||
let endSubmitter = n.querySelector("form.end")
|
||||
let endPath = startSubmitter.getAttribute("action")
|
||||
let endRequest = new XMLHttpRequest()
|
||||
endRequest.open("POST", endPath, true)
|
||||
endRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
|
||||
|
||||
if (startSubmitter != null) startRequest.send()
|
||||
let end = () => {
|
||||
n.style.display = "none"
|
||||
if (endSubmitter != null) endRequest.send()
|
||||
}
|
||||
|
||||
n.style.animationPlayState = "running"
|
||||
remove.addEventListener("click", end)
|
||||
n.addEventListener("animationend", end)
|
||||
n.addEventListener("webkitAnimationEnd", end)
|
||||
}
|
||||
}
|
||||
|
||||
function initializeCheckBoxes() {
|
||||
let checks = document.querySelectorAll(".checkbox")
|
||||
for (let c of checks) {
|
||||
let input = c.querySelector("input[type=checkbox]")
|
||||
let mark = c.querySelector(".checkmark")
|
||||
let refresh = (value) => {
|
||||
value = input.getAttribute("checked")
|
||||
if (value == null) {
|
||||
input.removeAttribute("checked")
|
||||
mark.style.opacity = 0
|
||||
if (!c.classList.contains("is-light")) c.classList.add("is-light")
|
||||
} else {
|
||||
input.setAttribute("checked", "checked")
|
||||
mark.style.opacity = 100
|
||||
c.classList.remove("is-light")
|
||||
}
|
||||
}
|
||||
c.addEventListener("click", () => {
|
||||
let value = input.getAttribute("checked")
|
||||
if (value == null) input.setAttribute("checked", "checked")
|
||||
else input.removeAttribute("checked")
|
||||
refresh()
|
||||
})
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
function removeLoadingModal() {
|
||||
let loading = document.querySelector(".loading")
|
||||
setTimeout(() => (loading == null) ? null : loading.remove(), 505)
|
||||
try {
|
||||
let a = loading.animate([
|
||||
{ offset: 0, opacity: 1 },
|
||||
{ offset: 0.25, opacity: 0 },
|
||||
{ offset: 1, opacity: 0 }
|
||||
], { duration: 2000 })
|
||||
a.onfinish = loading.remove
|
||||
a.play()
|
||||
} catch { }
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
initializeNotificatioAnimation()
|
||||
initializePaginatedContent()
|
||||
initializeTabs()
|
||||
initializeToggles()
|
||||
initializeModals()
|
||||
initializeFormSelects()
|
||||
initializeFormNumerics()
|
||||
initializeFormPaginations()
|
||||
initializeFormValidation()
|
||||
initializeFormCollections()
|
||||
initializeMultiSelectTables()
|
||||
initializeUploader()
|
||||
checkImg()
|
||||
initializeMarqueeLabels()
|
||||
initializeCheckBoxes()
|
||||
|
||||
removeLoadingModal()
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getFullGameVersion(shortVer) {
|
||||
switch (shortVer) {
|
||||
case "re" :
|
||||
@@ -33,7 +33,7 @@
|
||||
return "GALAXY WAVE"
|
||||
case "galaxywave_delta":
|
||||
return "GALAXY WAVE DELTA"
|
||||
default:
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
@@ -41,20 +41,6 @@
|
||||
const versions = ["re", "matixx", "exchain", "nextage", "highvoltage", "fuzzup", "galaxywave", "galaxywave_delta"]
|
||||
const games = ["gf", "dm"]
|
||||
|
||||
function generateLeaderboards(infos, profiles) {
|
||||
let result = []
|
||||
|
||||
for (const version of versions) {
|
||||
for (const game of games) {
|
||||
result.push(generateLeaderboard(infos, profiles, version, game))
|
||||
}
|
||||
}
|
||||
|
||||
// Hide versions and games with no entries
|
||||
result = result.filter((e) => e.entries.length > 0)
|
||||
return result
|
||||
}
|
||||
|
||||
function generateLeaderboard(infos, profiles, version, game) {
|
||||
let entries = []
|
||||
let idx = 1
|
||||
@@ -73,35 +59,80 @@
|
||||
clear_diff: profile.clear_diff / 100
|
||||
}
|
||||
entries.push(scoreData)
|
||||
idx++
|
||||
idx++
|
||||
}
|
||||
|
||||
let result = {
|
||||
return {
|
||||
version: version,
|
||||
game: game,
|
||||
entries: entries
|
||||
}
|
||||
}
|
||||
|
||||
// Group leaderboards by version first, then by game (GuitarFreaks / DrumMania) within each version.
|
||||
// Versions/games with no entries are omitted entirely.
|
||||
function generateLeaderboardsByVersion(infos, profiles) {
|
||||
let result = []
|
||||
|
||||
for (const version of versions) {
|
||||
let gameBoards = []
|
||||
for (const game of games) {
|
||||
const board = generateLeaderboard(infos, profiles, version, game)
|
||||
if (board.entries.length > 0) gameBoards.push(board)
|
||||
}
|
||||
if (gameBoards.length > 0) {
|
||||
result.push({ version, games: gameBoards })
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
-
|
||||
const versionGroups = generateLeaderboardsByVersion(infos, profiles)
|
||||
|
||||
each board in generateLeaderboards(infos, profiles)
|
||||
h3 #{getFullGameName(board.game)} #{getFullGameVersion(board.version)}
|
||||
mixin leaderboardTable(entries)
|
||||
table
|
||||
tr
|
||||
th Rank
|
||||
th Name
|
||||
th Skill
|
||||
tr
|
||||
th Rank
|
||||
th Name
|
||||
th Skill
|
||||
th All Skill
|
||||
th Songs Cleared
|
||||
th Hardest Clear
|
||||
each e in board.entries
|
||||
tr
|
||||
each e in entries
|
||||
tr
|
||||
td #{e.rank}
|
||||
td #{e.name}
|
||||
td #{e.skill}
|
||||
td #{e.all_skill}
|
||||
td #{e.clear_music_num}
|
||||
td #{e.clear_diff}
|
||||
|
||||
|
||||
link(rel="stylesheet", href="static/css/webui_util.css", type="text/css")
|
||||
script(src = "static/js/webui_util.js")
|
||||
|
||||
if versionGroups.length == 0
|
||||
p.has-text-grey No leaderboard data available yet.
|
||||
else
|
||||
.tabs.is-toggle.is-toggle-rounded.is-small#tabs
|
||||
ul
|
||||
each vg, vIdx in versionGroups
|
||||
li(tab-group="leaderboard-version", tab-index=vIdx, class=(vIdx == 0) ? "is-active" : "")
|
||||
a #{getFullGameVersion(vg.version)}
|
||||
|
||||
each vg, vIdx in versionGroups
|
||||
#tab-content(tab-group="leaderboard-version", tab-index=vIdx, class=(vIdx == 0) ? "is-active" : "")
|
||||
if vg.games.length > 1
|
||||
.tabs#tabs
|
||||
ul
|
||||
each board, gIdx in vg.games
|
||||
li(tab-group=("leaderboard-game-" + vg.version), tab-index=gIdx, class=(gIdx == 0) ? "is-active" : "")
|
||||
a #{getFullGameName(board.game)}
|
||||
each board, gIdx in vg.games
|
||||
#tab-content(tab-group=("leaderboard-game-" + vg.version), tab-index=gIdx, class=(gIdx == 0) ? "is-active" : "")
|
||||
+leaderboardTable(board.entries)
|
||||
else
|
||||
each board in vg.games
|
||||
h4 #{getFullGameName(board.game)}
|
||||
+leaderboardTable(board.entries)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user