map menu 'action' is working
This commit is contained in:
parent
82731a4884
commit
72d79f8d84
@ -146,6 +146,7 @@ export default {
|
|||||||
item_type: 'entite',
|
item_type: 'entite',
|
||||||
id: this.entites[i].entite.id,
|
id: this.entites[i].entite.id,
|
||||||
cid: this.concernement.id,
|
cid: this.concernement.id,
|
||||||
|
agissante: this.entites[i].entite.agissante,
|
||||||
isSensor: true
|
isSensor: true
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -158,7 +159,7 @@ export default {
|
|||||||
frictionAir: 0,
|
frictionAir: 0,
|
||||||
// mass: Math.pow(3, this.entites.length),
|
// mass: Math.pow(3, this.entites.length),
|
||||||
mass: 10,
|
mass: 10,
|
||||||
restitution: 0.4,
|
restitution: 0.1,
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
group: -1
|
group: -1
|
||||||
},
|
},
|
||||||
@ -345,15 +346,94 @@ export default {
|
|||||||
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});
|
||||||
}
|
}
|
||||||
|
// map_mode action
|
||||||
|
if (this.map_mode === 'action'){
|
||||||
|
var dist, dir, x_force, ori_pos;
|
||||||
|
var x_force = 0;
|
||||||
|
if(!this.concernement.has_agissantes) {
|
||||||
|
// does not has actions -> take a side
|
||||||
|
// apply a force in direction of one side or an other depending of the start position
|
||||||
|
// the force is exponentialy proportional to the distance from the side
|
||||||
|
dir = this.pos.x > this.canvas.width/2 ? 1 : -1; // get the direction to the closest side
|
||||||
|
dist = (dir < 0 ? this.pos.x : this.canvas.width - this.pos.x); // get the distance from the side
|
||||||
|
ori_pos = {x:this.canvas.width/2, y:this.canvas.height/2};
|
||||||
|
x_force = Math.pow(dist/700,10) * dir;
|
||||||
|
}else{
|
||||||
|
// has action, get 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
|
||||||
|
ori_pos = dir < 0 ? {x:this.canvas.width, y:this.canvas.height/2} : {x:0, y:this.canvas.height/2}
|
||||||
|
x_force = Math.pow(dist/800,10) * dir;
|
||||||
|
}
|
||||||
|
// x_force = (dist > 200 ? Math.pow(dist/700,10) : 0) * dir
|
||||||
|
Matter.Body.applyForce(
|
||||||
|
this.body,
|
||||||
|
ori_pos,
|
||||||
|
{
|
||||||
|
x: x_force,
|
||||||
|
y: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Matter.Body.setAngle(this.body, 0);
|
||||||
|
Matter.Body.setAngularSpeed(this.body, 0);
|
||||||
this.draw()
|
this.draw()
|
||||||
},
|
},
|
||||||
draw() {
|
draw() {
|
||||||
|
|
||||||
if (!this.ctx) return;
|
if (!this.ctx) return;
|
||||||
|
|
||||||
|
// record the position from the main matter body
|
||||||
this.pos = this.body.position;
|
this.pos = this.body.position;
|
||||||
|
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
|
this.drawBoussole();
|
||||||
|
}
|
||||||
|
|
||||||
|
// contours
|
||||||
|
this.drawContour();
|
||||||
|
|
||||||
|
if (this.opened) {
|
||||||
|
// place all entities points
|
||||||
|
// OR using entitées matter bodies
|
||||||
|
for (let i = 0; i < this.body.parts.length; i++) {
|
||||||
|
if (this.body.parts[i].item_type === 'entite'
|
||||||
|
// draw only entite agissante if map mode is action
|
||||||
|
&& ((this.map_mode === 'action' && this.body.parts[i].agissante) || this.map_mode !== "action")) {
|
||||||
|
let part = this.body.parts[i];
|
||||||
|
this.ctx.beginPath();
|
||||||
|
this.ctx.arc(part.position.x, part.position.y, 0.3*this.scale, 0, 2 * Math.PI, false);
|
||||||
|
// console.log(part.id, this.opened_entite_id);
|
||||||
|
if (part.id === this.opened_entite_id) {
|
||||||
|
this.ctx.fillStyle = "#F00";
|
||||||
|
} else {
|
||||||
|
this.ctx.fillStyle = "#000";
|
||||||
|
}
|
||||||
|
this.ctx.fill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// map mode action
|
||||||
|
else if (this.concernement.has_agissantes && this.map_mode === "action") {
|
||||||
|
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];
|
||||||
|
this.ctx.beginPath();
|
||||||
|
this.ctx.arc(part.position.x, part.position.y, 1*this.scale, 0, 2 * Math.PI, false);
|
||||||
|
// console.log(part.id, this.opened_entite_id);
|
||||||
|
if (part.id === this.opened_entite_id) {
|
||||||
|
this.ctx.fillStyle = "#F00";
|
||||||
|
} else {
|
||||||
|
this.ctx.fillStyle = "#000";
|
||||||
|
}
|
||||||
|
this.ctx.fill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
drawBoussole(){
|
||||||
// BOUSSOLE
|
// BOUSSOLE
|
||||||
// exterieur circle
|
// exterieur circle
|
||||||
this.ctx.beginPath();
|
this.ctx.beginPath();
|
||||||
@ -407,15 +487,19 @@ export default {
|
|||||||
// vertical
|
// vertical
|
||||||
|
|
||||||
this.ctx.stroke();
|
this.ctx.stroke();
|
||||||
}
|
},
|
||||||
|
drawContour(){
|
||||||
// contours
|
|
||||||
if (this.salientPoints.length > 3) {
|
if (this.salientPoints.length > 3) {
|
||||||
|
var fillStyle;
|
||||||
|
if (this.map_mode === "action" && !this.concernement.has_agissantes){
|
||||||
|
fillStyle = "rgba(255,255,255,0.3)";
|
||||||
|
}else{
|
||||||
|
fillStyle = "rgba(255,255,255,0.8)"
|
||||||
|
}
|
||||||
this.ctx.beginPath();
|
this.ctx.beginPath();
|
||||||
this.ctx.lineWidth = 1;
|
this.ctx.lineWidth = 1;
|
||||||
this.ctx.strokeStyle = "#000";
|
this.ctx.strokeStyle = "#000";
|
||||||
this.ctx.fillStyle = "rgba(255,255,255,0.8)";
|
this.ctx.fillStyle = fillStyle;
|
||||||
this.ctx.moveTo(this.pos.x+this.salientPoints[0].pos.x*this.scale*1.15, this.pos.y+this.salientPoints[0].pos.y*this.scale*1.15)
|
this.ctx.moveTo(this.pos.x+this.salientPoints[0].pos.x*this.scale*1.15, this.pos.y+this.salientPoints[0].pos.y*this.scale*1.15)
|
||||||
for (let j = 1; j < this.salientPoints.length; j++) {
|
for (let j = 1; j < this.salientPoints.length; j++) {
|
||||||
this.ctx.lineTo(this.pos.x+this.salientPoints[j].pos.x*this.scale*1.15, this.pos.y+this.salientPoints[j].pos.y*this.scale*1.15)
|
this.ctx.lineTo(this.pos.x+this.salientPoints[j].pos.x*this.scale*1.15, this.pos.y+this.salientPoints[j].pos.y*this.scale*1.15)
|
||||||
@ -424,43 +508,6 @@ export default {
|
|||||||
this.ctx.fill();
|
this.ctx.fill();
|
||||||
this.ctx.stroke();
|
this.ctx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.opened) {
|
|
||||||
// place all entities points
|
|
||||||
// using entities array
|
|
||||||
// for (let i = 0; i < this.entites.length; i++) {
|
|
||||||
// let entite = this.entites[i];
|
|
||||||
// // console.log('entite', entite);
|
|
||||||
// this.ctx.beginPath();
|
|
||||||
// this.ctx.arc(this.pos.x+entite.display.pos.x*this.scale, this.pos.y+entite.display.pos.y*this.scale, 5, 0, 2 * Math.PI, false);
|
|
||||||
// this.ctx.strokeStyle = "#F00";
|
|
||||||
// this.ctx.stroke();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// OR using entitées matter bodies
|
|
||||||
for (let i = 0; i < this.body.parts.length; i++) {
|
|
||||||
if (this.body.parts[i].item_type === 'entite') {
|
|
||||||
let part = this.body.parts[i];
|
|
||||||
this.ctx.beginPath();
|
|
||||||
this.ctx.arc(part.position.x, part.position.y, 0.3*this.scale, 0, 2 * Math.PI, false);
|
|
||||||
// console.log(part.id, this.opened_entite_id);
|
|
||||||
if (part.id === this.opened_entite_id) {
|
|
||||||
this.ctx.fillStyle = "#F00";
|
|
||||||
} else {
|
|
||||||
this.ctx.fillStyle = "#000";
|
|
||||||
}
|
|
||||||
this.ctx.fill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// // concernement id @center
|
|
||||||
// this.ctx.beginPath();
|
|
||||||
// // this.ctx.arc(this.pos.x, this.pos.y, 4, 0, 2 * Math.PI, false);
|
|
||||||
// this.ctx.fillStyle = "#000";
|
|
||||||
// this.ctx.fillText(this.concernement.id, this.pos.x, this.pos.y)
|
|
||||||
// this.ctx.fill();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
@ -21,7 +21,7 @@ export default {
|
|||||||
if (this.infos.type === 'concernement') {
|
if (this.infos.type === 'concernement') {
|
||||||
this.concernement = this.concernementsByID[this.infos.id];
|
this.concernement = this.concernementsByID[this.infos.id];
|
||||||
} else {
|
} else {
|
||||||
this.entite = this.allEntitesById[this.infos.id].entite;
|
this.entite = this.allEntitesById[this.infos.id];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@ -40,7 +40,7 @@ export default {
|
|||||||
if (n.type === 'concernement') {
|
if (n.type === 'concernement') {
|
||||||
this.concernement = this.concernementsByID[n.id];
|
this.concernement = this.concernementsByID[n.id];
|
||||||
} else {
|
} else {
|
||||||
this.entite = this.allEntitesById[n.id].entite;
|
this.entite = this.allEntitesById[n.id];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
|
@ -183,8 +183,12 @@ export default {
|
|||||||
if (query.length) {
|
if (query.length) {
|
||||||
// open/close all concernements
|
// open/close all concernements
|
||||||
this.openCloseConcernements(query[0].id)
|
this.openCloseConcernements(query[0].id)
|
||||||
// push route
|
// push route (keep the hash for map_mode)
|
||||||
this.$router.push({name: 'concernement', params: {id: query[0].id}});
|
this.$router.push({
|
||||||
|
name: 'concernement',
|
||||||
|
hash: `#${this.map_mode}`,
|
||||||
|
params: {id: query[0].id}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,16 +204,27 @@ export default {
|
|||||||
});
|
});
|
||||||
if (clickedEntityBodies.length) {
|
if (clickedEntityBodies.length) {
|
||||||
// we have clicked on an entite
|
// we have clicked on an entite
|
||||||
this.$router.push({name: 'concernement', params: {id: this.opened.id, eid: clickedEntityBodies[0].id}});
|
this.$router.push({
|
||||||
|
name: 'concernement',
|
||||||
|
hash: `#${this.map_mode}`,
|
||||||
|
params: {id: this.opened.id, eid: clickedEntityBodies[0].id}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// otherwise we close the entite and come back to the concernement
|
// otherwise we close the entite and come back to the concernement
|
||||||
this.$router.push({name: 'concernement', params: {id: this.opened.id}});
|
this.$router.push({
|
||||||
|
name: 'concernement',
|
||||||
|
hash: `#${this.map_mode}`,
|
||||||
|
params: {id: this.opened.id}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if no concernement opened retrun to home (closing concernement contents opened)
|
// if no concernement opened retrun to home (closing concernement contents opened)
|
||||||
// and reset the opened state in concernement store
|
// and reset the opened state in concernement store
|
||||||
this.resetConcernementOpened();
|
this.resetConcernementOpened();
|
||||||
this.$router.push({name: 'home'});
|
this.$router.push({
|
||||||
|
name: 'home',
|
||||||
|
hash: `#${this.map_mode}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,17 +52,17 @@ export const ConcernementsStore = defineStore({
|
|||||||
this.concernements = [];
|
this.concernements = [];
|
||||||
allconcernements.forEach(concernement => {
|
allconcernements.forEach(concernement => {
|
||||||
concernement.entites_byid = {};
|
concernement.entites_byid = {};
|
||||||
|
concernement.entitesagissantes_byid = {};
|
||||||
|
concernement.has_agissantes = false;
|
||||||
concernement.entites.forEach(entite => {
|
concernement.entites.forEach(entite => {
|
||||||
concernement.entites_byid[entite.entite.id] = entite;
|
concernement.entites_byid[entite.entite.id] = entite;
|
||||||
// record a flat list of all entités of all concernement for map-popup
|
// record entite agissante
|
||||||
if (typeof this.allEntitesById[entite.entite.id] === "undefined") {
|
if (entite.entite.agissante) {
|
||||||
this.allEntitesById[entite.entite.id] = {
|
concernement.entitesagissantes_byid[entite.entite.id] = entite;
|
||||||
entite: entite,
|
concernement.has_agissantes = true;
|
||||||
concernements: [concernement]
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
this.allEntitesById[entite.entite.id].concernements.push(concernement);
|
|
||||||
}
|
}
|
||||||
|
// record a flat list of all entités of all concernement for map-popup
|
||||||
|
this.allEntitesById[entite.entite.id] = entite;
|
||||||
});
|
});
|
||||||
this.concernements.push(concernement);
|
this.concernements.push(concernement);
|
||||||
this.concernementsByID[concernement.id] = concernement;
|
this.concernementsByID[concernement.id] = concernement;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user