Skip to content

Commit 468f52a

Browse files
authored
Merge pull request #8 from johnmartel/feature/show-token-alignment
Feature/show token alignment
2 parents cdeff6b + 14a70c3 commit 468f52a

13 files changed

Lines changed: 284 additions & 9 deletions

File tree

.codeclimate.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ checks:
4141
config:
4242
threshold: # language-specific defaults. an override will affect all languages.
4343
plugins:
44+
duplication:
45+
enabled: true
46+
config:
47+
languages:
48+
javascript:
49+
mass_threshold: 65
4450
fixme:
4551
enabled: true
4652
exclude_patterns:

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"plugin:foundry-vtt/recommended"
1919
],
2020
"rules": {
21+
"import/extensions": ["error", "always"],
2122
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false, "argsIgnorePattern": "^_" }]
2223
},
2324
"overrides": [

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
on:
2+
push:
3+
tags:
4+
- 'v*'
5+
6+
name: Release
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
- name: Zip files
16+
run: |
17+
zip -r hover-align.zip module.json README.md CHANGELOG.md LICENSE modules lang
18+
- name: Create Release
19+
id: create_release
20+
uses: actions/create-release@v1
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
with:
24+
tag_name: ${{ github.ref }}
25+
release_name: Release ${{ github.ref }}
26+
draft: false
27+
prerelease: false
28+
- name: Upload Release Asset
29+
id: upload-release-asset
30+
uses: actions/upload-release-asset@v1.0.2
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
with:
34+
upload_url: ${{ steps.create_release.outputs.upload_url }}
35+
asset_path: ./hover-align.zip
36+
asset_name: hover-align.zip
37+
asset_content_type: application/zip

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# v1.0.0
2+
3+
Initial release

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@
77

88
Simple FoundryVTT module that displays character (both PC/NPC) alignment on hovering a token.
99

10+
It will display the alignment for all tokens to the GM and only for player-owned tokens to players.
11+
12+
This module uses the Core functionality used to display the token tooltip without interfering with it.
13+
14+
![sample](doc/sample.gif)
15+
1016
## Installation
1117

12-
TBD
18+
You could either:
19+
20+
1. Navigate to the Foundry Setup screen and click on the Modules tab
21+
1. Click Install Module and look for HoverAlign
22+
23+
or:
24+
25+
1. Start FVTT and browse to the Game Modules tab in the Configuration and Setup menu
26+
1. Select the Install Module button and enter the following URL: https://raw.githubusercontent.com/johnmartel/hover-align/master/module.json
27+
1. Click Install and wait for installation to complete
1328

1429
## Development
1530

__tests__/moduleLogger.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import ModuleLogger from '@modules/moduleLogger';
2+
3+
describe('moduleLogger', () => {
4+
it('should inject module tag to console.debug', () => {
5+
const spy = jest.spyOn(console, 'debug');
6+
7+
ModuleLogger.debug('test debug');
8+
9+
expect(spy).toHaveBeenCalledWith('[hover-align] test debug');
10+
});
11+
12+
it('should inject module tag to console.error', () => {
13+
const spy = jest.spyOn(console, 'error');
14+
15+
ModuleLogger.error('test error');
16+
17+
expect(spy).toHaveBeenCalledWith('[hover-align] test error');
18+
});
19+
20+
it('should inject module tag to console.info', () => {
21+
const spy = jest.spyOn(console, 'info');
22+
23+
ModuleLogger.info('test info');
24+
25+
expect(spy).toHaveBeenCalledWith('[hover-align] test info');
26+
});
27+
28+
it('should inject module tag to console.log', () => {
29+
const spy = jest.spyOn(console, 'log');
30+
31+
ModuleLogger.log('test log');
32+
33+
expect(spy).toHaveBeenCalledWith('[hover-align] test log');
34+
});
35+
36+
it('should inject module tag to console.warn', () => {
37+
const spy = jest.spyOn(console, 'warn');
38+
39+
ModuleLogger.warn('test warn');
40+
41+
expect(spy).toHaveBeenCalledWith('[hover-align] test warn');
42+
});
43+
44+
afterEach(() => {
45+
jest.restoreAllMocks();
46+
});
47+
});

__tests__/showAlignment.test.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import showAlignment from '@modules/showAlignment';
2+
3+
const PLAYER_TOKEN = true;
4+
const NPC_TOKEN = false;
5+
6+
function initializeToken(hasPlayerOwner, originalGetTooltipText) {
7+
const token = {
8+
actor: {
9+
data: {
10+
data: {
11+
details: {
12+
alignment: 'Chaotic Evil',
13+
},
14+
},
15+
},
16+
hasPlayerOwner: hasPlayerOwner,
17+
},
18+
drawTooltip: jest.fn(() => token._getTooltipText()),
19+
refresh: jest.fn(),
20+
tooltip: { text: '' },
21+
uuid: 'test-token',
22+
_getTooltipText: originalGetTooltipText,
23+
};
24+
return token;
25+
}
26+
27+
describe('showAlignment', () => {
28+
global.game = {
29+
user: { isGM: false },
30+
};
31+
32+
describe('when hovering over a token', () => {
33+
it('should display alignment for GM', () => {
34+
game.user.isGM = true;
35+
const originalGetTooltipText = jest.fn(() => '');
36+
const token = initializeToken(NPC_TOKEN, originalGetTooltipText);
37+
38+
showAlignment(token, true);
39+
40+
expect(token._getTooltipText()).toEqual('hover-align.alignment.title: Chaotic Evil');
41+
expect(token.drawTooltip).toHaveBeenCalled();
42+
expect(token.refresh).toHaveBeenCalled();
43+
});
44+
45+
it('should append alignment to any tooltip set by the core', () => {
46+
game.user.isGM = true;
47+
const originalGetTooltipText = jest.fn(() => '+ 300ft');
48+
const token = initializeToken(NPC_TOKEN, originalGetTooltipText);
49+
50+
showAlignment(token, true);
51+
52+
expect(token._getTooltipText()).toEqual('+ 300ft\nhover-align.alignment.title: Chaotic Evil');
53+
expect(token.drawTooltip).toHaveBeenCalled();
54+
expect(token.refresh).toHaveBeenCalled();
55+
});
56+
57+
it('should display alignment for player when token is owned by a player', () => {
58+
game.user.isGM = false;
59+
const originalGetTooltipText = jest.fn(() => '');
60+
const token = initializeToken(PLAYER_TOKEN, originalGetTooltipText);
61+
62+
showAlignment(token, true);
63+
64+
expect(token._getTooltipText()).toEqual('hover-align.alignment.title: Chaotic Evil');
65+
expect(token.drawTooltip).toHaveBeenCalled();
66+
expect(token.refresh).toHaveBeenCalled();
67+
});
68+
69+
it('should not display alignment for player when token is not owned by a player', () => {
70+
game.user.isGM = false;
71+
const originalGetTooltipText = jest.fn(() => '');
72+
const token = initializeToken(NPC_TOKEN, originalGetTooltipText);
73+
74+
showAlignment(token, true);
75+
76+
expect(token._getTooltipText()).toBeEmpty();
77+
expect(token.drawTooltip).toHaveBeenCalled();
78+
expect(token.refresh).toHaveBeenCalled();
79+
});
80+
});
81+
82+
describe('when hovering out of a token', () => {
83+
it('should reset the tooltip to what is provided by the core', () => {
84+
game.user.isGM = false;
85+
const originalGetTooltipText = jest.fn(() => '+ 300ft');
86+
const token = initializeToken(PLAYER_TOKEN, originalGetTooltipText);
87+
88+
showAlignment(token, false);
89+
90+
expect(token._getTooltipText()).toEqual('+ 300ft');
91+
expect(token.drawTooltip).toHaveBeenCalled();
92+
expect(token.refresh).toHaveBeenCalled();
93+
});
94+
});
95+
});

doc/sample.gif

4.22 MB
Loading

lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"hover-align.title": "HoverAlign"
2+
"hover-align.alignment.title": "Alignment"
33
}

module.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
],
1818
"url": "https://github.com/johnmartel/hover-align",
1919
"manifest": "https://raw.githubusercontent.com/johnmartel/hover-align/master/module.json",
20-
"download": "https://github.com/johnmartel/hover-align/archive/master.zip",
20+
"download": "https://github.com/johnmartel/hover-align/releases/latest/download/hover-align.zip",
2121
"license": "https://github.com/johnmartel/hover-align/blob/master/LICENSE",
2222
"readme": "https://github.com/johnmartel/hover-align/blob/master/README.md",
23-
"bugs": "https://github.com/johnmartel/hover-align/issues"
23+
"bugs": "https://github.com/johnmartel/hover-align/issues",
24+
"changelog": "https://github.com/johnmartel/hover-align/blob/master/CHANGELOG.md"
2425
}

0 commit comments

Comments
 (0)