1818 * }
1919 */
2020export default class Shape {
21- _text = '' ;
22- _width = 15 ;
23- _height = 5 ;
24- _x = 10 ;
25- _y = 10 ;
26- _background ;
27- _foreground ;
28- _animation ;
21+ _options = { } ;
2922
3023 /**
3124 * Constructor is responsible for initializing base properties.
@@ -54,13 +47,35 @@ export default class Shape {
5447 this . setAnimation ( animation ) ;
5548 }
5649
50+ /**
51+ * Get option value.
52+ *
53+ * @param {String } path Path can be set with dot-notation
54+ * @returns {* }
55+ */
56+ get ( path ) {
57+ return path . split ( '.' ) . reduce ( ( obj , key ) => obj [ key ] , this . _options ) ;
58+ }
59+
60+ /**
61+ * Set new option value.
62+ *
63+ * @param {String } path
64+ * @param {* } value
65+ * @returns {Shape }
66+ */
67+ set ( path , value ) {
68+ this . _options [ path ] = value ;
69+ return this ;
70+ }
71+
5772 /**
5873 * Get text content from this shape.
5974 *
6075 * @returns {String }
6176 */
6277 getText ( ) {
63- return this . _text ;
78+ return this . get ( 'text' ) ;
6479 }
6580
6681 /**
@@ -70,7 +85,7 @@ export default class Shape {
7085 * @returns {Shape }
7186 */
7287 setText ( text = '' ) {
73- this . _text = text ;
88+ this . set ( 'text' , text ) ;
7489 return this ;
7590 }
7691
@@ -80,7 +95,7 @@ export default class Shape {
8095 * @returns {Number }
8196 */
8297 getWidth ( ) {
83- return this . _width ;
98+ return this . get ( 'width' ) ;
8499 }
85100
86101 /**
@@ -90,7 +105,7 @@ export default class Shape {
90105 * @returns {Shape }
91106 */
92107 setWidth ( width = 15 ) {
93- this . _width = width ;
108+ this . set ( 'width' , width ) ;
94109 return this ;
95110 }
96111
@@ -100,7 +115,7 @@ export default class Shape {
100115 * @returns {Number }
101116 */
102117 getHeight ( ) {
103- return this . _height ;
118+ return this . get ( 'height' ) ;
104119 }
105120
106121 /**
@@ -110,7 +125,7 @@ export default class Shape {
110125 * @returns {Shape }
111126 */
112127 setHeight ( height = 5 ) {
113- this . _height = height ;
128+ this . set ( 'height' , height ) ;
114129 return this ;
115130 }
116131
@@ -120,7 +135,7 @@ export default class Shape {
120135 * @returns {{x: Number, y: Number} }
121136 */
122137 getPosition ( ) {
123- return { x : this . _x , y : this . _y } ;
138+ return { x : this . get ( 'x' ) , y : this . get ( 'y' ) } ;
124139 }
125140
126141 /**
@@ -130,9 +145,9 @@ export default class Shape {
130145 * @param {Number } [y=10] Absolute coordinate Y
131146 * @returns {Shape }
132147 */
133- setPosition ( x = this . _x , y = this . _y ) {
134- this . _x = x ;
135- this . _y = y ;
148+ setPosition ( x = 10 , y = 10 ) {
149+ this . set ( 'x' , x ) ;
150+ this . set ( 'y' , y ) ;
136151 return this ;
137152 }
138153
@@ -142,7 +157,7 @@ export default class Shape {
142157 * @returns {String }
143158 */
144159 getBackground ( ) {
145- return this . _background ;
160+ return this . get ( 'background' ) ;
146161 }
147162
148163 /**
@@ -152,7 +167,7 @@ export default class Shape {
152167 * @returns {Shape }
153168 */
154169 setBackground ( background ) {
155- this . _background = background ;
170+ this . set ( 'background' , background ) ;
156171 return this ;
157172 }
158173
@@ -162,7 +177,7 @@ export default class Shape {
162177 * @returns {String }
163178 */
164179 getForeground ( ) {
165- return this . _foreground ;
180+ return this . get ( 'foreground' ) ;
166181 }
167182
168183 /**
@@ -172,7 +187,7 @@ export default class Shape {
172187 * @returns {Shape }
173188 */
174189 setForeground ( foreground ) {
175- this . _foreground = foreground ;
190+ this . set ( 'foreground' , foreground ) ;
176191 return this ;
177192 }
178193
@@ -182,7 +197,7 @@ export default class Shape {
182197 * @returns {Object }
183198 */
184199 getAnimation ( ) {
185- return this . _animation ;
200+ return this . get ( 'animation' ) ;
186201 }
187202
188203 /**
@@ -193,7 +208,7 @@ export default class Shape {
193208 * @returns {Shape }
194209 */
195210 setAnimation ( animation ) {
196- this . _animation = animation ;
211+ this . set ( 'animation' , animation ) ;
197212 return this ;
198213 }
199214
@@ -203,7 +218,7 @@ export default class Shape {
203218 * @returns {Boolean }
204219 */
205220 isAnimated ( ) {
206- return ! ! this . _animation ;
221+ return ! ! this . get ( 'animation' ) ;
207222 }
208223
209224 /**
0 commit comments