Skip to content

Commit

Permalink
FEAT: add selectable attribute mod on defenses stats
Browse files Browse the repository at this point in the history
FIX: error on calc REX defense
  • Loading branch information
joaquinpereyra98 committed Jun 23, 2024
1 parent ffacb79 commit f685d6e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 43 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "simply-sheet-swse",
"title": "Simply Sheet for Star War: Saga Edition",
"description": "",
"version": "0.5.4",
"version": "0.5.5",
"compatibility": {
"minimun": "11",
"verified": "11"
Expand All @@ -16,7 +16,7 @@
}
],
"url": "https://github.com/joaquinpereyra98/simply-sheet-swse",
"download": "https://github.com/joaquinpereyra98/simply-sheet-swse/releases/download/v0.5.4/module.zip",
"download": "https://github.com/joaquinpereyra98/simply-sheet-swse/releases/download/v0.5.5/module.zip",
"manifest": "https://github.com/joaquinpereyra98/simply-sheet-swse/releases/latest/download/module.json",
"readme": "README.md",
"relationships": {
Expand Down
73 changes: 41 additions & 32 deletions src/actor-sheet/actor-sheet.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SWSEActorSheet } from "../../../../systems/swse/module/actor/actor-sheet.mjs";
import { onToggle } from "../../../../systems/swse/module/common/listeners.mjs";
import { createAttackDialog } from "../utils.mjs";
export class SimplySWSEActorSheet extends SWSEActorSheet {
/** @override */
Expand Down Expand Up @@ -33,7 +32,6 @@ export class SimplySWSEActorSheet extends SWSEActorSheet {
this.prepareBeastComponent(context);
this.prepareForcePowers(context);
this.prepareEquipment(context);

return context;
}
/**
Expand Down Expand Up @@ -77,12 +75,13 @@ export class SimplySWSEActorSheet extends SWSEActorSheet {
}
prepareForcePowers(context) {
const { powers, secrets, techniques, regimens } = this.actor;

const powersFinal = foundry.utils.deepClone(powers).map( i => {
const useTracker = this.actor.getFlag("simply-sheet-swse", "useTracker") || {};
i.useTracker = useTracker[i.id]
return i
})

const powersFinal = foundry.utils.deepClone(powers).map((i) => {
const useTracker =
this.actor.getFlag("simply-sheet-swse", "useTracker") || {};
i.useTracker = useTracker[i.id];
return i;
});

context.forcePowers = {
forcePower: powersFinal,
Expand Down Expand Up @@ -152,12 +151,24 @@ export class SimplySWSEActorSheet extends SWSEActorSheet {
const val = $(selector).val();
this.actor.update({ [`system.skills.${id}.attribute`]: val });
});
html.find(".select-defense-attribute").on("change", (ev) => {
const selector = ev.currentTarget;
const id = selector.dataset.id;
const val = $(selector).val();
this.actor.setFlag("simply-sheet-swse", `${id}Attribute`, val)
});
html
.find("[data-action=create-attack]")
.on("click", this._onCreateAttack.bind(this));
html.find(".uses-force-checkbox").on("change", this._onToggleForceUse.bind(this))
html.find("[data-action=increase-uses]").on("click", this._onIncreaseForceUses.bind(this))
html.find("[data-action=decrease-uses]").on("click", this._onDecreaseForceUses.bind(this))
html
.find(".uses-force-checkbox")
.on("change", this._onToggleForceUse.bind(this));
html
.find("[data-action=increase-uses]")
.on("click", this._onIncreaseForceUses.bind(this));
html
.find("[data-action=decrease-uses]")
.on("click", this._onDecreaseForceUses.bind(this));
}
_onIncreaseItemQuantity(event) {
event.preventDefault();
Expand All @@ -168,7 +179,6 @@ export class SimplySWSEActorSheet extends SWSEActorSheet {
} else {
item.update({ "system.quantity": item.system.quantity + 1 });
}

}
_onEquipToggle(event) {
event.preventDefault();
Expand All @@ -189,41 +199,40 @@ export class SimplySWSEActorSheet extends SWSEActorSheet {
event.preventDefault();
const id = event.currentTarget.dataset.itemId;
const item = this.actor.items.get(id);
let useTracker = this.actor.getFlag("simply-sheet-swse", "useTracker") || {};
let useTracker =
this.actor.getFlag("simply-sheet-swse", "useTracker") || {};

if (!useTracker[item.id]) {
useTracker[item.id] = [false];
useTracker[item.id] = [false];
} else {
useTracker[item.id].push(false);
useTracker[item.id].push(false);
}

this.actor.setFlag("simply-sheet-swse", "useTracker", useTracker);
}

}
_onDecreaseForceUses(event) {
event.preventDefault();
const id = event.currentTarget.dataset.itemId;
const item = this.actor.items.get(id);
const useTracker = this.actor.getFlag("simply-sheet-swse", "useTracker") || {};

const useTracker =
this.actor.getFlag("simply-sheet-swse", "useTracker") || {};

if (useTracker[item.id]) {
useTracker[item.id].pop();
useTracker[item.id].pop();
}

this.actor.setFlag("simply-sheet-swse", "useTracker", useTracker);
}

_onToggleForceUse(event) {
event.preventDefault();
const li = event.currentTarget.closest(".item");
const item = this.actor.items.get(li.dataset.itemId);
const key = event.currentTarget.dataset.key;
let useTracker = this.actor.getFlag("simply-sheet-swse", "useTracker");
this.actor.setFlag("simply-sheet-swse", "useTracker", useTracker);
}
_onToggleForceUse(event) {
event.preventDefault();
const li = event.currentTarget.closest(".item");
const item = this.actor.items.get(li.dataset.itemId);
const key = event.currentTarget.dataset.key;
let useTracker = this.actor.getFlag("simply-sheet-swse", "useTracker");

if (useTracker && useTracker[item.id]) {
if (useTracker && useTracker[item.id]) {
useTracker[item.id][key] = !useTracker[item.id][key];
this.actor.setFlag("simply-sheet-swse", "useTracker", useTracker);
}
}
}

}
49 changes: 45 additions & 4 deletions src/actor-sheet/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,50 @@ import { SWSEActor } from "../../../../systems/swse/module/actor/actor.mjs";
export class SimplySWSEActor extends SWSEActor {
_prepareCharacterData(system) {
super._prepareCharacterData(system);
const defences = ["fortitude", "will", "reflex"];
defences.forEach((def) => {
system.defense[def].total += system.levelSummary;
});
system.defense.fortitude = this.prepareFortitude();
system.defense.will = this.prepareWill();
system.defense.reflex = this.prepareReflex();
}
prepareFortitude() {
const {armorBonus, classBonus, miscBonus, override} = this.system.defense.fortitude;
const attributeBonus = this.getFlag('simply-sheet-swse', 'fortitudeAttribute') || "con";
const total = 10 + armorBonus + classBonus + miscBonus + this.system.attributes[attributeBonus]?.mod;
return {
...this.system.defense.fortitude,
total: (override || total) + this.system.levelSummary,
attributeBonus: attributeBonus,
}
}

prepareWill() {
const {armorBonus, classBonus, miscBonus, override} = this.system.defense.will;
const attributeBonus = this.getFlag('simply-sheet-swse', 'willAttribute') || "wis";
const total = 10 + armorBonus + classBonus + miscBonus + this.system.attributes[attributeBonus]?.mod;
return {
...this.system.defense.will,
total: (override || total) + this.system.levelSummary,
attributeBonus: attributeBonus,
}
}
prepareReflex() {
const { armorBonus, classBonus, miscBonus, override } = this.system.defense.reflex;
const attributeBonus = this.getFlag('simply-sheet-swse', 'reflexAttribute') || "dex";
const attrMod = this.system.attributes[attributeBonus]?.mod || 0;

const bonusArray = this.getEquippedItems()
.map(item => item.maximumDexterityBonus)
.filter(bonus => typeof bonus === 'number' && bonus > 0);

const minAttributeBonus = Math.min(attrMod, ...bonusArray);

const baseTotal = 10 + armorBonus + classBonus + miscBonus + minAttributeBonus;
const total = (override || baseTotal) + this.system.levelSummary;

return {
...this.system.defense.reflex,
total,
attributeBonus
};
}

}
2 changes: 0 additions & 2 deletions src/simply-sheet-swase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { SimplySWSEActorSheet } from "./actor-sheet/actor-sheet.mjs";
import { prepareTemplates } from "./utils.mjs";
import { SimplySWSEActor } from "./actor-sheet/actor.mjs";
Hooks.on("init", function () {
console.log(CONFIG.Actor.documentClass);
prepareTemplates();
Actors.registerSheet("simply-sheet-swase", SimplySWSEActorSheet, {
makeDefault: true,
label: "SIMPLY-SHEET-SWASE.SheetLabel",
});
CONFIG.Actor.documentClass = SimplySWSEActor;
console.log(CONFIG.Actor.documentClass);
});
Hooks.on("preCreateActor", (document, data, options, userId) => {
document.updateSource({ ["system.ignorePrerequisites"]: true });
Expand Down
6 changes: 6 additions & 0 deletions styles/simply-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
margin-bottom: 5px;
border-bottom: 2px solid #424ca491;
}
.simply-sheet .tab-summary .defence.panel .defense-block select.select-defense-attribute {
padding: 0;
height: auto;
margin-right: 2px;
font-size: 0.9rem;
}

.simply-sheet .tab-summary .skill-table td.total-skill {
font-size: large;
Expand Down
12 changes: 9 additions & 3 deletions template/parts/summary-tab-parts/defence-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@
</div>
<div class="flex-col">
<label class=" small-header">Ability</label>
<div class="unlabeled-input">
<input class="input" type="text" value="{{def.abilityBonus}}" disabled />
</div>
<select class="select-defense-attribute" data-id="{{id}}" name="">
{{#select def.attributeBonus}}
{{#if (eq id "will")}}
{{/if}}
{{#each ../abilities as |ability key|}}
<option value="{{key}}">{{ability.label}}</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="flex-col">
<label class=" small-header">Class</label>
Expand Down

0 comments on commit f685d6e

Please sign in to comment.