1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-12 16:53:07 +00:00
Pixelorama/src/Classes/LayerEffect.gd

42 lines
1.1 KiB
GDScript3
Raw Normal View History

Implement layer effects (#940) * Basic logic for layer effects * Add an FX button and the ability to add effects, no way to remove or change properties of effects yet * Basic and ugly UI for adding and removing effects, no property changing yet * Swap effects * Fix preload shader paths * Change parameters for layer effects * Change gradient parameter in layer effect shaders, and other fixes * Use CollapsibleContainers for the shader properties * Set the correct gradient interpolation mode and color space in the UI * Make effects of group layers apply to children * Change `apply_fx` to `apply_effects`, formatting, some extra doc comments * Apply effects to other canvases, when merging layers and when exporting * Display humanized names of the shader unifrms * Some UI improvements to the LayerEffectsSettings * Add an Enabled button in the layer effects window, and change checkboxes to checkbuttons * Change BaseLayer.apply_effects() to take a cel as a parameter instead * Make layer effect buttons be affected by the modulate icon color * Add option in the View menu whether layer effects are displayed in the canvas or not * Rename `apply_effects()` to `display_effects()` * Add translation strings * Add nearest filter to the gradient map * Don't change Main.tscn * Fix more translations * Change the default cursor shape of the generated UI elements of the layer effects * Add undo/redo and effect application (apply effect destructively) There are some errors due to the usage of anonymous lambda methods in undo/redo, but it seems to be working well regardless. * Make layer effect application work on all cels
2023-11-21 23:06:25 +00:00
class_name LayerEffect
extends RefCounted
var name := ""
var shader: Shader
var params := {}
var enabled := true
2023-12-01 01:12:55 +00:00
func _init(_name := "", _shader: Shader = null, _params := {}) -> void:
Implement layer effects (#940) * Basic logic for layer effects * Add an FX button and the ability to add effects, no way to remove or change properties of effects yet * Basic and ugly UI for adding and removing effects, no property changing yet * Swap effects * Fix preload shader paths * Change parameters for layer effects * Change gradient parameter in layer effect shaders, and other fixes * Use CollapsibleContainers for the shader properties * Set the correct gradient interpolation mode and color space in the UI * Make effects of group layers apply to children * Change `apply_fx` to `apply_effects`, formatting, some extra doc comments * Apply effects to other canvases, when merging layers and when exporting * Display humanized names of the shader unifrms * Some UI improvements to the LayerEffectsSettings * Add an Enabled button in the layer effects window, and change checkboxes to checkbuttons * Change BaseLayer.apply_effects() to take a cel as a parameter instead * Make layer effect buttons be affected by the modulate icon color * Add option in the View menu whether layer effects are displayed in the canvas or not * Rename `apply_effects()` to `display_effects()` * Add translation strings * Add nearest filter to the gradient map * Don't change Main.tscn * Fix more translations * Change the default cursor shape of the generated UI elements of the layer effects * Add undo/redo and effect application (apply effect destructively) There are some errors due to the usage of anonymous lambda methods in undo/redo, but it seems to be working well regardless. * Make layer effect application work on all cels
2023-11-21 23:06:25 +00:00
name = _name
shader = _shader
params = _params
func duplicate() -> LayerEffect:
return LayerEffect.new(name, shader, params.duplicate())
2023-12-01 01:12:55 +00:00
func serialize() -> Dictionary:
var p_str := {}
for param in params:
p_str[param] = var_to_str(params[param])
return {"name": name, "shader_path": shader.resource_path, "params": p_str, "enabled": enabled}
func deserialize(dict: Dictionary) -> void:
if dict.has("name"):
name = dict["name"]
if dict.has("shader_path"):
var path: String = dict["shader_path"]
2024-03-22 01:07:21 +00:00
var shader_to_load := load(path)
2023-12-01 01:12:55 +00:00
if is_instance_valid(shader_to_load) and shader_to_load is Shader:
shader = shader_to_load
if dict.has("params"):
for param in dict["params"]:
if typeof(dict["params"][param]) == TYPE_STRING:
dict["params"][param] = str_to_var(dict["params"][param])
params = dict["params"]
if dict.has("enabled"):
enabled = dict["enabled"]