44import * as React from "react" ;
55import "../../styles/Clue.css" ;
66import { DEFAULT_CLUE_STATE } from "./ClueSimulator" ;
7+ import CONSTANTS from "../../constants" ;
78export interface IRefObject {
89 [ key : string ] : React . RefObject < SVGRectElement > ;
910}
1011interface IProps {
1112 displayImage : string ;
12- neopixel : number [ ]
13+ neopixel : number [ ] ;
1314}
14- const LED_TINT_FACTOR = 0.5
1515export class ClueSvg extends React . Component < IProps , { } > {
1616 private svgRef : React . RefObject < SVGSVGElement > = React . createRef ( ) ;
17- private neopixel : React . RefObject < SVGCircleElement > = React . createRef ( )
18- private pixelStopGradient : React . RefObject < SVGStopElement > = React . createRef ( )
17+ private neopixel : React . RefObject < SVGCircleElement > = React . createRef ( ) ;
18+ private pixelStopGradient : React . RefObject <
19+ SVGStopElement
20+ > = React . createRef ( ) ;
1921
2022 private buttonRefs : IRefObject = {
2123 BTN_A : React . createRef ( ) ,
@@ -36,12 +38,11 @@ export class ClueSvg extends React.Component<IProps, {}> {
3638 }
3739 componentDidMount ( ) {
3840 this . updateDisplay ( ) ;
39- this . updateNeopixel ( )
40-
41+ this . updateNeopixel ( ) ;
4142 }
4243 componentDidUpdate ( ) {
4344 this . updateDisplay ( ) ;
44- this . updateNeopixel ( )
45+ this . updateNeopixel ( ) ;
4546 }
4647
4748 render ( ) {
@@ -56,11 +57,24 @@ export class ClueSvg extends React.Component<IProps, {}> {
5657 width = "100%"
5758 height = "100%"
5859 >
59- < defs >
60- < radialGradient id = "grad1" cx = "50%" cy = "50%" r = "70%" fx = "50%" fy = "50%" >
61- < stop offset = "0%" stopColor = "rgb(0,0,0)" stopOpacity = "1" ref = { this . pixelStopGradient } />
60+ < defs >
61+ < radialGradient
62+ id = "grad1"
63+ cx = "50%"
64+ cy = "50%"
65+ r = "70%"
66+ fx = "50%"
67+ fy = "50%"
68+ >
69+ < stop
70+ offset = "0%"
71+ stopColor = "rgb(0,0,0)"
72+ stopOpacity = "1"
73+ ref = { this . pixelStopGradient }
74+ />
6275 < stop offset = "100%" stopOpacity = "0" />
63- </ radialGradient > </ defs >
76+ </ radialGradient >
77+ </ defs >
6478 < g id = "Green" >
6579 < rect
6680 className = "cls-1"
@@ -949,13 +963,14 @@ export class ClueSvg extends React.Component<IProps, {}> {
949963 </ g >
950964 < text x = { 318 } y = { 85 } className = "sim-text-outside" >
951965 Neopixel
952- </ text >
966+ </ text >
953967 < circle cx = { 345 } cy = { 115 } r = "30" fill = "url(#grad1)" />
954968 < circle cx = { 345 } cy = { 115 } r = "12" ref = { this . neopixel } />
955969 </ svg >
956970 </ div >
957971 ) ;
958972 }
973+
959974 private updateDisplay ( ) {
960975 if ( this . displayRef . current && this . props . displayImage ) {
961976 this . displayRef . current . setAttribute (
@@ -964,25 +979,31 @@ export class ClueSvg extends React.Component<IProps, {}> {
964979 ) ;
965980 }
966981 }
982+
967983 private updateNeopixel ( ) {
968- const { neopixel } = this . props
969- const rgbColor = `rgb(${ neopixel [ 0 ] + ( 255 - neopixel [ 0 ] ) * LED_TINT_FACTOR } ,
970- ${ neopixel [ 1 ] + ( 255 - neopixel [ 1 ] ) * LED_TINT_FACTOR } ,${ neopixel [ 2 ] + ( 255 - neopixel [ 2 ] ) * LED_TINT_FACTOR } )`
984+ const { neopixel } = this . props ;
985+ const rgbColor = `rgb(${ neopixel [ 0 ] +
986+ ( 255 - neopixel [ 0 ] ) * CONSTANTS . LED_TINT_FACTOR } ,
987+ ${ neopixel [ 1 ] +
988+ ( 255 - neopixel [ 1 ] ) * CONSTANTS . LED_TINT_FACTOR } ,${ neopixel [ 2 ] +
989+ ( 255 - neopixel [ 2 ] ) * CONSTANTS . LED_TINT_FACTOR } )`;
971990
972991 if ( this . neopixel . current ) {
973- this . neopixel . current . setAttribute ( ' fill' , rgbColor )
992+ this . neopixel . current . setAttribute ( " fill" , rgbColor ) ;
974993 }
975994 if ( this . pixelStopGradient . current ) {
976995 if ( neopixel === DEFAULT_CLUE_STATE . neopixel ) {
977- console . log ( "remove opacity" )
978-
979- this . pixelStopGradient . current . setAttribute ( 'stop-opacity' , '0' )
996+ this . pixelStopGradient . current . setAttribute (
997+ "stop-opacity" ,
998+ "0"
999+ ) ;
9801000 } else {
981- this . pixelStopGradient . current . setAttribute ( 'stop-opacity' , '1' )
982-
1001+ this . pixelStopGradient . current . setAttribute (
1002+ "stop-opacity" ,
1003+ "1"
1004+ ) ;
9831005 }
984- this . pixelStopGradient . current . setAttribute ( ' stop-color' , rgbColor )
1006+ this . pixelStopGradient . current . setAttribute ( " stop-color" , rgbColor ) ;
9851007 }
986-
9871008 }
9881009}
0 commit comments