Skip to content

Commit

Permalink
refactor: ♻️ Initial pass, actor/item sheets open and rolling dice works
Browse files Browse the repository at this point in the history
  • Loading branch information
aMediocreDad committed Jul 3, 2022
1 parent b61547a commit 762a59c
Show file tree
Hide file tree
Showing 51 changed files with 646 additions and 636 deletions.
4 changes: 2 additions & 2 deletions src/actor/actor-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import localize from "@utils/localize-string.js";

export class ForbiddenLandsActor extends Actor {
get actorProperties() {
return this.data.data;
return this.system;
}

get attributes() {
Expand Down Expand Up @@ -38,7 +38,7 @@ export class ForbiddenLandsActor extends Actor {
return {
alias: this.token?.name || this.name,
actorId: this.id,
actorType: this.data.type,
actorType: this.system.type,
isBroken: this.isBroken,
sceneId: this.token?.parent.id,
tokenId: this.token?.id,
Expand Down
30 changes: 15 additions & 15 deletions src/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
altInteraction = game.settings.get("forbidden-lands", "alternativeSkulls");

getData() {
const data = this.actorData.toObject();
const data = this.actor.toObject();
data.items?.sort((a, b) => (a.sort || 0) - (b.sort || 0));
return data;
}
Expand All @@ -16,7 +16,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
}

get actorProperties() {
return this.actorData.data;
return this.actor.system;
}

get rollData() {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
// Attribute markers
html.find(".change-attribute").on("click contextmenu", (ev) => {
const attributeName = $(ev.currentTarget).data("attribute");
const attribute = this.actor.data.data.attribute[attributeName];
const attribute = this.actorProperties.attribute[attributeName];
let value = attribute.value;
if ((ev.type === "click" && !this.altInteraction) || (ev.type === "contextmenu" && this.altInteraction)) {
value = Math.max(value - 1, 0);
Expand All @@ -58,13 +58,13 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
value = Math.min(value + 1, attribute.max);
}
this.actor.update({
["data.attribute." + attributeName + ".value"]: value,
["system.attribute." + attributeName + ".value"]: value,
});
});

// Willpower markers
html.find(".change-willpower").on("click contextmenu", (ev) => {
const attribute = this.actor.data.data.bio.willpower;
const attribute = this.actorProperties.bio.willpower;
let value = attribute.value;
if ((ev.type === "click" && !this.altInteraction) || (ev.type === "contextmenu" && this.altInteraction)) {
value = Math.max(value - 1, 0);
Expand All @@ -74,7 +74,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
) {
value = Math.min(value + 1, attribute.max);
}
this.actor.update({ "data.bio.willpower.value": value });
this.actor.update({ "system.bio.willpower.value": value });
});

// Items
Expand Down Expand Up @@ -103,10 +103,10 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
(ev.type === "contextmenu" && !this.altInteraction) ||
(ev.type === "click" && this.altInteraction)
) {
value = Math.min(value + 1, item.data.data.bonus.max);
value = Math.min(value + 1, item.itemProperties.bonus.max);
}
item.update({
"data.bonus.value": value,
"system.bonus.value": value,
});
});

Expand Down Expand Up @@ -140,7 +140,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
this.actor.updateEmbeddedDocuments("Item", [
{
_id: itemId,
"data.quantity": ev.currentTarget.value,
"system.quantity": ev.currentTarget.value,
},
]);
});
Expand Down Expand Up @@ -346,7 +346,7 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
}

computeSkills(data) {
for (let skill of Object.values(data.data.skill)) {
for (let skill of Object.values(data.system.skill)) {
skill[`has${skill?.attribute?.capitalize()}`] = false;
if (CONFIG.fbl.attributes.includes(skill.attribute)) skill[`has${skill.attribute.capitalize()}`] = true;
}
Expand All @@ -355,18 +355,18 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
computeItems(data) {
for (const item of Object.values(data.items)) {
// Shields were long treated as armor. They are not. This is a workaround for that.
if (item.data.part === "shield") item.isWeapon = true;
if (item.system.part === "shield") item.isWeapon = true;
else if (CONFIG.fbl.itemTypes.includes(item.type)) item[`is${item.type.capitalize()}`] = true;
}
}

computeItemEncumbrance(data) {
const type = data.type;
const weight = isNaN(Number(data?.data.weight))
? this.config.encumbrance[data?.data.weight] ?? 1
: Number(data?.data.weight) ?? 1;
const weight = isNaN(Number(data?.system.weight))
? this.config.encumbrance[data?.system.weight] ?? 1
: Number(data?.system.weight) ?? 1;
// Only return weight for these types.
if (type === "rawMaterial") return 1 * Number(data.data.quantity);
if (type === "rawMaterial") return 1 * Number(data.system.quantity);
if (["gear", "armor", "weapon"].includes(type)) return weight;
// Talents, Spells, and the like dont have weight.
return 0;
Expand Down
36 changes: 18 additions & 18 deletions src/actor/character/character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ForbiddenLandsActorSheet } from "../actor-sheet.js";
import { ForbiddenLandsCharacterGenerator } from "@components/character-generator/character-generator.js";
import { FBLRoll, FBLRollHandler } from "@components/roll-engine/engine.js";
import localizeString from "@utils/localize-string";
import { ActorSheetConfig } from "@utils/sheet-config.js";
//import { ActorSheetConfig } from "@utils/sheet-config.js";

export class ForbiddenLandsCharacterSheet extends ForbiddenLandsActorSheet {
static get defaultOptions() {
Expand Down Expand Up @@ -78,9 +78,9 @@ export class ForbiddenLandsCharacterSheet extends ForbiddenLandsActorSheet {
const operator = $(ev.currentTarget).data("operator");
const modifier = ev.type === "contextmenu" ? 5 : 1;
let coins = [
this.actor.data.data.currency.gold.value,
this.actor.data.data.currency.silver.value,
this.actor.data.data.currency.copper.value,
this.actor.actorProperties.currency.gold.value,
this.actor.actorProperties.currency.silver.value,
this.actor.actorProperties.currency.copper.value,
];
let i = { gold: 0, silver: 1, copper: 2 }[currency];
if (operator === "plus") {
Expand Down Expand Up @@ -109,19 +109,19 @@ export class ForbiddenLandsCharacterSheet extends ForbiddenLandsActorSheet {
for (let item of Object.values(data.items)) {
weightCarried += this.computeItemEncumbrance(item);
}
for (let consumable of Object.values(data.data.consumable)) {
for (let consumable of Object.values(data.system.consumable)) {
if (consumable.value > 0) {
weightCarried += 1;
}
}
const coinsCarried =
parseInt(data.data.currency.gold.value) +
parseInt(data.data.currency.silver.value) +
parseInt(data.data.currency.copper.value);
parseInt(data.system.currency.gold.value) +
parseInt(data.system.currency.silver.value) +
parseInt(data.system.currency.copper.value);
weightCarried += Math.floor(coinsCarried / 100) * 0.5;
const modifiers = this.actor.getRollModifierOptions("carryingCapacity");
const weightAllowed = data.data.attribute.strength.max * 2 + (parseInt(modifiers[0]?.value) || 0);
data.data.encumbrance = {
const weightAllowed = data.system.attribute.strength.max * 2 + (parseInt(modifiers[0]?.value) || 0);
data.system.encumbrance = {
value: weightCarried,
max: weightAllowed,
over: weightCarried > weightAllowed,
Expand Down Expand Up @@ -189,13 +189,13 @@ export class ForbiddenLandsCharacterSheet extends ForbiddenLandsActorSheet {
}

/* Override */
_onConfigureSheet(event) {
event.preventDefault();
new ActorSheetConfig(this.actor, {
top: this.position.top + 40,
left: this.position.left + (this.position.width - 400) / 2,
}).render(true);
}
// _onConfigureSheet(event) {
// event.preventDefault();
// new ActorSheetConfig(this.actor, {
// top: this.position.top + 40,
// left: this.position.left + (this.position.width - 400) / 2,
// }).render(true);
// }

_getHeaderButtons() {
let buttons = super._getHeaderButtons();
Expand All @@ -219,7 +219,7 @@ export class ForbiddenLandsCharacterSheet extends ForbiddenLandsActorSheet {
class: "char-gen",
icon: "fas fa-leaf",
onclick: async () => {
const hasFilledAttributes = Object.values(this.actor.data.data.attribute)
const hasFilledAttributes = Object.values(this.actor.actorProperties.attribute)
.flatMap((a) => a.value + a.max)
.some((v) => v > 0);

Expand Down
10 changes: 5 additions & 5 deletions src/actor/character/templates/character-limited-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</td>
<td>
<label>
{{localize data.bio.kin.label}}:
{{localize system.bio.kin.label}}:
</label>
</td>
<td>
Expand All @@ -27,23 +27,23 @@
<tr>
<td>
<label>
{{localize data.bio.age.label}}:
{{localize system.bio.age.label}}:
</label>
</td>
<td>
???
</td>
<td>
<label>
{{localize data.bio.reputation.label}}:
{{localize system.bio.reputation.label}}:
</label>
</td>
<td>
???
</td>
<td>
<label>
{{localize data.bio.profession.label}}:
{{localize system.bio.profession.label}}:
</label>
</td>
<td>
Expand All @@ -57,7 +57,7 @@
<div class="margin padding">
<!-- prettier-ignore -->
{{! prettier-ignore }}
{{editor content=data.bio.note.value target="data.bio.note.value"}}
{{editor system.bio.note.value target="system.bio.note.value"}}
</div>
</div>
</div>
Expand Down
34 changes: 17 additions & 17 deletions src/actor/character/templates/character-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,55 @@
<input class="name" name="name" type="text" value="{{name}}" />
</td>
<td>
<label>{{localize data.bio.kin.label}}:</label>
<label>{{localize system.bio.kin.label}}:</label>
</td>
<td>
<input class="kin" name="data.bio.kin.value" type="text" value="{{data.bio.kin.value}}" />
<input class="kin" name="system.bio.kin.value" type="text" value="{{system.bio.kin.value}}" />
</td>
</tr>
<tr>
<td>
<label>{{localize data.bio.age.label}}:</label>
<label>{{localize system.bio.age.label}}:</label>
</td>
<td>
<input name="data.bio.age.value" type="number" value="{{data.bio.age.value}}"
<input name="system.bio.age.value" type="number" value="{{system.bio.age.value}}"
data-dtype="Number" />
</td>
<td>
<label>{{localize data.bio.reputation.label}}:</label>
<label>{{localize system.bio.reputation.label}}:</label>
</td>
<td>
<input name="data.bio.reputation.value" type="number" value="{{data.bio.reputation.value}}"
<input name="system.bio.reputation.value" type="number" value="{{system.bio.reputation.value}}"
data-dtype="Number" />
</td>
<td>
<label>{{localize data.bio.profession.label}}:</label>
<label>{{localize system.bio.profession.label}}:</label>
</td>
<td>
<input class="profession" name="data.bio.profession.value" type="text"
value="{{data.bio.profession.value}}" />
<input class="profession" name="system.bio.profession.value" type="text"
value="{{system.bio.profession.value}}" />
</td>
</tr>
<tr>
<td>
<label>{{localize data.bio.experience.label}}:</label>
<label>{{localize system.bio.experience.label}}:</label>
</td>
<td>
<input name="data.bio.experience.value" type="number" value="{{data.bio.experience.value}}"
<input name="system.bio.experience.value" type="number" value="{{system.bio.experience.value}}"
data-dtype="Number" />
</td>
<td>
<label>{{localize data.bio.willpower.label}}:</label>
<label>{{localize system.bio.willpower.label}}:</label>
</td>
<td>
<input name="data.bio.willpower.value" type="number" value="{{data.bio.willpower.value}}"
min="{{data.bio.willpower.min}}" max="{{data.bio.willpower.max}}" data-dtype="Number" />
<input name="system.bio.willpower.value" type="number" value="{{system.bio.willpower.value}}"
min="{{system.bio.willpower.min}}" max="{{system.bio.willpower.max}}" data-dtype="Number" />
</td>
<td colspan="2">
<div
class="skulls willpower {{#unless data.bio.willpower.value }}broken{{/unless}} flex row align-center">
class="skulls willpower {{#unless system.bio.willpower.value }}broken{{/unless}} flex row align-center">
<a class="change-willpower">
{{#skulls data.bio.willpower.value data.bio.willpower.max}}
{{#skulls system.bio.willpower.value system.bio.willpower.max}}
<i
class="skull {{#if @damaged}}far fa-circle{{else}}{{#if alternativeSkulls}} fas fa-circle {{else}} far fa-times-circle{{/if}}{{/if}}"></i>
{{/skulls}}
Expand Down Expand Up @@ -112,7 +112,7 @@
<div class="tab note" data-group="primary" data-tab="note">
<!-- prettier-ignore -->
{{! prettier-ignore }}
{{editor content=data.bio.note.value target="data.bio.note.value" button=true owner=owner
{{editor system.bio.note.value target="system.bio.note.value" button=true owner=owner
editable=true}}
</div>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/actor/character/templates/npc-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@
<input class="name" name="name" type="text" value="{{name}}" />
</td>
<td>
<label>{{localize data.bio.kin.label}}:</label>
<label>{{localize system.bio.kin.label}}:</label>
</td>
<td>
<input class="kin" name="data.bio.kin.value" type="text" value="{{data.bio.kin.value}}" />
<input class="kin" name="system.bio.kin.value" type="text" value="{{system.bio.kin.value}}" />
</td>
</tr>
<tr>
<td>
<label>{{localize data.bio.age.label}}:</label>
<label>{{localize system.bio.age.label}}:</label>
</td>
<td>
<input name="data.bio.age.value" type="number" value="{{data.bio.age.value}}"
<input name="system.bio.age.value" type="number" value="{{system.bio.age.value}}"
data-dtype="Number" />
</td>
<td>
<label>{{localize data.bio.reputation.label}}:</label>
<label>{{localize system.bio.reputation.label}}:</label>
</td>
<td>
<input name="data.bio.reputation.value" type="number" value="{{data.bio.reputation.value}}"
<input name="system.bio.reputation.value" type="number" value="{{system.bio.reputation.value}}"
data-dtype="Number" />
</td>
<td>
<label>{{localize data.bio.profession.label}}:</label>
<label>{{localize system.bio.profession.label}}:</label>
</td>
<td>
<input class="profession" name="data.bio.profession.value" type="text"
value="{{data.bio.profession.value}}" />
<input class="profession" name="system.bio.profession.value" type="text"
value="{{system.bio.profession.value}}" />
</td>
</tr>
</table>
Expand Down Expand Up @@ -79,7 +79,7 @@
<div class="tab note" data-group="primary" data-tab="note">
<!-- prettier-ignore -->
{{! prettier-ignore }}
{{editor content=data.bio.note.value target="data.bio.note.value" button=true owner=owner
{{editor system.bio.note.value target="system.bio.note.value" button=true owner=owner
editable=true}}
</div>
</div>
Expand Down
Loading

0 comments on commit 762a59c

Please sign in to comment.