Skip to content

Commit

Permalink
Added tools and replication
Browse files Browse the repository at this point in the history
  • Loading branch information
ZotyDev committed Jan 20, 2024
1 parent b006803 commit 4044699
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/apiReference.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!> **All** methods here do not replicate to users, they are executed **locally**
> **All** methods here are replicated to all the users!
## Screen Shake
```js
ChromaticCanvas.screenShake(intensity: Number, duration: Number,
Expand Down
8 changes: 7 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "chromatic-canvas",
"title": "🎴 Chromatic Canvas (Library)",
"description": "Library that adds special effects to the canvas",
"version": "1.0.1",
"version": "1.1.0",
"library": true,
"authors": [
{
Expand Down Expand Up @@ -43,9 +43,15 @@
"id": "toolbox",
"type": "module",
"compatibility": {}
},
{
"id": "socketlib",
"type": "module",
"compatibility": {}
}
]
},
"socket": true,
"esmodules": [
"./module/scripts/module.js"
]
Expand Down
7 changes: 7 additions & 0 deletions module/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
{
"chromatic-canvas": {
"tool": {
"screen-shake": {
"title": "Screen Shake"
}
}
}
}
1 change: 1 addition & 0 deletions module/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export class Constants {
static ID = 'chromatic-canvas';
static NAME_FLAT = 'Chromatic Canvas';
static NAME = `🎴 ${Constants.NAME_FLAT}`;
static SOCKET;
static D;
}
39 changes: 38 additions & 1 deletion module/scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Hooks.once('init', () => {

// Setup the API and methods
window['ChromaticCanvas'] = {
screenShake: ChromaticCanvasLayer.screenShake,
screenShake: (intensity = 1, duration = 500, iterations = 1) => {
C.SOCKET.executeForEveryone('screenShake', intensity, duration, iterations);
}
}

Hooks.call('chromatic-canvas.ready');
Expand All @@ -41,4 +43,39 @@ Hooks.once('init', () => {
group: 'interface',
layerClass: ChromaticCanvasLayer,
}

Hooks.on('getSceneControlButtons', (controls) => {
// Setup listener for the module tools
if (!canvas.scene) return;

const screenShakeTool = {
name: 'screen-shake',
title: game.i18n.localize('chromatic-canvas.tool.screen-shake.title'),
icon: 'fas fa-waveform',
onClick: async () => {
C.SOCKET.executeForEveryone('screenShake', 1, 500, 1);
},
button: true
}

controls.push({
name: C.ID,
title: C.NAME_FLAT,
layer: 'chromaticCanvas',
icon: 'fas fa-panorama',
visible: game.user.isGM,
tools: [
screenShakeTool
]
});
});
});

// Setup the socket
Hooks.once('socketlib.ready', () =>
{
C.SOCKET = socketlib.registerModule(C.ID);

// Tags
C.SOCKET.register('screenShake', ChromaticCanvasLayer.screenShake);
})

0 comments on commit 4044699

Please sign in to comment.