Browse Source

define Effect.js

master
HxxxxxS 1 year ago
parent
commit
1ec7601306
  1. 37
      src/effects/Effect.js

37
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);
}
}
Loading…
Cancel
Save