Item Logic
- Adds Item logic field - Adds Item Logic handlers
This commit is contained in:
parent
4663845c5f
commit
4b0da99276
8 changed files with 155 additions and 60 deletions
|
@ -3,20 +3,17 @@ export class BladesHelpers {
|
|||
/**
|
||||
* Removes a duplicate item type from charlist.
|
||||
*
|
||||
* @param {string} item_type
|
||||
* @param {Actor} actor
|
||||
* @param {Object} item_data
|
||||
* @param {Entity} actor
|
||||
*/
|
||||
static removeDuplicatedItemType(item_type, actor) {
|
||||
static removeDuplicatedItemType(item_data, actor) {
|
||||
|
||||
let distinct_types = ["class", "heritage", "background", "vice", "crew_type"];
|
||||
|
||||
if (distinct_types.indexOf(item_type) >= 0) {
|
||||
actor.items.forEach(i => {
|
||||
if (i.data.type === item_type) {
|
||||
actor.deleteOwnedItem(i.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
// If the Item has the exact same name - remove it from list.
|
||||
actor.items.forEach(i => {
|
||||
if (i.data.name === item_data.name) {
|
||||
actor.deleteOwnedItem(i.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,16 +96,18 @@ export class BladesHelpers {
|
|||
if ('logic' in item_data.data) {
|
||||
let logic = JSON.parse(item_data.data.logic);
|
||||
|
||||
// Different logic behav. dep on operator.
|
||||
switch (logic.operator) {
|
||||
|
||||
// Add when creating.
|
||||
case "addition":
|
||||
entity.update({
|
||||
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) + logic.value
|
||||
});
|
||||
break;
|
||||
|
||||
if (logic) {
|
||||
// Different logic behav. dep on operator.
|
||||
switch (logic.operator) {
|
||||
|
||||
// Add when creating.
|
||||
case "addition":
|
||||
entity.update({
|
||||
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) + logic.value
|
||||
});
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,22 +124,27 @@ export class BladesHelpers {
|
|||
if ('logic' in item_data.data) {
|
||||
let logic = JSON.parse(item_data.data.logic)
|
||||
|
||||
// Different logic behav. dep on operator.
|
||||
switch (logic.operator) {
|
||||
|
||||
// Subtract when removing.
|
||||
case "addition":
|
||||
entity.update({
|
||||
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) - logic.value
|
||||
});
|
||||
break;
|
||||
if (logic) {
|
||||
// Different logic behav. dep on operator.
|
||||
switch (logic.operator) {
|
||||
// Subtract when removing.
|
||||
case "addition":
|
||||
entity.update({
|
||||
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) - logic.value
|
||||
});
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a nested dynamic attribute.
|
||||
* @param {Object} obj
|
||||
* @param {string} property
|
||||
*/
|
||||
static getNestedProperty(obj, property) {
|
||||
return property.split('.').reduce((r, e) => {
|
||||
return r[e];
|
||||
|
|
|
@ -63,17 +63,17 @@ Hooks.once("init", async function() {
|
|||
});
|
||||
|
||||
// Equals handlebar.
|
||||
Handlebars.registerHelper('eq', function (a, b, options) {
|
||||
Handlebars.registerHelper('eq', (a, b, options) => {
|
||||
return (a === b) ? options.fn(this) : '';
|
||||
});
|
||||
|
||||
// NotEquals handlebar.
|
||||
Handlebars.registerHelper('noteq', function (a, b, options) {
|
||||
Handlebars.registerHelper('noteq', (a, b, options) => {
|
||||
return (a !== b) ? options.fn(this) : '';
|
||||
});
|
||||
|
||||
// ReputationTurf handlebar.
|
||||
Handlebars.registerHelper('repturf', function (turfs_amount, options) {
|
||||
Handlebars.registerHelper('repturf', (turfs_amount, options) => {
|
||||
let html = options.fn(this);
|
||||
var turfs_amount_int = parseInt(turfs_amount);
|
||||
|
||||
|
@ -89,19 +89,37 @@ Hooks.once("init", async function() {
|
|||
return html;
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('crew_vault_coins', (max_coins, options) => {
|
||||
|
||||
let html = options.fn(this);
|
||||
for (let i = 1; i <= max_coins; i++) {
|
||||
|
||||
html += "<input type=\"radio\" id=\"crew-coins-vault-" + i + "\" name=\"data.vault.value\" value=\"" + i + "\"><label for=\"crew-coins-vault-" + i + "\"></label>";
|
||||
}
|
||||
|
||||
return html;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* Hooks
|
||||
*/
|
||||
Hooks.on("preCreateOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
BladesHelpers.removeDuplicatedItemType(child_data.type, parent_entity);
|
||||
|
||||
BladesHelpers.removeDuplicatedItemType(child_data, parent_entity);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Hooks.on("createOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
|
||||
BladesHelpers.callItemLogic(child_data, parent_entity);
|
||||
return true;
|
||||
});
|
||||
|
||||
Hooks.on("deleteOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
|
||||
BladesHelpers.undoItemLogic(child_data, parent_entity);
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -80,13 +80,6 @@ export class BladesCrewSheet extends ActorSheet {
|
|||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
|
||||
// Update the Actor
|
||||
return this.object.update(formData);
|
||||
}
|
||||
|
||||
/** override */
|
||||
_getFormData(form) {
|
||||
const FD = BladesHelpers.getFormDataHelper(form, this.editors);
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
/*
|
||||
* Custom Radio Squared
|
||||
*/
|
||||
@mixin custom_radio_square($width, $height) {
|
||||
@mixin custom_radio_square($side) {
|
||||
|
||||
display: flex;
|
||||
$default_color: white;
|
||||
|
@ -106,8 +106,8 @@
|
|||
label {
|
||||
|
||||
& {
|
||||
height: $height;
|
||||
width: $width;
|
||||
height: $side;
|
||||
width: $side;
|
||||
background-color: $accent_color;
|
||||
|
||||
vertical-align: middle;
|
||||
|
|
|
@ -302,13 +302,16 @@ $red: red;
|
|||
margin: 0px 30px;
|
||||
}
|
||||
|
||||
$coin_size: 15px;
|
||||
$coin_margin: 3px;
|
||||
|
||||
.coins {
|
||||
@include custom_radio_square(15px, 15px);
|
||||
@include custom_radio_square($coin_size);
|
||||
flex-wrap: wrap;
|
||||
|
||||
label {
|
||||
margin-right: 3px;
|
||||
margin-bottom: 3px;
|
||||
margin-right: $coin_margin;
|
||||
margin-bottom: $coin_margin;
|
||||
|
||||
&[for$="0"] {
|
||||
border-width: 2px;
|
||||
|
@ -324,11 +327,21 @@ $red: red;
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Crew Coins
|
||||
.crew-coins {
|
||||
@include custom_radio_square($coin_size);
|
||||
flex-wrap: wrap;
|
||||
max-width: 4 * ($coin_size + $coin_margin);
|
||||
|
||||
label {
|
||||
margin-right: $coin_margin;
|
||||
margin-bottom: $coin_margin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reputation
|
||||
|
||||
|
||||
// Stress
|
||||
#crew-reputation {
|
||||
border-top: 3px solid black;
|
||||
@include toothradio(17px, 50px, "assets/teeth/stresstooth-halfgrey.png", "assets/teeth/stresstooth-red.png");
|
||||
|
|
|
@ -472,6 +472,35 @@
|
|||
* .coins.coins-stashed {
|
||||
width: 190px;
|
||||
}
|
||||
* .crew-coins {
|
||||
display: flex;
|
||||
/* Hide the browser's default checkbox */
|
||||
flex-wrap: wrap;
|
||||
max-width: 72px;
|
||||
}
|
||||
* .crew-coins label {
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
background-color: grey;
|
||||
vertical-align: middle;
|
||||
border: 1px solid black;
|
||||
}
|
||||
* .crew-coins label[for$="-0"] {
|
||||
margin-right: 0px;
|
||||
}
|
||||
* .crew-coins input {
|
||||
display: none;
|
||||
}
|
||||
* .crew-coins input:checked ~ label {
|
||||
background-color: white;
|
||||
}
|
||||
* .crew-coins input:checked + label {
|
||||
background-color: grey;
|
||||
}
|
||||
* .crew-coins label {
|
||||
margin-right: 3px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
* #crew-reputation {
|
||||
border-top: 3px solid black;
|
||||
display: flex;
|
||||
|
|
|
@ -71,11 +71,13 @@
|
|||
"hold": ["strong"],
|
||||
"experience": [0],
|
||||
"hold_types": ["weak", "strong"],
|
||||
"coins": [0],
|
||||
"coins": {
|
||||
"max": 4,
|
||||
"value": [0]
|
||||
},
|
||||
"vault": {
|
||||
"value": [0],
|
||||
"max": 0,
|
||||
"default": 0
|
||||
"max": 0
|
||||
},
|
||||
"turfs": [8],
|
||||
"features": [],
|
||||
|
|
|
@ -85,6 +85,47 @@
|
|||
<div class="gray-label">Turf</div>
|
||||
</div>
|
||||
|
||||
{{!-- Coins --}}
|
||||
<div id="crew-coins">
|
||||
|
||||
<div id="crew-coins-hands">
|
||||
<div class="stripe">
|
||||
<label for="crew-coins-hands-0">Coins</label>
|
||||
</div>
|
||||
<div class="crew-coins coins-hands">
|
||||
{{#multiboxes data.coins.value}}
|
||||
<input type="radio" id="crew-coins-hands-0" name="data.coins.value" value="0" checked="checked">
|
||||
<input type="radio" id="crew-coins-hands-1" name="data.coins.value" value="1">
|
||||
<label for="crew-coins-hands-1"></label>
|
||||
<input type="radio" id="crew-coins-hands-2" name="data.coins.value" value="2">
|
||||
<label for="crew-coins-hands-2"></label>
|
||||
<input type="radio" id="crew-coins-hands-3" name="data.coins.value" value="3">
|
||||
<label for="crew-coins-hands-3"></label>
|
||||
<input type="radio" id="crew-coins-hands-4" name="data.coins.value" value="4">
|
||||
<label for="crew-coins-hands-4"></label>
|
||||
{{/multiboxes}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if data.vault.max}}
|
||||
<div id="crew-coins-vault">
|
||||
|
||||
<div class="stripe">
|
||||
<label for="crew-coins-vault-0">Vault</label>
|
||||
</div>
|
||||
<div class="crew-coins coins-vault">
|
||||
{{#multiboxes data.vault.value}}
|
||||
<input type="radio" id="crew-coins-vault-0" name="data.vault.value" value="0" checked="checked">
|
||||
{{#crew_vault_coins data.vault.max}}{{/crew_vault_coins}}
|
||||
{{/multiboxes}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
|
||||
{{!-- Heat/Wanted --}}
|
||||
<div id="heat-wanted" class="flex-horizontal big-teeth-section">
|
||||
|
||||
<div id="crew-heat" class="big-teeth">
|
||||
|
@ -183,11 +224,6 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div id="crew-coins">
|
||||
<div class="label-stripe">
|
||||
<p><label>Coins (max: 4 + {{data.vault.max}})</label></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
|
Reference in a new issue