Skip to content

Commit

Permalink
Issue vttred#35: monster abilities and equipment sort
Browse files Browse the repository at this point in the history
order rework. sort by attack pattern, then weapons before abilities,
then alphabetical.  Sort inventory and spells alphabetically within groups.
Set ability default attack pattern to transparent, and allow to cycle
 back to transparent attack pattern.
  • Loading branch information
hogwrassler committed Aug 14, 2022
1 parent a63d1a1 commit b09ec49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions src/module/actor/monster-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ export class OseActorSheetMonster extends OseActorSheet {
_prepareItems(data) {
const itemsData = this.actor.data.items;
const containerContents = {};
const attackPatterns = {};
const attackPatterns = {
};

let colors = Object.keys(CONFIG.OSE.colors);
colors.push("transparent");

// Set up attack patterns in specific order
for (var i = 0; i < colors.length; i++)
{
attackPatterns[colors[i]] = [];
}

// Partition items by category
let [weapons, items, armors, spells, containers] = itemsData.reduce(
Expand All @@ -53,10 +63,8 @@ export class OseActorSheetMonster extends OseActorSheet {
];
return arr;
}
// Grab attack groups
// Add Items to their respective attack groups
if (["weapon", "ability"].includes(item.type)) {
if (attackPatterns[item.data.data.pattern] === undefined)
attackPatterns[item.data.data.pattern] = [];
attackPatterns[item.data.data.pattern].push(item);
}
// Classify items into types
Expand Down Expand Up @@ -116,13 +124,21 @@ export class OseActorSheetMonster extends OseActorSheet {
containers: containers,
armors: armors,
};

data.attackPatterns = attackPatterns;
// Sort items and spells alphabetically within their groups
data.spells = sortedSpells;
[
...Object.values(data.attackPatterns),
...Object.values(data.owned),
...Object.values(data.spells),
].forEach((o) => o.sort((a, b) => (a.data.sort || 0) - (b.data.sort || 0)));
].forEach((o) => o.sort((a, b) => a.data.name.localeCompare(b.data.name)));

// Within each attack pattern, weapons come before abilities,
// and are then alphabetized
Object.values(data.attackPatterns).forEach(
(o) => o.sort((a, b) =>
b.data.type.localeCompare(a.data.type) || a.data.name.localeCompare(b.data.name))
);
}

/**
Expand Down Expand Up @@ -236,7 +252,9 @@ export class OseActorSheetMonster extends OseActorSheet {
_cycleAttackPatterns(event) {
const item = super._getItemFromActor(event);
let currentColor = item.data.data.pattern;
// Attack patterns include all OSE colors and transparent
let colors = Object.keys(CONFIG.OSE.colors);
colors.push("transparent");
let index = colors.indexOf(currentColor);
if (index + 1 == colors.length) {
index = 0;
Expand Down
2 changes: 1 addition & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
},
"ability": {
"templates": ["common", "rollable"],
"pattern": "white",
"pattern": "transparent",
"requirements": "",
"roll": "",
"rollType": "result",
Expand Down

0 comments on commit b09ec49

Please sign in to comment.