refactoring: replaced all matter sub body part (entites, etc) by directly paperjs groups
This commit is contained in:
parent
a90458f145
commit
7c589b0327
@ -336,24 +336,6 @@ export default {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
// Create parts of the body : entities
|
|
||||||
for (let i = 0; i < this.entites.length; i++) {
|
|
||||||
// parts.push(Matter.Bodies.circle(this.pos.x+this.entites[i].display.pos.x, this.pos.y+this.entites[i].display.pos.y, 15, {
|
|
||||||
// item_type: 'entite',
|
|
||||||
// id: this.entites[i].id
|
|
||||||
// }))
|
|
||||||
this.body_parts.push(Matter.Bodies.circle(this.entites[i].display.pos.x, this.entites[i].display.pos.y, 0.8, {
|
|
||||||
item_type: 'entite',
|
|
||||||
id: this.entites[i].entite.id,
|
|
||||||
cid: this.concernement.id,
|
|
||||||
agissante: this.entites[i].entite.agissante,
|
|
||||||
isSensor: true
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create parts of the body : besoins and responses
|
|
||||||
this.createBesoinsBodyParts();
|
|
||||||
|
|
||||||
// create the body
|
// create the body
|
||||||
this.body = Matter.Body.create({
|
this.body = Matter.Body.create({
|
||||||
parts: this.body_parts,
|
parts: this.body_parts,
|
||||||
@ -397,49 +379,6 @@ export default {
|
|||||||
y: -delta + Math.random()*delta*2
|
y: -delta + Math.random()*delta*2
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createBesoinsBodyParts(){
|
|
||||||
let res_fields = ['qui','quoi','ou','avec'];
|
|
||||||
let arc = (360 / 16); // unit arc
|
|
||||||
let r = (this.ray * this.scale)/5; // unit ray
|
|
||||||
let br = r - r/3; // besoin ray
|
|
||||||
|
|
||||||
for (let i = 0; i < this.concernement.besoins.length; i++) {
|
|
||||||
let start_a = arc * i; // angle depart (for reponses)
|
|
||||||
let center_a = start_a + arc/2; // angle central
|
|
||||||
let x = Math.cos(center_a*(Math.PI/180)) * br;
|
|
||||||
let y = Math.sin(center_a*(Math.PI/180)) * br;
|
|
||||||
|
|
||||||
this.body_parts.push(Matter.Bodies.circle(x, y, 0.8, {
|
|
||||||
item_type: 'besoin',
|
|
||||||
id: this.concernement.besoins[i].id,
|
|
||||||
cid: this.concernement.id,
|
|
||||||
isSensor: true
|
|
||||||
}));
|
|
||||||
|
|
||||||
let res_arc = arc / (1 + this.concernement.besoins[i].reponses.length); // unit arc for responses depending responses number
|
|
||||||
for (let j = 0; j < this.concernement.besoins[i].reponses.length; j++) {
|
|
||||||
let res_a = start_a + res_arc * (j+1); // angle for response line
|
|
||||||
for (let f = 0; f < res_fields.length; f++) { // loop through all 4 fields, keep only the last one filled
|
|
||||||
if( this.concernement.besoins[i].reponses[j][res_fields[f]] // if field filled
|
|
||||||
&& (f === res_fields.length -1 || !this.concernement.besoins[i].reponses[j][res_fields[f+1]]) // and is last field or last field filled
|
|
||||||
){
|
|
||||||
let rr = this.ray * this.scale - r*f - r/2; // reponse field ray
|
|
||||||
let rx = Math.cos(res_a*(Math.PI/180)) * rr;
|
|
||||||
let ry = Math.sin(res_a*(Math.PI/180)) * rr;
|
|
||||||
|
|
||||||
this.body_parts.push(Matter.Bodies.circle(rx, ry, 0.8, {
|
|
||||||
item_type: 'reponse',
|
|
||||||
// field: res_fields[f],
|
|
||||||
id: this.concernement.besoins[i].reponses[j].id,
|
|
||||||
bid: this.concernement.besoins[i].id,
|
|
||||||
cid: this.concernement.id,
|
|
||||||
isSensor: true
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// PAPER OBJECTS
|
// PAPER OBJECTS
|
||||||
initPaperObjects(){
|
initPaperObjects(){
|
||||||
this.paper_objects = new paper.Group({
|
this.paper_objects = new paper.Group({
|
||||||
@ -449,6 +388,7 @@ export default {
|
|||||||
this.paper_objects.addChild(this.setPaperBoussoleBG());
|
this.paper_objects.addChild(this.setPaperBoussoleBG());
|
||||||
this.paper_objects.addChild(this.setPaperContour());
|
this.paper_objects.addChild(this.setPaperContour());
|
||||||
this.paper_objects.addChild(this.setPaperEntites());
|
this.paper_objects.addChild(this.setPaperEntites());
|
||||||
|
|
||||||
if (this.concernement.has_puissancedagir) {
|
if (this.concernement.has_puissancedagir) {
|
||||||
this.paper_objects.addChild(this.setPaperPuissanceagirBG());
|
this.paper_objects.addChild(this.setPaperPuissanceagirBG());
|
||||||
this.paper_objects.addChild(this.setPaperPuissanceagirICON());
|
this.paper_objects.addChild(this.setPaperPuissanceagirICON());
|
||||||
@ -709,17 +649,37 @@ export default {
|
|||||||
pivot: new paper.Point(this.pos),
|
pivot: new paper.Point(this.pos),
|
||||||
name: 'entites'
|
name: 'entites'
|
||||||
});
|
});
|
||||||
for (let i = 0; i < this.body.parts.length; i++) {
|
for (let i = 0; i < this.entites.length; i++) {
|
||||||
if (this.body.parts[i].item_type === 'entite') {
|
|
||||||
let part = this.body.parts[i];
|
|
||||||
g.addChild(new paper.Path.Circle({
|
g.addChild(new paper.Path.Circle({
|
||||||
center: [part.position.x, part.position.y],
|
pivot: new paper.Point(this.pos),
|
||||||
|
center: [this.pos.x + this.entites[i].display.pos.x, this.pos.y + this.entites[i].display.pos.y],
|
||||||
radius: 0.5, //0.3
|
radius: 0.5, //0.3
|
||||||
fillColor: '#000',
|
fillColor: '#000',
|
||||||
item_id: part.id,
|
item_id: this.entites[i].entite.id,
|
||||||
item_type: 'entite'
|
item_type: 'entite'
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
return g;
|
||||||
|
},
|
||||||
|
setPaperAgissantes(){
|
||||||
|
let g = new paper.Group({
|
||||||
|
pivot: new paper.Point(this.pos),
|
||||||
|
name: 'agissantes'
|
||||||
|
});
|
||||||
|
for (let i = 0; i < this.entites.length; i++) {
|
||||||
|
if (this.entites[i].entite.agissante) {
|
||||||
|
g.addChild(new paper.Path.Circle({
|
||||||
|
pivot: new paper.Point(this.pos),
|
||||||
|
center: [this.pos.x + this.entites[i].display.pos.x, this.pos.y + this.entites[i].display.pos.y],
|
||||||
|
radius: 0.5, //0.3
|
||||||
|
fillColor: '#000',
|
||||||
|
strokeColor: '#000',
|
||||||
|
strokeWidth: 3,
|
||||||
|
item_id: this.entites[i].entite.id,
|
||||||
|
item_type: 'entite'
|
||||||
|
}))
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return g;
|
return g;
|
||||||
},
|
},
|
||||||
@ -803,37 +763,53 @@ export default {
|
|||||||
name: 'puissanceagir_besoins'
|
name: 'puissanceagir_besoins'
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < this.body.parts.length; i++) {
|
let res_fields = ['qui','quoi','ou','avec'];
|
||||||
if (this.body.parts[i].item_type === 'besoin' || this.body.parts[i].item_type === 'reponse') {
|
let arc = (360 / 16); // unit arc
|
||||||
let part = this.body.parts[i];
|
let r = (this.ray * this.scale)/5; // unit ray
|
||||||
|
let br = r - r/3; // besoin ray
|
||||||
|
|
||||||
|
for (let i = 0; i < this.concernement.besoins.length; i++) {
|
||||||
|
let start_a = arc * i; // angle depart (for reponses)
|
||||||
|
let center_a = start_a + arc/2; // angle central
|
||||||
|
let x = Math.cos(center_a*(Math.PI/180)) * br;
|
||||||
|
let y = Math.sin(center_a*(Math.PI/180)) * br;
|
||||||
|
|
||||||
switch (part.item_type) {
|
|
||||||
case 'besoin':
|
|
||||||
g.addChild(
|
g.addChild(
|
||||||
new paper.Path({
|
new paper.Path({
|
||||||
segments: this.getDiamondSegments(part.position.x, part.position.y, 1),
|
|
||||||
fillColor: '#000',
|
|
||||||
pivot: new paper.Point(this.pos),
|
pivot: new paper.Point(this.pos),
|
||||||
item_id: part.id,
|
segments: this.getDiamondSegments(this.pos.x + x, this.pos.y + y, 1),
|
||||||
|
fillColor: '#000',
|
||||||
|
item_id: this.concernement.besoins[i].id,
|
||||||
|
item_cid: this.concernement.id,
|
||||||
item_type: 'besoin'
|
item_type: 'besoin'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
break;
|
|
||||||
case 'reponse':
|
let res_arc = arc / (1 + this.concernement.besoins[i].reponses.length); // unit arc for responses depending responses number
|
||||||
|
for (let j = 0; j < this.concernement.besoins[i].reponses.length; j++) {
|
||||||
|
let res_a = start_a + res_arc * (j+1); // angle for response line
|
||||||
|
for (let f = 0; f < res_fields.length; f++) { // loop through all 4 fields, keep only the last one filled
|
||||||
|
if( this.concernement.besoins[i].reponses[j][res_fields[f]] // if field filled
|
||||||
|
&& (f === res_fields.length -1 || !this.concernement.besoins[i].reponses[j][res_fields[f+1]]) // and is last field or last field filled
|
||||||
|
){
|
||||||
|
let rr = this.ray * this.scale - r*f - r/2; // reponse field ray
|
||||||
|
let rx = Math.cos(res_a*(Math.PI/180)) * rr;
|
||||||
|
let ry = Math.sin(res_a*(Math.PI/180)) * rr;
|
||||||
|
|
||||||
g.addChild(
|
g.addChild(
|
||||||
new paper.Path({
|
new paper.Path({
|
||||||
segments: this.getDiamondSegments(part.position.x, part.position.y, 1),
|
pivot: new paper.Point(this.pos),
|
||||||
|
segments: this.getDiamondSegments(this.pos.x + rx, this.pos.y + ry, 1),
|
||||||
fillColor: '#eee',
|
fillColor: '#eee',
|
||||||
strokeColor: "#000",
|
strokeColor: "#000",
|
||||||
strokeWidth: 1,
|
strokeWidth: 1,
|
||||||
pivot: new paper.Point(this.pos),
|
item_id: this.concernement.besoins[i].reponses[j].id,
|
||||||
item_id: part.id,
|
item_bid: this.concernement.besoins[i].id,
|
||||||
item_bid: part.bid,
|
item_cid: this.concernement.id,
|
||||||
item_cid: part.cid,
|
|
||||||
item_type: 'reponse'
|
item_type: 'reponse'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -849,27 +825,6 @@ export default {
|
|||||||
[x, y - r]
|
[x, y - r]
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
setPaperAgissantes(){
|
|
||||||
let g = new paper.Group({
|
|
||||||
pivot: new paper.Point(this.pos),
|
|
||||||
name: 'agissantes'
|
|
||||||
});
|
|
||||||
for (let i = 0; i < this.body.parts.length; i++) {
|
|
||||||
if (this.body.parts[i].item_type === 'entite' && this.body.parts[i].agissante) {
|
|
||||||
let part = this.body.parts[i];
|
|
||||||
g.addChild(new paper.Path.Circle({
|
|
||||||
center: [part.position.x, part.position.y],
|
|
||||||
radius: 0.3, //0.3
|
|
||||||
fillColor: '#000',
|
|
||||||
strokeColor: '#000',
|
|
||||||
strokeWidth: 3,
|
|
||||||
item_id: part.id,
|
|
||||||
item_type: 'entite'
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return g;
|
|
||||||
},
|
|
||||||
setPaperDoleanceBG(){
|
setPaperDoleanceBG(){
|
||||||
var r = this.ray * this.scale * 0.8; // ray
|
var r = this.ray * this.scale * 0.8; // ray
|
||||||
var dr = r/2; // demi ray
|
var dr = r/2; // demi ray
|
||||||
@ -1803,7 +1758,7 @@ export default {
|
|||||||
: this.canvas.width - pseudo_center_x;
|
: this.canvas.width - pseudo_center_x;
|
||||||
// max and min force
|
// max and min force
|
||||||
let minf = 0;
|
let minf = 0;
|
||||||
let maxf = 10;
|
let maxf = 6;
|
||||||
// scale factor
|
// scale factor
|
||||||
let scale = (maxf-minf) / (maxp-minp);
|
let scale = (maxf-minf) / (maxp-minp);
|
||||||
// get the inversed distance
|
// get the inversed distance
|
||||||
@ -1840,7 +1795,7 @@ export default {
|
|||||||
: pseudo_center_x;
|
: pseudo_center_x;
|
||||||
// max and min force
|
// max and min force
|
||||||
let minf = 0;
|
let minf = 0;
|
||||||
let maxf = 2;
|
let maxf = 1;
|
||||||
// scale factor
|
// scale factor
|
||||||
let scale = (maxf-minf) / (maxp-minp);
|
let scale = (maxf-minf) / (maxp-minp);
|
||||||
// get the inversed distance from the side
|
// get the inversed distance from the side
|
||||||
@ -1867,19 +1822,46 @@ export default {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
applyShuffleForces() {
|
applyShuffleForces() {
|
||||||
var dist, dir, x_velocity;
|
// var dist, dir, x_velocity;
|
||||||
dir = this.pos.x > this.canvas.width/2 ? -1 : 1; // get the direction to the centre
|
// dir = this.pos.x > this.canvas.width/2 ? -1 : 1; // get the direction to the centre
|
||||||
dist = (dir < 0 ? this.pos.x - this.canvas.width/2 : this.canvas.width/2 - this.pos.x); // get the distance from the side
|
// dist = (dir < 0 ? this.pos.x - this.canvas.width/2 : this.canvas.width/2 - this.pos.x); // get the distance from the side
|
||||||
x_velocity = Math.pow(dist/650,10) * dir;
|
// x_velocity = Math.pow(dist/650,10) * dir;
|
||||||
|
let pseudo_center_x = (this.canvas.width - this.cartouch_width) / 2;
|
||||||
|
// get the direction to the centre
|
||||||
|
let dir = this.pos.x > pseudo_center_x
|
||||||
|
? -1 // to left
|
||||||
|
: 1; // to right
|
||||||
|
// max & min item position
|
||||||
|
let minp = 0;
|
||||||
|
let maxp = dir < 0
|
||||||
|
? this.canvas.width - pseudo_center_x
|
||||||
|
: pseudo_center_x;
|
||||||
|
// max and min force
|
||||||
|
let minf = 0;
|
||||||
|
let maxf = 10;
|
||||||
|
// scale factor
|
||||||
|
let scale = (maxf-minf) / (maxp-minp);
|
||||||
|
// get the inversed distance from the side
|
||||||
|
let dist = dir < 0
|
||||||
|
? this.pos.x - pseudo_center_x
|
||||||
|
: pseudo_center_x - this.pos.x;
|
||||||
|
|
||||||
Matter.Body.setVelocity(this.body, {x: x_velocity, y: 0});
|
let x_velocity = Math.exp(minf + scale*(dist-minp));
|
||||||
|
|
||||||
|
let y_velocity = -10 + Math.random() * 10;
|
||||||
|
// let ori_pos = dir < 0
|
||||||
|
// ? {x:this.canvas.width, y:this.body.position.y}
|
||||||
|
// : {x:0, y:this.body.position.y};
|
||||||
|
// let x_force = Math.pow(dist/800,10) * dir;
|
||||||
|
|
||||||
|
Matter.Body.setVelocity(this.body, {x: x_velocity, y: y_velocity});
|
||||||
},
|
},
|
||||||
onAfterEngineUpdate (event) {
|
onAfterEngineUpdate (event) {
|
||||||
// respawn element if outside screen
|
// respawn element if outside screen
|
||||||
// if(this.pos.x < 0
|
// if(this.pos.x <= 0
|
||||||
// || this.pos.x > this.canvas.width
|
// || this.pos.x >= this.canvas.width
|
||||||
// || this.pos.y < 0
|
// || this.pos.y <= 0
|
||||||
// || this.pos.y > this.canvas.height){
|
// || this.pos.y >= this.canvas.height){
|
||||||
// this.pos = this.getRandomPos()
|
// this.pos = this.getRandomPos()
|
||||||
// Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
// Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
||||||
// this.setInitBodyVelocity();
|
// this.setInitBodyVelocity();
|
||||||
@ -1956,34 +1938,8 @@ export default {
|
|||||||
&& this.map_mode !== 'doleancer'
|
&& this.map_mode !== 'doleancer'
|
||||||
&& this.map_mode !== 'action' ) {
|
&& this.map_mode !== 'action' ) {
|
||||||
this.paper_objects.children.entites.visible = true;
|
this.paper_objects.children.entites.visible = true;
|
||||||
// if (this.opened_entite_id) {
|
|
||||||
// // console.log('this.paper_objects.children.entites', this.paper_objects.children.entites);
|
|
||||||
// this.paper_objects.children.entites.children.forEach((entite) => {
|
|
||||||
// // console.log('entite', entite);
|
|
||||||
// if (entite.item_id === this.opened_entite_id) {
|
|
||||||
// entite.style.fillColor = '#01ffe2';
|
|
||||||
// } else {
|
|
||||||
// entite.style.fillColor = '#000';
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// this.paper_objects.children.entites.children.forEach((entite) => {
|
|
||||||
// entite.style.fillColor = '#000';
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
this.paper_objects.children.entites.visible = false;
|
this.paper_objects.children.entites.visible = false;
|
||||||
// if(this.map_mode === 'puissancedagir'
|
|
||||||
// || this.map_mode === 'doleancer'
|
|
||||||
// || this.map_mode === 'action' ){
|
|
||||||
// this.paper_objects.children.entites.visible = false;
|
|
||||||
// }else{
|
|
||||||
// this.paper_objects.children.entites.visible = true;
|
|
||||||
// // this.paper_objects.children.entites.children.forEach((entite) => {
|
|
||||||
// // // entite.style.strokeWidth = 2;
|
|
||||||
// // // entite.style.strokeColor = "#fff";
|
|
||||||
// // })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user