Skip to content

Commit

Permalink
Merge pull request #26 from gludington/075datastructure
Browse files Browse the repository at this point in the history
075datastructure
  • Loading branch information
gludington authored Nov 24, 2020
2 parents 4abf250 + f884241 commit 86b77e1
Show file tree
Hide file tree
Showing 19 changed files with 459 additions and 294 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: conditional-visibility CI

on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: npm install, build, and test
run: npm install
- name: Update Version
shell: bash
id: set-version
run: echo "::set-output name=version::$(node .github/workflows/set-version.js ${{ github.ref }})"
- run: npm run package
- name: Create Release
id: create_versioned_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: Release ${{ steps.set-version.outputs.version }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './dist/module.json,./package/*.zip'
17 changes: 17 additions & 0 deletions .github/workflows/set-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var fs = require('fs');
const manifest = JSON.parse(fs.readFileSync('src/module.json', 'utf8'));
// first argument is node, second is the filename of the script, third is the version we pass in our workflow.
// expected tag format is 'refs/tags/v{major}.{minor}.{patch}"
const tagVersion = process.argv[2].split('/').slice(-1)[0];
if (!tagVersion || !tagVersion.startsWith('v')) {
console.error(`Invalid version specified: ${tagVersion}`);
process.exitCode = 1;
} else {
manifest.version = tagVersion.substring(1); // strip the 'v'-prefix
manifest.download = `https://github.com/gludington/conditional-visibility/releases/download/conditional-visibility-${tagVersion}.zip`
manifest.manifest = `https://github.com/gludington/conditional-visibility/releases/download/${tagVersion}/module.json`,
manifest.changelog= `https://github.com/gludington/conditional-visibility/blob/${tagVersion}/CHANGELOG.md`,
manifest.readme = `https://github.com/gludington/conditional-visibility/blob/${tagVersion}/README.md`,
fs.writeFileSync('src/module.json', JSON.stringify(manifest, null, 4)); // pretty print JSON back to module.json
console.log(tagVersion);
}
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ async function copyFiles() {
'fonts',
'assets',
'templates',
'packs',
'icons',
'module.json',
'system.json',
Expand Down Expand Up @@ -213,6 +214,7 @@ async function clean() {
files.push(
'lang',
'templates',
'packs',
'assets',
'module',
`${name}.js`,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.9",
"description": "",
"scripts": {
"package": "gulp package",
"package": "gulp clean && gulp build && gulp package",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collect-coverage",
Expand Down
65 changes: 17 additions & 48 deletions spec/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ConditionalVisibility } from '../src/module/ConditionalVisibility';

//@ts-ignore
(global as any).game = {
data: { version: "0.6.6"},
data: { version: "0.7.6"},
system: {id: 'asdf'},
socket: {
on:jest.fn().mockImplementation((name, data) => {})
Expand All @@ -11,13 +11,17 @@ import {ConditionalVisibility } from '../src/module/ConditionalVisibility';

//@ts-ignore
(global as any).CONFIG = {
statusEffects: []
statusEffects: [],
};
class Token {
private _isVisible;
get isVisible(): boolean {
return this._isVisible;
}
}

//@ts-ignore
(global as any).isNewerVersion = (version:string, base:string) => {
return parseFloat(version) >= parseFloat(base);
}
(global as any).Token = Token;

describe('Setup - onInit', () => {

Expand All @@ -28,26 +32,26 @@ describe('Setup - onInit', () => {
it('Establish three conditions for an unrecognized game system', () => {
ConditionalVisibility.onInit();
expect(CONFIG.statusEffects.length).toBe(3);
expect(CONFIG.statusEffects[0]).toBe('modules/conditional-visibility/icons/unknown.svg');
expect(CONFIG.statusEffects[1]).toBe('modules/conditional-visibility/icons/foggy.svg');
expect(CONFIG.statusEffects[2]).toBe('modules/conditional-visibility/icons/moon.svg');
expect(CONFIG.statusEffects[0].icon).toBe('modules/conditional-visibility/icons/unknown.svg');
expect(CONFIG.statusEffects[1].icon).toBe('modules/conditional-visibility/icons/foggy.svg');
expect(CONFIG.statusEffects[2].icon).toBe('modules/conditional-visibility/icons/moon.svg');
});

it('Establish four conditions for dnd5e', () => {
game.system.id = "dnd5e";
ConditionalVisibility.onInit();
expect(CONFIG.statusEffects.length).toBe(4);
expect(CONFIG.statusEffects[0]).toBe('modules/conditional-visibility/icons/unknown.svg');
expect(CONFIG.statusEffects[1]).toBe('modules/conditional-visibility/icons/foggy.svg');
expect(CONFIG.statusEffects[2]).toBe('modules/conditional-visibility/icons/moon.svg');
expect(CONFIG.statusEffects[3]).toBe('modules/conditional-visibility/icons/newspaper.svg');
expect(CONFIG.statusEffects[0].icon).toBe('modules/conditional-visibility/icons/unknown.svg');
expect(CONFIG.statusEffects[1].icon).toBe('modules/conditional-visibility/icons/foggy.svg');
expect(CONFIG.statusEffects[2].icon).toBe('modules/conditional-visibility/icons/moon.svg');
expect(CONFIG.statusEffects[3].icon).toBe('modules/conditional-visibility/icons/newspaper.svg');
});

it('Establish one condition for pf2e', () => {
game.system.id = "pf2e";
ConditionalVisibility.onInit();
expect(CONFIG.statusEffects.length).toBe(1);
expect(CONFIG.statusEffects[0]).toBe('systems/pf2e/icons/conditions-2/invisible.png');
expect(CONFIG.statusEffects[0].icon).toBe('systems/pf2e/icons/conditions/invisible.png');
});
});

Expand All @@ -60,45 +64,10 @@ describe('Ready - initialize', () => {
const tokenHud:any = {};
it('it should set up a listener for modifyEmbeddedDocument and redraw', () => {
ConditionalVisibility.initialize(sightLayer, tokenHud);
//@ts-ignore
expect(ConditionalVisibility.INSTANCE._isV7).toBe(false);
expect(game.socket.on).toHaveBeenCalledWith("modifyEmbeddedDocument", expect.any(Function));
expect(sightLayer.initialize).toHaveBeenCalled();
expect(sightLayer.refresh).not.toHaveBeenCalled();
//TODO 2nd mock not getting called?
//expect(sightLayer.update).toHaveBeenCalled();
})
});

describe("shouldRedraw", () => {

beforeEach(() => {
const sightLayer:any = {
initialize: jest.fn().mockResolvedValue(43),
refresh: jest.fn().mockResolvedValue(43),
update: jest.fn().mockResolvedValue(43)
};
const tokenHud:any = {};
ConditionalVisibility.initialize(sightLayer, tokenHud);
});

it ("Should not redraw on a null change", () => {
const toTest = {};
expect(ConditionalVisibility.INSTANCE.shouldRedraw(toTest)).toBe(false);
});

it ("Should redraw on adding an effects change", () => {
const toTest = { effects: []};
expect(ConditionalVisibility.INSTANCE.shouldRedraw(toTest)).toBe(true);
});

it ("Should not redraw on adding with no module flags change", () => {
const toTest = { flags: {}};
expect(ConditionalVisibility.INSTANCE.shouldRedraw(toTest)).toBe(false);
});

it ("Should redraw on adding with module flags change", () => {
const toTest = { flags: {'conditional-visibility': {}}};
expect(ConditionalVisibility.INSTANCE.shouldRedraw(toTest)).toBe(true);
});
});
36 changes: 20 additions & 16 deletions spec/systems/ConditionalVisibilityPf2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ConditionalVisibility } from '../../src/module/ConditionalVisibility';
import { StatusEffect } from '../../src/module/Constants';
import {ConditionalVisibilitySystemPf2e } from '../../src/module/systems/ConditionalVisibilitySystemPf2e';
//@ts-ignore
(global as any).game = {
data: { version: "0.6.6"},
system: {id: 'asdf'},
data: { version: "0.7.6"},
system: {id: 'pf2e'},
socket: {
on:jest.fn().mockImplementation((name, data) => {})
}
Expand All @@ -18,48 +20,50 @@ import {ConditionalVisibilitySystemPf2e } from '../../src/module/systems/Conditi
return parseFloat(version) >= parseFloat(base);
}

describe('ConditionalVisibilitySystem5e', () => {
describe('ConditionalVisibilitySystemPf2e', () => {

const system:ConditionalVisibilitySystemPf2e = new ConditionalVisibilitySystemPf2e();
//@ts-ignore
const system:ConditionalVisibilitySystemPf2e = ConditionalVisibility.newSystem();

describe('Setup', () => {
it('Establishes one condition for pf2e', () => {
const effects:Map<string, string> = system.effectsByIcon();
const effects:Map<string, StatusEffect> = system.effectsByIcon();
expect(effects.size).toBe(1);
expect(effects.get('systems/pf2e/icons/conditions-2/invisible.png')).toBe('invisible');
expect(effects.get('systems/pf2e/icons/conditions/invisible.png').id).toBe('conditional-visibility.invisible');
});
});

describe('if token is invisible', () => {

let flags:any = {};
let token:any = { data: { effects:[]}};
let token:any = { data : { flags: {
'conditional-visibility': { 'invisible':true }
}}};

beforeEach(() => {
flags = {};
token = { data: { effects:['systems/pf2e/icons/conditions-2/invisible.png']}};
});

it ('empty capabilities cannot see it', () => {
flags.seeinvisible = false;
flags= {}
//@ts-ignore
expect(system.seeInvisible(token, token.data.effects, flags)).toBe(false);
expect(system.seeInvisible(token, flags)).toBe(false);
});

it ('seeinvisible can see it', () => {
flags.seeinvisible = true;
flags = {seeinvisible: true};
//@ts-ignore
expect(system.seeInvisible(token, token.data.effects, flags)).toBe(true);
expect(system.seeInvisible(token, flags)).toBe(true);
});
it ('seeobscured cannot see it', () => {
flags.seeobscured = true;
flags = {seeobscured: true};
//@ts-ignore
expect(system.seeInvisible(token, token.data.effects, flags)).toBe(false);
expect(system.seeInvisible(token, flags)).toBe(false);
});
it ('seeindarkness cannot see it', () => {
flags.seeobscured = true;
flags = {seeindarkness: true};
//@ts-ignore
expect(system.seeInvisible(token, token.data.effects, flags)).toBe(false);
expect(system.seeInvisible(token, flags)).toBe(false);
});
});
});
34 changes: 20 additions & 14 deletions spec/systems/ConditionalVisibilitySystem5e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { StatusEffect } from '../../src/module/Constants';
import { ConditionalVisibility } from '../../src/module/ConditionalVisibility';
import {ConditionalVisibilitySystem5e } from '../../src/module/systems/ConditionalVisibilitySystem5e';
//@ts-ignore
(global as any).game = {
data: { version: "0.6.6"},
system: {id: 'asdf'},
system: {id: 'dnd5e'},
socket: {
on:jest.fn().mockImplementation((name, data) => {})
}
Expand All @@ -20,16 +22,18 @@ import {ConditionalVisibilitySystem5e } from '../../src/module/systems/Condition

describe('ConditionalVisibilitySystem5e', () => {

const system:ConditionalVisibilitySystem5e = new ConditionalVisibilitySystem5e();
//@ts-ignore
const system:ConditionalVisibilitySystem5e = ConditionalVisibility.newSystem();

describe('Setup', () => {
it('Establishes four conditions for dnd5e', () => {
const effects:Map<string, string> = system.effectsByIcon();
const effects:Map<string, StatusEffect> = system.effectsByIcon();
expect(effects.size).toBe(4);
expect(effects.get('modules/conditional-visibility/icons/unknown.svg')).toBe('invisible');
expect(effects.get('modules/conditional-visibility/icons/foggy.svg')).toBe('obscured');
expect(effects.get('modules/conditional-visibility/icons/moon.svg')).toBe('indarkness');
expect(effects.get('modules/conditional-visibility/icons/newspaper.svg')).toBe('hidden');
expect(effects.get('modules/conditional-visibility/icons/unknown.svg').id).toBe('conditional-visibility.invisible');
expect(effects.get('modules/conditional-visibility/icons/foggy.svg').id).toBe('conditional-visibility.obscured');
expect(effects.get('modules/conditional-visibility/icons/moon.svg').id).toBe('conditional-visibility.indarkness');
expect(effects.get('modules/conditional-visibility/icons/newspaper.svg').id).toBe('conditional-visibility.hidden');

});
});

Expand Down Expand Up @@ -74,26 +78,28 @@ describe('ConditionalVisibilitySystem5e', () => {

describe('Contested Test', () => {
let flags:any = { prc: 12};
let token:any = { data: { effects:['modules/conditional-visibility/icons/newspaper.svg']}};
let token:any = { data : { flags: {
'conditional-visibility': { 'hidden':true }
}}};

it('stealth higher than the prc cannot be seen', () => {
token.data.flags = { 'conditional-visibility': { _ste: 15}}
token.data.flags = { 'conditional-visibility': { hidden:true, _ste: 15}}
//@ts-ignore
expect(system.seeContested(token, token.data.effects, flags)).toBe(false);
expect(system.seeContested(token, flags)).toBe(false);
expect(system.canSee(token, flags)).toBe(false);
});

it('stealth equal to the prc can be seen', () => {
token.data.flags = { 'conditional-visibility': { _ste: 12}}
token.data.flags = { 'conditional-visibility': { hidden:true, _ste: 12}}
//@ts-ignore
expect(system.seeContested(token, token.data.effects, flags)).toBe(true);
expect(system.seeContested(token, flags)).toBe(true);
expect(system.canSee(token, flags)).toBe(true);
});

it('stealth lower than the prc can be seen', () => {
token.data.flags = { 'conditional-visibility': { _ste: 10}}
token.data.flags = { 'conditional-visibility': { hidden:true, _ste: 10}}
//@ts-ignore
expect(system.seeContested(token, token.data.effects, flags)).toBe(true);
expect(system.seeContested(token, flags)).toBe(true);
expect(system.canSee(token, flags)).toBe(true);
});

Expand Down
Loading

0 comments on commit 86b77e1

Please sign in to comment.