bol/module/actor/actor-sheet.js

291 lines
10 KiB
JavaScript
Raw Normal View History

2021-07-08 10:12:12 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
2022-03-20 23:17:52 +01:00
import { BoLRoll } from "../controllers/bol-rolls.js";
2022-02-23 20:39:58 +01:00
import { BoLUtility } from "../system/bol-utility.js";
2021-07-08 10:12:12 +02:00
export class BoLActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
2021-07-08 10:12:12 +02:00
classes: ["bol", "sheet", "actor"],
template: "systems/bol/templates/actor/actor-sheet.hbs",
2022-09-27 20:47:30 +02:00
width: 860,
2021-07-08 10:12:12 +02:00
height: 600,
2022-03-27 22:56:43 +02:00
dragDrop: [{ dragSelector: ".items-list .item", dropSelector: null }],
2021-07-08 10:12:12 +02:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }]
});
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
2022-07-17 18:20:05 +02:00
function onLoad() {
let logoSheet = BoLUtility.getLogoActorSheet()
2024-01-12 18:42:12 +01:00
$(".bol-actor-form").css("backgroundImage", `url(${logoSheet})`)
2022-07-17 18:20:05 +02:00
}
// Setup everything onload
$(function () { onLoad(); });
2021-07-08 10:12:12 +02:00
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Add Inventory Item
html.find('.item-create').click(this._onItemCreate.bind(this));
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("itemId"));
item.sheet.render(true);
2022-02-23 20:39:58 +01:00
})
// Equip/Unequip item
html.find('.item-equip').click(this._onToggleEquip.bind(this));
2024-09-04 08:57:26 +02:00
html.find('.create-item').click(ev => {
this.actor.createEmbeddedDocuments('Item', [{ name: game.i18n.localize("BOL.ui.newEquipment"), type: "item" }], { renderSheet: true });
2022-02-16 09:11:49 +01:00
});
2022-03-20 23:17:52 +01:00
2024-09-04 08:57:26 +02:00
html.find('.create-natural-weapon').click(ev => {
let system = foundry.utils.duplicate(game.bol.config.defaultNaturalWeapon)
this.actor.createEmbeddedDocuments('Item', [{ name: game.i18n.localize("BOL.ui.newNaturalWeapon"), type: "item", system }], { renderSheet: true });
});
html.find('.create-natural-protection').click(ev => {
let system = foundry.utils.duplicate(game.bol.config.defaultNaturalProtection)
this.actor.createEmbeddedDocuments('Item', [{ name: game.i18n.localize("BOL.ui.newNaturalProtection"), type: "item", system }], { renderSheet: true });
});
2022-03-10 21:05:53 +01:00
html.find(".toggle-fight-option").click((ev) => {
const li = $(ev.currentTarget).parents(".item")
2022-03-20 23:17:52 +01:00
this.actor.toggleFightOption(li.data("itemId"))
2022-03-10 21:05:53 +01:00
})
2022-03-20 23:17:52 +01:00
2022-01-23 09:25:09 +01:00
html.find(".inc-dec-btns-alchemy").click((ev) => {
const li = $(ev.currentTarget).parents(".item");
2022-03-20 23:17:52 +01:00
this.actor.spendAlchemyPoint(li.data("itemId"), 1)
2022-01-23 09:25:09 +01:00
})
2023-03-18 13:51:46 +01:00
html.find(".inc-dec-btns-resource").click((ev) => {
const dataset = ev.currentTarget.dataset;
const target = dataset.target
const incr = parseInt(dataset.incr)
this.actor.incDecResources(target, incr)
})
2022-01-23 09:25:09 +01:00
// Incr./Decr. career ranks
html.find(".inc-dec-btns").click((ev) => {
const li = $(ev.currentTarget).parents(".item");
2022-03-20 23:17:52 +01:00
if (li) {
const item = this.actor.items.get(li.data("itemId"));
2022-03-20 23:17:52 +01:00
if (item) {
const dataset = ev.currentTarget.dataset;
const operator = dataset.operator;
const target = dataset.target;
2022-02-11 23:29:57 +01:00
const incr = parseInt(dataset.incr)
const min = parseInt(dataset.min)
const max = parseInt(dataset.max) || 10000
2022-07-01 15:48:54 +02:00
let value = eval("item." + target)
2022-02-11 23:29:57 +01:00
value = value || 0
2022-07-01 15:48:54 +02:00
//console.log("IncDec", item, target, value, operator, min, max)
2022-03-20 23:17:52 +01:00
if (operator === "minus") {
if (value >= min + incr) value -= incr;
else value = min;
}
2022-03-20 23:17:52 +01:00
if (operator === "plus") {
if (value <= max - incr) value += incr;
else value = max;
}
2022-03-20 23:17:52 +01:00
let update = { [`${target}`]: value };
item.update(update);
}
}
});
2021-07-08 10:12:12 +02:00
// Delete Inventory Item
html.find('.item-delete').click(ev => {
Dialog.confirm({
2022-11-25 20:47:28 +01:00
title: game.i18n.localize("BOL.ui.deletetitle"),
content: game.i18n.localize("BOL.ui.confirmdelete"),
yes: () => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")])
li.slideUp(200, () => this.render(false));
},
2022-03-20 23:17:52 +01:00
no: () => { },
defaultYes: false,
});
2021-07-08 10:12:12 +02:00
});
// Rollable abilities.
html.find('.rollable').click(this._onRoll.bind(this));
2021-07-08 10:12:12 +02:00
}
/* -------------------------------------------- */
/** @override */
2022-09-27 20:47:30 +02:00
async getData(options) {
2022-07-01 15:48:54 +02:00
const data = super.getData(options)
const actorData = foundry.utils.duplicate(data)
let formData = foundry.utils.duplicate(data)
2022-01-23 09:25:09 +01:00
formData.config = game.bol.config
2022-07-01 15:48:54 +02:00
formData.data = actorData
2022-01-23 09:25:09 +01:00
formData.details = this.actor.details
formData.attributes = this.actor.attributes
formData.aptitudes = this.actor.aptitudes
formData.resources = this.actor.getResourcesFromType()
2022-08-31 23:00:41 +02:00
formData.xp = this.actor.system.xp
2022-01-23 09:25:09 +01:00
formData.equipment = this.actor.equipment
2022-04-10 16:38:09 +02:00
formData.equipmentCreature = this.actor.equipmentCreature
2022-01-23 09:25:09 +01:00
formData.weapons = this.actor.weapons
formData.protections = this.actor.protections
formData.spells = this.actor.spells
formData.alchemy = this.actor.alchemy
formData.containers = this.actor.containers
formData.treasure = this.actor.treasure
2022-11-23 21:34:51 +01:00
formData.boleffects = this.actor.boleffects
2022-03-10 21:05:53 +01:00
formData.alchemyrecipe = this.actor.alchemyrecipe
2022-12-23 23:24:09 +01:00
formData.horoscopes = this.actor.horoscopes
2022-03-10 21:05:53 +01:00
formData.vehicles = this.actor.vehicles
formData.fightoptions = this.actor.fightoptions
formData.ammos = this.actor.ammos
formData.misc = this.actor.misc
2024-01-12 18:42:12 +01:00
formData.xplog = this.actor.xplog
2022-02-23 20:39:58 +01:00
formData.combat = this.actor.buildCombat()
2022-11-30 20:58:27 +01:00
formData.initiativeRank = this.actor.getInitiativeRank()
2022-09-02 16:08:56 +02:00
//formData.combatCreature = this.actor.buildCombatCreature()
2022-01-23 09:25:09 +01:00
formData.features = this.actor.buildFeatures()
formData.isGM = game.user.isGM
2022-03-20 23:17:52 +01:00
formData.options = this.options
formData.owner = this.document.isOwner
formData.editScore = this.options.editScore
2024-01-12 18:42:12 +01:00
formData.useBougette = (this.actor.type == "character" && BoLUtility.getUseBougette()) || false
2022-11-29 15:23:05 +01:00
formData.bougette = this.actor.getBougette()
2022-07-01 16:30:21 +02:00
formData.charType = this.actor.getCharType()
2024-01-12 18:42:12 +01:00
formData.villainy = this.actor.getVillainy()
formData.isUndead = this.actor.isUndead()
2024-01-12 18:42:12 +01:00
formData.biography = await TextEditor.enrichHTML(this.object.system.details?.biography || "", { async: true })
formData.notes = await TextEditor.enrichHTML(this.object.system.details.notes || "", { async: true })
2022-01-23 09:25:09 +01:00
formData.isSorcerer = this.actor.isSorcerer()
formData.isAlchemist = this.actor.isAlchemist()
2022-12-23 23:24:09 +01:00
formData.isAstrologer = this.actor.isAstrologer()
formData.isMysteries = formData.isSorcerer || formData.isAlchemist || formData.isAstrologer
2022-01-23 09:25:09 +01:00
formData.isPriest = this.actor.isPriest()
2022-12-25 18:00:42 +01:00
formData.horoscopeGroupList = game.settings.get("bol", "horoscope-group")
2022-03-20 23:17:52 +01:00
2022-03-10 21:05:53 +01:00
formData.isGM = game.user.isGM
2022-01-03 00:09:27 +01:00
2022-03-10 21:05:53 +01:00
console.log("ACTORDATA", formData)
2022-01-03 00:09:27 +01:00
return formData;
}
/* -------------------------------------------- */
2021-07-08 10:12:12 +02:00
/**
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
* @param {Event} event The originating click event
* @private
*/
_onItemCreate(event) {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
const type = header.dataset.type;
// Grab any data associated with this control.
const data = foundry.utils.duplicate(header.dataset);
2021-07-08 10:12:12 +02:00
// Initialize a default name.
const name = `New ${type.capitalize()}`;
// Prepare the item object.
const itemData = {
name: name,
type: type,
data: data
};
// Remove the type from the dataset since it's in the itemData.type prop.
delete itemData.data["type"];
// Finally, create the item!
return this.actor.createEmbeddedDocuments("Item", [itemData]);
}
_onToggleEquip(event) {
event.preventDefault();
const li = $(event.currentTarget).closest(".item");
const item = this.actor.items.get(li.data("itemId"));
return this.actor.toggleEquipItem(item);
}
2021-07-08 10:12:12 +02:00
/**
* Handle clickable rolls.
* @param {Event} event The originating click event
* @private
*/
_onRoll(event) {
event.preventDefault();
2022-03-20 23:17:52 +01:00
const element = event.currentTarget
const dataset = element.dataset
const rollType = dataset.rollType
const li = $(event.currentTarget).closest(".item")
switch (rollType) {
case "attribute":
2022-03-21 23:21:05 +01:00
BoLRoll.attributeCheck(this.actor, dataset.key, event)
break;
2022-03-20 23:17:52 +01:00
case "aptitude":
2022-03-21 23:21:05 +01:00
BoLRoll.aptitudeCheck(this.actor, dataset.key, event)
break;
2022-03-20 23:17:52 +01:00
case "weapon":
2022-03-21 23:21:05 +01:00
BoLRoll.weaponCheck(this.actor, event)
2021-12-24 18:33:37 +01:00
break;
2022-03-20 23:17:52 +01:00
case "spell":
2022-03-21 23:21:05 +01:00
BoLRoll.spellCheck(this.actor, event)
2022-01-23 09:25:09 +01:00
break;
2022-03-20 23:17:52 +01:00
case "alchemy":
2022-03-21 23:21:05 +01:00
BoLRoll.alchemyCheck(this.actor, event)
2022-01-23 09:25:09 +01:00
break;
2022-03-20 23:17:52 +01:00
case "protection":
2022-01-16 22:06:49 +01:00
this.actor.rollProtection(li.data("item-id"))
break;
2022-03-20 23:17:52 +01:00
case "damage":
2022-01-16 22:06:49 +01:00
this.actor.rollWeaponDamage(li.data("item-id"))
break;
2022-03-20 23:17:52 +01:00
case "aptitudexp":
this.actor.incAptitudeXP(dataset.key)
break;
case "attributexp":
this.actor.incAttributeXP(dataset.key)
break;
case "careerxp":
2024-01-12 18:42:12 +01:00
this.actor.incCareerXP(li.data("item-id"))
2022-03-20 23:17:52 +01:00
break;
2022-12-23 23:24:09 +01:00
case "horoscope-minor":
BoLRoll.horoscopeCheck(this.actor, event, "minor")
break
case "horoscope-major":
BoLRoll.horoscopeCheck(this.actor, event, "major")
2024-01-12 18:42:12 +01:00
break
2022-12-23 23:24:09 +01:00
case "horoscope-major-group":
BoLRoll.horoscopeCheck(this.actor, event, "majorgroup")
2024-01-12 18:42:12 +01:00
break
case "bougette":
this.actor.rollBougette()
break;
2022-03-20 23:17:52 +01:00
default: break;
2021-07-08 10:12:12 +02:00
}
}
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
2021-07-08 10:12:12 +02:00
}