Skip to content

Commit b04d82d

Browse files
committed
Added getters and setters for properties
1 parent 687ec04 commit b04d82d

4 files changed

Lines changed: 224 additions & 23 deletions

File tree

src/gameobjects/shape/arc/Arc.js

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var Class = require('../../../utils/Class');
99
var DegToRad = require('../../../math/DegToRad');
1010
var Earcut = require('../../../geom/polygon/Earcut');
1111
var GeomCircle = require('../../../geom/circle/Circle');
12-
var Shape = require('../Shape');
1312
var MATH_CONST = require('../../../math/const');
13+
var Shape = require('../Shape');
1414

1515
/**
1616
* @classdesc
@@ -46,10 +46,10 @@ var Arc = new Class({
4646

4747
Shape.call(this, scene, 'Arc', new GeomCircle(0, 0, radius));
4848

49-
this.startAngle = DegToRad(startAngle);
50-
this.endAngle = DegToRad(endAngle);
51-
this.anticlockwise = anticlockwise;
52-
this.iterations = 0.01;
49+
this._startAngle = startAngle;
50+
this._endAngle = endAngle;
51+
this._anticlockwise = anticlockwise;
52+
this._iterations = 0.01;
5353

5454
this.setPosition(x, y);
5555
this.setSize(this.data.radius, this.data.radius);
@@ -63,48 +63,135 @@ var Arc = new Class({
6363
this.updateData();
6464
},
6565

66-
setSmoothing: function (value)
66+
iterations: {
67+
68+
get: function ()
69+
{
70+
return this._iterations;
71+
},
72+
73+
set: function (value)
74+
{
75+
this._iterations = value;
76+
77+
this.updateData();
78+
}
79+
80+
},
81+
82+
radius: {
83+
84+
get: function ()
85+
{
86+
return this.data.radius;
87+
},
88+
89+
set: function (value)
90+
{
91+
this.data.radius = value;
92+
93+
this.updateData();
94+
}
95+
96+
},
97+
98+
startAngle: {
99+
100+
get: function ()
101+
{
102+
return this._startAngle;
103+
},
104+
105+
set: function (value)
106+
{
107+
this._startAngle = value;
108+
109+
this.updateData();
110+
}
111+
112+
},
113+
114+
endAngle: {
115+
116+
get: function ()
117+
{
118+
return this._endAngle;
119+
},
120+
121+
set: function (value)
122+
{
123+
this._endAngle = value;
124+
125+
this.updateData();
126+
}
127+
128+
},
129+
130+
anticlockwise: {
131+
132+
get: function ()
133+
{
134+
return this._anticlockwise;
135+
},
136+
137+
set: function (value)
138+
{
139+
this._anticlockwise = value;
140+
141+
this.updateData();
142+
}
143+
144+
},
145+
146+
setRadius: function (value)
147+
{
148+
this.radius = value;
149+
150+
return this;
151+
},
152+
153+
setIterations: function (value)
67154
{
68155
if (value === undefined) { value = 0.01; }
69156

70157
this.iterations = value;
71158

72-
return this.updateData();
159+
return this;
73160
},
74161

75162
setStartAngle: function (angle, anticlockwise)
76163
{
77-
this.startAngle = DegToRad(angle);
164+
this._startAngle = angle;
78165

79166
if (anticlockwise !== undefined)
80167
{
81-
this.anticlockwise = anticlockwise;
168+
this._anticlockwise = anticlockwise;
82169
}
83170

84171
return this.updateData();
85172
},
86173

87174
setEndAngle: function (angle, anticlockwise)
88175
{
89-
this.endAngle = DegToRad(angle);
176+
this._endAngle = angle;
90177

91178
if (anticlockwise !== undefined)
92179
{
93-
this.anticlockwise = anticlockwise;
180+
this._anticlockwise = anticlockwise;
94181
}
95182

96183
return this.updateData();
97184
},
98185

99186
updateData: function ()
100187
{
101-
var step = this.iterations;
188+
var step = this._iterations;
102189
var iteration = step;
103190

104191
var radius = this.data.radius;
105-
var startAngle = this.startAngle;
106-
var endAngle = this.endAngle;
107-
var anticlockwise = this.anticlockwise;
192+
var startAngle = DegToRad(this._startAngle);
193+
var endAngle = DegToRad(this._endAngle);
194+
var anticlockwise = this._anticlockwise;
108195

109196
var x = radius / 2;
110197
var y = radius / 2;

src/gameobjects/shape/ellipse/Ellipse.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Ellipse = new Class({
4343
Shape.call(this, scene, 'Ellipse', new GeomEllipse(width / 2, height / 2, width, height));
4444

4545
// The number of points used to draw the ellipse. Higher values create smoother renders at the cost of more triangles being drawn.
46-
this.smoothness = 64;
46+
this._smoothness = 64;
4747

4848
this.setPosition(x, y);
4949
this.setSize(width, height);
@@ -57,10 +57,33 @@ var Ellipse = new Class({
5757
this.updateData();
5858
},
5959

60+
smoothness: {
61+
62+
get: function ()
63+
{
64+
return this.__smoothness;
65+
},
66+
67+
set: function (value)
68+
{
69+
this.__smoothness = value;
70+
71+
this.updateData();
72+
}
73+
74+
},
75+
76+
setSmoothness: function (value)
77+
{
78+
this._smoothness = value;
79+
80+
return this.updateData();
81+
},
82+
6083
updateData: function ()
6184
{
6285
var path = [];
63-
var points = this.data.getPoints(this.smoothness);
86+
var points = this.data.getPoints(this._smoothness);
6487

6588
for (var i = 0; i < points.length; i++)
6689
{

src/gameobjects/shape/star/Star.js

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ var Star = new Class({
4242

4343
Shape.call(this, scene, 'Star', null);
4444

45-
this.points = points;
46-
this.innerRadius = innerRadius;
47-
this.outerRadius = outerRadius;
45+
this._points = points;
46+
this._innerRadius = innerRadius;
47+
this._outerRadius = outerRadius;
4848

4949
this.setPosition(x, y);
5050
this.setSize(outerRadius * 2, outerRadius * 2);
@@ -58,13 +58,82 @@ var Star = new Class({
5858
this.updateData();
5959
},
6060

61+
setPoints: function (value)
62+
{
63+
this._points = value;
64+
65+
return this.updateData();
66+
},
67+
68+
setInnerRadius: function (value)
69+
{
70+
this._innerRadius = value;
71+
72+
return this.updateData();
73+
},
74+
75+
setOuterRadius: function (value)
76+
{
77+
this._outerRadius = value;
78+
79+
return this.updateData();
80+
},
81+
82+
points: {
83+
84+
get: function ()
85+
{
86+
return this._points;
87+
},
88+
89+
set: function (value)
90+
{
91+
this._points = value;
92+
93+
this.updateData();
94+
}
95+
96+
},
97+
98+
innerRadius: {
99+
100+
get: function ()
101+
{
102+
return this._innerRadius;
103+
},
104+
105+
set: function (value)
106+
{
107+
this._innerRadius = value;
108+
109+
this.updateData();
110+
}
111+
112+
},
113+
114+
outerRadius: {
115+
116+
get: function ()
117+
{
118+
return this._outerRadius;
119+
},
120+
121+
set: function (value)
122+
{
123+
this._outerRadius = value;
124+
125+
this.updateData();
126+
}
127+
128+
},
129+
61130
updateData: function ()
62131
{
63132
var path = [];
64133

65-
var points = this.points;
66-
var innerRadius = this.innerRadius;
67-
var outerRadius = this.outerRadius;
134+
var points = this._points;
135+
var innerRadius = this._innerRadius;
136+
var outerRadius = this._outerRadius;
68137

69138
var rot = Math.PI / 2 * 3;
70139
var step = Math.PI / points;

src/gameobjects/shape/triangle/Triangle.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ var Triangle = new Class({
6060
this.updateData();
6161
},
6262

63+
/**
64+
* [description]
65+
*
66+
* @method Phaser.Geom.Triangle#setTo
67+
* @since 3.13.0
68+
*
69+
* @param {number} [x1=0] - [description]
70+
* @param {number} [y1=0] - [description]
71+
* @param {number} [x2=0] - [description]
72+
* @param {number} [y2=0] - [description]
73+
* @param {number} [x3=0] - [description]
74+
* @param {number} [y3=0] - [description]
75+
*
76+
* @return {Phaser.Geom.Triangle} This Triangle object.
77+
*/
78+
setTo: function (x1, y1, x2, y2, x3, y3)
79+
{
80+
this.data.setTo(x1, y1, x2, y2, x3, y3);
81+
82+
return this.updateData();
83+
},
84+
6385
updateData: function ()
6486
{
6587
var path = [];

0 commit comments

Comments
 (0)