Skip to content

Commit

Permalink
fix(perf): intelligently handle transparent pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Feb 17, 2021
1 parent 34d6089 commit 9d150e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
42 changes: 25 additions & 17 deletions src/Pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,33 @@ module.exports = class Pixel {
this.hex = hex;
this.matches = [];

const usedPalettes = [];

items.forEach((item) => {
item.hexColours.forEach(({ value }, index) => {
if (value.toLowerCase().includes(hex.toLowerCase())) {
if (!usedPalettes.includes(item.name)) {
this.matches.push({
palette: {
name: item.name,
description: item.description,
},
position: position(index),
});

usedPalettes.push(item.name);
this.isTransparent = hex === '0';

if (!this.isTransparent) {
delete this.isTransparent;
}

if (!this.isTransparent) {
const usedPalettes = [];

items.forEach((item) => {
item.hexColours.forEach(({ value }, index) => {
if (value.toLowerCase().includes(hex.toLowerCase())) {
if (!usedPalettes.includes(item.name)) {
this.matches.push({
palette: {
name: item.name,
description: item.description,
},
position: position(index),
});

usedPalettes.push(item.name);
}
}
}
});
});
});
}
}

get palettes() {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/companion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('WarframeCompanion', () => {
t1: '9C5D42',
t2: '9C5D42',
t3: '413E3B',
en: 'F6DC13',
en: '0',
},
attcol: {
t0: 'B0BDB8',
Expand Down Expand Up @@ -62,7 +62,8 @@ describe('WarframeCompanion', () => {
emissive: [],
energy: [
{
hex: 'F6DC13',
hex: '0',
isTransparent: true,
matches: [],
},
],
Expand Down

0 comments on commit 9d150e0

Please sign in to comment.