Skip to content

Commit 602ad99

Browse files
committed
feat: solve the problem of circular dependency.
1 parent 5afb5c6 commit 602ad99

File tree

4 files changed

+68
-67
lines changed

4 files changed

+68
-67
lines changed

src/core/Particle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import Rgb from "../utils/Rgb";
55
import Puid from "../utils/Puid";
66
import Util from "../utils/Util";
7+
import PropUtil from "../utils/PropUtil";
78
import ease from "../math/ease";
89
import Vector2D from "../math/Vector2D";
910
import MathUtil from "../math/MathUtil";
@@ -62,7 +63,7 @@ export default class Particle {
6263

6364
this.rgb = new Rgb();
6465
this.reset();
65-
conf && Util.setProp(this, conf);
66+
conf && PropUtil.setProp(this, conf);
6667
}
6768

6869
getDirection() {

src/initialize/InitializeUtil.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Util from "../utils/Util";
1+
import PropUtil from "../utils/PropUtil";
22
import Initialize from "./Initialize";
33
import MathUtil from "../math/MathUtil";
44

@@ -20,8 +20,8 @@ export default {
2020

2121
// init
2222
init(emitter, particle, initialize) {
23-
Util.setProp(particle, initialize);
24-
Util.setVectorVal(particle, initialize);
23+
PropUtil.setProp(particle, initialize);
24+
PropUtil.setVectorVal(particle, initialize);
2525
},
2626

2727
bindEmitter(emitter, particle) {

src/utils/PropUtil.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export default {
2+
hasProp(target, key) {
3+
if (!target) return false;
4+
return target[key] !== undefined;
5+
// return obj.hasOwnProperty(key);
6+
},
7+
8+
/**
9+
* set the prototype in a given prototypeObject
10+
*
11+
* @memberof Proton#Proton.Util
12+
* @method setProp
13+
*
14+
* @todo add description for param `target`
15+
* @todo translate desription from chinese to english
16+
*
17+
* @param {Object} target
18+
* @param {Object} prototypeObject An object of single prototypes
19+
*
20+
* @return {Object} target
21+
*/
22+
setProp(target, props) {
23+
for (let prop in props) {
24+
if (target.hasOwnProperty(prop)) {
25+
target[prop] = Span.getSpanValue(props[prop]);
26+
}
27+
}
28+
29+
return target;
30+
},
31+
32+
/**
33+
* @memberof Proton#Proton.Util
34+
* @method setVectorVal
35+
*
36+
* @todo add description for param `target`
37+
* @todo add description for param `conf`
38+
* @todo add description for function
39+
*
40+
* @param {Object} target
41+
* @param {Object} conf
42+
*/
43+
setVectorVal(particle, conf = null) {
44+
if (!conf) return;
45+
46+
if (this.hasProp(conf, "x")) particle.p.x = conf["x"];
47+
if (this.hasProp(conf, "y")) particle.p.y = conf["y"];
48+
49+
if (this.hasProp(conf, "vx")) particle.v.x = conf["vx"];
50+
if (this.hasProp(conf, "vy")) particle.v.y = conf["vy"];
51+
52+
if (this.hasProp(conf, "ax")) particle.a.x = conf["ax"];
53+
if (this.hasProp(conf, "ay")) particle.a.y = conf["ay"];
54+
55+
if (this.hasProp(conf, "p")) particle.p.copy(conf["p"]);
56+
if (this.hasProp(conf, "v")) particle.v.copy(conf["v"]);
57+
if (this.hasProp(conf, "a")) particle.a.copy(conf["a"]);
58+
59+
if (this.hasProp(conf, "position")) particle.p.copy(conf["position"]);
60+
if (this.hasProp(conf, "velocity")) particle.v.copy(conf["velocity"]);
61+
if (this.hasProp(conf, "accelerate")) particle.a.copy(conf["accelerate"]);
62+
}
63+
};

src/utils/Util.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Span from "../math/Span";
21
import ImgUtil from "./ImgUtil";
32

43
export default {
@@ -86,68 +85,6 @@ export default {
8685
}
8786
},
8887

89-
/**
90-
* @memberof Proton#Proton.Util
91-
* @method setVectorVal
92-
*
93-
* @todo add description for param `target`
94-
* @todo add description for param `conf`
95-
* @todo add description for function
96-
*
97-
* @param {Object} target
98-
* @param {Object} conf
99-
*/
100-
setVectorVal(particle, conf = null) {
101-
if (!conf) return;
102-
103-
if (this.hasProp(conf, "x")) particle.p.x = conf["x"];
104-
if (this.hasProp(conf, "y")) particle.p.y = conf["y"];
105-
106-
if (this.hasProp(conf, "vx")) particle.v.x = conf["vx"];
107-
if (this.hasProp(conf, "vy")) particle.v.y = conf["vy"];
108-
109-
if (this.hasProp(conf, "ax")) particle.a.x = conf["ax"];
110-
if (this.hasProp(conf, "ay")) particle.a.y = conf["ay"];
111-
112-
if (this.hasProp(conf, "p")) particle.p.copy(conf["p"]);
113-
if (this.hasProp(conf, "v")) particle.v.copy(conf["v"]);
114-
if (this.hasProp(conf, "a")) particle.a.copy(conf["a"]);
115-
116-
if (this.hasProp(conf, "position")) particle.p.copy(conf["position"]);
117-
if (this.hasProp(conf, "velocity")) particle.v.copy(conf["velocity"]);
118-
if (this.hasProp(conf, "accelerate")) particle.a.copy(conf["accelerate"]);
119-
},
120-
121-
hasProp(target, key) {
122-
if (!target) return false;
123-
return target[key] !== undefined;
124-
// return obj.hasOwnProperty(key);
125-
},
126-
127-
/**
128-
* set the prototype in a given prototypeObject
129-
*
130-
* @memberof Proton#Proton.Util
131-
* @method setProp
132-
*
133-
* @todo add description for param `target`
134-
* @todo translate desription from chinese to english
135-
*
136-
* @param {Object} target
137-
* @param {Object} prototypeObject An object of single prototypes
138-
*
139-
* @return {Object} target
140-
*/
141-
setProp(target, props) {
142-
for (let prop in props) {
143-
if (target.hasOwnProperty(prop)) {
144-
target[prop] = Span.getSpanValue(props[prop]);
145-
}
146-
}
147-
148-
return target;
149-
},
150-
15188
/**
15289
* This will get the image data. It could be necessary to create a Proton.Zone.
15390
*

0 commit comments

Comments
 (0)