Fix gears and containers

This commit is contained in:
sladecraven 2022-03-05 23:39:35 +01:00
parent e608945133
commit ae2d926324
5 changed files with 19 additions and 17 deletions

View File

@ -63,11 +63,12 @@ export class SoSActorSheet extends ActorSheet {
if ( container.type == 'container') { if ( container.type == 'container') {
container.data.contains = [] container.data.contains = []
container.data.containerEnc = 0; container.data.containerEnc = 0;
for (let gear of data.data.gears) { for (let gear of formData.gears) {
if ( gear.data.containerid == container.id) { console.log("GEAR", gear, container)
container.data.contains.push( gear ); if ( gear.data.data.containerid == container.id) {
if ( !gear.data.neg && !gear.data.software ) { container.data.contains.push( gear )
container.data.containerEnc += (gear.big > 0) ? gear.big : 1; if ( !gear.data.data.neg && !gear.data.data.software ) {
container.data.containerEnc += (gear.data.data.big > 0) ? gear.data.data.big : 1;
} }
} }
} }

View File

@ -169,7 +169,7 @@ export class SoSActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async wornObject( itemID) { async wornObject( itemID) {
let item = this.getOwnedItem(itemID); let item = this.items.get(itemID);
if (item && item.data.data) { if (item && item.data.data) {
let update = { _id: item.id, "data.worn": !item.data.data.worn }; let update = { _id: item.id, "data.worn": !item.data.data.worn };
await this.updateEmbeddedDocuments("Item", [update]); await this.updateEmbeddedDocuments("Item", [update]);
@ -178,7 +178,7 @@ export class SoSActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async equipObject(itemID) { async equipObject(itemID) {
let item = this.getOwnedItem(itemID); let item = this.items.get(itemID)
if (item && item.data.data) { if (item && item.data.data) {
let update = { _id: item.id, "data.equiped": !item.data.data.equiped }; let update = { _id: item.id, "data.equiped": !item.data.data.equiped };
await this.updateEmbeddedDocuments("Item", [update]); await this.updateEmbeddedDocuments("Item", [update]);
@ -376,21 +376,22 @@ export class SoSActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async addObjectToContainer( itemId, containerId ) { async addObjectToContainer( itemId, containerId ) {
let container = this.data.items.find( item => item._id == containerId && item.type == 'container'); let container = this.data.items.find( item => item.id == containerId && item.type == 'container')
let object = this.data.items.find( item => item._id == itemId ); let object = this.data.items.find( item => item.id == itemId )
//console.log("Found", container, object)
if ( container ) { if ( container ) {
if ( object.type == 'container') { if ( object.type == 'container') {
ui.notifications.warn("Only 1 level of container... sorry"); ui.notifications.warn("Only 1 level of container... sorry");
return return
} }
let alreadyInside = this.data.items.filter( item => item.data.containerid && item.data.containerid == containerId); let alreadyInside = this.data.items.filter( item => item.data.data.containerid && item.data.data.containerid == containerId);
if ( alreadyInside.length >= container.data.container ) { if ( alreadyInside.length >= container.data.data.container ) {
ui.notifications.warn("Container is already full !"); ui.notifications.warn("Container is already full !");
} else { } else {
await this.updateOwnedItem( { _id: object.id, 'data.containerid':containerId }); await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':containerId }]);
} }
} else if ( object && object.data.containerid) { // remove from container } else if ( object && object.data.data.containerid) { // remove from container
await this.updateOwnedItem( { _id: object.id, 'data.containerid':"" }); await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':"" }]);
} }
} }

View File

@ -256,7 +256,7 @@ export class SoSUtility {
label: "Yes, delete it", label: "Yes, delete it",
callback: () => { callback: () => {
console.log("Delete : ", itemId); console.log("Delete : ", itemId);
actorSheet.actor.deleteOwnedItem(itemId); actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
li.slideUp(200, () => actorSheet.render(false)); li.slideUp(200, () => actorSheet.render(false));
} }
}, },

View File

@ -7,7 +7,7 @@
"url": "https://gitlab.com/LeRatierBretonnien/foundryvtt-shadows-over-sol/", "url": "https://gitlab.com/LeRatierBretonnien/foundryvtt-shadows-over-sol/",
"license": "LICENSE.txt", "license": "LICENSE.txt",
"flags": {}, "flags": {},
"version": "2.0.3", "version": "2.0.4",
"minimumCoreVersion": "0.8.0", "minimumCoreVersion": "0.8.0",
"compatibleCoreVersion": "9", "compatibleCoreVersion": "9",
"scripts": [], "scripts": [],

View File

@ -270,7 +270,7 @@
</div> </div>
</li> </li>
<ul class="item-list alternate-list list-item-margin1"> <ul class="item-list alternate-list list-item-margin1">
{{#each data.data.contains as |subgear key|}} {{#each data.contains as |subgear key|}}
<li class="item flexrow list-item" data-item-id="{{subgear.id}}"> <li class="item flexrow list-item" data-item-id="{{subgear.id}}">
<img class="sheet-skill-img" src="{{subgear.img}}"/> <img class="sheet-skill-img" src="{{subgear.img}}"/>
<span class="conseq-label">{{subgear.data.name}}</span> <span class="conseq-label">{{subgear.data.name}}</span>