Skip to content

Commit

Permalink
Merge pull request #18 from jopeek/pr17
Browse files Browse the repository at this point in the history
Pr17
  • Loading branch information
jopeek committed Dec 18, 2020
2 parents bc10478 + b750ffe commit 85f2910
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 44 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
@@ -0,0 +1,16 @@
root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@

.idea/
module-releases_template.txt
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -14,4 +14,4 @@ To install a module, follow these instructions:

### Feedback

If you have any suggestions or feedback, please contact me on Discord (ChalkOne#0156).
If you have any suggestions or feedback, please contact me on Discord (ChalkOne#0156).
34 changes: 21 additions & 13 deletions module.json
@@ -1,15 +1,23 @@
{
"name": "token-info-icons",
"title": "Token Info Icons",
"description": "Simple module that displays Speed, AC, and Passive Perception on Tokens for the GM or optionally players.",
"version": "2.1.3",
"minimumCoreVersion": "0.7.7",
"compatibleCoreVersion": "0.7.7",
"author": "Jan Ole Peek (ChalkOne)",
"systems": ["dnd5e", "pf2e", "pf1"],
"scripts": ["/token-info-icons.js"],
"styles": ["/css/token-info-icons.css"],
"url": "https://github.com/jopeek/fvtt-token-info-icons",
"manifest": "https://raw.githubusercontent.com/jopeek/fvtt-token-info-icons/master/module.json",
"download": "https://github.com/jopeek/fvtt-token-info-icons/archive/master.zip"
"name": "token-info-icons",
"title": "Token Info Icons",
"description": "Simple module that displays Speed, AC, and Passive Perception on Tokens for the GM or optionally players.",
"version": "2.2.0",
"minimumCoreVersion": "0.7.7",
"compatibleCoreVersion": "0.7.8",
"author": "Jan Ole Peek (ChalkOne)",
"systems": [
"dnd5e",
"pf2e",
"pf1"
],
"scripts": [
"/token-info-icons.js"
],
"styles": [
"/css/token-info-icons.css"
],
"url": "https://github.com/jopeek/fvtt-token-info-icons",
"manifest": "https://raw.githubusercontent.com/jopeek/fvtt-token-info-icons/master/module.json",
"download": "https://github.com/jopeek/fvtt-token-info-icons/archive/master.zip"
}
82 changes: 53 additions & 29 deletions token-info-icons.js
@@ -1,17 +1,19 @@
class TokenInfoIcons {

const MODULE_NAME = 'token-info-icons';
const GMONLY_MODULE_SETTING = 'gmOnly';
const ALL_PASSIVE_SENSES_MODULE_SETTING = 'allPassiveSenses';
const POSITION_MODULE_SETTING = 'position';

class TokenInfoIcons {
static async addTokenInfoButtons(app, html, data) {

let actor = canvas.tokens.get(data._id).actor;
//let actor = game.actors.get(data.actorId);
if (actor === undefined) return;

let ac = 10
if (game.world.system === "pf1") {
ac = actor.data.data.attributes.ac.normal.total
ac = actor.data.data.attributes.ac.normal.total
} else {
ac = (isNaN(parseInt(actor.data.data.attributes.ac.value)) || parseInt(actor.data.data.attributes.ac.value) === 0) ? 10 : parseInt(actor.data.data.attributes.ac.value);
ac = (isNaN(parseInt(actor.data.data.attributes.ac.value)) || parseInt(actor.data.data.attributes.ac.value) === 0) ? 10 : parseInt(actor.data.data.attributes.ac.value);
}

let perceptionTitle = "Passive Perception";
Expand All @@ -22,7 +24,7 @@ class TokenInfoIcons {
} else if (game.world.system === "pf2e") {
if (actor.data.type === "npc" || actor.data.type === "familiar") {
perception = perception + actor.data.data.attributes.perception.value;
}else {
} else {
const proficiency = actor.data.data.attributes.perception.rank ? actor.data.data.attributes.perception.rank * 2 + actor.data.data.details.level.value : 0;
perception = perception + actor.data.data.abilities[actor.data.data.attributes.perception.ability].mod + proficiency + actor.data.data.attributes.perception.item;
}
Expand All @@ -36,7 +38,7 @@ class TokenInfoIcons {
let speed = "";

if (game.world.system === "pf2e") {
if (actor.data.type === "npc") {
if (actor.data.type === "npc") {
speed = '<span style="white-space: pre;" title="Speed"><i class="fas fa-walking"></i><span style="font-size: 0.65em;"> ' + actor.data.data.attributes.speed.value + '</span></span>';
} else if (actor.data.type === "familiar") {
// Familiars seem to get either 25 ft. land or water speed
Expand All @@ -57,54 +59,76 @@ class TokenInfoIcons {

let newdiv = '<div class="token-info-container">';

let position = game.settings.get("token-info-icons", "position");
let position = game.settings.get(MODULE_NAME, POSITION_MODULE_SETTING);

let defaultButtons = '<div class="control-icon token-info-icon">' + speed + '</div><div class="control-icon token-info-icon" title="Armor Class: ' + ac + '"><i class="fas fa-shield-alt"></i> ' + ac + '</div><div class="control-icon token-info-icon" title="Passive Perception: ' + perception + '"><i class="fas fa-eye"></i> ' + perception + '</div>'

let passiveSensesButtons = '';
if (!['pf2e', 'pf1'].includes(game.world.system) && game.settings.get(MODULE_NAME, ALL_PASSIVE_SENSES_MODULE_SETTING)) {
const investigation = actor.data.data.skills.inv.passive;
const insight = actor.data.data.skills.ins.passive;
const stealth = actor.data.data.skills.ste.passive;

const passiveInvestigationButton = `<div class="control-icon token-info-icon" title="Passive Investigation: ${investigation}"><i class="fas fa-search"></i> ${investigation}</div>`;
const passiveInsightButton = `<div class="control-icon token-info-icon" title="Passive Insight: ${insight}"><i class="fas fa-lightbulb"></i> ${insight}</div>`;
const passiveStealthButton = `<div class="control-icon token-info-icon" title="Passive Stealth: ${stealth}"><i class="fas fa-eye-slash"></i> ${stealth}</div>`;
passiveSensesButtons = `${passiveInvestigationButton}${passiveInsightButton}${passiveStealthButton}`;
}

let buttons = $('<div class="col token-info-column-' + position + '"><div class="control-icon token-info-icon">' + speed + '</div><div class="control-icon token-info-icon" title="Armor Class: ' + ac + '"><i class="fas fa-shield-alt"></i> ' + ac + '</div><div class="control-icon token-info-icon" title="' + perceptionTitle + ': ' + perception + '"><i class="fas fa-eye"></i> ' + perception + '</div></div>');
let buttons = $(`<div class="col token-info-column-${position}">${defaultButtons}${passiveSensesButtons}</div>`);

html.find('.col.left').wrap(newdiv);
html.find('.col.left').before(buttons);
}

}

Hooks.on('ready', () => {
let gmOnly = game.settings.get("token-info-icons", "gmOnly");
const gmOnly = game.settings.get(MODULE_NAME, GMONLY_MODULE_SETTING);

if (gmOnly) {
if (game.user.isGM) {
Hooks.on('renderTokenHUD', (app, html, data) => { TokenInfoIcons.addTokenInfoButtons(app, html, data) });
Hooks.on('renderTokenHUD', (app, html, data) => {
TokenInfoIcons.addTokenInfoButtons(app, html, data)
});
}
} else {
Hooks.on('renderTokenHUD', (app, html, data) => { TokenInfoIcons.addTokenInfoButtons(app, html, data) });
Hooks.on('renderTokenHUD', (app, html, data) => {
TokenInfoIcons.addTokenInfoButtons(app, html, data)
});
}


});

Hooks.once("init", () => {
game.settings.register("token-info-icons", "gmOnly", {
name: "GM only?",
hint: "Show the token info to the GM only or to all players?",
scope: "world",
config: true,
default: true,
type: Boolean
game.settings.register(MODULE_NAME, GMONLY_MODULE_SETTING, {
name: "GM only?",
hint: "Show the token info to the GM only or to all players?",
scope: "world",
config: true,
default: true,
type: Boolean
});

game.settings.register(MODULE_NAME, ALL_PASSIVE_SENSES_MODULE_SETTING, {
name: 'Show all passive senses (dnd5e)',
hint: 'Show passive perception/investigation/insight/stealth instead of just passive perception',
scope: "world",
config: true,
default: false,
type: Boolean
});

const choices = new Array("Left", "Right");

game.settings.register("token-info-icons", "position", {
name: "Token Position",
hint: "Which side of the token should the info appear on?",
game.settings.register(MODULE_NAME, POSITION_MODULE_SETTING, {
name: "Token Position",
hint: "Which side of the token should the info appear on?",
scope: "world",
config: true,
type: String,
type: String,
default: "left",
choices: {
"left": "left",
"right": "right",
}
});
});
});

console.log("Token Info Icons loaded");

0 comments on commit 85f2910

Please sign in to comment.