Skip to content

Commit

Permalink
Updated to support FVTT v0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-newsome committed Jan 21, 2020
1 parent 14883b9 commit 5415c69
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This system adds support for Pathfinder Second Edition to Foundry VTT.
This is the initial alpha release of the Pathfinder Second Edition system.

Patch Notes:
* v0.447: Fixed issues with orphaned spell migration and incorporated chat damage buttons as a core feature.
* v0.445: Added support for FVTT v0.4.5.


Expand Down
13 changes: 11 additions & 2 deletions scripts/actor/sheet/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class ActorSheetPF2eCharacter extends ActorSheetPF2e {
}
}

let embeddedEntityUpdate = [];
// Iterate through all spells in the temp spellbook and check that they are assigned to a valid spellcasting entry. If not place in unassigned.
for ( let i of tempSpellbook ) {

Expand All @@ -242,8 +243,9 @@ class ActorSheetPF2eCharacter extends ActorSheetPF2e {
spellbooks[location] = spellbooks[location] || {};

// Update spell to perminantly have the correct ID now
console.log(`PF2e System | Prepare Actor Data | Updating location for ${i.name}`);
this.actor.updateEmbeddedEntity("OwnedItem", { "_id": i._id, "data.location.value": spellcastingEntriesList[0]});
//console.log(`PF2e System | Prepare Actor Data | Updating location for ${i.name}`);
//this.actor.updateEmbeddedEntity("OwnedItem", { "_id": i._id, "data.location.value": spellcastingEntriesList[0]});
embeddedEntityUpdate.push({ "_id": i._id, "data.location.value": spellcastingEntriesList[0]});

this._prepareSpell(actorData, spellbooks[location], i);
} else { // else throw it in the orphaned list.
Expand All @@ -252,6 +254,13 @@ class ActorSheetPF2eCharacter extends ActorSheetPF2e {

}

// Update all embedded entities that have an incorrect location.
if (embeddedEntityUpdate.length) {
console.log(`PF2e System | Prepare Actor Data | Updating location for the following embedded entities: `, embeddedEntityUpdate);
this.actor.updateManyEmbeddedEntities("OwnedItem", embeddedEntityUpdate);
ui.notifications.info(`PF2e actor data migration for orphaned spells applied. Please close actor and open again for changes to take affect.`);
}



// Assign and return
Expand Down
14 changes: 12 additions & 2 deletions scripts/actor/sheet/npc.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class ActorSheetPF2eNPC extends ActorSheetPF2e {
this._prepareSpell(actorData, spellbooks["unassigned"], i);
} */

let embeddedEntityUpdate = [];

// Iterate through all spells in the temp spellbook and check that they are assigned to a valid spellcasting entry. If not place in unassigned.
for ( let i of tempSpellbook ) {

Expand All @@ -201,14 +203,22 @@ class ActorSheetPF2eNPC extends ActorSheetPF2e {
spellbooks[location] = spellbooks[location] || {};

// Update spell to perminantly have the correct ID now
console.log(`PF2e System | Prepare NPC Data | Updating location for ${i.name}`);
this.actor.updateEmbeddedEntity("OwnedItem", { "_id": i._id, "data.location.value": spellcastingEntriesList[0]});
//console.log(`PF2e System | Prepare NPC Data | Updating location for ${i.name}`);
//this.actor.updateEmbeddedEntity("OwnedItem", { "_id": i._id, "data.location.value": spellcastingEntriesList[0]});
embeddedEntityUpdate.push({ "_id": i._id, "data.location.value": spellcastingEntriesList[0]});

this._prepareSpell(actorData, spellbooks[location], i);
}

}

// Update all embedded entities that have an incorrect location.
if (embeddedEntityUpdate.length) {
console.log(`PF2e System | Prepare Actor Data | Updating location for the following embedded entities: `, embeddedEntityUpdate);
this.actor.updateManyEmbeddedEntities("OwnedItem", embeddedEntityUpdate);
ui.notifications.info(`PF2e actor data migration for orphaned spells applied. Please close actor and open again for changes to take affect.`);
}

// Assign and return
actorData.actions = actions;
actorData.attacks = attacks;
Expand Down
53 changes: 53 additions & 0 deletions scripts/chat/chatdamagebuttonsPF2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class ChatDamageButtonsPF2e extends Application {
constructor(app) {
super(app);
}

init () {

Hooks.on('renderChatMessage', (message, html, data) => {

if ( !message.isRoll || message.roll.parts[0].faces == 20) return

let btnStyling = 'width: 22px; height:22px; font-size:10px;line-height:1px';

const fullDamageButton = $(`<button class="dice-total-fullDamage-btn" style="${btnStyling}"><i class="fas fa-user-minus" title="Click to apply full damage to selected token(s)."></i></button>`);
const halfDamageButton = $(`<button class="dice-total-halfDamage-btn" style="${btnStyling}"><i class="fas fa-user-shield" title="Click to apply half damage to selected token(s)."></i></button>`);
const doubleDamageButton = $(`<button class="dice-total-doubleDamage-btn" style="${btnStyling}"><i class="fas fa-user-injured" title="Click to apply double damage to selected token(s)."></i></button>`);
const fullHealingButton = $(`<button class="dice-total-fullHealing-btn" style="${btnStyling}"><i class="fas fa-user-plus" title="Click to apply full healing to selected token(s)."></i></button>`);

const btnContainer = $('<span class="dmgBtn-container" style="position:absolute; right:0; bottom:1px;"></span>');
btnContainer.append(fullDamageButton);
btnContainer.append(halfDamageButton);
btnContainer.append(doubleDamageButton);
btnContainer.append(fullHealingButton);

html.find('.dice-total').append(btnContainer);

// Handle button clicks
fullDamageButton.click(ev => {
ev.stopPropagation();
CONFIG.Actor.entityClass.applyDamage(html, 1);
});

halfDamageButton.click(ev => {
ev.stopPropagation();
CONFIG.Actor.entityClass.applyDamage(html, 0.5);
});

doubleDamageButton.click(ev => {
ev.stopPropagation();
CONFIG.Actor.entityClass.applyDamage(html, 2);
});

fullHealingButton.click(ev => {
ev.stopPropagation();
CONFIG.Actor.entityClass.applyDamage(html, -1);
});

})
}
}

let chatButtons = new ChatDamageButtonsPF2e();
chatButtons.init();
17 changes: 9 additions & 8 deletions scripts/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ItemPF2e extends Item {
const token = this.actor.token;
const templateData = {
actor: this.actor,
tokenId: token ? `${token.scene._id}.${token.id}` : null,
tokenId: token ? `${token.scene._id}.${token._id}` : null,
item: this.data,
data: this.getChatData()
};
Expand Down Expand Up @@ -670,21 +670,22 @@ class ItemPF2e extends Item {

// Deduct an item quantity
if ( chg.value <= 1 && qty.value > 1 ) {
this.actor.updateOwnedItem({
id: this.data.id,
let options = {
"_id": this.data._id,
'data.quantity.value': Math.max(qty.value - 1, 0),
'data.charges.value': chg.max
}, true);
};
this.actor.updateEmbeddedEntity("OwnedItem", options);
}

// Optionally destroy the item
else if ( chg.value <= 1 && qty.value <= 1 && itemData['autoDestroy'].value ) {
this.actor.deleteOwnedItem(this.data.id);
this.actor.removeEmbeddedEntity("OwnedItem", this.data._id);
}

// Deduct the remaining charges
else {
this.actor.updateOwnedItem({id: this.data.id, 'data.charges.value': Math.max(chg.value - 1, 0)});
this.actor.updateEmbeddedEntity("OwnedItem", {_id: this.data._id, 'data.charges.value': Math.max(chg.value - 1, 0)});
}
}
}
Expand Down Expand Up @@ -833,7 +834,7 @@ class ItemPF2e extends Item {
else {
const scene = game.scenes.get(sceneId);
if ( !scene ) return;
let tokenData = scene.data.tokens.find(t => t.id === Number(tokenId));
let tokenData = scene.data.tokens.find(t => t._id === tokenId);
if ( tokenData ) token = new Token(tokenData);
}
if ( !token ) return;
Expand All @@ -842,7 +843,7 @@ class ItemPF2e extends Item {

// Get the Item
if ( !actor ) return;
const itemId = Number(card.attr("data-item-id"));
const itemId = card.attr("data-item-id");
//let itemData = actor.items.find(i => i.id === itemId);
let itemData = (actor.getOwnedItem(itemId) || {}).data;
if ( !itemData ) return;
Expand Down
7 changes: 4 additions & 3 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "pf2e",
"title": "Pathfinder 2nd Edition",
"description": "An early alpha game system for running games of Pathfinder 2nd Edition in the Foundry VTT environment.",
"version": 0.446,
"version": 0.447,
"schema": 0.411,
"minimumCoreVersion": "0.4.2",
"minimumCoreVersion": "0.4.5",
"author": "hooking",
"scripts": [
"./scripts/init.js",
Expand All @@ -17,7 +17,8 @@
"./scripts/item/sheet.js",
"./scripts/actor/trait-selector.js",
"./scripts/dice.js",
"./scripts/packs/spell-browser.js"
"./scripts/packs/spell-browser.js",
"./scripts/chat/chatdamagebuttonsPF2e.js"
],
"styles": ["./css/pf2e.css"],
"packs": [
Expand Down
2 changes: 1 addition & 1 deletion templates/actors/actor-classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h3>Class Levels</h3>

<ol class="class-list inventory-list directory-list">
{{#each actor.classes}}
<li class="item" data-item-id="{{this.id}}">
<li class="item" data-item-id="{{this._id}}">
<header class="item-header">
<h4 class="class-name">{{this.name}}</h4>
<span class="class-levels">{{this.data.levels.value}}</span>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/action-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card action-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card action-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/armor-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/backpack-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/consumable-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/equipment-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/feat-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/melee-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/spell-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/tool-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/chat/weapon-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item.id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card weapon-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/items/action-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{{#select data.weapon.value}}
<option value=""></option>
{{#each weapons as |item i|}}
<option value="{{item.id}}">{{item.name}}</option>
<option value="{{item._id}}">{{item.name}}</option>
{{/each}}
{{/select}}
</select>
Expand Down

0 comments on commit 5415c69

Please sign in to comment.