From a1a784345496c884f80837271142fa19617a2d8a Mon Sep 17 00:00:00 2001
From: supervj <64861570+supervj@users.noreply.github.com>
Date: Wed, 9 Jun 2021 01:16:38 -0400
Subject: [PATCH] Further Updates to starship sheet
With the help of Cyr we made some progress
Connected fuel burn and refuel
connected power die
connected power routing
added debug handlebar helper to help see scope of html pages
---
module/actor/entity.js | 13 +++----
module/actor/sheets/newSheet/starship.js | 49 ++++++++++++++++--------
sw5e.js | 4 ++
templates/actors/newActor/starship.html | 22 ++++-------
4 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/module/actor/entity.js b/module/actor/entity.js
index 349bcf4d..1b89681f 100644
--- a/module/actor/entity.js
+++ b/module/actor/entity.js
@@ -343,7 +343,8 @@ export default class Actor5e extends Actor {
// push to derived since based on attributes
// data.attributes.hp.tempmax = sizeData.shldDiceRolled[].reduce((a, b) => a + b, 0) + str.mod * shld.diceMax;
// if (data.attributes.hp.temp === null) data.attributes.hp.temp = data.attributes.hp.tempmax;
- data.attributes.pwrdice.die = SW5E.powerDieTypes[tiers];
+ sizeData.pwrDice = SW5E.powerDieTypes[tiers];
+ data.attributes.power.die = sizeData.pwrDice;
data.attributes.cost.baseBuild = sizeData.buildBaseCost;
data.attributes.workforce.minBuild = sizeData.buildMinWorkforce;
data.attributes.workforce.max = data.attributes.workforce.minBuild * 5;
@@ -367,7 +368,7 @@ export default class Actor5e extends Actor {
data.attributes.workforce.minEquip = sizeData.equipMinWorkforce;
data.attributes.equip.cargoCap = sizeData.cargoCap;
data.attributes.fuel.cost = sizeData.fuelCost;
- data.attributes.fuel.value = sizeData.fuelCap;
+ data.attributes.fuel.cap = sizeData.fuelCap;
data.attributes.equip.foodCap = sizeData.foodCap;
@@ -702,12 +703,10 @@ export default class Actor5e extends Actor {
}
_computeFuel(actorData) {
- let fuel = actorData.data.attributes.fuel.value;
+ const fuel = actorData.data.attributes.fuel;
// Compute Fuel percentage
- fuel = fuel.toNearest(0.1);
- const max = actorData.data.attributes.fuel.cap;
- const pct = Math.clamped((fuel * 100) / max, 0, 100);
- return { value: fuel.toNearest(0.1), max, pct, fueled: pct > 0 };
+ const pct = Math.clamped((fuel.value.toNearest(0.1) * 100) / fuel.cap, 0, 100);
+ return { ...fuel, pct, fueled: pct > 0 };
}
/* -------------------------------------------- */
diff --git a/module/actor/sheets/newSheet/starship.js b/module/actor/sheets/newSheet/starship.js
index 973dcbbd..cb846d2b 100644
--- a/module/actor/sheets/newSheet/starship.js
+++ b/module/actor/sheets/newSheet/starship.js
@@ -137,6 +137,10 @@ export default class ActorSheet5eStarship extends ActorSheet5e {
super.activateListeners(html);
html.find(".health .rollable").click(this._onRollHPFormula.bind(this));
html.find('.refuel').click(this._onIncrementFuelLevel.bind(this));
+ html.find('.burnfuel').click(this._onDecrementFuelLevel.bind(this));
+ html.find('#engineslidervalue')[0].addEventListener('input', this._engineSliderUpdate.bind(this));
+ html.find('#shieldslidervalue')[0].addEventListener('input', this._shieldSliderUpdate.bind(this));
+ html.find('#weaponslidervalue')[0].addEventListener('input', this._weaponSliderUpdate.bind(this));
}
/* -------------------------------------------- */
@@ -163,17 +167,31 @@ export default class ActorSheet5eStarship extends ActorSheet5e {
* @private
*/
_onIncrementFuelLevel(event) {
- event.preventDefault();
- const fuelcaparray = this.actor.data.effects.changes;
- var fuelcappos = fuelcaparray.indexOf('fuel.cap');
- const refuel = this.actor.data.effect.changes[fuelcappos].value;
- this.actor.update({"data.attributes.fuel.value": refuel});
+ // event.preventDefault();
+ // const fuelcaparray = this.actor.data.effects.changes;
+ // var fuelcappos = fuelcaparray.indexOf('fuel.cap');
+ // const refuel = this.actor.data.effect.changes[fuelcappos].value;
+ this.actor.update({"data.attributes.fuel.value": this.actor.data.data.attributes.fuel.cap});
}
-}
- function engineSliderUpdate(num) {
+
+ /* -------------------------------------------- */
+
+ /**
+ * Handle a starship burning fuel
+ * @param {Event} event The original click event
+ * @private
+ */
+ _onDecrementFuelLevel(event) {
+ // event.preventDefault();
+ // const fuelcaparray = this.actor.data.effects.changes;
+ // var fuelcappos = fuelcaparray.indexOf('fuel.cap');
+ // const refuel = this.actor.data.effect.changes[fuelcappos].value;
+ this.actor.update({"data.attributes.fuel.value": this.actor.data.data.attributes.fuel.value - 1});
+ }
+ _engineSliderUpdate(input) {
var symbol;
var coefficient;
- switch(num) {
+ switch(input.target.value) {
case "0":
symbol = "↓";
coefficient = 0.5;
@@ -188,13 +206,13 @@ export default class ActorSheet5eStarship extends ActorSheet5e {
};
let slideroutput = symbol;
document.querySelector('#engineslideroutput').value = slideroutput;
- this.actor.update({"data.attributes.engpow": coefficient});
+ this.actor.update({"data.attributes.power.routing.engines": coefficient});
}
- function shieldSliderUpdate(num) {
+ _shieldSliderUpdate(input) {
var symbol;
var coefficient;
- switch(num) {
+ switch(input.target.value) {
case "0":
symbol = "↓";
coefficient = 0.5;
@@ -209,13 +227,13 @@ export default class ActorSheet5eStarship extends ActorSheet5e {
};
let slideroutput = symbol;
document.querySelector('#shieldslideroutput').value = slideroutput;
- this.actor.update({"data.attributes.shieldpow": coefficient});
+ this.actor.update({"data.attributes.power.routing.shields": coefficient});
}
- function weaponSliderUpdate(num) {
+ _weaponSliderUpdate(input) {
var symbol;
var coefficient;
- switch(num) {
+ switch(input.target.value) {
case "0":
symbol = "↓";
coefficient = 0.5;
@@ -230,5 +248,6 @@ export default class ActorSheet5eStarship extends ActorSheet5e {
};
let slideroutput = symbol;
document.querySelector('#weaponslideroutput').value = slideroutput;
- this.actor.update({"data.attributes.weaponpow": coefficient});
+ this.actor.update({"data.attributes.power.routing.weapons": coefficient});
}
+}
diff --git a/sw5e.js b/sw5e.js
index 026e4b42..20cbd2f7 100644
--- a/sw5e.js
+++ b/sw5e.js
@@ -281,6 +281,10 @@ Handlebars.registerHelper('round', function(value) {
return Math.floor(value);
});
+Handlebars.registerHelper('debug', function(value) {
+ console.log(value)
+ return value;
+})
function setFolderBackground(html) {
html.find("header.folder-header").each(function() {
diff --git a/templates/actors/newActor/starship.html b/templates/actors/newActor/starship.html
index 4e3a206d..e01113dd 100644
--- a/templates/actors/newActor/starship.html
+++ b/templates/actors/newActor/starship.html
@@ -175,7 +175,7 @@
|
@@ -224,11 +224,11 @@