Skip to content

Commit 2f01a01

Browse files
committed
Tweak how opacity is applied so it's only applied to the playerfill or playerstroke parts; this means transparent pyramids still show the pips
1 parent 763c740 commit 2f01a01

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/renderers/_base.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ export abstract class RendererBase {
676676
// const clone = got.clone();
677677
// const clone = got;
678678

679+
// load opacity and only apply it to player fills
680+
let opacity = 1;
681+
if (g.opacity !== undefined) {
682+
opacity = g.opacity;
683+
}
684+
679685
// Colourize (`player` first, then `colour` if defined)
680686
// adapted for two colours
681687
const colourVals = [g.colour, g.colour2];
@@ -702,15 +708,15 @@ export abstract class RendererBase {
702708
throw new Error("The list of colours provided is not long enough to support the number of players in this game.");
703709
}
704710
const fill = this.options.colours[player - 1];
705-
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill(fill); });
706-
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke(fill); isStroke = true; });
711+
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill({color: fill, opacity}); });
712+
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke({color: fill, opacity}); isStroke = true; });
707713
}
708714
} else if (colourVal !== undefined) {
709715
const normColour = this.resolveColour(colourVal as string|number|Gradient, "#000");
710716
// @ts-expect-error (poor SVGjs typing)
711-
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill(normColour); });
717+
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill({color: normColour, opacity}); });
712718
// @ts-expect-error (poor SVGjs typing)
713-
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke(normColour); isStroke = true; });
719+
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke({color: normColour, opacity}); isStroke = true; });
714720
}
715721
// if colour is fully undefined, try to deduce the highest contrast colour
716722
else {
@@ -736,22 +742,14 @@ export abstract class RendererBase {
736742
};
737743
const normColour = this.resolveColour(func, "#000");
738744
// @ts-expect-error (poor SVGjs typing)
739-
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill(normColour); });
745+
got.find(`[data-playerfill${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.fill({color: normColour, opacity}); });
740746
// @ts-expect-error (poor SVGjs typing)
741-
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke(normColour); isStroke = true; });
747+
got.find(`[data-playerstroke${i > 0 ? i+1 : ""}=true]`).each(function(this: SVGElement) { this.stroke({color: normColour, opacity}); isStroke = true; });
742748
}
743749
}
744750
haveStrokes.push(isStroke);
745751
}
746752

747-
// Apply requested opacity
748-
if (g.opacity !== undefined) {
749-
got.fill({opacity: g.opacity});
750-
if (haveStrokes.reduce((prev, curr) => prev || curr, false)) {
751-
got.stroke({opacity: g.opacity});
752-
}
753-
}
754-
755753
// nested.add(clone);
756754
const use = nested.use(got).height(cellsize).width(cellsize).x(-cellsize / 2).y(-cellsize / 2);
757755
// const use = nested.use(got).height(cellsize).width(cellsize).x(0).y(0);

0 commit comments

Comments
 (0)