Skip to content

Commit

Permalink
feat: add opacity option to particle effects
Browse files Browse the repository at this point in the history
Closes #305
  • Loading branch information
ghost91- committed Mar 22, 2023
1 parent a96abf4 commit afa74ce
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 18 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ options are:
| Speed | A factor that adjusts the speed of the effect relative to its base speed. |
| Lifetime | A factor that adjusts the lifetime of the individual particles. |
| Density | The density of the effect. For most effects, it represents the number of particles per grid unit. |
| Opacity | A factor between 0 and 1 that adjusts the opacity of the particles. |
| Tint | Tint the effect with this color. |
| Animations | A selection of animations from the list of animations for the effect to use. If it is empty, the default animation is used. |

Expand Down Expand Up @@ -371,24 +372,24 @@ You can get a complete list by typing `CONFIG.fxmaster.filters` in your web cons

#### Available Particle Effects With Supported Options

| Type | `scale` | `direction` | `speed` | `lifetime` | `density` | `tint` | `animations` |
| ------------ | :-----: | :---------: | :-----: | :--------: | :-------: | :----: | :--------------------------: |
| `snowstorm` ||||||| |
| `bubbles` || ||||| |
| `clouds` ||||| || |
| `embers` || ||||| |
| `rainsimple` ||||||| |
| `stars` || ||||| |
| `crows` || ||||| |
| `bats` || ||||| |
| `spiders` || ||||| |
| `fog` || ||||| |
| `raintop` ||||||| |
| `birds` || ||||| ✓ (`glide`, `flap`, `mixed`) |
| `leaves` || ||||| |
| `rain` ||||||| |
| `snow` ||||||| |
| `eagles` || ||||| ✓ (`glide`, `flap`) |
| Type | `scale` | `direction` | `speed` | `lifetime` | `density` | `alpha` | `tint` | `animations` |
| ------------ | :-----: | :---------: | :-----: | :--------: | :-------: | :-----: | :----: | :--------------------------: |
| `snowstorm` |||||| | | |
| `bubbles` || |||| | | |
| `clouds` ||||| | | | |
| `embers` || |||| | | |
| `rainsimple` |||||| | | |
| `stars` || |||| | | |
| `crows` || |||| | | |
| `bats` || |||| | | |
| `spiders` || |||| | | |
| `fog` || |||| | | |
| `raintop` |||||| | | |
| `birds` || |||| | | ✓ (`glide`, `flap`, `mixed`) |
| `leaves` || |||| | | |
| `rain` |||||| | | |
| `snow` |||||| | | |
| `eagles` || |||| | | ✓ (`glide`, `flap`) |

#### Particle Effect Options

Expand All @@ -399,6 +400,7 @@ You can get a complete list by typing `CONFIG.fxmaster.filters` in your web cons
| `speed` | `number` | A factor that adjusts the speed of the effect relative to its base speed. |
| `lieftime` | `number` | A factor that adjusts the lifetime of the individual particles. |
| `density` | `number` | The density of the effect. For most effects, it represents the number of particles per grid unit. |
| `alpha` | `number` | A factor between 0 and 1 that adjusts the opacity of the particles (this is called “Opacity” in the Particle Effects Management). |
| `tint` | `{value: string, apply: boolean}` | Tint the effect with this color. |
| `animations` | `string[]` | An array of animations from list of animations for the effect to use. If it is empty or not defined, the default animation is used. |

Expand Down
1 change: 1 addition & 0 deletions lang/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"FXMASTER.Noise": "Soroll",
"FXMASTER.LineWidth": "Amplada de línia",
"FXMASTER.Density": "Densitat",
"FXMASTER.Opacity": "Opacitat",
"FXMASTER.Tint": "Tint",
"FXMASTER.Scale": "Escala",
"FXMASTER.ScaleHint": "Escala del video",
Expand Down
1 change: 1 addition & 0 deletions lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "Rauschen",
"FXMASTER.LineWidth": "Liniendicke",
"FXMASTER.Density": "Dichte",
"FXMASTER.Opacity": "Deckkraft",
"FXMASTER.Tint": "Farbton",
"FXMASTER.Scale": "Skala",
"FXMASTER.ScaleHint": "Videoskalierung",
Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "Noise",
"FXMASTER.LineWidth": "Line Width",
"FXMASTER.Density": "Density",
"FXMASTER.Opacity": "Opacity",
"FXMASTER.Tint": "Tint",
"FXMASTER.Scale": "Scale",
"FXMASTER.ScaleHint": "Video scaling",
Expand Down
1 change: 1 addition & 0 deletions lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "Ruido",
"FXMASTER.LineWidth": "Grosor de línea",
"FXMASTER.Density": "Densidad",
"FXMASTER.Opacity": "Opacidad",
"FXMASTER.Tint": "Tono",
"FXMASTER.Scale": "Escalado",
"FXMASTER.ScaleHint": "Escalado de vídeo",
Expand Down
1 change: 1 addition & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "Bruit",
"FXMASTER.LineWidth": "Largeur de la ligne",
"FXMASTER.Density": "Densité",
"FXMASTER.Opacity": "Opacité",
"FXMASTER.Tint": "Teinte",
"FXMASTER.Scale": "Échelle",
"FXMASTER.ScaleHint": "Échelle de la vidéo",
Expand Down
1 change: 1 addition & 0 deletions lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"FXMASTER.Contrast": "コントラスト",
"FXMASTER.Noise": "ノイズ",
"FXMASTER.Density": "濃度",
"FXMASTER.Opacity": "不透明",
"FXMASTER.Tint": "色味",
"FXMASTER.Scale": "縮尺",
"FXMASTER.ScaleHint": "映像の縮尺を設定します。",
Expand Down
1 change: 1 addition & 0 deletions lang/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "노이즈",
"FXMASTER.LineWidth": "선 두께",
"FXMASTER.Density": "밀도",
"FXMASTER.Opacity": "불투명도",
"FXMASTER.Tint": "색상화",
"FXMASTER.Scale": "크기",
"FXMASTER.ScaleHint": "영상 크기 조절",
Expand Down
1 change: 1 addition & 0 deletions lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"FXMASTER.Noise": "Ruído",
"FXMASTER.LineWidth": "Largura da Linha",
"FXMASTER.Density": "Densidade",
"FXMASTER.Opacity": "Opacidade",
"FXMASTER.Tint": "Matiz",
"FXMASTER.Scale": "Escala",
"FXMASTER.ScaleHint": "Dimensionamento de vídeo",
Expand Down
25 changes: 25 additions & 0 deletions src/particle-effects/effects/effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ export class FXMasterParticleEffect extends ParticleEffect {
step: 0.1,
decimals: 1,
},
alpha: {
label: "FXMASTER.Opacity",
type: "range",
min: 0,
value: 1,
max: 1,
step: 0.1,
decimals: 1,
},
tint: {
label: "FXMASTER.Tint",
type: "color",
Expand Down Expand Up @@ -130,6 +139,7 @@ export class FXMasterParticleEffect extends ParticleEffect {
this._applyDirectionToConfig(options, config);
this._applyLifetimeToConfig(options, config);
this._applyTintToConfig(options, config);
this._applyAlphaToConfig(options, config);
}

/** @protected */
Expand Down Expand Up @@ -219,6 +229,21 @@ export class FXMasterParticleEffect extends ParticleEffect {
}
}

/** @protected */
_applyAlphaToConfig(options, config) {
const factor = options.alpha?.value ?? 1;

config.behaviors
.filter((behavior) => behavior.type === "alpha")
.forEach(({ config }) => this._applyFactorToValueList(config.alpha, factor));

config.behaviors
.filter((behavior) => behavior.type === "alphaStatic")
.forEach(({ config }) => {
config.alpha *= factor;
});
}

/** @override */
play({ prewarm = false } = {}) {
if (prewarm) {
Expand Down

0 comments on commit afa74ce

Please sign in to comment.