Skip to content

Commit

Permalink
feat: parse color palette entries into rows/colums/palettes
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Feb 17, 2021
1 parent e1e664d commit 29a8822
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/Archwing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { items, loadMods } = require('./utils');
const { items, loadMods, mapColors } = require('./utils');

class WarframeArchwing {
constructor(archwing) {
Expand All @@ -11,7 +11,7 @@ class WarframeArchwing {
this.polarized = archwing.polarized;
this.upgrades = loadMods(archwing.upgrades);

this.colors = archwing.pricol;
this.colors = mapColors(archwing.pricol);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Companion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { items, loadMods } = require('./utils');
const { items, loadMods, mapColors } = require('./utils');

class WarframeCompanion {
constructor(companion) {
Expand Down Expand Up @@ -28,7 +28,7 @@ class WarframeCompanion {
delete cosmetic.consumeOnBuild;
});
}
this.colors = companion.pricol;
this.colors = mapColors(companion.pricol);
this.upgrades = loadMods(companion.upgrades);
this.type = companion.type;
if (companion.itemName) this.name = companion.itemName;
Expand Down
4 changes: 2 additions & 2 deletions src/Mech.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { items, loadMods } = require('./utils');
const { items, loadMods, mapColors } = require('./utils');

module.exports = class WarframeMech {
constructor(mech) {
Expand Down Expand Up @@ -30,7 +30,7 @@ module.exports = class WarframeMech {
});
}

this.colors = mech.pricol;
this.colors = mapColors(mech.pricol);
this.upgrades = loadMods(mech.upgrades);

// ?? no idea what this is
Expand Down
35 changes: 35 additions & 0 deletions src/Pixel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const Items = require('warframe-items');

const items = new Items(['Skins']).filter((i) => i.hexColours);

const position = (ind) => ({
row: (ind % 18) + 1,
col: Math.ceil(ind / 18),
});

module.exports = class Pixel {
constructor(hex) {
this.hex = hex;
this.matches = [];

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

get palettes() {
return Array.from(new Set(this.matches.map((match) => match.palette.name)));
}
};
10 changes: 5 additions & 5 deletions src/Warframe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { items, loadMods } = require('./utils');
const { items, loadMods, mapColors } = require('./utils');

class Warframe {
constructor(frame) {
Expand Down Expand Up @@ -35,10 +35,10 @@ class Warframe {
this.upgrades = loadMods(frame.upgrades);

this.colors = {
syandana: frame.eyecol,
primary: frame.pricol,
sigil: frame.sigcol,
attachments: frame.attcol,
syandana: mapColors(frame.eyecol),
primary: mapColors(frame.pricol),
sigil: mapColors(frame.sigcol),
attachments: mapColors(frame.attcol),
};
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const Items = require('warframe-items');

const items = new Items();

const Pixel = require('./Pixel');

function translateFocus(focus = '') {
if (focus.includes('Focus/Attack')) {
return 'Madurai';
Expand Down Expand Up @@ -81,9 +83,32 @@ function loadMods(upgrades = []) {
};
}

const exisColo = (color) => (color ? new Pixel(color) : null);

function mapColors(colors = undefined) {
if (colors) {
return {
primary: exisColo(colors.t0),
secondary: exisColo(colors.t1),
tertiary: exisColo(colors.t2),
accents: exisColo(colors.t3),
emissive: [
exisColo(colors.m0),
exisColo(colors.m1),
].filter((c) => c),
energy: [
exisColo(colors.en),
exisColo(colors.en1),
].filter((c) => c),
};
}
return colors;
}

module.exports = {
translateFocus,
loadMods,
translatePolarity,
items,
mapColors,
};
28 changes: 23 additions & 5 deletions test/unit/companion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,29 @@ describe('WarframeCompanion', () => {
xp: 548455507,
polarized: 7,
colors: {
t0: '92B1C6',
t1: '9C5D42',
t2: '9C5D42',
t3: '413E3B',
en: 'F6DC13',
accents: {
hex: '413E3B',
matches: [],
},
emissive: [],
energy: [
{
hex: 'F6DC13',
matches: [],
},
],
primary: {
hex: '92B1C6',
matches: [],
},
secondary: {
hex: '9C5D42',
matches: [],
},
tertiary: {
hex: '9C5D42',
matches: [],
},
},
upgrades: { arcanes: [], mods: [] },
type: 'beast',
Expand Down
19 changes: 1 addition & 18 deletions test/unit/mech.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,14 @@ describe('WarframeMech', () => {
uniqueName: '/Lotus/Upgrades/Skins/Necramech/NecraMechCSkin',
},
],
pricol: {
t0: '2E2E2D',
t1: '9FA1A2',
t2: '291D1C',
t3: '243445',
m0: 'EBFF67',
m1: '374B50',
en: 'FF3806',
},
uniqueName: '/Lotus/Powersuits/EntratiMech/NechroTech',
upgrades: [],
};

const mech = new WarframeMech(sampleMech);

assert.deepEqual(mech, {
colors: {
en: 'FF3806',
m0: 'EBFF67',
m1: '374B50',
t0: '2E2E2D',
t1: '9FA1A2',
t2: '291D1C',
t3: '243445',
},
colors: undefined,
cosmetics: [
{
category: 'Skins',
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const example = (number) => require(`../data/exampleData${number}.json`);
const ArsenalData = require('../../src/ArsenalParser');

// Testing the main class
describe('ArsenalData', () => {
describe('Mock ArsenalData', () => {
describe('#constructor', () => {
it('should handle real data', () => {
['1', '2', '3', '4', '5', '6'].forEach((ind) => {
assert.isOk(new ArsenalData(example(ind)));
assert.isOk(new ArsenalData(example(ind)), `${ind} failed`);
});
});
});
Expand Down
30 changes: 30 additions & 0 deletions test/unit/pixel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const { assert } = require('chai');

// Archwing.js testing
const Pixel = require('../../src/Pixel.js');

describe('Pixel', () => {
describe('#constructor', () => {
it('should parse and match hex codes', () => {
const sampleCodes = ['2E203D', '9078EA', 'D6A3EC', '49667C', 'E6B0FE', 'E6B0FE', '2E203D'];
sampleCodes.forEach((hex) => {
const pixel = new Pixel(hex);
assert.equal(pixel.hex, hex, 'Hex mismatch');
assert.isNotEmpty(pixel.matches, 'No matches resolved');
assert.isNotEmpty(pixel.palettes, 'Real pixels should give palettes');
});
});

it('should handle being passed an unknown hex', () => {
const fakeHex = '023nva';
const fakePixel = new Pixel(fakeHex);

assert.isOk(fakePixel);
assert.equal(fakePixel.hex, fakeHex, 'Hex mismatch');
assert.isEmpty(fakePixel.matches, 'Match list mismatch');
assert.isEmpty(fakePixel.palettes, 'Fake hex should not have palettes');
});
});
});
26 changes: 4 additions & 22 deletions test/unit/warframe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,16 @@ describe('Warframe', () => {
upgrades: { arcanes: [], mods: [] },
colors: {
syandana: {
t0: 'FF588A',
t1: 'FE1C50',
t2: 'FF0D43',
t3: 'FF5C9F',
en: 'FF70A9',
primary: { hex: 'FF588A', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 2, col: 2 } }] }, secondary: { hex: 'FE1C50', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 8, col: 2 } }] }, tertiary: { hex: 'FF0D43', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 3, col: 2 } }] }, accents: { hex: 'FF5C9F', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 7, col: 2 } }] }, emissive: [], energy: [{ hex: 'FF70A9', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 12, col: 2 } }] }],
},
primary: {
t0: 'FF588A',
t1: 'FE1C50',
t2: 'FF0D43',
t3: 'FF5C9F',
m0: 'FF70A9',
m1: 'FF70A9',
en: 'FF70A9',
primary: { hex: 'FF588A', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 2, col: 2 } }] }, secondary: { hex: 'FE1C50', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 8, col: 2 } }] }, tertiary: { hex: 'FF0D43', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 3, col: 2 } }] }, accents: { hex: 'FF5C9F', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 7, col: 2 } }] }, emissive: [{ hex: 'FF70A9', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 12, col: 2 } }] }, { hex: 'FF70A9', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 12, col: 2 } }] }], energy: [{ hex: 'FF70A9', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 12, col: 2 } }] }],
},
sigil: {
t0: '3F9FB7',
t1: '808080',
t2: 'BABABA',
t3: '808080',
en: 'FFBA80',
primary: { hex: '3F9FB7', matches: [{ palette: { name: 'Classic', description: 'Unlocks additional color options for Warframe customization.' }, position: { row: 16, col: 2 } }] }, secondary: { hex: '808080', matches: [{ palette: { name: 'Tenno', description: 'Unlocks additional color options reflecting the default colors used on each standard Warframe.' }, position: { row: 10, col: 3 } }] }, tertiary: { hex: 'BABABA', matches: [{ palette: { name: 'Tenno', description: 'Unlocks additional color options reflecting the default colors used on each standard Warframe.' }, position: { row: 12, col: 1 } }, { palette: { name: 'Tenno', description: 'Unlocks additional color options reflecting the default colors used on each standard Warframe.' }, position: { row: 5, col: 4 } }] }, accents: { hex: '808080', matches: [{ palette: { name: 'Tenno', description: 'Unlocks additional color options reflecting the default colors used on each standard Warframe.' }, position: { row: 10, col: 3 } }] }, emissive: [], energy: [{ hex: 'FFBA80', matches: [] }],
},
attachments: {
t0: 'FF588A',
t1: 'FE1C50',
t2: 'FF0D43',
t3: 'FF5C9F',
en: 'FF70A9',
primary: { hex: 'FF588A', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 2, col: 2 } }] }, secondary: { hex: 'FE1C50', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 8, col: 2 } }] }, tertiary: { hex: 'FF0D43', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 3, col: 2 } }] }, accents: { hex: 'FF5C9F', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 7, col: 2 } }] }, emissive: [], energy: [{ hex: 'FF70A9', matches: [{ palette: { name: 'Valentine', description: 'Unlocks a collection of lovely colors.' }, position: { row: 12, col: 2 } }] }],
},
},
}), 'Invalid parsing of warframe data',
Expand Down

0 comments on commit 29a8822

Please sign in to comment.