initialize Ikonis system module with motherboard configuration and feature management UI
This commit is contained in:
commit
7bffeacaac
16 changed files with 1008 additions and 0 deletions
160
scripts/ikonis-config.js
Normal file
160
scripts/ikonis-config.js
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
import { DEFAULT_AUGMENTS, getAttachedFeature } from './ikonis-data.js';
|
||||
|
||||
export class IkonisAugmentConfig {
|
||||
static async open() {
|
||||
const augments = game.settings.get('dh-ikonis', 'augmentsList') || DEFAULT_AUGMENTS;
|
||||
const defaultBondedUuid = game.settings.get('dh-ikonis', 'defaultBondedUuid') || "";
|
||||
|
||||
const processedAugments = [];
|
||||
for (const a of augments) {
|
||||
const aug = { ...a };
|
||||
if (aug.featureUuid) {
|
||||
const item = await getAttachedFeature(aug.featureUuid);
|
||||
if (item) aug.featureName = item.name;
|
||||
}
|
||||
processedAugments.push(aug);
|
||||
}
|
||||
|
||||
let bondedName = "";
|
||||
if (defaultBondedUuid) {
|
||||
const item = await getAttachedFeature(defaultBondedUuid);
|
||||
if (item) bondedName = item.name;
|
||||
}
|
||||
|
||||
const template = "modules/dh-ikonis/templates/ikonis-config.hbs";
|
||||
const content = await foundry.applications.handlebars.renderTemplate(template, { augments: processedAugments, defaultBondedUuid, bondedName });
|
||||
|
||||
return foundry.applications.api.DialogV2.wait({
|
||||
window: {
|
||||
title: "Global Hardware Manager",
|
||||
icon: "fa-solid fa-microchip",
|
||||
width: 800,
|
||||
height: 650,
|
||||
resizable: true
|
||||
},
|
||||
content: content,
|
||||
buttons: [
|
||||
{
|
||||
action: "add", label: "Add New", icon: "fa-solid fa-plus",
|
||||
callback: () => { this._onAdd(); return false; }
|
||||
},
|
||||
{
|
||||
action: "reset", label: "Reset", icon: "fa-solid fa-undo",
|
||||
callback: () => { this._onReset(); return false; }
|
||||
},
|
||||
{
|
||||
action: "save", label: "Save & Close", icon: "fa-solid fa-save",
|
||||
callback: (event, button) => this._onSave(event, button)
|
||||
}
|
||||
],
|
||||
render: (event, app) => {
|
||||
const html = app.element;
|
||||
|
||||
const form = html.querySelector('form');
|
||||
if (form) {
|
||||
form.style.height = "100%";
|
||||
form.style.maxHeight = "100%";
|
||||
form.style.display = "flex";
|
||||
form.style.flexDirection = "column";
|
||||
form.style.overflow = "hidden";
|
||||
}
|
||||
const formContent = html.querySelector('.form-content');
|
||||
if (formContent) {
|
||||
formContent.style.flex = "1";
|
||||
formContent.style.overflow = "hidden";
|
||||
formContent.style.display = "flex";
|
||||
formContent.style.flexDirection = "column";
|
||||
}
|
||||
|
||||
html.querySelectorAll('[data-action="delete"]').forEach(el => {
|
||||
el.addEventListener('click', () => this._onDelete(el.dataset.id, app));
|
||||
});
|
||||
|
||||
html.addEventListener('drop', async (e) => {
|
||||
// V14 namespaced TextEditor
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(e);
|
||||
if (data.type !== "Item") return;
|
||||
|
||||
const targetRow = e.target.closest('[data-id]');
|
||||
const targetBonded = e.target.closest('.bonded-drop-zone');
|
||||
|
||||
if (targetBonded) {
|
||||
await game.settings.set('dh-ikonis', 'defaultBondedUuid', data.uuid);
|
||||
app.close(); this.open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetRow) {
|
||||
const id = targetRow.dataset.id;
|
||||
const augs = game.settings.get('dh-ikonis', 'augmentsList') || [...DEFAULT_AUGMENTS];
|
||||
const idx = augs.findIndex(a => String(a.id) === String(id));
|
||||
if (idx !== -1) {
|
||||
augs[idx].featureUuid = data.uuid;
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', augs);
|
||||
}
|
||||
app.close(); this.open();
|
||||
}
|
||||
});
|
||||
|
||||
html.querySelectorAll('[data-action="clearFeature"]').forEach(el => {
|
||||
el.addEventListener('click', async (e) => {
|
||||
const id = el.dataset.id;
|
||||
const augs = game.settings.get('dh-ikonis', 'augmentsList') || [...DEFAULT_AUGMENTS];
|
||||
const idx = augs.findIndex(a => String(a.id) === String(id));
|
||||
if (idx !== -1) {
|
||||
augs[idx].featureUuid = null;
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', augs);
|
||||
}
|
||||
app.close(); this.open();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static async _onAdd() {
|
||||
const augments = game.settings.get('dh-ikonis', 'augmentsList') || [...DEFAULT_AUGMENTS];
|
||||
augments.push({ id: foundry.utils.randomID(), name: "New Augment", effect: "Effect", cost: "Cost", precompile: 1 });
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', augments);
|
||||
this.open();
|
||||
}
|
||||
|
||||
static async _onDelete(id, app) {
|
||||
const augments = (game.settings.get('dh-ikonis', 'augmentsList') || []).filter(a => String(a.id) !== String(id));
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', augments);
|
||||
app.close(); this.open();
|
||||
}
|
||||
|
||||
static async _onReset() {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: { title: "Reset" }, content: "Reset to defaults?", yes: { label: "Reset" }
|
||||
});
|
||||
if (confirmed) {
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', DEFAULT_AUGMENTS);
|
||||
await game.settings.set('dh-ikonis', 'defaultBondedUuid', "");
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
|
||||
static async _onSave(event, button) {
|
||||
// V14 namespaced FormDataExtended
|
||||
const fde = new foundry.applications.ux.FormDataExtended(button.form);
|
||||
const data = foundry.utils.expandObject(fde.object);
|
||||
const currentAugs = game.settings.get('dh-ikonis', 'augmentsList') || [];
|
||||
|
||||
const augments = Object.entries(data.augments || {}).map(([id, val]) => {
|
||||
const existing = currentAugs.find(a => String(a.id) === String(id));
|
||||
return {
|
||||
id,
|
||||
name: val.name,
|
||||
effect: val.effect,
|
||||
cost: val.cost,
|
||||
precompile: parseInt(val.precompile) || 1,
|
||||
featureUuid: existing?.featureUuid || null
|
||||
};
|
||||
});
|
||||
|
||||
await game.settings.set('dh-ikonis', 'augmentsList', augments);
|
||||
ui.notifications.info("Global Hardware saved!");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue