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