Skip to content

Commit

Permalink
fix: handle color value 256 (#104)
Browse files Browse the repository at this point in the history
When an entity has "ByLayer 62" we want to use the color defined in the entity instead of the layer, unless the color is 256. 256 is a special value to say that the entity has to use the color defined in the layer. 

Co-authored-by: Rafa <rafa@debian-BULLSEYE-live-builder-AMD64>
  • Loading branch information
rafaelgc and Rafa authored Aug 29, 2022
1 parent 90fd82a commit 80e9fa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/getRGBForEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import logger from './util/logger'
export default (layers, entity) => {
const layerTable = layers[entity.layer]
if (layerTable) {
const colorNumber = ('colorNumber' in entity) ? entity.colorNumber : layerTable.colorNumber
const colorDefinedInEntity = ('colorNumber' in entity && entity.colorNumber !== 256)
const colorNumber = colorDefinedInEntity ? entity.colorNumber : layerTable.colorNumber
const rgb = colors[colorNumber]
if (rgb) {
return rgb
Expand Down
18 changes: 18 additions & 0 deletions test/unit/colorbylayer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import expect from 'expect'

import getRGBForEntity from '../../src/getRGBForEntity'

describe('colors', () => {
it('Color defined in the entity but with value 256 means that we have to use the color defined in the layer.', () => {
const fakeEntity = {
layer: "0",
colorNumber: 256
};
const fakeLayers = {
"0": {
colorNumber: 1
}
}
expect(getRGBForEntity(fakeLayers, fakeEntity)).toEqual([255, 0, 0])
})
})

0 comments on commit 80e9fa1

Please sign in to comment.