Add base gnome extensions

This commit is contained in:
2024-01-17 15:38:16 -05:00
parent 78ab940cae
commit 6d45aaa042
330 changed files with 47886 additions and 0 deletions

View File

@ -0,0 +1,89 @@
import { ColorEffect } from '../effects/color_effect.js';
import { NoiseEffect } from '../effects/noise_effect.js';
/// An object to manage effects (by not destroying them all the time)
export const EffectsManager = class EffectsManager {
constructor(connections) {
this.connections = connections;
this.used = [];
this.color_effects = [];
this.noise_effects = [];
}
connect_to_destroy(effect) {
effect.old_actor = effect.get_actor();
if (effect.old_actor)
effect.old_actor_id = effect.old_actor.connect('destroy', _ => {
this.remove(effect);
});
this.connections.connect(effect, 'notify::actor', _ => {
let actor = effect.get_actor();
if (effect.old_actor && actor != effect.old_actor)
effect.old_actor.disconnect(effect.old_actor_id);
if (actor) {
effect.old_actor_id = actor.connect('destroy', _ => {
this.remove(effect);
});
}
});
}
new_color_effect(params, settings) {
let effect;
if (this.color_effects.length > 0) {
effect = this.color_effects.splice(0, 1)[0];
effect.set(params);
} else
effect = new ColorEffect(params, settings);
this.used.push(effect);
this.connect_to_destroy(effect);
return effect;
}
new_noise_effect(params, settings) {
let effect;
if (this.noise_effects.length > 0) {
effect = this.noise_effects.splice(0, 1)[0];
effect.set(params);
} else
effect = new NoiseEffect(params, settings);
this.used.push(effect);
this.connect_to_destroy(effect);
return effect;
}
remove(effect) {
effect.get_actor()?.remove_effect(effect);
if (effect.old_actor)
effect.old_actor.disconnect(effect.old_actor_id);
delete effect.old_actor;
delete effect.old_actor_id;
let index = this.used.indexOf(effect);
if (index >= 0) {
this.used.splice(index, 1);
if (effect instanceof ColorEffect)
this.color_effects.push(effect);
else if (effect instanceof NoiseEffect)
this.noise_effects.push(effect);
}
}
destroy_all() {
this.used.forEach(effect => { this.remove(effect); });
[
this.used,
this.color_effects,
this.noise_effects
].forEach(array => {
array.splice(0, array.length);
});
}
};