Skip to content

Commit

Permalink
fix: Show actor skills, not data items in skills list. Not sure this …
Browse files Browse the repository at this point in the history
…is the way I want to go, need to read up on the data model.

Fills the 'all skills' dropdown from the compendium, but can't actually use it yet. (Not that I'm sure I want to keep it.)
  • Loading branch information
xdy committed Jul 26, 2020
1 parent 5a5dcde commit f44fe27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
35 changes: 22 additions & 13 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,53 @@ export class TwodsixActorSheet extends ActorSheet {
//

data.isToken = this.actor.isToken;
data.itemsByType = {};
this._prepareCharacterItems(data);

if (data.items) {
for (const item of data.items) {
let list = data.itemsByType[item.type];
return data
}

private _prepareCharacterItems(sheetData:any) {
const actor = sheetData.actor;

actor.itemsByType = [];

if (actor.items) {
for (const item of sheetData.items) {
let list = actor.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
actor.itemsByType[item.type] = list;
}
list.push(item);
}

data.skills = data.itemsByType['skill'];
data.weapons = data.itemsByType['weapon'];
actor.skills = actor.itemsByType['skill'];
actor.weapons = actor.itemsByType['weapon'];
actor.armors = actor.itemsByType['armor'];
actor.gear = actor.itemsByType['skill'];
//TODO Handle if weapons, armors and/or gear are undefined
// character.inventory = character.weapons.concat(character.armors, character.gear);
}

// TODO Not sure this is the proper format.
async function addAllSkillsFromCompendium() {
async function addAllSkillsFromCompendium():Promise<void> {
const skillPack = game.packs.filter(c => c.metadata.entity && c.metadata.entity == 'Item' && c.metadata.name == 'skills')[0];
const entities = await skillPack.getContent();

data.allskills = entities.reduce(function (result, item) {
actor.allskills = entities.reduce(function (result, item) {
result[item.data.data.label] = item;
return result;
}, {});
}

addAllSkillsFromCompendium();

return data
}

/** @override */
static get defaultOptions():FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["twodsix", "sheet", "actor"],
template: "systems/twodsix/templates/actors/actor-sheet.html",
width: 600,
width: 900,
height: 600,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills"}]
});
Expand Down
14 changes: 7 additions & 7 deletions static/templates/actors/actor-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ <h1 class="charname">

{{!-- Sheet Body --}}
<section class="sheet-body">
{{log data.skills}}
{{log data.characteristics}}

<div class="tab skills" data-group="primary" data-tab="skills">
<div class="skills grid grid-2col">
<div class="skills flexrow flex-group-center">
<div class="skills grid grid-2col">
<h2 class="clearfix flexbreak">Skills</h2>

<!--TODO Filter out skills from items, I can see items filled, but not data.skills.-->
{{#each items as |skills key|}}
{{log actor.skills}}
{{log actor.allskills}}

{{#each actor.skills as |skills key|}}
<div class="rollable-skill">
<div class="skills flexrow flex-group-center">
<label class="resource-label">{{skills.name}}</label>
Expand Down Expand Up @@ -108,9 +108,9 @@ <h2 class="clearfix flexbreak">Skills</h2>
<!-- TODO And here I should have all skills from the compendium available-->
<div class="flexrow flex-group-center" style="grid-column-start: 1;grid-column-end:3;">
<h2 class="flexbreak">Add Skill:</h2>
<select name="data.addskillselect" style="width:200px;">
<select name="actor.addskillselect" style="width:200px;">
<option></option>
{{#each data.allskills as |skills key|}}
{{#each actor.allskills as |skills key|}}
<option value="{{key}}">{{skills.name}}</option>
{{/each}}
</select>
Expand All @@ -131,7 +131,7 @@ <h2 class="flexbreak">Add Skill:</h2>
class="fas fa-plus"></i> Add item</a>
</div>
</li>
{{#each actor.items as |item id|}}
{{#each actor.inventory as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-image">
<img src="{{item.img}}" title="{{item.name}}" width="24" height="24" alt="item name"/>
Expand Down

0 comments on commit f44fe27

Please sign in to comment.