Skip to content

Commit

Permalink
Fix item tag display (#260)
Browse files Browse the repository at this point in the history
* Properly look up tag image value

* Correct asset access for ose-dev

* Add type to user guide button

* Show a dash if a treasure table yields no results

* Feedback when treasure table yields no results
  • Loading branch information
maschill92 authored Oct 17, 2022
1 parent d39ab0b commit 0cb9e02
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 47 deletions.
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineConfig([
plugins: [
nodeResolve(),
typescript(),
terser(),
!isWatchMode && terser(),
copy({
patterns: staticFileFolders.map((folderName) => `${folderName}/**/*`),
rootDir: "./src/",
Expand Down
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"OSE.roll.individualInitGroup": "Initiative Rolls",

"OSE.table.treasure.roll": "Roll Treasure",
"OSE.table.treasure.noItems": "No items",

"OSE.details.name": "Name",
"OSE.details.class": "Class",
Expand Down
51 changes: 40 additions & 11 deletions src/module/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export type OseConfig = {
/** Path for system dist */
systemPath: () => string;
/** Root path for OSE system */
systemRoot: string;
/** Path for system assets */
assetsPath: string;
scores: Record<Attribute, string>;
scores_short: Record<Attribute, string>;
exploration_skills: Record<ExplorationSkill, string>;
Expand Down Expand Up @@ -44,8 +49,14 @@ export type InventoryItemTag =
| "charge";

export const OSE: OseConfig = {
systemPath: () => {
return `/systems/${game.system.id}/dist`;
systemPath(): string {
return `${this.systemRoot}/dist`;
},
get systemRoot(): string {
return `/systems/${game.system.id}`
},
get assetsPath(): string {
return `${this.systemRoot}/assets`
},
scores: {
str: "OSE.scores.str.long",
Expand Down Expand Up @@ -146,15 +157,33 @@ export const OSE: OseConfig = {
charge: "OSE.items.Charge",
},
tag_images: {
melee: "systems/ose/assets/melee.png",
missile: "systems/ose/assets/missile.png",
slow: "systems/ose/assets/slow.png",
twohanded: "systems/ose/assets/twohanded.png",
blunt: "systems/ose/assets/blunt.png",
brace: "systems/ose/assets/brace.png",
splash: "systems/ose/assets/splash.png",
reload: "systems/ose/assets/reload.png",
charge: "systems/ose/assets/charge.png",
get melee() {
return `${OSE.assetsPath}/melee.png`;
},
get missile() {
return `${OSE.assetsPath}/missile.png`;
},
get slow() {
return `${OSE.assetsPath}/slow.png`;
},
get twohanded() {
return `${OSE.assetsPath}/twohanded.png`;
},
get blunt() {
return `${OSE.assetsPath}/blunt.png`;
},
get brace() {
return `${OSE.assetsPath}/brace.png`;
},
get splash() {
return `${OSE.assetsPath}/splash.png`;
},
get reload() {
return `${OSE.assetsPath}/reload.png`;
},
get charge() {
return `${OSE.assetsPath}/charge.png`;
},
},
monster_saves: {
0: {
Expand Down
2 changes: 1 addition & 1 deletion src/module/dialog/character-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class OseCharacterCreator extends FormApplication {
const itemData = {
name: game.i18n.localize("OSE.items.gp.short"),
type: "item",
img: "systems/ose/assets/gold.png",
img: `${OSE.assetsPath}/gold.png`,
data: {
treasure: true,
cost: 1,
Expand Down
12 changes: 10 additions & 2 deletions src/module/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ export const registerHelpers = async function () {
return Math.round(parseFloat(weight) / 100) / 10;
});

Handlebars.registerHelper("getTagIcon", function (tag) {
return CONFIG.OSE.tag_images[tag as InventoryItemTag];
Handlebars.registerHelper("getTagIcon", function (tagValue: string) {
let tagKey = (Object.keys(CONFIG.OSE.tags) as InventoryItemTag[])
// find key for the tag display name who's name matches the provided tag text.
.find((findTagName) => CONFIG.OSE.tags[findTagName] === tagValue);
// if that tag key is found, return the image for the tag key
return tagKey ? CONFIG.OSE.tag_images[tagKey] : null;
});

Handlebars.registerHelper("counter", function (status, value, max) {
Expand All @@ -56,6 +60,10 @@ export const registerHelpers = async function () {
return `${OSE.systemPath()}${relativePath}`;
});

Handlebars.registerHelper("asset", function (relativePath) {
return `${OSE.assetsPath}${relativePath}`;
});

// helper for parsing inline rolls
Handlebars.registerHelper("parseInline", function (html) {
return TextEditor.enrichHTML(html);
Expand Down
12 changes: 6 additions & 6 deletions src/module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export class OseItem extends Item {
// Replacing default image */
static get defaultIcons() {
return {
spell: "systems/ose/assets/default/spell.png",
ability: "systems/ose/assets/default/ability.png",
armor: "systems/ose/assets/default/armor.png",
weapon: "systems/ose/assets/default/weapon.png",
item: "systems/ose/assets/default/item.png",
container: "systems/ose/assets/default/bag.png",
spell: `${OSE.assetsPath}/default/spell.png`,
ability: `${OSE.assetsPath}/default/ability.png`,
armor: `${OSE.assetsPath}/default/armor.png`,
weapon: `${OSE.assetsPath}/default/weapon.png`,
item: `${OSE.assetsPath}/default/item.png`,
container: `${OSE.assetsPath}/default/bag.png`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/ose.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Hooks.on("renderSidebarTab", async (object, html) => {
const styling =
"border:none;margin-right:2px;vertical-align:middle;margin-bottom:5px";
$(
`<button data-action="userguide"><img src='systems/ose/assets/dragon.png' width='16' height='16' style='${styling}'/>Old School Guide</button>`
`<button type="button" data-action="userguide"><img src='${OSE.assetsPath}/dragon.png' width='16' height='16' style='${styling}'/>Old School Guide</button>`
).insertAfter(docs);
html.find('button[data-action="userguide"]').click((ev) => {
new FrameViewer("https://vttred.github.io/ose", {
Expand Down
52 changes: 27 additions & 25 deletions src/templates/chat/roll-treasure.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<div class="ose chat-card treasure-card">
<header class="card-header flexrow">
<img src="systems/ose/assets/treasure.png" title="{{table.name}}" width="36" height="36" />
<h3>{{table.name}}</h3>
</header>
<div class="card-content">
<ol class="treasure-list">
{{#each treasure as |t|}}
<li class="treasure flexrow">
{{#if t.img}}<img src="{{t.img}}" width="36" height="36" />{{/if}}
<div>
<div>{{{t.text}}}</div>
<ol>
{{#each t.treasure}}
<li class="sub flexrow">
{{#if img}}<img src="{{img}}" width="28" height="28" />{{/if}}
<div>{{{text}}}</div>
</li>
{{/each}}
</ol>
</div>
</li>
{{/each}}
</ol>
</div>
<div class="ose chat-card treasure-card">
<header class="card-header flexrow">
<img src="{{asset '/treasure.png'}}" title="{{table.name}}" width="36" height="36" />
<h3>{{table.name}}</h3>
</header>
<div class="card-content">
<ol class="treasure-list">
{{#each treasure as |t|}}
<li class="treasure flexrow">
{{#if t.img}}<img src="{{t.img}}" width="36" height="36" />{{/if}}
<div>
<div>{{{t.text}}}</div>
<ol>
{{#each t.treasure}}
<li class="sub flexrow">
{{#if img}}<img src="{{img}}" width="28" height="28" />{{/if}}
<div>{{{text}}}</div>
</li>
{{/each}}
</ol>
</div>
</li>
{{else}}
<li>{{localize "OSE.table.treasure.noItems"}}</li>
{{/each}}
</ol>
</div>
</div>

0 comments on commit 0cb9e02

Please sign in to comment.