-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaterialdeck-systemtemplate.js
More file actions
169 lines (143 loc) · 5.59 KB
/
materialdeck-systemtemplate.js
File metadata and controls
169 lines (143 loc) · 5.59 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* This is a very basic system module template for Material Deck Premium.
* As configured, it will run on a DnD5e world, to change it to another system set `systemId` in `game.materialDeck.registerSystem` and the 'id' in 'relationships' in 'module.json' to the desired system.
*
* For the full system dev documentation, visit: https://materialfoundry.github.io/MaterialDeck/systemDevelopment/gettingStarted/
*/
//Module id taken from manifest.json
const moduleId = 'materialdeck-systemtemplate';
//Function to more easily localize text for the system module
const localize = (str) => {
return game.i18n.localize(`MATERIALDECK_SYSTEMTEMPLATE.${str}`);
}
//The 'MaterialDeck_Ready' hook is called when Material Deck is done initializing
Hooks.once('MaterialDeck_Ready', () => {
//Get module data from the manifest
const moduleData = game.modules.get(moduleId);
//Register a gaming system to Material Deck
game.materialDeck.registerSystem({
systemId: 'dnd5e',
moduleId,
systemName: 'System Template',
version: moduleData.version,
manifest: moduleData.manifest,
documentation: "https://github.com/MaterialFoundry/MaterialDeck_SystemTemplate/blob/main/README.md/",
actions: [
//Actions that the system module edits
tokenAction
//otherAction
//audioAction
//etc
]
});
});
//tokenAction defines how the Token Action is changed
const tokenAction = {
id: 'token',
//settingsConfig adds new settings or edits existing settings
settingsConfig: function() {
return [
//Add options to the 'mode' setting
{
id: "mode",
appendOptions: [
{ value: "inventory", label: localize("Inventory") },
{ value: "spellbook", label: localize("Spellbook") }
]
},
//Add a wrapper with settings that are only displayed when 'mode' is set to 'inventory'
{
id: "inventory-wrapper",
type: "wrapper",
after: "mode", //Position this wrapper after the 'mode' setting
visibility: { showOn: [ { mode: "inventory" } ] }, //Show only if 'mode' is set to 'inventory'
indent: 1, //Move the contents of the wrapper slightly to the right
settings: [
//Contents of the wrapper
{
label: "Inventory Checkbox",
id: 'inventoryMode.checkbox',
type: 'checkbox',
default: true
}
]
},
//Add a range setting that will be displayed in every mode
{
id: "range",
label: "Range",
type: "range", //Create a range slider
before: "colors-table", //Position it before 'colors-table'
min: "0",
max: "10",
default: "2",
displayValue: true
}
]
},
//buttonActions configures what to on button interactions
buttonActions: function(settings) {
let buttonActions = { update: [], keyDown: [], keyUp: [], hold: [] };
//If 'mode' is set to 'inventory'
if (settings.mode === 'inventory') {
//Run tokenAction.onUpdate when the button is updated or when the 'controlToken' hook is called
buttonActions.update.push({
run: this.onUpdate,
on: ['controlToken']
})
//Run tokenAction.onKeyUp when the button is released
buttonActions.keyUp.push({
run: this.onKeyUp,
stopOnHold: true //Prevent this from running if the hold button action is triggered
})
//Run tokenAction.onHold when the button is held down for 1000ms
buttonActions.hold.push({
run: this.onHold,
delay: 1000
})
}
return buttonActions;
},
onUpdate: function(data) {
console.log('Button is updated', data);
//If a token is selected
if (data.token) {
return {
text: data.token.name, //Display the token's name on the button
icon: data.token.texture.src //Display the token's image on the button
}
}
//If no token is selected
else {
return {
text: "No token selected",
icon: ""
}
}
},
counter: 0,
onKeyUp: function(data) {
console.log('Button is released', data);
//If 'Inventory Checkbox' is checked
if (data.settings.inventoryMode.checkbox) {
//Increment the counter
tokenAction.counter++;
//Display the counter on the button
data.button.setTitle(`Counter:\n${tokenAction.counter}`);
//Set the icon to a FontAwesome icon
data.button.setIcon('fas fa-thumbs-up');
}
},
onHold: function(data) {
console.log('Button is held down', data);
//If 'Inventory Checkbox' is checked
if (data.settings.inventoryMode.checkbox) {
//Reset the counter
tokenAction.counter = 0;
//Display the counter on the button
data.button.setTitle(`Counter Reset!`);
//Set the icon to a FontAwesome icon
data.button.setIcon('fas fa-rotate-reverse');
}
}
}