Added some code documentation

pull/21833/head
Steffen Kolmer 2020-10-21 19:06:10 +02:00
parent 3ea4560019
commit 1c556c97d3
4 changed files with 81 additions and 17 deletions

View File

@ -1,9 +1,29 @@
/**
* Defines the constructor of a canvas based room effect
*/
export interface ICanvasEffectConstructable { export interface ICanvasEffectConstructable {
/**
* @param {{[key:string]:any}} options? Optional animation options
* @returns ICanvasEffect Returns a new instance of the canvas effect
*/
new(options?: { [key: string]: any }): ICanvasEffect new(options?: { [key: string]: any }): ICanvasEffect
} }
/**
* Defines the interface of a canvas based room effect
*/
export default interface ICanvasEffect { export default interface ICanvasEffect {
/**
* @param {HTMLCanvasElement} canvas The canvas instance as the render target of the animation
* @param {number} timeout? A timeout that defines the runtime of the animation (defaults to false)
*/
start: (canvas: HTMLCanvasElement, timeout?: number) => Promise<void>, start: (canvas: HTMLCanvasElement, timeout?: number) => Promise<void>,
/**
* Stops the current animation
*/
stop: () => Promise<void>, stop: () => Promise<void>,
/**
* Returns a value that defines if the animation is currently running
*/
isRunning: boolean isRunning: boolean
} }

View File

@ -9,10 +9,25 @@ declare global {
} }
export type ConfettiOptions = { export type ConfettiOptions = {
/**
* max confetti count
*/
maxCount: number, maxCount: number,
/**
* particle animation speed
*/
speed: number, speed: number,
/**
* the confetti animation frame interval in milliseconds
*/
frameInterval: number, frameInterval: number,
/**
* the alpha opacity of the confetti (between 0 and 1, where 1 is opaque and 0 is invisible)
*/
alpha: number, alpha: number,
/**
* use gradient instead of solid particle color
*/
gradient: boolean, gradient: boolean,
} }
@ -28,15 +43,10 @@ type ConfettiParticle = {
} }
export const DefaultOptions: ConfettiOptions = { export const DefaultOptions: ConfettiOptions = {
//set max confetti count
maxCount: 150, maxCount: 150,
//syarn addet the particle animation speed
speed: 3, speed: 3,
//the confetti animation frame interval in milliseconds
frameInterval: 15, frameInterval: 15,
//the alpha opacity of the confetti (between 0 and 1, where 1 is opaque and 0 is invisible)
alpha: 1.0, alpha: 1.0,
//use gradient instead of solid particle color
gradient: false, gradient: false,
}; };

View File

@ -1,3 +1,8 @@
/**
* Checks a message if it contains one of the provided emojis
* @param {Object} content The message
* @param {Array<string>} emojis The list of emojis to check for
*/
export const containsEmoji = (content: { msgtype: string, body: string }, emojis: Array<string>): boolean => { export const containsEmoji = (content: { msgtype: string, body: string }, emojis: Array<string>): boolean => {
return emojis.some((emoji) => content.body.includes(emoji)); return emojis.some((emoji) => content.body.includes(emoji));
} }

View File

@ -1,25 +1,59 @@
import { _t, _td } from "../../../../languageHandler"; import { _t, _td } from "../../../../languageHandler";
export type Effect = { export type Effect<TOptions extends { [key: string]: any }> = {
/**
* one or more emojis that will trigger this effect
*/
emojis: Array<string>; emojis: Array<string>;
/**
* the matrix message type that will trigger this effect
*/
msgType: string; msgType: string;
/**
* the room command to trigger this effect
*/
command: string; command: string;
/**
* a function that returns the translated description of the effect
*/
description: () => string; description: () => string;
/**
* a function that returns the translated fallback message. this message will be shown if the user did not provide a custom message
*/
fallbackMessage: () => string; fallbackMessage: () => string;
options: { /**
[key: string]: any * animation options
} */
options: TOptions;
} }
type ConfettiOptions = { type ConfettiOptions = {
/**
* max confetti count
*/
maxCount: number, maxCount: number,
/**
* particle animation speed
*/
speed: number, speed: number,
/**
* the confetti animation frame interval in milliseconds
*/
frameInterval: number, frameInterval: number,
/**
* the alpha opacity of the confetti (between 0 and 1, where 1 is opaque and 0 is invisible)
*/
alpha: number, alpha: number,
/**
* use gradient instead of solid particle color
*/
gradient: boolean, gradient: boolean,
} }
const effects: Array<Effect> = [ /**
* This configuration defines room effects that can be triggered by custom message types and emojis
*/
const effects: Array<Effect<{ [key: string]: any }>> = [
{ {
emojis: ['🎊', '🎉'], emojis: ['🎊', '🎉'],
msgType: 'nic.custom.confetti', msgType: 'nic.custom.confetti',
@ -27,18 +61,13 @@ const effects: Array<Effect> = [
description: () => _td("Sends the given message with confetti"), description: () => _td("Sends the given message with confetti"),
fallbackMessage: () => _t("sends confetti") + " 🎉", fallbackMessage: () => _t("sends confetti") + " 🎉",
options: { options: {
//set max confetti count
maxCount: 150, maxCount: 150,
//syarn addet the particle animation speed
speed: 3, speed: 3,
//the confetti animation frame interval in milliseconds
frameInterval: 15, frameInterval: 15,
//the alpha opacity of the confetti (between 0 and 1, where 1 is opaque and 0 is invisible)
alpha: 1.0, alpha: 1.0,
//use gradient instead of solid particle color
gradient: false, gradient: false,
} as ConfettiOptions, },
}, } as Effect<ConfettiOptions>,
]; ];
export default effects; export default effects;