Fix faction sheet goal clocks

This commit is contained in:
agaringer 2021-08-07 14:28:16 -04:00
parent 5bf27dc417
commit 209f23b4ea
6 changed files with 78 additions and 30 deletions

View file

@ -223,4 +223,35 @@ export class BladesHelpers {
/* -------------------------------------------- */
/**
* Creates options for faction clocks.
*
* @param {int[]} sizes
* array of possible clock sizes
* @param {int} default_size
* default clock size
* @param {int} current_size
* current clock size
* @returns {string}
* html-formatted option string
*/
static createListOfClockSizes( sizes, default_size, current_size ) {
let text = ``;
sizes.forEach( size => {
text += `<option value="${size}"`;
if ( !( current_size ) && ( size === default_size ) ) {
text += ` selected`;
} else if ( size === current_size ) {
text += ` selected`;
}
text += `>${size}</option>`;
});
return text;
}
}

View file

@ -65,6 +65,16 @@ export class BladesItem extends Item {
this._prepareCohort(data);
}
if (item_data.type === "faction") {
if( !data.goal_1_clock_value ){ data.goal_1_clock_value = 0 }
if( data.goal_1_clock_max === 0 ){ data.goal_1_clock_max = 4 }
if( !data.goal_2_clock_value ){ data.goal_2_clock_value = 0 }
if( data.goal_2_clock_max === 0 ){ data.goal_2_clock_max = 4 }
data.size_list_1 = BladesHelpers.createListOfClockSizes( game.system.bobclocks.sizes, data.goal_1_clock_max, parseInt( data.goal_1_clock_max ) );
data.size_list_2 = BladesHelpers.createListOfClockSizes( game.system.bobclocks.sizes, data.goal_2_clock_max, parseInt( data.goal_2_clock_max ) );
}
}
/**

View file

@ -32,16 +32,8 @@ export async function bladesRoll(dice_amount, attribute_name = "", position = "r
async function showChatRollMessage(r, zeromode, attribute_name = "", position = "", effect = "") {
let speaker = ChatMessage.getSpeaker();
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
let rolls = [];
let rolls = (r.terms)[0].results;
let attribute_label = BladesHelpers.getAttributeLabel(attribute_name);
// Backward Compat for rolls.
if (isBelow070) {
rolls = (r.parts)[0].rolls;
} else {
rolls = (r.terms)[0].results;
}
// Retrieve Roll status.
let roll_status = getBladesRollStatus(rolls, zeromode);
@ -102,16 +94,8 @@ async function showChatRollMessage(r, zeromode, attribute_name = "", position =
*/
export function getBladesRollStatus(rolls, zeromode = false) {
// Dice API has changed in 0.7.0 so need to keep that in mind.
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
let sorted_rolls = [];
// Sort roll values from lowest to highest.
if (isBelow070) {
sorted_rolls = rolls.map(i => i.roll).sort();
} else {
sorted_rolls = rolls.map(i => i.result).sort();
}
let sorted_rolls = rolls.map(i => i.result).sort();
let roll_status = "failure"
@ -167,16 +151,8 @@ export function getBladesRollStress(rolls, zeromode = false) {
var stress = 6;
// Dice API has changed in 0.7.0 so need to keep that in mind.
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
let sorted_rolls = [];
// Sort roll values from lowest to highest.
if (isBelow070) {
sorted_rolls = rolls.map(i => i.roll).sort();
} else {
sorted_rolls = rolls.map(i => i.result).sort();
}
let sorted_rolls = rolls.map(i => i.result).sort();
let roll_status = "failure"

View file

@ -29,7 +29,10 @@ Hooks.once("init", async function() {
game.blades = {
dice: bladesRoll
}
};
game.system.bobclocks = {
sizes: [ 4, 6, 8 ]
};
CONFIG.Item.documentClass = BladesItem;
CONFIG.Actor.documentClass = BladesActor;

View file

@ -1071,6 +1071,13 @@
* .clock-block .clocks.clocks-4 {
position: relative;
}
* .clock-block .clocks.clocks-4.small .blades-clock,
* .clock-block .clocks.clocks-6.small .blades-clock,
* .clock-block .clocks.clocks-8.small .blades-clock,
* .clock-block .clocks.clocks-12.small .blades-clock {
width: 100px;
height: 100px;
}
* .clock-block .clocks.clocks-4 .blades-clock {
position: relative;
padding: 0;

View file

@ -19,8 +19,29 @@
{{#if isGM }}
<label class="label-stripe">{{localize "BITD.Goal"}}</label>
Clock {{data.goal_1_clock_max}}:<br>{{data.goal_1}}<br><br>
Clock {{data.goal_2_clock_max}}:<br>{{data.goal_2}}<br><br>
<div class="flex-vertical clock-block" id="faction-goal-clock">
<div class="clocks clocks-{{data.goal_1_clock_max}} small" id="faction-clock-1">
{{{blades-clock "data.goal_1_clock_value" data.goal_1_clock_max data.goal_1_clock_value (concat item.id "-1")}}}
</div>
<div id="clock-max-1">
<select id="max-1" name="data.goal_1_clock_max">
{{{data.size_list_1}}}
</select>
</div>
<textarea rows="1" name="data.goal_1">{{data.goal_1}}</textarea>
<div class="clocks clocks-{{data.goal_1_clock_max}} small" id="faction-clock-2">
{{{blades-clock "data.goal_2_clock_value" data.goal_2_clock_max data.goal_2_clock_value (concat item.id "-2")}}}
</div>
<div id="clock-max-2">
<select id="max-2" name="data.goal_2_clock_max">
{{{data.size_list_2}}}
</select>
</div>
<textarea rows="1" name="data.goal_2">{{data.goal_2}}</textarea>
</div>
<label class="label-stripe">{{localize "BITD.NotableNPCs"}}</label>
<textarea rows="10" name="data.notables">{{data.notables}}</textarea>
<label class="label-stripe">{{localize "BITD.Turf"}}</label>