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
This commit is contained in:
supervj 2021-06-09 01:16:38 -04:00
parent 3f4c8119ad
commit d7879fad94
4 changed files with 52 additions and 36 deletions

View file

@ -382,7 +382,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;
@ -406,7 +407,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;
@ -782,12 +783,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 };
}
/* -------------------------------------------- */

View file

@ -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});
}
}

View file

@ -292,6 +292,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() {

View file

@ -175,7 +175,7 @@
</td>
<td>
<label>
{{localize "SW5E.CrewCap"}}: {{data.attributes.crewMinWorkforce}}
{{localize "SW5E.CrewCap"}}: {{data.attributes.equip.crewMinWorkforce}}
</label>
</td>
@ -224,11 +224,11 @@
<table style="border:none;">
<tr>
<td align="center"><strong>{{localize "SW5E.EnginePl"}}</strong></td>
<td rowspan=3><input type="range" orient="vertical" id="engineslidervalue" class="vertslider" value="1" step="1" min="0" max="2" oninput="engineSliderUpdate(value)"></td>
<td rowspan=3><input type="range" orient="vertical" id="engineslidervalue" class="vertslider" value={{data.attributes.power.routing.engines}} step="1" min="0" max="2" ></td>
<td align="center"><strong>{{localize "SW5E.EquipmentShieldProficiency"}}</strong></td>
<td rowspan=3><input type="range" orient="vertical" id="shieldslidervalue" class="vertslider" value="1" step="1" min="0" max="2" oninput="shieldSliderUpdate(value)"></td>
<td rowspan=3><input type="range" orient="vertical" id="shieldslidervalue" class="vertslider" value={{data.attributes.power.routing.shields}} step="1" min="0" max="2" ></td>
<td align="center"><strong>{{localize "SW5E.ItemTypeWeaponPl"}}</strong></td>
<td rowspan=3><input type="range" orient="vertical" id="weaponslidervalue" class="vertslider" value="1" step="1" min="0" max="2" oninput="weaponSliderUpdate(value)"></td>
<td rowspan=3><input type="range" orient="vertical" id="weaponslidervalue" class="vertslider" value={{data.attributes.power.routing.weapons}} step="1" min="0" max="2" ></td>
</tr>
<tr>
<td rowspan=2 align="center"><strong><output for=value id="engineslideroutput">=</output></td>
@ -271,17 +271,11 @@
<br /> -->
<table style="border: none; width: 400px;">
<tr><th colspan=3 align="left">{{localize "SW5E.PowerDieAlloc"}}</th><th colspan=3 align="right">
{{localize "SW5E.PowerDie"}}:
<select class="actor-size" name="data.attributes.pd">
{{#select data.attributes.power.die}}
<option value=""> </option>
{{#each config.powerDieTypes as |pd|}}
<option value="{{pd}}">{{pd}}</option>
{{/each}}
{{/select}}
</select></th>
<label>
{{localize "SW5E.PowerDie"}}: {{data.attributes.power.die}}
</label>
</tr>
<tr><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Central</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Comms</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Engines</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Sensors</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Shields</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Weapons</th>
<tr><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Central</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Comms</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Engines</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Sensors</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Shields</th><th style="border-top: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;">Weapons</th>
<tr>
<td style="border-bottom: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;"><input class="hpformula" style="max-width:25px;" name="data.attributes.pwrdice.central.value" value="{{data.attributes.pwrdice.central.value}}" placeholder="{{data.attributes.pwrdice.central.value}}" /> / {{data.attributes.cscap}}</td>
<td style="border-bottom: 2px solid #0d99cc; border-left: 2px solid #0d99cc; border-right: 2px solid #0d99cc;"><input class="hpformula" style="max-width:25px;" name="data.attributes.pwrdice.comms.value" value="{{data.attributes.pwrdice.comms.value}}" placeholder="{{data.attributes.pwrdice.comms.value}}" /> / {{data.attributes.sscap}}</td>