mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2025-10-28 20:45:35 -05:00
v1.198.1
This commit is contained in:
165
js/dmscreen/dmscreen-panels.js
Normal file
165
js/dmscreen/dmscreen-panels.js
Normal file
@@ -0,0 +1,165 @@
|
||||
import {
|
||||
PANEL_TYP_INITIATIVE_TRACKER, PANEL_TYP_INITIATIVE_TRACKER_CREATURE_VIEWER,
|
||||
PANEL_TYP_INITIATIVE_TRACKER_PLAYER_V0,
|
||||
PANEL_TYP_INITIATIVE_TRACKER_PLAYER_V1,
|
||||
} from "./dmscreen-consts.js";
|
||||
import {InitiativeTracker} from "./initiativetracker/dmscreen-initiativetracker.js";
|
||||
import {InitiativeTrackerPlayerV0, InitiativeTrackerPlayerV1} from "./dmscreen-playerinitiativetracker.js";
|
||||
import {InitiativeTrackerCreatureViewer} from "./dmscreen-initiativetrackercreatureviewer.js";
|
||||
|
||||
export class PanelContentManagerFactory {
|
||||
static _PANEL_TYPES = {};
|
||||
|
||||
static registerPanelType ({panelType, Cls}) {
|
||||
this._PANEL_TYPES[panelType] = Cls;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static async pFromSavedState ({board, saved, ixTab, panel}) {
|
||||
if (!this._PANEL_TYPES[saved.t]) return undefined;
|
||||
|
||||
const ContentManager = new this._PANEL_TYPES[saved.t]({board, panel});
|
||||
await ContentManager.pLoadState({ixTab, saved});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static getSaveableContent (
|
||||
{
|
||||
type,
|
||||
toSaveTitle,
|
||||
$content,
|
||||
},
|
||||
) {
|
||||
if (!this._PANEL_TYPES[type]) return undefined;
|
||||
|
||||
return this._PANEL_TYPES[type]
|
||||
.getSaveableContent({
|
||||
type,
|
||||
toSaveTitle,
|
||||
$content,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
class _PanelContentManager {
|
||||
static _PANEL_TYPE = null;
|
||||
static _TITLE = null;
|
||||
static _IS_STATELESS = false;
|
||||
|
||||
static _register () {
|
||||
PanelContentManagerFactory.registerPanelType({panelType: this._PANEL_TYPE, Cls: this});
|
||||
return null;
|
||||
}
|
||||
|
||||
static getSaveableContent (
|
||||
{
|
||||
type,
|
||||
toSaveTitle,
|
||||
$content,
|
||||
},
|
||||
) {
|
||||
return {
|
||||
t: type,
|
||||
r: toSaveTitle,
|
||||
s: this._IS_STATELESS
|
||||
? {}
|
||||
: $($content.children()[0]).data("getState")(),
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
constructor (
|
||||
{
|
||||
board,
|
||||
panel,
|
||||
},
|
||||
) {
|
||||
this._board = board;
|
||||
this._panel = panel;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {jQuery}
|
||||
*/
|
||||
_$getPanelElement ({state}) {
|
||||
throw new Error("Unimplemented!");
|
||||
}
|
||||
|
||||
async pDoPopulate ({state = {}, title = null} = {}) {
|
||||
this._panel.set$ContentTab(
|
||||
this.constructor._PANEL_TYPE,
|
||||
state,
|
||||
$(`<div class="panel-content-wrapper-inner"></div>`).append(this._$getPanelElement({state})),
|
||||
title || this.constructor._TITLE,
|
||||
true,
|
||||
);
|
||||
|
||||
this._board.fireBoardEvent({type: "panelPopulate", payload: {type: this.constructor._PANEL_TYPE}});
|
||||
}
|
||||
|
||||
_doHandleTabRenamed ({ixTab, saved}) {
|
||||
if (saved.r != null) this._panel.tabDatas[ixTab].tabRenamed = true;
|
||||
}
|
||||
|
||||
async pLoadState ({ixTab, saved}) {
|
||||
await this.pDoPopulate({state: saved.s, title: saved.r});
|
||||
this._doHandleTabRenamed({ixTab, saved});
|
||||
}
|
||||
}
|
||||
|
||||
export class PanelContentManager_InitiativeTracker extends _PanelContentManager {
|
||||
static _PANEL_TYPE = PANEL_TYP_INITIATIVE_TRACKER;
|
||||
static _TITLE = "Initiative Tracker";
|
||||
|
||||
static _ = this._register();
|
||||
|
||||
_$getPanelElement ({state}) {
|
||||
return InitiativeTracker.$getPanelElement(this._board, state);
|
||||
}
|
||||
}
|
||||
|
||||
export class PanelContentManager_InitiativeTrackerCreatureViewer extends _PanelContentManager {
|
||||
static _PANEL_TYPE = PANEL_TYP_INITIATIVE_TRACKER_CREATURE_VIEWER;
|
||||
static _TITLE = "Creature Viewer";
|
||||
static _IS_STATELESS = true;
|
||||
|
||||
static _ = this._register();
|
||||
|
||||
_$getPanelElement ({state}) {
|
||||
return InitiativeTrackerCreatureViewer.$getPanelElement(this._board, state);
|
||||
}
|
||||
}
|
||||
|
||||
export class PanelContentManager_InitiativeTrackerPlayerViewV1 extends _PanelContentManager {
|
||||
static _PANEL_TYPE = PANEL_TYP_INITIATIVE_TRACKER_PLAYER_V1;
|
||||
static _TITLE = "Initiative Tracker";
|
||||
static _IS_STATELESS = true;
|
||||
|
||||
static _ = this._register();
|
||||
|
||||
_$getPanelElement ({state}) {
|
||||
return InitiativeTrackerPlayerV1.$getPanelElement(this._board, state);
|
||||
}
|
||||
}
|
||||
|
||||
export class PanelContentManager_InitiativeTrackerPlayerViewV0 extends _PanelContentManager {
|
||||
static _PANEL_TYPE = PANEL_TYP_INITIATIVE_TRACKER_PLAYER_V0;
|
||||
static _TITLE = "Initiative Tracker";
|
||||
static _IS_STATELESS = true;
|
||||
|
||||
static _ = this._register();
|
||||
|
||||
_$getPanelElement ({state}) {
|
||||
return InitiativeTrackerPlayerV0.$getPanelElement(this._board, state);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user