Skip to content

Commit

Permalink
Merge pull request #32 from orffen/v10-devel
Browse files Browse the repository at this point in the history
r7 - FoundryVTT v10 required
  • Loading branch information
orffen committed Aug 25, 2022
2 parents 854a871 + 973b7a7 commit b2eafe3
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 61 deletions.
6 changes: 3 additions & 3 deletions module/basicfantasyrpg.mjs
Expand Up @@ -96,10 +96,10 @@ Hooks.on("createActor", async function(actor) {

Hooks.on("createToken", async function(token, options, id) {
if (token.actor.type === "monster") {
let newHitPoints = new Roll(`${token.actor.data.data.hitDice.number}${token.actor.data.data.hitDice.size}+${token.actor.data.data.hitDice.mod}`);
let newHitPoints = new Roll(`${token.actor.system.hitDice.number}${token.actor.system.hitDice.size}+${token.actor.system.hitDice.mod}`);
await newHitPoints.evaluate({ async: true });
token.actor.data.data.hitPoints.value = Math.max(1, newHitPoints.total);
token.actor.data.data.hitPoints.max = Math.max(1, newHitPoints.total);
token.actor.system.hitPoints.value = Math.max(1, newHitPoints.total);
token.actor.system.hitPoints.max = Math.max(1, newHitPoints.total);
}
});

Expand Down
18 changes: 9 additions & 9 deletions module/documents/actor.mjs
Expand Up @@ -29,8 +29,8 @@ export class BasicFantasyRPGActor extends Actor {
* is queried and has a roll executed directly from it).
*/
prepareDerivedData() {
const actorData = this.data;
const data = actorData.data;
const actorData = this;
const data = actorData.system;
const flags = actorData.flags.basicfantasyrpg || {};

// Make separate methods for each Actor type (character, monster, etc.) to keep
Expand All @@ -46,7 +46,7 @@ export class BasicFantasyRPGActor extends Actor {
if (actorData.type !== 'character') return;

// Make modifications to data here. For example:
const data = actorData.data;
const data = actorData.system;

// Loop through ability scores, and add their modifiers to our sheet output.
for (let [key, ability] of Object.entries(data.abilities)) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class BasicFantasyRPGActor extends Actor {
_prepareMonsterData(actorData) {
if (actorData.type !== 'monster') return;

const data = actorData.data;
const data = actorData.system;
data.xp.value = function () {
let xpLookup = [10, 25, 75, 145, 240, 360, 500, 670, 875, 1075, 1300, 1575, 1875, 2175, 2500, 2850, 3250, 3600, 4000, 4500, 5250, 6000, 6750, 7500, 8250, 9000];
let specialAbilityLookup = [3, 12, 25, 30, 40, 45, 55, 65, 70, 75, 90, 95, 100, 110, 115, 125, 135, 145, 160, 175, 200, 225, 250, 275, 300, 325];
Expand All @@ -106,10 +106,10 @@ export class BasicFantasyRPGActor extends Actor {
* Calculate monster attack bonus
*/
_calculateMonsterAttackBonus() {
if (this.data.data.hitDice.number < 1) {
if (this.system.hitDice.number < 1) {
return 0;
}
switch (this.data.data.hitDice.number) {
switch (this.system.hitDice.number) {
case 9: return 8;
case 10:
case 11: return 9
Expand All @@ -133,7 +133,7 @@ export class BasicFantasyRPGActor extends Actor {
case 29:
case 30:
case 31: return 15;
default: return this.data.data.hitDice.number;
default: return this.system.hitDice.number;
}
}

Expand All @@ -155,7 +155,7 @@ export class BasicFantasyRPGActor extends Actor {
* Prepare character roll data.
*/
_getCharacterRollData(data) {
if (this.data.type !== 'character') return;
if (this.system.type !== 'character') return;

// Copy the ability scores to the top level, so that rolls can use
// formulas like `@str.bonus + 4`.
Expand All @@ -175,7 +175,7 @@ export class BasicFantasyRPGActor extends Actor {
* Prepare NPC roll data.
*/
_getMonsterRollData(data) {
if (this.data.type !== 'monster') return;
if (this.system.type !== 'monster') return;

// Process additional NPC data here.

Expand Down
8 changes: 4 additions & 4 deletions module/documents/item.mjs
Expand Up @@ -20,7 +20,7 @@ export class BasicFantasyRPGItem extends Item {
// If present, return the actor's roll data.
if ( !this.actor ) return null;
const rollData = this.actor.getRollData();
rollData.item = foundry.utils.deepClone(this.data.data);
rollData.item = foundry.utils.deepClone(this.system);

return rollData;
}
Expand All @@ -31,20 +31,20 @@ export class BasicFantasyRPGItem extends Item {
* @private
*/
async roll() {
const item = this.data;
const item = this;

// Initialize chat data.
const speaker = ChatMessage.getSpeaker({ actor: this.actor });
const rollMode = game.settings.get('core', 'rollMode');
const label = `Roll: ${game.i18n.localize('ITEM.Type' + item.type.capitalize())} - ${item.name}`;

// If there's no roll data, or the formula is empty, send a chat message.
if (!this.data.data.formula || !this.data.data.formula.value) {
if (!this.system.formula || !this.system.formula.value) {
ChatMessage.create({
speaker: speaker,
rollMode: rollMode,
flavor: label,
content: item.data.description ?? ''
content: item.description ?? ''
});
} else { // Otherwise, create a roll and send a chat message from it.
// Retrieve roll data.
Expand Down
31 changes: 17 additions & 14 deletions module/sheets/actor-sheet.mjs
Expand Up @@ -19,24 +19,27 @@ export class BasicFantasyRPGActorSheet extends ActorSheet {

/** @override */
get template() {
return `systems/basicfantasyrpg/templates/actor/actor-${this.actor.data.type}-sheet.html`;
return `systems/basicfantasyrpg/templates/actor/actor-${this.actor.type}-sheet.html`;
}

/* -------------------------------------------- */

/** @override */
getData() {
async 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();

//enrichedBiography -- enriches system.biography for editor
context.enrichedBiography = await TextEditor.enrichHTML(this.object.system.biography, {async: true});

// Use a safe clone of the actor data for further operations.
const actorData = this.actor.data.toObject(false);
const actorData = this.actor.toObject(false);

// Add the actor's data to context.data for easier access, as well as flags.
context.data = actorData.data;
context.data = actorData.system;
context.flags = actorData.flags;

// Prepare character data and items.
Expand Down Expand Up @@ -137,16 +140,16 @@ export class BasicFantasyRPGActorSheet extends ActorSheet {
// Append to gear.
if (i.type === 'item') {
gear.push(i);
carriedWeight._addWeight(i.data.weight.value, i.data.quantity.value);
carriedWeight._addWeight(i.system.weight.value, i.system.quantity.value);
} else if (i.type === 'weapon') { // Append to weapons.
weapons.push(i);
carriedWeight._addWeight(i.data.weight.value, 1); // Weapons are always quantity 1
carriedWeight._addWeight(i.system.weight.value, 1); // Weapons are always quantity 1
} else if (i.type === 'armor') { // Append to armors.
armors.push(i);
carriedWeight._addWeight(i.data.weight.value, 1); // Armor is always quantity 1
carriedWeight._addWeight(i.system.weight.value, 1); // Armor is always quantity 1
} else if (i.type === 'spell') { // Append to spells.
if (i.data.spellLevel.value != undefined) {
spells[i.data.spellLevel.value].push(i);
if (i.system.spellLevel.value != undefined) {
spells[i.system.spellLevel.value].push(i);
}
} else if (i.type === 'feature') { // Append to features.
features.push(i);
Expand Down Expand Up @@ -199,12 +202,12 @@ export class BasicFantasyRPGActorSheet extends ActorSheet {

// Prepare Spells
html.find('.spell-prepare').click(ev => {
const change = event.currentTarget.dataset.change;
const change = ev.currentTarget.dataset.change;
if (parseInt(change)) {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("itemId"));
let newValue = item.data.data.prepared.value + parseInt(change);
item.update({"data.prepared.value": newValue});
let newValue = item.system.prepared.value + parseInt(change);
item.update({"system.prepared.value": newValue});
}
});

Expand Down Expand Up @@ -276,14 +279,14 @@ export class BasicFantasyRPGActorSheet extends ActorSheet {
const item = this.actor.items.get(itemId);
let label = dataset.label ? `Roll: ${dataset.label}` : `Roll: ${dataset.attack.capitalize()} attack with ${item.name}`;
let rollFormula = 'd20+@ab';
if (this.actor.data.type == 'character') {
if (this.actor.type == 'character') {
if (dataset.attack == 'melee') {
rollFormula += '+@str.bonus';
} else if (dataset.attack == 'ranged') {
rollFormula += '+@dex.bonus';
}
}
rollFormula += '+' + item.data.data.bonusAb.value;
rollFormula += '+' + item.system.bonusAb.value;
let roll = new Roll(rollFormula, this.actor.getRollData());
roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
Expand Down
11 changes: 7 additions & 4 deletions module/sheets/item-sheet.mjs
Expand Up @@ -21,18 +21,21 @@ export class BasicFantasyRPGItemSheet extends ItemSheet {

// Alternatively, you could use the following return statement to do a
// unique item sheet by type, like `weapon-sheet.html`.
return `${path}/item-${this.item.data.type}-sheet.html`;
return `${path}/item-${this.item.type}-sheet.html`;
}

/* -------------------------------------------- */

/** @override */
getData() {
async getData() {
// Retrieve base data structure.
const context = super.getData();

// enrichedDescription - enriches system.description for editor
context.enrichedDescription = await TextEditor.enrichHTML(this.object.system.description, {async: true});

// Use a safe clone of the item data for further operations.
const itemData = context.item.data;
const itemData = context.item;

// Retrieve the roll data for TinyMCE editors.
context.rollData = {};
Expand All @@ -42,7 +45,7 @@ export class BasicFantasyRPGItemSheet extends ItemSheet {
}

// Add the actor's data to context.data for easier access, as well as flags.
context.data = itemData.data;
context.data = itemData.system;
context.flags = itemData.flags;

return context;
Expand Down
23 changes: 16 additions & 7 deletions system.json
@@ -1,11 +1,20 @@
{
"name": "basicfantasyrpg",
"id": "basicfantasyrpg",
"title": "Basic Fantasy RPG",
"description": "The Basic Fantasy RPG system for FoundryVTT!",
"version": "r6",
"minimumCoreVersion": "0.8.9",
"compatibleCoreVersion": "9",
"author": "Orffen",
"version": "r7",
"compatibility": {
"minimum": "10",
"verified": "10",
"maximum": "10"
},
"authors": [
{
"name": "Orffen",
"email": "orffen@orffenspace.com",
"discord": "Orffen#4571"
}
],
"esmodules": ["module/basicfantasyrpg.mjs"],
"styles": ["styles/basicfantasyrpg.css"],
"scripts": [],
Expand All @@ -23,6 +32,6 @@
"secondaryTokenAttribute": null,
"url": "https://github.com/orffen/basicfantasyrpg",
"manifest": "https://raw.githubusercontent.com/orffen/basicfantasyrpg/main/system.json",
"download": "https://github.com/orffen/basicfantasyrpg/archive/refs/tags/r6.zip",
"download": "https://github.com/orffen/basicfantasyrpg/archive/refs/tags/r7.zip",
"license": "LICENSE.txt"
}
}
5 changes: 1 addition & 4 deletions templates/actor/actor-monster-sheet.html
Expand Up @@ -100,11 +100,8 @@ <h1 class="charname"><input name="name" type="text" value="{{actor.name}}" place

{{!-- Description Tab --}}
<div class="tab description" data-group="primary" data-tab="description">
{{!-- If you want TinyMCE editors to output inline rolls when rendered, you need to pass the actor's roll data to the rollData property. --}}
{{editor content=data.biography target="data.biography" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedBiography target="system.biography" button=true editable=editable}}
</div>

</section>
</form>

<!-- <script>document.getElementsByName('data.attackBonus.value')[0].disabled = true;</script> -->
4 changes: 2 additions & 2 deletions templates/actor/parts/actor-combat.html
Expand Up @@ -50,7 +50,7 @@ <h4>{{weapon.name}}</h4>
<a class="rollable" data-roll-type="weapon" data-attack="melee"><img src="systems/basicfantasyrpg/styles/melee.svg" title="{{localize 'BASICFANTASYRPG.Melee'}} {{localize 'BASICFANTASYRPG.Attack'}}" width="24" height="24"/></a>
<a class="rollable" data-roll-type="weapon" data-attack="ranged"><img src="systems/basicfantasyrpg/styles/ranged.svg" title="{{localize 'BASICFANTASYRPG.Ranged'}} {{localize 'BASICFANTASYRPG.Attack'}}" width="24" height="24"/></a>
<span class="flexshrink">/</span>
<a class="rollable" data-roll-type="damage" data-roll="{{weapon.data.damage.value}}" data-label="{{weapon.name}} {{localizeLowerCase weapon.data.damage.label}}"><img src="systems/basicfantasyrpg/styles/damage.svg" title="{{weapon.data.damage.value}}" width="24" height="24"/></a>
<a class="rollable" data-roll-type="damage" data-roll="{{weapon.system.damage.value}}" data-label="{{weapon.name}} {{localizeLowerCase weapon.system.damage.label}}"><img src="systems/basicfantasyrpg/styles/damage.svg" title="{{weapon.system.damage.value}}" width="24" height="24"/></a>
</div>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
Expand All @@ -76,7 +76,7 @@ <h4>{{weapon.name}}</h4>
</div>
<h4>{{armor.name}}</h4>
</div>
<div class="item-prop">{{localize armor.data.armorClass.abbr}} {{armor.data.armorClass.value}}</div>
<div class="item-prop">{{localize armor.system.armorClass.abbr}} {{armor.system.armorClass.value}}</div>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
Expand Down
3 changes: 1 addition & 2 deletions templates/actor/parts/actor-description.html
Expand Up @@ -23,5 +23,4 @@

</section>

{{!-- If you want TinyMCE editors to output inline rolls when rendered, you need to pass the actor's roll data to the rollData property. --}}
{{editor content=data.biography target="data.biography" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedBiography target="system.biography" button=true editable=editable}}
2 changes: 1 addition & 1 deletion templates/actor/parts/actor-features.html
Expand Up @@ -14,7 +14,7 @@
</div>
<h4>{{item.name}}</h4>
</div>
<div class="item-formula item-prop rollable" data-roll-type="item">{{item.data.formula.value}}</div>
<div class="item-formula item-prop rollable" data-roll-type="item">{{item.system.formula.value}}</div>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
Expand Down
6 changes: 3 additions & 3 deletions templates/actor/parts/actor-items.html
Expand Up @@ -53,11 +53,11 @@
<div class="item-image">
<a class="rollable" data-roll-type="item"><img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/></a>
</div>
<h4>{{item.data.quantity.value}} {{item.name}}</h4>
<h4>{{item.system.quantity.value}} {{item.name}}</h4>
</div>
<div class="item-prop grid grid-2col">
<div class="flex-left align-right">{{item.data.weight.value}} lbs.</div>
<div class="flex-right">{{item.data.price.value}}</div>
<div class="flex-left align-right">{{item.system.weight.value}} lbs.</div>
<div class="flex-right">{{item.system.price.value}}</div>
</div>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
Expand Down
2 changes: 1 addition & 1 deletion templates/actor/parts/actor-spells.html
Expand Up @@ -29,7 +29,7 @@ <h4>{{item.name}}</h4>
</div>
<div class="item-prop grid grid-3col">
<div class="flex-group-right"><a class="item-control spell-prepare" data-change="-1"><i class="fas fa-minus"></i></a></div>
<div class="flex-group-center">{{item.data.prepared.value}}</div>
<div class="flex-group-center">{{item.system.prepared.value}}</div>
<div class="flex-group-left"><a class="item-control spell-prepare" data-change="+1"><i class="fas fa-plus"></i></a></div>
</div>
<div class="item-controls">
Expand Down
2 changes: 1 addition & 1 deletion templates/item/item-armor-sheet.html
Expand Up @@ -25,7 +25,7 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh

{{!-- Description Tab --}}
<div class="description">
{{editor content=data.description target="data.description" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedDescription target="system.description" button=true editable=editable}}
</div>

</section>
Expand Down
2 changes: 1 addition & 1 deletion templates/item/item-feature-sheet.html
Expand Up @@ -17,7 +17,7 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh

{{!-- Description Tab --}}
<div class="description">
{{editor content=data.description target="data.description" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedDescription target="system.description" button=true editable=editable}}
</div>

</section>
Expand Down
2 changes: 1 addition & 1 deletion templates/item/item-item-sheet.html
Expand Up @@ -25,7 +25,7 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh

{{!-- Description --}}
<div class="description">
{{editor content=data.description target="data.description" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedDescription target="system.description" button=true editable=editable}}
</div>

</section>
Expand Down
3 changes: 1 addition & 2 deletions templates/item/item-sheet.html
Expand Up @@ -19,8 +19,7 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh

{{!-- Description Tab --}}
<div class="tab" data-group="primary" data-tab="description">
{{!-- To render inline rolls in a TinyMCE editor, you need to pass the parent actor's (if any) roll data to the rollData prop. --}}
{{editor content=data.description target="data.description" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedDescription target="system.description" button=true editable=editable}}
</div>

{{!-- Attributes Tab --}}
Expand Down
2 changes: 1 addition & 1 deletion templates/item/item-spell-sheet.html
Expand Up @@ -33,7 +33,7 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh

{{!-- Description Tab --}}
<div class="description">
{{editor content=data.description target="data.description" rollData=rollData button=true owner=owner editable=editable}}
{{editor enrichedDescription target="system.description" button=true editable=editable}}
</div>

</section>
Expand Down

0 comments on commit b2eafe3

Please sign in to comment.