From 1ec7601306b18d4f4e317c55ddef040dbc0e618b Mon Sep 17 00:00:00 2001 From: HxxxxxS <16c52527@opayq.com> Date: Thu, 31 Oct 2024 23:08:42 +0100 Subject: [PATCH] define Effect.js --- src/effects/Effect.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/effects/Effect.js diff --git a/src/effects/Effect.js b/src/effects/Effect.js new file mode 100644 index 0000000..e64c338 --- /dev/null +++ b/src/effects/Effect.js @@ -0,0 +1,37 @@ +export default class Effect { + constructor(options = {}) { + this.enabled = options.enabled !== undefined ? options.enabled : true; + this.priority = options.priority || 0; + this.params = options.params || {}; + this.debug = options.debug || false; + this.id = options.id || `effect-${Math.random().toString(36).substr(2, 9)}`; + } + + // Enable or disable the effect + enable() { this.enabled = true; } + disable() { this.enabled = false; } + + // Update parameters for live adjustments + updateParams(newParams = {}) { Object.assign(this.params, newParams); } + + // Set default parameters, to be called in subclasses + setDefaults(defaultParams) { this.params = { ...defaultParams, ...this.params }; } + + // Log messages if debug mode is enabled + debugLog(...args) { if (this.debug) console.log(`[${this.constructor.name} - ${this.id}]`, ...args); } + + // Get parameter with fallback + getParam(key, fallback) { return key in this.params ? this.params[key] : fallback; } + + // Lifecycle hooks for optional custom behavior + beforeApply(ctx, video, params) { /* Optionally overridden in subclass */ } + afterApply(ctx, video, params) { /* Optionally overridden in subclass */ } + + // Base apply method to be implemented in each subclass + apply(ctx, video, params) { + if (!this.enabled) return; + this.beforeApply(ctx, video, params); + throw new Error("apply() method must be implemented by subclass"); + this.afterApply(ctx, video, params); + } +}