#7 - Manage container

This commit is contained in:
sladecraven 2021-03-22 21:02:56 +01:00
parent 2353ba5ff9
commit baf84bee35
6 changed files with 81 additions and 12 deletions

View File

@ -31,16 +31,35 @@ export class SoSActorSheet extends ActorSheet {
data.data.deckSize = this.actor.getDeckSize();
data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => {
if ( a.name > b.name ) return 1;
return -1;
});
if ( a.name > b.name ) return 1;
return -1;
});
data.data.skill1 = data.data.skills.slice(0, Math.ceil(data.data.skills.length/2) )
data.data.skill2 = data.data.skills.slice(Math.ceil(data.data.skills.length/2), data.data.skills.length )
data.data.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => {
if ( a.name > b.name ) return 1;
return -1;
});
data.data.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') );
data.data.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') );
// Build the gear tree
data.data.gearsRoot = data.data.gears.filter(item => item.data.containerid == "");
for ( let container of data.data.gearsRoot) {
if ( container.type == 'container') {
container.data.contains = []
container.data.containerEnc = 0;
for (let gear of data.data.gears) {
if ( gear.data.containerid == container._id) {
container.data.contains.push( gear );
if ( !gear.data.neg && !gear.data.software ) {
container.data.containerEnc += (gear.big > 0) ? gear.big : 1;
}
}
}
}
}
data.data.weapons = this.actor.data.items.filter( item => item.type == 'weapon');
data.data.armors = this.actor.data.items.filter( item => item.type == 'armor');
data.data.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items);
@ -57,16 +76,11 @@ export class SoSActorSheet extends ActorSheet {
data.data.weaknessList = this.actor.data.items.filter( item => item.type == 'weakness');
data.data.geneline = this.actor.data.items.find( item => item.type == 'geneline');
data.data.editStatSkill = this.options.editStatSkill;
console.log("stats", data);
//console.log("stats", data);
return data;
}
/* -------------------------------------------- */
async _onDrop(event) {
super._onDrop(event);
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
@ -164,6 +178,14 @@ export class SoSActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
async _onDrop(event) {
let toSuper = await SoSUtility.processItemDropEvent(this, event);
if ( toSuper) {
super._onDrop(event);
}
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {

View File

@ -372,6 +372,26 @@ export class SoSActor extends Actor {
this.checkDeath();
}
/* -------------------------------------------- */
async addObjectToContainer( itemId, containerId ) {
let container = this.data.items.find( item => item._id == containerId && item.type == 'container');
let object = this.data.items.find( item => item._id == itemId );
if ( container ) {
if ( object.type == 'container') {
ui.notifications.warn("Only 1 level of container... sorry");
return
}
let alreadyInside = this.data.items.filter( item => item.data.containerid && item.data.containerid == containerId);
if ( alreadyInside.length >= container.data.container ) {
ui.notifications.warn("Container is already full !");
} else {
await this.updateOwnedItem( { _id: object._id, 'data.containerid':containerId });
}
} else if ( object && object.data.containerid) { // remove from container
await this.updateOwnedItem( { _id: object._id, 'data.containerid':"" });
}
}
/* -------------------------------------------- */
async applyWounds( flipData ) {
if ( flipData.damageStatus == 'no_damage') {

View File

@ -382,4 +382,16 @@ export class SoSUtility extends Entity {
defender.applyWounds( flipData );
}
/* -------------------------------------------- */
static async processItemDropEvent(actorSheet, event) {
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
let objectID = dragData.id || dragData.data._id;
//console.log("drag/drop", dragData, actorSheet.actor._id, dropID, objectID);
if (dragData.type == 'Item' && dropID) {
actorSheet.actor.addObjectToContainer(objectID, dropID );
}
return true;
}
}

View File

@ -550,6 +550,9 @@ ul, li {
.alternate-list > .list-item:nth-child(odd) {
background: rgb(160, 130, 100, 0.05);
}
.list-item-margin1 {
margin-left: 1rem;
}
.xp-level-up {
margin: 0.125rem;
box-shadow: inset 0px 0px 1px #00000096;

View File

@ -2,7 +2,7 @@
"name": "foundryvtt-shadows-over-sol",
"title": "Shadows over Sol",
"description": "Shadows over Sol for FoundryVTT",
"version": "0.1.13",
"version": "0.1.14",
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9",

View File

@ -259,7 +259,7 @@
</ul>
<div><h4>Equipment/Gears</h4></div>
<ul class="item-list alternate-list">
{{#each data.gears as |gear key|}}
{{#each data.gearsRoot as |gear key|}}
<li class="item flexrow list-item" data-item-id="{{gear._id}}">
<img class="sheet-skill-img" src="{{gear.img}}"/>
<span class="conseq-label">{{gear.name}}</span>
@ -269,6 +269,18 @@
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
<ul class="item-list alternate-list list-item-margin1">
{{#each data.contains as |subgear key|}}
<li class="item flexrow list-item" data-item-id="{{subgear._id}}">
<img class="sheet-skill-img" src="{{subgear.img}}"/>
<span class="conseq-label">{{subgear.name}}</span>
<div class="item-controls">
<a class="item-control item-equip" title="Worn">{{#if armor.data.worn}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
{{/each}}
</ul>
{{/each}}
</ul>
</div>