vehicules pour la feuille de groupe - v0.0.14
This commit is contained in:
@@ -48,7 +48,17 @@ export class VermineActorSheet extends ActorSheet {
|
||||
|
||||
// Prepare NPC data and items.
|
||||
if (actorData.type == 'npc') {
|
||||
this._prepareItems(context);
|
||||
this._prepareNpcItems(context);
|
||||
}
|
||||
|
||||
// Prepare Group data and items.
|
||||
if (actorData.type == 'group') {
|
||||
this._prepareGroupItems(context);
|
||||
}
|
||||
|
||||
// Prepare Creature data and items.
|
||||
if (actorData.type == 'npc') {
|
||||
this._prepareCreatureItems(context);
|
||||
}
|
||||
|
||||
// Add roll data for TinyMCE editors.
|
||||
@@ -180,6 +190,116 @@ export class VermineActorSheet extends ActorSheet {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Npc sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareNpcItems(context) {
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const traits = [];
|
||||
|
||||
|
||||
// Iterate through items, allocating to containers
|
||||
for (let i of context.items) {
|
||||
i.img = i.img || DEFAULT_TOKEN;
|
||||
// Append to gear.
|
||||
if (i.type === 'item') {
|
||||
gear.push(i);
|
||||
}
|
||||
else if (i.type === 'trait') {
|
||||
traits.push(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Group sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareGroupItems(context) {
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const defenses = [];
|
||||
const abilities = [];
|
||||
const weapons = [];
|
||||
const vehicles = [];
|
||||
|
||||
// Iterate through items, allocating to containers
|
||||
for (let i of context.items) {
|
||||
i.img = i.img || DEFAULT_TOKEN;
|
||||
// Append to gear.
|
||||
if (i.type === 'item') {
|
||||
gear.push(i);
|
||||
}
|
||||
else if (i.type === 'defense') {
|
||||
defenses.push(i);
|
||||
}
|
||||
else if (i.type === 'weapon') {
|
||||
weapons.push(i);
|
||||
}
|
||||
else if (i.type === 'ability') {
|
||||
abilities.push(i);
|
||||
}
|
||||
else if (i.type === 'vehicle') {
|
||||
vehicles.push(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
context.weapons = weapons;
|
||||
context.defenses = defenses;
|
||||
context.abilities = abilities;
|
||||
context.vehicles = vehicles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Creature sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareCreatureItems(context) {
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const traits = [];
|
||||
|
||||
|
||||
// Iterate through items, allocating to containers
|
||||
for (let i of context.items) {
|
||||
i.img = i.img || DEFAULT_TOKEN;
|
||||
// Append to gear.
|
||||
if (i.type === 'item') {
|
||||
gear.push(i);
|
||||
}
|
||||
else if (i.type === 'trait') {
|
||||
traits.push(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
|
||||
}
|
||||
async _onItemCreate(event) {
|
||||
event.preventDefault();
|
||||
const header = event.currentTarget;
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
import {onManageActiveEffect, prepareActiveEffectCategories} from "../system/effects.mjs";
|
||||
import { VermineActorSheet } from "./actor-sheet.mjs";
|
||||
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {VermineActorSheet}
|
||||
*/
|
||||
export class VermineGroupSheet extends VermineActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["vermine2047", "sheet", "actor"],
|
||||
template: "systems/vermine2047/templates/actor/actor-sheet.html",
|
||||
width: 600,
|
||||
height: 600,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
get template() {
|
||||
return `systems/vermine2047/templates/actor/actor-${this.actor.type}-sheet.html`;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
getData() {
|
||||
// Retrieve the data structure from the base sheet. You can inspect or log
|
||||
// the context variable to see the structure, but some key properties for
|
||||
// sheets are the actor object, the data object, whether or not it's
|
||||
// editable, the items array, and the effects array.
|
||||
const context = super.getData();
|
||||
|
||||
// Use a safe clone of the actor data for further operations.
|
||||
const actorData = this.actor.toObject(false);
|
||||
|
||||
// Add the actor's data to context.data for easier access, as well as flags.
|
||||
context.system = actorData.system;
|
||||
context.flags = actorData.flags;
|
||||
context.config = CONFIG.VERMINE;
|
||||
|
||||
// Prepare character data and items.
|
||||
if (actorData.type == 'character') {
|
||||
this._prepareItems(context);
|
||||
this._prepareCharacterData(context);
|
||||
}
|
||||
|
||||
// Prepare NPC data and items.
|
||||
if (actorData.type == 'npc') {
|
||||
this._prepareItems(context);
|
||||
}
|
||||
|
||||
// Add roll data for TinyMCE editors.
|
||||
context.rollData = context.actor.getRollData();
|
||||
|
||||
// Prepare active effects
|
||||
context.effects = prepareActiveEffectCategories(this.actor.effects);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Character sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareCharacterData(context) {
|
||||
// Handle ability scores.
|
||||
for (let [k, v] of Object.entries(context.system.abilities)) {
|
||||
v.label = game.i18n.localize(context.system.abilities[k].label) ?? k;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Character sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareItems(context) {
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const features = [];
|
||||
const spells = {
|
||||
0: [],
|
||||
1: [],
|
||||
2: [],
|
||||
3: [],
|
||||
4: [],
|
||||
5: [],
|
||||
6: [],
|
||||
7: [],
|
||||
8: [],
|
||||
9: []
|
||||
};
|
||||
|
||||
// Iterate through items, allocating to containers
|
||||
for (let i of context.items) {
|
||||
i.img = i.img || DEFAULT_TOKEN;
|
||||
// Append to gear.
|
||||
if (i.type === 'item') {
|
||||
gear.push(i);
|
||||
}
|
||||
// Append to features.
|
||||
else if (i.type === 'feature') {
|
||||
features.push(i);
|
||||
}
|
||||
// Append to spells.
|
||||
else if (i.type === 'spell') {
|
||||
if (i.system.spellLevel != undefined) {
|
||||
spells[i.system.spellLevel].push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
context.features = features;
|
||||
context.spells = spells;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Render the item sheet for viewing/editing prior to the editable check.
|
||||
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);
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.isEditable) return;
|
||||
|
||||
// Add Inventory Item
|
||||
html.find('.item-create').click(this._onItemCreate.bind(this));
|
||||
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
item.delete();
|
||||
li.slideUp(200, () => this.render(false));
|
||||
});
|
||||
|
||||
// Active Effect management
|
||||
html.find(".effect-control").click(ev => onManageActiveEffect(ev, this.actor));
|
||||
|
||||
// Rollable abilities.
|
||||
html.find('.rollable').click(this._onRoll.bind(this));
|
||||
|
||||
// Drag events for macros.
|
||||
if (this.actor.isOwner) {
|
||||
let handler = ev => this._onDragStart(ev);
|
||||
html.find('li.item').each((i, li) => {
|
||||
if (li.classList.contains("inventory-header")) return;
|
||||
li.setAttribute("draggable", true);
|
||||
li.addEventListener("dragstart", handler, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
async _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 = duplicate(header.dataset);
|
||||
// Initialize a default name.
|
||||
const name = `New ${type.capitalize()}`;
|
||||
// Prepare the item object.
|
||||
const itemData = {
|
||||
name: name,
|
||||
type: type,
|
||||
system: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.system["type"];
|
||||
|
||||
// Finally, create the item!
|
||||
return await Item.create(itemData, {parent: this.actor});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clickable rolls.
|
||||
* @param {Event} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
_onRoll(event) {
|
||||
event.preventDefault();
|
||||
const element = event.currentTarget;
|
||||
const dataset = element.dataset;
|
||||
|
||||
// Handle item rolls.
|
||||
if (dataset.rollType) {
|
||||
if (dataset.rollType == 'item') {
|
||||
const itemId = element.closest('.item').dataset.itemId;
|
||||
const item = this.actor.items.get(itemId);
|
||||
if (item) return item.roll();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle rolls that supply the formula directly.
|
||||
if (dataset.roll) {
|
||||
let label = dataset.label ? `[ability] ${dataset.label}` : '';
|
||||
let roll = new Roll(dataset.roll, this.actor.getRollData());
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
|
||||
flavor: label,
|
||||
rollMode: game.settings.get('core', 'rollMode'),
|
||||
});
|
||||
return roll;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,12 @@
|
||||
"systems/vermine2047/templates/actor/parts/actor-stories.hbs",
|
||||
"systems/vermine2047/templates/actor/parts/actor-effects.html",
|
||||
|
||||
// Group partials
|
||||
"systems/vermine2047/templates/actor/parts/group-vehicles.hbs",
|
||||
"systems/vermine2047/templates/actor/parts/group-info.hbs",
|
||||
"systems/vermine2047/templates/actor/parts/group-items.hbs",
|
||||
"systems/vermine2047/templates/actor/parts/group-experience.hbs",
|
||||
|
||||
// additional templates
|
||||
"systems/vermine2047/templates/roll.hbs",
|
||||
]);
|
||||
|
||||
@@ -9,12 +9,12 @@ export const registerHooks = function () {
|
||||
});
|
||||
|
||||
// changement de la pause
|
||||
/*Hooks.on("renderPause", async function () {
|
||||
Hooks.on("renderPause", async function () {
|
||||
if ($("#pause").attr("class") !== "paused") return;
|
||||
$(".paused img").attr("src", 'systems/vermine2047/assets/images/ui/vermine_pause.webp');
|
||||
$(".paused img").css({ "opacity": 1});
|
||||
$("#pause.paused figcaption").text("Communauté endormie...");
|
||||
});*/
|
||||
});
|
||||
|
||||
// Hooks.on('renderChatLog', (log, html, data) => VermineFight.chatListeners(html));
|
||||
// Hooks.on('renderChatMessage', (message, html, data) => VermineFight.chatMessageHandler(message, html, data));
|
||||
|
||||
@@ -6,6 +6,7 @@ import { VermineActor } from "./documents/actor.mjs";
|
||||
|
||||
import { VermineCharacterSheet } from "./sheets/character-sheet.mjs";
|
||||
import { VermineNpcSheet } from "./sheets/npc-sheet.mjs";
|
||||
import { VermineGroupSheet } from "./sheets/npc-group.mjs";
|
||||
import { VermineCreatureSheet } from "./sheets/creature-sheet.mjs";
|
||||
|
||||
import { VermineItem } from "./documents/item.mjs";
|
||||
@@ -65,6 +66,11 @@ Hooks.once('init', async function() {
|
||||
types: ['creature'],
|
||||
makeDefault: true,
|
||||
}); // Register vehicle Sheet
|
||||
|
||||
Actors.registerSheet('vermine2047', VermineGroupSheet, {
|
||||
types: ['group'],
|
||||
makeDefault: true,
|
||||
}); // Register vehicle Sheet
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("vermine2047", VermineItemSheet, { makeDefault: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user