Skip to content

Commit

Permalink
Symbaroum update (Drental#72)
Browse files Browse the repository at this point in the history
* Symbaroum traits

* removed _id

* symbaroum icons

* clean-up code
  • Loading branch information
Khaali-dev authored Aug 31, 2021
1 parent a6b30b3 commit 11bc0ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
49 changes: 34 additions & 15 deletions scripts/actions/symbaroum/symbaroum-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ActionHandlerSymbaroum extends ActionHandler {
if (!token)
return result;

let tokenId = token.data._id;
let tokenId = token.id;

result.tokenId = tokenId;

Expand All @@ -22,19 +22,23 @@ export class ActionHandlerSymbaroum extends ActionHandler {
if (!actor)
return result;

result.actorId = actor._id;
result.actorId = actor.id;

let actorType = actor.data.type;


let mysticalPowers = this._getMysticalPowers(actor, tokenId)
let traits = this._getTraits(actor, tokenId);
let weapons = this._getWeapons(actor, tokenId);
let armors = this._getArmors(actor, tokenId);;
let armors = this._getArmors(actor, tokenId);
let abilities = this._getAbilities(actor, tokenId);
let attributes = this._getAttributes(actor, tokenId);

this._combineCategoryWithList(result, this.i18n('tokenactionhud.symbaroum.mysticalPowers'), mysticalPowers);
this._combineCategoryWithList(result, this.i18n('tokenactionhud.armour'), armors);
this._combineCategoryWithList(result, this.i18n('tokenactionhud.traits'), traits);
if(!game.settings.get('symbaroum', 'combatAutomation')){
this._combineCategoryWithList(result, this.i18n('tokenactionhud.armour'), armors);
};
this._combineCategoryWithList(result, this.i18n('tokenactionhud.weapons'), weapons);
this._combineCategoryWithList(result, this.i18n('tokenactionhud.symbaroum.abilities'), abilities);
this._combineCategoryWithList(result, this.i18n('tokenactionhud.attributes'), attributes);
Expand All @@ -46,15 +50,24 @@ export class ActionHandlerSymbaroum extends ActionHandler {
}

_getMysticalPowers(actor, tokenId) {
let filteredItems = actor.items.filter(item => item.data?.type === "mysticalPower");
let filteredItems = actor.items.filter(item => (item.data?.type === "mysticalPower")&&(item.data.data?.script));
let result = this.initializeEmptyCategory('actorPowers');
let powersCategory = this.initializeEmptySubcategory();
powersCategory.actions = this._produceMap(tokenId, filteredItems, 'mysticalPower');

this._combineSubcategoryWithCategory(result, this.i18n('tokenactionhud.roll'), powersCategory);
return result;
}

_getTraits(actor, tokenId) {
let filteredItems = actor.items.filter(item => (item.data?.type === "trait")&&(item.data.data?.script));
let result = this.initializeEmptyCategory('actorsTraits');
let traitsCategory = this.initializeEmptySubcategory();
traitsCategory.actions = this._produceMap(tokenId, filteredItems, 'trait');

this._combineSubcategoryWithCategory(result, this.i18n('tokenactionhud.roll'), traitsCategory);
return result;
}

_getWeapons(actor, tokenId) {
let filteredItems = actor.items.filter(item => (item.data?.type === "weapon")&&(item.data.data?.state === "active"));
let result = this.initializeEmptyCategory('actorWeapons');
Expand All @@ -77,7 +90,7 @@ export class ActionHandlerSymbaroum extends ActionHandler {
}

_getAbilities(actor, tokenId) {
let filteredItems = actor.items.filter(item => item.data?.type === "ability");
let filteredItems = actor.items.filter(item => (item.data?.type === "ability")&&(item.data.data?.script));
let result = this.initializeEmptyCategory('actorAbilities');
let abilitiesCategory = this.initializeEmptySubcategory();
abilitiesCategory.actions = this._produceMap(tokenId, filteredItems, 'ability');
Expand All @@ -97,12 +110,18 @@ export class ActionHandlerSymbaroum extends ActionHandler {
return result;
}

/** @private */
_produceMap(tokenId, itemSet, macroType) {
return itemSet.filter(i => !!i).map(i => {
let encodedValue = [macroType, tokenId, i.data._id].join(this.delimiter);
let item = { name: i.name, encodedValue: encodedValue, id: i.data._id };
return item;
});
}
_produceMap(tokenId, itemSet, type) {
return itemSet.map((i) => {
let encodedValue = [type, tokenId, i.id].join(this.delimiter);
let img = this._getImage(i);
let result = { name: i.name, encodedValue: encodedValue, id: i.id, img: img };
return result;
});
}

_getImage(item) {
let result = '';
if (settings.get('showIcons')) result = item.img ?? '';
return !result?.includes('systems/symbaroum/asset/image/trait.png') ? result : '';
}
}
10 changes: 9 additions & 1 deletion scripts/rollHandlers/symbaroum/symbaroum-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class RollHandlerBaseSymbaroum extends RollHandler {
if (payload.length != 3) {
super.throwInvalidValueErr();
}

let macroType = payload[0];
let tokenId = payload[1];
let itemId = payload[2];
Expand All @@ -30,6 +29,9 @@ export class RollHandlerBaseSymbaroum extends RollHandler {
case 'mysticalPower':
this._handleMysticalPowers(macroType, event, actor, itemId);
break;
case 'trait':
this._handleTraits(macroType, event, actor, itemId);
break;
case 'attribute':
this._handleAttributes(macroType, event, actor, itemId);
break;
Expand Down Expand Up @@ -60,6 +62,12 @@ export class RollHandlerBaseSymbaroum extends RollHandler {
actor.usePower(usedPower[0]);
}

_handleTraits(macroType, event, actor, actionId) {

let usedPower = actor.items.filter(item => item.id === actionId);
actor.usePower(usedPower[0]);
}

_handleAttributes(macroType, event, actor, actionId) {
actor.rollAttribute(actionId);
}
Expand Down

0 comments on commit 11bc0ba

Please sign in to comment.