more paperjs refactoring

This commit is contained in:
2023-06-05 14:33:03 +02:00
parent 3a473ea932
commit f314ff11f2
3 changed files with 63 additions and 220 deletions

View File

@@ -110,8 +110,6 @@ export default {
// add mouse control
// https://github.com/liabru/matter-js/issues/491#issuecomment-331329404
this.mouse = Matter.Mouse.create(this.canvasMap.canvas);
// this.canvasMap.canvas.addEventListener('mousemove', this.onMouseMove)
// this.canvasMap.canvas.addEventListener('click', this.onClick)
this.animate()
},
@@ -121,10 +119,7 @@ export default {
...mapActions(ConcernementsStore,['resetConcernementOpened']),
...mapActions(CommonStore,['setHoverElmt']),
animate () {
// this.canvasMap.ctx.clearRect(0, 0, this.canvasMap.canvas.width, this.canvasMap.canvas.height)
// this.canvasMap.canvas.dispatchEvent(this.animateEvent)
Matter.Engine.update(this.engine, 1);
// this.checkMouseHover();
window.requestAnimationFrame(this.animate);
},
onCanvasClick(event){
@@ -137,148 +132,7 @@ export default {
hash: `#${this.map_mode}`
});
}
},
// onMouseMove_OLD (e) {
// // this.checkMouseHover();
// },
checkMouseHover_OLD(){
// check item mouse over
// let query;
// if (this.opened) {
// // if a concernement is opened we query the opened concernement's parts (aka entitées bodies)
// const bodies = Matter.Composite.allBodies(this.world);
// for (let body of bodies) {
// if (body.item_type === "concernement" && body.id === this.opened.id) {
// query = Matter.Query.point(body.parts, this.mouse.position);
// break;
// }
// }
// } else {
// // if no concernement opened we query concernements
// query = Matter.Query.point(this.world.bodies, this.mouse.position)
// }
let hover_elmt = null;
if (query && query.length) {
// if we have a results
for (let body of query) {
console.log('mouse hover body.item_type', body.item_type);
// if (!this.opened // if no concernement is opened
// && body.item_type === "concernement" // if it is a concernement
// && typeof this.concernementsByID[body.id] !== "undefined" // if the id exists
// && !this.concernementsByID[body.id].opened) { // if the concernement is not opened
// hover_elmt = {
// type: 'concernement',
// id: body.id
// };
// }
// if (body.item_type === "entite" // if it is an entite
// && this.opened // if a concernement is opened
// && typeof this.opened.entites_byid[body.id] !== "undefined") { // if the entity exists
// hover_elmt = {
// type: 'entite',
// id: body.id
// };
// }
if (body.item_type === "besoin" // if it is a besoin
&& this.opened) { // if a concernement is opened
hover_elmt = {
type: 'besoin',
id: body.id
};
}
if (body.item_type === "reponse" // if it is a besoin
&& this.opened) { // if a concernement is opened
hover_elmt = {
type: 'reponse',
field: body.field,
id: body.id,
bid: body.bid,
cid: body.cid
};
}
}
// console.log(`hover_elmt type: ${hover_elmt.type}, id: ${hover_elmt.id}`);
}
// this.setHoverElmt(hover_elmt);
// if (hover_elmt) {
// document.body.style.cursor = "pointer";
// } else {
// document.body.style.cursor = "auto";
// }
},
// onClick_OLD (e) {
// console.log('onClick', this, e);
// // get the clicked element from matter
// // const query = Matter.Query.point(Matter.Composite.allBodies(this.world), this.mouse.position)
// let query;
// if (this.opened) {
// // if a concernement is opened we query the opened concernement's parts (aka entitées bodies)
// const bodies = Matter.Composite.allBodies(this.world);
// for (let body of bodies) {
// if (body.item_type === "concernement" && body.id === this.opened.id) {
// query = Matter.Query.point(body.parts, this.mouse.position);
// break;
// }
// }
// } else {
// // if no concernement opened we query concernements
// query = Matter.Query.point(this.world.bodies, this.mouse.position)
// }
// // console.log(this.mouse.position);
// console.log('click query', query);
// // no concernement is yet opened, we deal concernements
// if (!this.opened) {
// if (query.length) {
// // // open/close all concernements
// // this.openCloseConcernements(query[0].id)
// // // push route (keep the hash for map_mode)
// // this.$router.push({
// // name: 'concernement',
// // hash: `#${this.map_mode}`,
// // params: {id: query[0].id}
// // });
// }
// }
// // concernement is already opened, we deal with entités
// if (this.opened) {
// if (query.length) {
// // let clickedEntityBodies = [];
// // query.forEach(body => {
// // // console.log('body id:', body.id);
// // if (body.item_type === "entite") {
// // clickedEntityBodies.push(body);
// // }
// // });
// // if (clickedEntityBodies.length) {
// // // we have clicked on an entite
// // this.$router.push({
// // name: 'concernement',
// // hash: `#${this.map_mode}`,
// // params: {id: this.opened.id, eid: clickedEntityBodies[0].id}
// // });
// // } else {
// // // otherwise we close the entite and come back to the concernement
// // this.$router.push({
// // name: 'concernement',
// // hash: `#${this.map_mode}`,
// // params: {id: this.opened.id}
// // });
// // }
// } else {
// // if no concernement opened retrun to home (closing concernement contents opened)
// // and reset the opened state in concernement store
// this.resetConcernementOpened();
// this.$router.push({
// name: 'home',
// hash: `#${this.map_mode}`
// });
// }
// }
// }
}
},
beforeUpdate () {
},