Skip to content

Commit 21fe2d0

Browse files
committed
refactor: updated palettes to the new paint syntax
1 parent 77fb8d1 commit 21fe2d0

2 files changed

Lines changed: 42 additions & 33 deletions

File tree

engine/src/Core/Interfaces/IPalette.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ import type { SingleOrMultiple } from "../../Types/SingleOrMultiple.js";
33

44
export interface IPaletteColorsFill {
55
enable: boolean;
6+
opacity?: RangeValue;
67
value: SingleOrMultiple<string>;
78
}
89

910
export interface IPaletteColorsStroke {
11+
opacity?: RangeValue;
1012
value: SingleOrMultiple<string>;
1113
width: RangeValue;
1214
}
1315

1416
export interface IPaletteColors {
1517
fill?: IPaletteColorsFill;
16-
stroke?: SingleOrMultiple<IPaletteColorsStroke>;
18+
stroke?: IPaletteColorsStroke;
1719
}
1820

1921
export interface IPalette {
2022
background: string;
2123
blendMode: GlobalCompositeOperation;
22-
colors: IPaletteColors;
24+
colors: SingleOrMultiple<IPaletteColors>;
2325
name: string;
2426
}

engine/src/Options/Classes/Particles/ParticlesOptions.ts

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,49 @@ export class ParticlesOptions implements IParticlesOptions, IOptionLoader<IParti
134134
}
135135

136136
const paletteColors = paletteData.colors,
137-
paletteFill = paletteColors.fill,
138-
paletteStroke = paletteColors.stroke,
139-
defaultPaintStrokeIndex = 0,
140137
defaultPaintStrokeWidth = 0,
141-
palettePaint: IPaint = {
142-
fill: paletteFill
143-
? {
138+
defaultPaintVariantsLength = 1,
139+
firstPaintVariantIndex = 0,
140+
defaultPalettePaintVariant: IPaint = {},
141+
colorVariants = isArray(paletteColors) ? paletteColors : [paletteColors],
142+
palettePaintVariants = colorVariants.flatMap<IPaint>(variant => {
143+
const paletteFill = variant.fill,
144+
paletteStroke = variant.stroke,
145+
fillPart: IPaint["fill"] = paletteFill
146+
? {
147+
color: {
148+
value: paletteFill.value,
149+
},
150+
enable: paletteFill.enable,
151+
opacity: paletteFill.opacity,
152+
}
153+
: undefined;
154+
155+
if (!paletteStroke) {
156+
return [
157+
{
158+
fill: fillPart,
159+
},
160+
];
161+
}
162+
163+
return [
164+
{
165+
fill: fillPart,
166+
stroke: {
144167
color: {
145-
value: paletteFill.value,
168+
value: paletteStroke.value,
146169
},
147-
enable: paletteFill.enable,
148-
}
149-
: undefined,
150-
};
151-
152-
if (paletteStroke) {
153-
if (isArray(paletteStroke)) {
154-
const firstStroke = paletteStroke[defaultPaintStrokeIndex];
155-
156-
if (firstStroke) {
157-
palettePaint.stroke = {
158-
color: {
159-
value: firstStroke.value,
170+
opacity: paletteStroke.opacity,
171+
width: paletteStroke.width || defaultPaintStrokeWidth,
160172
},
161-
width: firstStroke.width || defaultPaintStrokeWidth,
162-
};
163-
}
164-
} else {
165-
palettePaint.stroke = {
166-
color: {
167-
value: paletteStroke.value,
168173
},
169-
width: paletteStroke.width,
170-
};
171-
}
172-
}
174+
];
175+
}),
176+
palettePaint: SingleOrMultiple<IPaint> =
177+
palettePaintVariants.length > defaultPaintVariantsLength
178+
? palettePaintVariants
179+
: (palettePaintVariants[firstPaintVariantIndex] ?? defaultPalettePaintVariant);
173180

174181
this.load({
175182
paint: palettePaint,

0 commit comments

Comments
 (0)