Skip to content

Commit

Permalink
feat: solve the problem of circular dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
drawcall committed Sep 10, 2021
1 parent 5afb5c6 commit 602ad99
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/core/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Rgb from "../utils/Rgb";
import Puid from "../utils/Puid";
import Util from "../utils/Util";
import PropUtil from "../utils/PropUtil";
import ease from "../math/ease";
import Vector2D from "../math/Vector2D";
import MathUtil from "../math/MathUtil";
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class Particle {

this.rgb = new Rgb();
this.reset();
conf && Util.setProp(this, conf);
conf && PropUtil.setProp(this, conf);
}

getDirection() {
Expand Down
6 changes: 3 additions & 3 deletions src/initialize/InitializeUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Util from "../utils/Util";
import PropUtil from "../utils/PropUtil";
import Initialize from "./Initialize";
import MathUtil from "../math/MathUtil";

Expand All @@ -20,8 +20,8 @@ export default {

// init
init(emitter, particle, initialize) {
Util.setProp(particle, initialize);
Util.setVectorVal(particle, initialize);
PropUtil.setProp(particle, initialize);
PropUtil.setVectorVal(particle, initialize);
},

bindEmitter(emitter, particle) {
Expand Down
63 changes: 63 additions & 0 deletions src/utils/PropUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export default {
hasProp(target, key) {
if (!target) return false;
return target[key] !== undefined;
// return obj.hasOwnProperty(key);
},

/**
* set the prototype in a given prototypeObject
*
* @memberof Proton#Proton.Util
* @method setProp
*
* @todo add description for param `target`
* @todo translate desription from chinese to english
*
* @param {Object} target
* @param {Object} prototypeObject An object of single prototypes
*
* @return {Object} target
*/
setProp(target, props) {
for (let prop in props) {
if (target.hasOwnProperty(prop)) {
target[prop] = Span.getSpanValue(props[prop]);
}
}

return target;
},

/**
* @memberof Proton#Proton.Util
* @method setVectorVal
*
* @todo add description for param `target`
* @todo add description for param `conf`
* @todo add description for function
*
* @param {Object} target
* @param {Object} conf
*/
setVectorVal(particle, conf = null) {
if (!conf) return;

if (this.hasProp(conf, "x")) particle.p.x = conf["x"];
if (this.hasProp(conf, "y")) particle.p.y = conf["y"];

if (this.hasProp(conf, "vx")) particle.v.x = conf["vx"];
if (this.hasProp(conf, "vy")) particle.v.y = conf["vy"];

if (this.hasProp(conf, "ax")) particle.a.x = conf["ax"];
if (this.hasProp(conf, "ay")) particle.a.y = conf["ay"];

if (this.hasProp(conf, "p")) particle.p.copy(conf["p"]);
if (this.hasProp(conf, "v")) particle.v.copy(conf["v"]);
if (this.hasProp(conf, "a")) particle.a.copy(conf["a"]);

if (this.hasProp(conf, "position")) particle.p.copy(conf["position"]);
if (this.hasProp(conf, "velocity")) particle.v.copy(conf["velocity"]);
if (this.hasProp(conf, "accelerate")) particle.a.copy(conf["accelerate"]);
}
};
63 changes: 0 additions & 63 deletions src/utils/Util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Span from "../math/Span";
import ImgUtil from "./ImgUtil";

export default {
Expand Down Expand Up @@ -86,68 +85,6 @@ export default {
}
},

/**
* @memberof Proton#Proton.Util
* @method setVectorVal
*
* @todo add description for param `target`
* @todo add description for param `conf`
* @todo add description for function
*
* @param {Object} target
* @param {Object} conf
*/
setVectorVal(particle, conf = null) {
if (!conf) return;

if (this.hasProp(conf, "x")) particle.p.x = conf["x"];
if (this.hasProp(conf, "y")) particle.p.y = conf["y"];

if (this.hasProp(conf, "vx")) particle.v.x = conf["vx"];
if (this.hasProp(conf, "vy")) particle.v.y = conf["vy"];

if (this.hasProp(conf, "ax")) particle.a.x = conf["ax"];
if (this.hasProp(conf, "ay")) particle.a.y = conf["ay"];

if (this.hasProp(conf, "p")) particle.p.copy(conf["p"]);
if (this.hasProp(conf, "v")) particle.v.copy(conf["v"]);
if (this.hasProp(conf, "a")) particle.a.copy(conf["a"]);

if (this.hasProp(conf, "position")) particle.p.copy(conf["position"]);
if (this.hasProp(conf, "velocity")) particle.v.copy(conf["velocity"]);
if (this.hasProp(conf, "accelerate")) particle.a.copy(conf["accelerate"]);
},

hasProp(target, key) {
if (!target) return false;
return target[key] !== undefined;
// return obj.hasOwnProperty(key);
},

/**
* set the prototype in a given prototypeObject
*
* @memberof Proton#Proton.Util
* @method setProp
*
* @todo add description for param `target`
* @todo translate desription from chinese to english
*
* @param {Object} target
* @param {Object} prototypeObject An object of single prototypes
*
* @return {Object} target
*/
setProp(target, props) {
for (let prop in props) {
if (target.hasOwnProperty(prop)) {
target[prop] = Span.getSpanValue(props[prop]);
}
}

return target;
},

/**
* This will get the image data. It could be necessary to create a Proton.Zone.
*
Expand Down

0 comments on commit 602ad99

Please sign in to comment.