-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parse color palette entries into rows/colums/palettes
- Loading branch information
Showing
11 changed files
with
131 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters