Skip to content

Commit 02d2838

Browse files
authored
Merge pull request #482 from Jlu18/colorshiftbug
Fixed colorshift bug and added test
2 parents ef25cd1 + 1e1e182 commit 02d2838

2 files changed

Lines changed: 184 additions & 137 deletions

File tree

src/myr/Myr.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,23 +1775,21 @@ class Myr {
17751775
//if the element is light
17761776
if(String(el.id).includes("lgt")){
17771777
let split = el.light.state.split(/\s|;/).filter(Boolean);
1778-
let colorIndex = split.indexOf("color:");
1779-
let baseCol = split[colorIndex+1];
1778+
let colorIndex = split.indexOf("color:")+1;
1779+
let baseCol = split[colorIndex];
17801780
if(this.colourNameToHex(baseCol)!==false){
17811781
baseCol = this.colourNameToHex(baseCol);
17821782
}
17831783
if(this.colourNameToHex(color) !== false){
17841784
color = this.colourNameToHex(color);
17851785
}
1786-
let anim = `
1787-
property: light.color;
1786+
let anim = `property: light.color;
17881787
from: ${baseCol};
17891788
to: ${color};
17901789
dur: ${this.cursor.duration};
17911790
dir: alternate;
17921791
loop: ${Boolean(this.cursor.loop)};
1793-
type: color;
1794-
`;
1792+
type: color;`;
17951793
el.animation__color = anim;
17961794
return outerElId;
17971795
}
@@ -1801,31 +1799,29 @@ class Myr {
18011799
let innerEl = el.els[i];
18021800
//innerEl.material.split(/\s|;/) returns an array of strings separated by " " and ";",
18031801
//color is always its first attribute (after "color: ")
1804-
let anim = `
1805-
property: components.material.material.color;
1806-
from: ${(innerEl.material.split(/\s|;/))[1]};
1807-
to: ${color};
1808-
dur: ${this.cursor.duration};
1809-
dir: alternate;
1810-
loop: ${Boolean(this.cursor.loop)};
1811-
isRawProperty: true;
1812-
type: color;
1813-
`;
1802+
let anim = `property: components.material.material.color;
1803+
from: ${(innerEl.material.split(/\s|;/))[1]};
1804+
to: ${color};
1805+
dur: ${this.cursor.duration};
1806+
dir: alternate;
1807+
loop: ${Boolean(this.cursor.loop)};
1808+
isRawProperty: true;
1809+
type: color;`;
18141810
innerEl.animation__color = anim;
18151811

18161812
}
18171813
return outerElId;
18181814
}
1819-
let anim = `
1820-
property: components.material.material.color;
1821-
from: ${(el.material.split(/\s|;/))[2]};
1822-
to: ${color};
1823-
dur: ${this.cursor.duration};
1824-
dir: alternate;
1825-
loop: ${Boolean(this.cursor.loop)};
1826-
isRawProperty: true;
1827-
type: color;
1828-
`;
1815+
1816+
const mat = el.material.split(/\s|;/);
1817+
let anim = `property: components.material.material.color;
1818+
from: ${mat[mat.indexOf("color:")+1]};
1819+
to: ${color};
1820+
dur: ${this.cursor.duration};
1821+
dir: alternate;
1822+
loop: ${Boolean(this.cursor.loop)};
1823+
isRawProperty: true;
1824+
type: color;`;
18291825
el.animation__color = anim;
18301826
return outerElId;
18311827
}

0 commit comments

Comments
 (0)