Crew Upgrades

- Adds Item type
- Adds Create and Remove logic
This commit is contained in:
Peter Varaksin 2020-04-28 13:46:04 +03:00
parent bb6e00d8b5
commit dea687654a
10 changed files with 141 additions and 9 deletions

3
TODO
View file

@ -11,4 +11,5 @@
- Add Crew XP cheetsheet
- Add Usage documentation to README.md
- Add Turf Validation (<= 6 max)
- Add turf connection validation
- Add turf connection validation
- Document usage of "logic" item property (crew_upgrades)

View file

@ -89,4 +89,62 @@ export class BladesHelpers {
}
/**
* Add item modification if logic exists.
* @param {Object} item_data
* @param {Entity} entity
*/
static callItemLogic(item_data, entity) {
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;
}
}
}
/**
* Undo Item modifications when item is removed.
* @param {Object} item_data
* @param {Entity} entity
*/
static undoItemLogic(item_data, entity) {
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;
}
}
}
static getNestedProperty(obj, property) {
return property.split('.').reduce((r, e) => {
return r[e];
}, obj);
}
}

View file

@ -90,3 +90,14 @@ Hooks.once("init", async function() {
});
});
/*
* Hooks
*/
Hooks.on("createOwnedItem", (parent, child, options, userId) => {
BladesHelpers.callItemLogic(child, parent);
});
Hooks.on("deleteOwnedItem", (parent, child, options, userId) => {
BladesHelpers.undoItemLogic(child, parent);
});

View file

@ -128,6 +128,7 @@ export class BladesCrewSheet extends ActorSheet {
if (item) {
const actor = this.actor;
BladesHelpers.removeDuplicatedItemType(item.data.type, actor);
BladesHelpers.callItemLogic(item, actor);
}
// Call parent on drop logic
@ -137,4 +138,5 @@ export class BladesCrewSheet extends ActorSheet {
}
/* -------------------------------------------- */
}

1
packs/crew_upgrades.db Normal file
View file

@ -0,0 +1 @@
{"_id":"M7k3sdhua5qmJ93M","name":"Vault 1","permission":{"default":0,"BwbqQh8sHfeKmUax":3},"type":"crew_upgrade","data":{"description":"Adds the Vault providing additional 4 Coin space","logic":"{\"attribute\":\"data.vault.max\",\"operator\":\"addition\",\"value\":4,\"requirement\":\"\"}","crew_type":""},"folder":null,"sort":300000,"flags":{}}

View file

@ -3,8 +3,8 @@
"title": "Blades in the Dark",
"description": "GBlades in the dark game system.",
"version": 0.1,
"minimumCoreVersion": "0.5.2",
"compatibleCoreVersion": "0.5.3",
"minimumCoreVersion": "0.5.3",
"compatibleCoreVersion": "0.5.5",
"templateVersion": 1,
"author": "megastruktur",
"esmodules": ["module/blades.js"],
@ -70,6 +70,13 @@
"system": "blades-in-the-dark",
"path": "./packs/crew_types.db",
"entity": "Item"
},
{
"name": "Crew Upgrades",
"label": "Crew Upgrades",
"system": "blades-in-the-dark",
"path": "./packs/crew_upgrades.db",
"entity": "Item"
}
]
}

View file

@ -72,7 +72,11 @@
"experience": [0],
"hold_types": ["weak", "strong"],
"coins": [0],
"vault": [0],
"vault": {
"value": [0],
"max": 0,
"default": 0
},
"turfs": [8],
"features": [],
"heat": [0],
@ -80,7 +84,7 @@
}
},
"Item": {
"types": ["item", "class", "ability", "heritage", "background", "vice", "crew_upgrade", "cohort", "crew_type", "crew_feature"],
"types": ["item", "class", "ability", "heritage", "background", "vice", "crew_upgrade", "cohort", "crew_type", "crew_feature", "crew_upgrade"],
"templates": {
"default": {
"description": ""
@ -89,6 +93,9 @@
"description": "",
"class": "",
"price": 1
},
"logic": {
"logic": ""
}
},
"item": {
@ -117,9 +124,6 @@
"ability": {
"templates": ["ability"]
},
"crew_upgrade": {
"templates": ["ability"]
},
"heritage": {
"templates": ["default"]
},
@ -137,6 +141,10 @@
"crew_feature": {
"templates": ["default"]
},
"crew_upgrade": {
"templates": ["default", "logic"],
"crew_type": ""
},
"crew_type": {
"description": "",
"turfs": {

View file

@ -155,7 +155,7 @@
</div>
{{!-- Crew Type --}}
<div>
<div class="section">
{{#each actor.items as |item id|}}
{{#eq item.type "crew_type"}}
<div class="item" data-item-id="{{item._id}}">
@ -165,4 +165,29 @@
{{/each}}
</div>
<div class="section">
<div id="crew-upgrades">
<div class="label-stripe">
<p><label>Crew Upgrades</label></p>
</div>
{{#each actor.items as |item id|}}
{{#eq item.type "crew_upgrade"}}
<div class="item flex-horizontal" data-item-id="{{item._id}}">
<div class="item-body flex-horizontal">
<img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/>
<div class="item-name">{{item.name}}</div>
</div>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
{{/eq}}
{{/each}}
</div>
<div id="crew-coins">
<div class="label-stripe">
<p><label>Coins (max: 4 + {{data.vault.max}})</label></p>
</div>
</div>
</div>
</form>

View file

@ -0,0 +1,18 @@
<form class="{{cssClass}}" autocomplete="off">
<header class="sheet-header">
<img class="profile-img" src="{{item.img}}" data-edit="img" title="{{item.name}}"/>
<div class="header-fields">
<h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeholder="Name"/></h1>
</div>
</header>
{{!-- Sheet Body --}}
<section class="sheet-body">
<label>Description</label>
<textarea name="data.description">{{data.description}}</textarea>
<label>Crew Type</label>
<input type="text" name="data.crew_type" value="{{data.crew_type}}">
<label>Logic</label>
<textarea name="data.logic">{{data.logic}}</textarea>
</section>
</form>

View file

@ -8,6 +8,7 @@
{{!-- Sheet Body --}}
<section class="sheet-body">
<label>Description</label>
<textarea name="data.description">{{data.description}}</textarea>
</section>
</form>