Skip to content

Commit

Permalink
Merge pull request #157 from jeremyregnerus/tokenimage
Browse files Browse the repository at this point in the history
Add switch to show token image instead of profile image
  • Loading branch information
zeel01 authored Feb 27, 2022
2 parents 4c7a2d4 + d08fd0c commit f718dde
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@
"HideMaxHP": "Hide maximum hit points",
"ShowCurrentHP": "Show current hit points",
"HideCurrentHP": "Hide current hit points",
"ProfileImage": "Profile Image",
"ShowProfileImage": "Show profile image",
"HideProfileImage": "Hide profile image",
"UseTokenImage": "Use token image",
"UseProfileImage": "Use profile image",
"ShowLair": "Show lair actions",
"HideLair": "Hide lair actions",
"OpenTokenizer": "Open VTTA Tokenizer",
Expand Down
1 change: 1 addition & 0 deletions scripts/Flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Flags {
"inline-secrets" : { type: Boolean, default: false , hidden: false },
"hidden-secrets" : { type: Boolean, default: false , hidden: false },
"hide-profile-image": { type: Boolean, default: false , hidden: false },
"use-token-image" : { type: Boolean, default: false , hidden: false },
"theme-choice" : { type: String , default: "default", hidden: true, setting: "default-theme" },
"custom-theme-class": { type: String , default: "" , hidden: false },
"editing" : { type: Boolean, default: true , hidden: false },
Expand Down
6 changes: 4 additions & 2 deletions scripts/dnd5e/MonsterBlock5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class MonsterBlock5e extends ActorSheet5eNPC {
}

// Process editable images
const images = form.querySelectorAll("img[data-edit]")
const images = form.querySelectorAll("img[data-edit], token.img[data-edit]")
for (let img of images) {
if (img.getAttribute("disabled")) continue;
let basePath = window.location.origin + "/";
Expand Down Expand Up @@ -631,6 +631,7 @@ export default class MonsterBlock5e extends ActorSheet5eNPC {
"current-hit-points": game.settings.get("monsterblock", "current-hit-points"),
"maximum-hit-points": game.settings.get("monsterblock", "maximum-hit-points"),
"hide-profile-image": game.settings.get("monsterblock", "hide-profile-image"),
"use-token-image": false,
"show-lair-actions": game.settings.get("monsterblock", "show-lair-actions"),
"theme-choice": game.settings.get("monsterblock", "default-theme"),
"custom-theme-class": game.settings.get("monsterblock", "custom-theme-class"),
Expand Down Expand Up @@ -687,7 +688,7 @@ export default class MonsterBlock5e extends ActorSheet5eNPC {
html.find(".profile-image").click((event) => {
event.preventDefault();

new ImagePopout(this.actor.data.img, {
new ImagePopout(event.target.currentSrc, {
title: this.actor.name,
shareable: true,
uuid: this.actor.uuid
Expand Down Expand Up @@ -870,6 +871,7 @@ export default class MonsterBlock5e extends ActorSheet5eNPC {
// Detect and activate TinyMCE rich text editors
html.find(".editor-content[data-edit]").each((i, div) => this._activateEditor(div));
html.find("img[data-edit]").contextmenu(ev => this._onEditImage(ev));
html.find("token.img[data-edit]").contextmenu(ev => this._onEditImage(ev));
}

if (!this.lastSelection) this.lastSelection = {};
Expand Down
9 changes: 7 additions & 2 deletions templates/dnd5e/parts/header/identity.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
</div>
{{#unless flags.hide-profile-image}}
<figure class="profile-image">
<img src="{{actor.img}}" data-edit="img"
title="{{actor.name}}{{#if flags.editing}} - {{ localize "MOBLOKS5E.EditHint" }}{{/if}}">
<img
{{#if flags.use-token-image}}
src="{{actor.token.img}}" data-edit="token.img"
{{else}}
src="{{actor.img}}" data-edit="img"
{{/if}}
title="{{actor.name}}{{#if flags.editing}} - {{ localize "MOBLOKS5E.EditHint" }}{{/if}}">
</figure>
{{/unless}}
3 changes: 3 additions & 0 deletions templates/dnd5e/parts/switch.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
{{~ localize off ~}}
{{~/if~}}
</a>
{{#if @partial-block}}
{{> @partial-block }}
{{/if}}
</li>
37 changes: 27 additions & 10 deletions templates/dnd5e/switches.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,35 @@
}}
</ul>
</li>
{{> "modules/monsterblock/templates/dnd5e/parts/switch.hbs"

{{#> "modules/monsterblock/templates/dnd5e/parts/switch.hbs"
flag=flags.hide-profile-image
control="hide-profile-image"
on="MOBLOKS5E.ShowProfileImage"
off="MOBLOKS5E.HideProfileImage"
control="hide-profile-image"
on="MOBLOKS5E.ProfileImage"
off="MOBLOKS5E.ProfileImage"
}}
<ul>
{{> "modules/monsterblock/templates/dnd5e/parts/switch.hbs"
flag=flags.hide-profile-image
control="hide-profile-image"
on="MOBLOKS5E.ShowProfileImage"
off="MOBLOKS5E.HideProfileImage"
}}
{{> "modules/monsterblock/templates/dnd5e/parts/switch.hbs"
flag=flags.use-token-image
control="use-token-image"
on="MOBLOKS5E.UseProfileImage"
off="MOBLOKS5E.UseTokenImage"
}}
{{#if info.vttatokenizer}}
{{> "modules/monsterblock/templates/dnd5e/parts/trigger.hbs"
control="openTokenizer"
title="MOBLOKS5E.OpenTokenizer"
}}
{{/if}}
</ul>
{{/"modules/monsterblock/templates/dnd5e/parts/switch.hbs"}}

{{#if info.hasLair}}
{{> "modules/monsterblock/templates/dnd5e/parts/switch.hbs"
flag=flags.show-lair-actions
Expand All @@ -105,12 +128,6 @@
on="MOBLOKS5E.HideBio"
off="MOBLOKS5E.ShowBio"
}}
{{#if info.vttatokenizer}}
{{> "modules/monsterblock/templates/dnd5e/parts/trigger.hbs"
control="openTokenizer"
title="MOBLOKS5E.OpenTokenizer"
}}
{{/if}}
{{> "modules/monsterblock/templates/dnd5e/parts/trigger.hbs"
control="resetDefaults"
title="MOBLOKS5E.resetDefaults.label"
Expand Down

0 comments on commit f718dde

Please sign in to comment.