-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
74 lines (67 loc) · 2.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { JournalLink } from './journallink.js';
import { Sync } from './sync.js';
// bump this to cause a sync on page load (one time)
const SYNC_VERSION = 1;
const MODULE_NAME = 'journal-links';
const NAME = 'Journal Links';
Hooks.on("init", () => {
console.log('journal-links | initializing');
let modulename = MODULE_NAME;
game.settings.register(MODULE_NAME, 'rebuildOnSave', {
name : 'Rebuild links on journal save',
hint: 'If unchecked, linking only happens on manual sync. As there is currently no way to manually sync, effectively disables linking.',
scope: 'world',
config: true,
type: Boolean,
default: true
});
game.settings.register(MODULE_NAME, 'headingTag', {
name : 'Heading tag for links',
hint: 'For <h1>Links</h1>, enter h1. Do not add classes, etc.',
scope: 'world',
config: true,
type: String,
default: 'h1'
});
game.settings.register(MODULE_NAME, 'debug', {
name : 'Debug logging',
scope: 'client',
config: true,
type: Boolean,
default: false
});
game.settings.register(MODULE_NAME, 'lastSyncedVersion', {
name : 'Last synced version',
hint: 'If we perform a bugfix that would benefit from resyncing, SYNC_VERSION will be out of -- forgive me -- sync, indicating we should perform a sync',
scope: 'world',
config: false,
type: Number,
default: 0
});
game.settings.registerMenu(MODULE_NAME, 'syncButton', {
name: 'Sync entries',
label: 'Sync now',
icon: 'fas fa-sync-alt',
type: Sync,
restricted: true
});
let jl = new JournalLink();
game.JournalLink = jl;
CONFIG.debug.JournalLinks = game.settings.get(MODULE_NAME, 'debug');
// things what update
Hooks.on('updateJournalEntry', game.JournalLink.updateJournalEntry.bind(jl));
Hooks.on('updateActor', game.JournalLink.updateActor.bind(jl));
Hooks.on('updateItem', game.JournalLink.updateItem.bind(jl));
// things what render
Hooks.on('renderJournalSheet', game.JournalLink.includeJournalLinks.bind(jl));
Hooks.on('renderActorSheet', game.JournalLink.includeActorLinks.bind(jl));
Hooks.on('renderItemSheet', game.JournalLink.includeItemLinks.bind(jl));
// initial sync
Hooks.on('ready', () => {
if (game.settings.get(MODULE_NAME, 'lastSyncedVersion') < SYNC_VERSION) {
console.log('journal-links | performing sync...');
game.JournalLink.sync();
game.settings.set(MODULE_NAME, 'lastSyncedVersion', SYNC_VERSION);
}
});
});