Skip to content

Commit

Permalink
Merge pull request #48 from damian-pastorini/develop
Browse files Browse the repository at this point in the history
- Reldens - Items System
  • Loading branch information
damian-pastorini authored Jan 25, 2021
2 parents 0a457c5 + ce7a4d7 commit b1b75bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/item/type/item-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class ItemBase
await this.manager.fireEvent(ItemsEvents.EQUIP_BEFORE+(revert ? 'Revert': 'Apply')+'Modifiers', this);
for(let i of Object.keys(this.modifiers)){
if(revert){
this.modifiers[i].revert();
this.modifiers[i].revert(this.target);
} else {
this.modifiers[i].apply();
this.modifiers[i].apply(this.target);
}
}
return this.manager.fireEvent(ItemsEvents.EQUIP+(revert ? 'Reverted' : 'Applied')+'Modifiers', this);
Expand Down
15 changes: 15 additions & 0 deletions lib/server/storage/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ class GroupModel extends ModelClass
return 'items_group';
}

static get relationMappings()
{
const { ItemModel } = require('./item');
return {
parent_item: {
relation: ModelClass.BelongsToOneRelation,
modelClass: ItemModel,
join: {
from: this.tableName+'.item_id',
to: 'items_item.id'
}
}
};
}

}

module.exports.GroupModel = GroupModel;
10 changes: 8 additions & 2 deletions lib/server/storage/models/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ItemModel extends ModelClass
static get relationMappings()
{
const { InventoryModel } = require('./inventory');
const { InventoryGroup } = require('./group');
const { GroupModel } = require('./group');
const { ModifiersModel } = require('./modifiers');
return {
items_inventory: {
Expand All @@ -30,7 +30,7 @@ class ItemModel extends ModelClass
},
items_group_id: {
relation: ModelClass.HasOneRelation,
modelClass: InventoryGroup,
modelClass: GroupModel,
join: {
from: 'items_item.group_id',
to: 'items_group.id'
Expand All @@ -47,6 +47,12 @@ class ItemModel extends ModelClass
};
}

static loadItemFullData()
{
return this.query()
.withGraphFetched('[items_inventory, items_group_id, items_modifiers]');
}

}

module.exports.ItemModel = ItemModel;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@reldens/items-system",
"scope": "@reldens",
"version": "0.9.4",
"version": "0.9.5",
"description": "Reldens - Items System",
"author": "Damian A. Pastorini",
"license": "MIT",
Expand Down

0 comments on commit b1b75bd

Please sign in to comment.