Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.0 - v9 compatibility, spam prevention, button hiding #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
614 changes: 576 additions & 38 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "foundryvtt-confetti",
"version": "1.0.5",
"version": "1.1.0",
"description": "",
"scripts": {
"publish": "gulp publish",
Expand All @@ -14,7 +14,7 @@
"author": "",
"license": "",
"devDependencies": {
"@typhonjs-fvtt/eslint-foundry.js": "^0.3.1",
"@typhonjs-fvtt/eslint-config-foundry.js": "^0.8.0",
"archiver": "^5.1.0",
"chalk": "^4.1.0",
"foundry-pc-types": "gitlab:foundry-projects/foundry-pc/foundry-pc-types",
Expand Down
3 changes: 2 additions & 1 deletion src/foundryvtt-confetti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ Hooks.on('renderChatLog', (app: any, html: JQuery<HTMLElement>) => {
}

const gmOnly = game.settings.get(MODULE_ID, MySettings.GmOnly);
if (!gmOnly || game.user.isGM) {
const showButton = game.settings.get(MODULE_ID, MySettings.ShowButton);
if (showButton && (!gmOnly || game.user.isGM)) {
_addConfettiButtons(html);
}
});
8 changes: 8 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"mute": {
"Name": "Mute",
"Hint": "If you think those sounds are annoying, imagine being the guy writing this thing."
},
"rapid-fire-limit": {
"Name": "Rapid Fire Limit (Seconds)",
"Hint": "Sometimes there *needs* to be a limit. (0 is no-limit)"
},
"show-button": {
"Name": "Show Button",
"Hint": "(Requires reload) Disable if you are only interested in using it from macros/modules and/or the button conflicts with other module(s)."
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "confetti",
"title": "Confetti",
"description": "Everyone loves confetti.",
"version": "1.0.5",
"version": "1.1.0",
"author": "Andrew Krigline (akrigline)",
"authors": [
{
Expand Down Expand Up @@ -35,7 +35,7 @@
}
],
"minimumCoreVersion": "0.7.9",
"compatibleCoreVersion": "0.8.2",
"compatibleCoreVersion": "9",
"socket": true,
"media": [
{
Expand All @@ -57,7 +57,7 @@
],
"bugs": "https://github.com/ElfFriend-DnD/foundryvtt-confetti/issues",
"changelog": "https://github.com/ElfFriend-DnD/foundryvtt-confetti/releases",
"download": "https://github.com/ElfFriend-DnD/foundryvtt-confetti/releases/download/v1.0.5/module.zip",
"download": "https://github.com/ElfFriend-DnD/foundryvtt-confetti/releases/download/v1.1.0/module.zip",
"manifest": "https://github.com/ElfFriend-DnD/foundryvtt-confetti/releases/latest/download/module.json",
"readme": "https://raw.githubusercontent.com/ElfFriend-DnD/foundryvtt-confetti/main/README.md",
"url": "https://github.com/ElfFriend-DnD/foundryvtt-confetti"
Expand Down
15 changes: 13 additions & 2 deletions src/module/classes/Confetti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Confetti {
dpr: number;
_rtime: Date; // used to keep track of resize
_timeout: boolean; // used in resize
_lastShot: Date; // used to prevent rapid fire

/**
* Create and initialize a new Confetti.
Expand All @@ -56,6 +57,7 @@ export class Confetti {
this._buildCanvas();
this._initListeners();
this.confettiSprites = {};
this._lastShot = new Date();

game.audio.pending.push(this._preloadSounds.bind(this));

Expand Down Expand Up @@ -100,7 +102,7 @@ export class Confetti {
* @private
*/
_initListeners() {
game.socket.on(`module.${MODULE_ID}`, (request: { data: ShootConfettiProps }) => {
(game.socket as any).on(`module.${MODULE_ID}`, (request: { data: ShootConfettiProps }) => {
log(false, 'got socket connection', {
request,
});
Expand Down Expand Up @@ -334,14 +336,23 @@ export class Confetti {
shootConfetti(shootConfettiProps: ShootConfettiProps) {
const socketProps = { data: shootConfettiProps };

const now = new Date();
const rapidFireLimit = game.settings.get(MODULE_ID, MySettings.RapidFireLimit);
if (rapidFireLimit && (this._lastShot.getTime() + rapidFireLimit * 1000 > now.getTime())) {
log(false, 'shootConfetti prevented by rapid fire setting');
return;
} else {
this._lastShot = now;
}

log(false, 'shootConfetti, emitting socket', {
shootConfettiProps,
socketProps,
});

this.handleShootConfetti(socketProps.data);

game.socket.emit(`module.${MODULE_ID}`, socketProps);
(game.socket as any).emit(`module.${MODULE_ID}`, socketProps);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/module/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum MySettings {
GmOnly = 'gm-only',
ConfettiMultiplier = 'confetti-multiplier',
Mute = 'mute',
RapidFireLimit = 'rapid-fire-limit',
ShowButton = 'show-button',
}

export enum MyFlags {}
19 changes: 19 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,23 @@ export const registerSettings = function () {
config: true,
hint: `${MODULE_ABBREV}.settings.${MySettings.Mute}.Hint`,
});

game.settings.register(MODULE_ID, MySettings.RapidFireLimit, {
name: `${MODULE_ABBREV}.settings.${MySettings.RapidFireLimit}.Name`,
default: 5,
range: { min: 0, max: 10, step: 1 },
type: Number,
scope: 'client',
config: true,
hint: `${MODULE_ABBREV}.settings.${MySettings.RapidFireLimit}.Hint`,
});

game.settings.register(MODULE_ID, MySettings.ShowButton, {
name: `${MODULE_ABBREV}.settings.${MySettings.ShowButton}.Name`,
default: true,
type: Boolean,
scope: 'client',
config: true,
hint: `${MODULE_ABBREV}.settings.${MySettings.ShowButton}.Hint`,
});
};