/** * Extend the basic ActorSheet with some very simple modifications * @extends {ActorSheet} */ import { DarkStarsUtility } from "./dark-stars-utility.js"; /* -------------------------------------------- */ export class DarkStarsActorSheet extends ActorSheet { /** @override */ static get defaultOptions() { return foundry.utils.mergeObject(super.defaultOptions, { classes: ["fvtt-dark-stars", "sheet", "actor"], template: "systems/fvtt-dark-stars/templates/actors/actor-sheet.hbs", width: 960, height: 720, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }], dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }], editScore: true }); } /* -------------------------------------------- */ async getData() { const objectData = this.object.system let actorData = foundry.utils.duplicate(objectData) let formData = { title: this.title, id: this.actor.id, type: this.actor.type, img: this.actor.img, name: this.actor.name, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", system: actorData, limited: this.object.limited, skills: this.actor.getSkills( ), perks: this.actor.getPerks( ), weapons: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getWeapons()) ), ammos: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getAmmos()) ), spells: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getSpells()) ), powers: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getPowers()) ), armors: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getArmors())), shields: this.actor.checkAndPrepareEquipments( foundry.utils.duplicate(this.actor.getShields())), equipments: this.actor.checkAndPrepareEquipments(foundry.utils.duplicate(this.actor.getEquipmentsOnly()) ), equippedWeapons: this.actor.checkAndPrepareEquipments(foundry.utils.duplicate(this.actor.getEquippedWeapons()) ), cybers: this.actor.checkAndPrepareEquipments(foundry.utils.duplicate(this.actor.getCybers()) ), genetics: this.actor.checkAndPrepareEquipments(foundry.utils.duplicate(this.actor.getGenetics()) ), equippedArmor: this.actor.getEquippedArmor(), equippedShield: this.actor.getEquippedShield(), subActors: foundry.utils.duplicate(this.actor.getSubActors()), encCapacity: this.actor.getEncumbranceCapacity(), conditions: this.actor.getConditions(), tasks: this.actor.getCumulativeTasks(), config: game.system.darkstars.config, description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}), notes: await TextEditor.enrichHTML(this.object.system.biodata.notes, {async: true}), containersTree: this.actor.containersTree, encCurrent: this.actor.encCurrent, options: this.options, owner: this.document.isOwner, editScore: this.options.editScore, isGM: game.user.isGM } this.formData = formData; console.log("PC : ", formData, this.object); return formData; } /* -------------------------------------------- */ /** @override */ activateListeners(html) { super.activateListeners(html); // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; html.bind("keydown", function(e) { // Ignore Enter in actores sheet if (e.keyCode === 13) return false; }); // Update Inventory Item html.find('.item-edit').click(ev => { const li = $(ev.currentTarget).parents(".item") let itemId = li.data("item-id") const item = this.actor.items.get( itemId ); item.sheet.render(true); }); // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item") DarkStarsUtility.confirmDelete(this, li) }) html.find('.item-add').click(ev => { let dataType = $(ev.currentTarget).data("type") this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true }) }) html.find('.subactor-edit').click(ev => { const li = $(ev.currentTarget).parents(".item"); let actorId = li.data("actor-id"); let actor = game.actors.get( actorId ); actor.sheet.render(true); }); html.find('.subactor-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); let actorId = li.data("actor-id"); this.actor.delSubActor(actorId); }); html.find('.edit-weapon-ammo').change(ev => { const li = $(ev.currentTarget).parents(".item") let weaponId = li.data("item-id") this.actor.setWeaponAmmo( weaponId, ev.currentTarget.value ) }) html.find('.skill-used-id').change(event => { const li = $(event.currentTarget).parents(".item"); this.actor.setSkillUsed( li.data("item-id"), event.currentTarget.checked ); } ); html.find('.quantity-minus').click(event => { const li = $(event.currentTarget).parents(".item"); this.actor.incDecQuantity( li.data("item-id"), -1 ); } ); html.find('.quantity-plus').click(event => { const li = $(event.currentTarget).parents(".item"); this.actor.incDecQuantity( li.data("item-id"), +1 ); } ); html.find('.ammo-minus').click(event => { const li = $(event.currentTarget).parents(".item") this.actor.incDecAmmo( li.data("item-id"), -1 ); } ); html.find('.ammo-plus').click(event => { const li = $(event.currentTarget).parents(".item") this.actor.incDecAmmo( li.data("item-id"), +1 ) } ); html.find('.roll-skill').click((event) => { const li = $(event.currentTarget).parents(".item") const skillId = li.data("item-id") this.actor.rollSkill(skillId) }); html.find('.roll-attribute').click((event) => { const attrKey = $(event.currentTarget).data("attr-key") this.actor.rollAttribute(attrKey) }) html.find('.start-cumulative-task').click((event) => { const li = $(event.currentTarget).parents(".item") const skillId = li.data("item-id") this.actor.rollSkill(skillId, true) }) html.find('.roll-weapon').click((event) => { const li = $(event.currentTarget).parents(".item"); const skillId = li.data("item-id") this.actor.rollWeapon(skillId) }); html.find('.lock-unlock-sheet').click((event) => { this.options.editScore = !this.options.editScore; this.render(true); }); html.find('.item-link a').click((event) => { const itemId = $(event.currentTarget).data("item-id"); const item = this.actor.getOwnedItem(itemId); item.sheet.render(true); }); html.find('.item-equip').click(ev => { const li = $(ev.currentTarget).parents(".item"); this.actor.equipItem( li.data("item-id") ); this.render(true); }); html.find('.update-field').change(ev => { const fieldName = $(ev.currentTarget).data("field-name"); let value = Number(ev.currentTarget.value); this.actor.update( { [`${fieldName}`]: value } ); }); } /* -------------------------------------------- */ /** @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; } /* -------------------------------------------- */ async _onDropItem(event, dragData) { console.log(">>>>>> DROPPED!!!!") const item = fromUuidSync(dragData.uuid) if (item == undefined) { item = this.actor.items.get( item.id ) } let ret = await this.actor.preprocessItem( event, item, true ) if ( ret ) { super._onDropItem(event, dragData) } } /* -------------------------------------------- */ /** @override */ _updateObject(event, formData) { // Update the Actor return this.object.update(formData); } }