|
@@ -23,6 +23,8 @@ import MatterAttractors from "matter-attractors";
|
|
// Matter.use(MatterAttractors);
|
|
// Matter.use(MatterAttractors);
|
|
// import polydecomp from "poly-decomp";
|
|
// import polydecomp from "poly-decomp";
|
|
|
|
|
|
|
|
+import paper from 'paper';
|
|
|
|
+
|
|
// import { easeInOutQuad, easeInOutQuart } from 'easing-utils';
|
|
// import { easeInOutQuad, easeInOutQuart } from 'easing-utils';
|
|
import Tween from "@tweenjs/tween.js";
|
|
import Tween from "@tweenjs/tween.js";
|
|
|
|
|
|
@@ -47,12 +49,15 @@ export default {
|
|
time: 0,
|
|
time: 0,
|
|
salientPoints: [],
|
|
salientPoints: [],
|
|
scale: 1,
|
|
scale: 1,
|
|
|
|
+ prev_scale: 1,
|
|
opacity: 0,
|
|
opacity: 0,
|
|
tween: null,
|
|
tween: null,
|
|
body: null,
|
|
body: null,
|
|
body_parts: [],
|
|
body_parts: [],
|
|
constraint: null,
|
|
constraint: null,
|
|
- isHover: false
|
|
|
|
|
|
+ isHover: false,
|
|
|
|
+ //
|
|
|
|
+ paper_objects: {}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
props: ['concernement', 'opened'],
|
|
props: ['concernement', 'opened'],
|
|
@@ -219,11 +224,14 @@ export default {
|
|
// record canvas and ctx for rendering (drawing)
|
|
// record canvas and ctx for rendering (drawing)
|
|
this.canvas = this.canvasMap.canvas
|
|
this.canvas = this.canvasMap.canvas
|
|
this.ctx = this.canvasMap.ctx
|
|
this.ctx = this.canvasMap.ctx
|
|
|
|
+ // this.paper = this.canvasMap.paper
|
|
|
|
|
|
// define init position of the item
|
|
// define init position of the item
|
|
this.pos = this.getRandomPos();
|
|
this.pos = this.getRandomPos();
|
|
//
|
|
//
|
|
this.initMatterBody()
|
|
this.initMatterBody()
|
|
|
|
+ //
|
|
|
|
+ this.initPaperObjects()
|
|
},
|
|
},
|
|
getRandomPos(){
|
|
getRandomPos(){
|
|
let pad = 200;
|
|
let pad = 200;
|
|
@@ -386,6 +394,38 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ initPaperObjects(){
|
|
|
|
+ this.paper_objects = new paper.Group({
|
|
|
|
+ pivot: new paper.Point(this.pos)
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.paper_objects.addChild(this.setPaperContour());
|
|
|
|
+ },
|
|
|
|
+ setPaperContour(){
|
|
|
|
+ // this.paper_objects.contours = new paper.Path.Circle({
|
|
|
|
+ // center: [this.pos.x, this.pos.y],
|
|
|
|
+ // radius: this.ray,
|
|
|
|
+ // fillColor: 'red'
|
|
|
|
+ // });
|
|
|
|
+ let gap = 1;//1.15;
|
|
|
|
+ let segments = [
|
|
|
|
+ [this.pos.x+this.salientPoints[0].pos.x*this.scale*gap, this.pos.y+this.salientPoints[0].pos.y*this.scale*gap]
|
|
|
|
+ ];
|
|
|
|
+ for (let j = 1; j < this.salientPoints.length; j++) {
|
|
|
|
+ segments.push([this.pos.x+this.salientPoints[j].pos.x*this.scale*gap, this.pos.y+this.salientPoints[j].pos.y*this.scale*gap])
|
|
|
|
+ }
|
|
|
|
+ segments.push([this.pos.x+this.salientPoints[0].pos.x*this.scale*gap, this.pos.y+this.salientPoints[0].pos.y*this.scale*gap])
|
|
|
|
+
|
|
|
|
+ return new paper.Path({
|
|
|
|
+ name: 'contours',
|
|
|
|
+ segments: segments,
|
|
|
|
+ strokeColor: '#000',
|
|
|
|
+ strokeWidth: 1,
|
|
|
|
+ fillColor: 'rgba(255,255,255,0.8)',
|
|
|
|
+ pivot: new paper.Point(this.pos)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ },
|
|
openClose(open) {
|
|
openClose(open) {
|
|
// console.log(`ConcernementsMapItem ${this.concernement.id} openClose: ${open}`);
|
|
// console.log(`ConcernementsMapItem ${this.concernement.id} openClose: ${open}`);
|
|
if (this.tween) {
|
|
if (this.tween) {
|
|
@@ -404,9 +444,13 @@ export default {
|
|
// https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
// https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
// revert to the original size (by reverting the previous scale)
|
|
// revert to the original size (by reverting the previous scale)
|
|
Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
|
|
Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
|
|
|
|
+ this.paper_objects.scale(1 / this.scale);
|
|
// then scale again to new scale
|
|
// then scale again to new scale
|
|
Matter.Body.scale(this.body, obj.s, obj.s)
|
|
Matter.Body.scale(this.body, obj.s, obj.s)
|
|
|
|
+ this.paper_objects.scale(obj.s);
|
|
|
|
+
|
|
// record new scale
|
|
// record new scale
|
|
|
|
+ this.prev_scale = this.scale;
|
|
this.scale = obj.s;
|
|
this.scale = obj.s;
|
|
this.opacity = obj.o;
|
|
this.opacity = obj.o;
|
|
|
|
|
|
@@ -422,6 +466,7 @@ export default {
|
|
length: 0
|
|
length: 0
|
|
});
|
|
});
|
|
Matter.Composite.add(this.matterEngine.world, [this.body, this.constraint]);
|
|
Matter.Composite.add(this.matterEngine.world, [this.body, this.constraint]);
|
|
|
|
+ this.prev_scale = this.scale;
|
|
});
|
|
});
|
|
// recreate the matter engine event to get it a the end of the events stack
|
|
// recreate the matter engine event to get it a the end of the events stack
|
|
Matter.Events.off(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
|
|
Matter.Events.off(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
|
|
@@ -437,11 +482,18 @@ export default {
|
|
// https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
// https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
// revert to the original size (by reverting the previous scale)
|
|
// revert to the original size (by reverting the previous scale)
|
|
Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
|
|
Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
|
|
|
|
+ this.paper_objects.scale(1 / this.scale);
|
|
// then scale again to new scale
|
|
// then scale again to new scale
|
|
Matter.Body.scale(this.body, obj.s, obj.s)
|
|
Matter.Body.scale(this.body, obj.s, obj.s)
|
|
|
|
+ this.paper_objects.scale(obj.s);
|
|
|
|
+
|
|
// record new scale
|
|
// record new scale
|
|
|
|
+ this.prev_scale = this.scale;
|
|
this.scale = obj.s;
|
|
this.scale = obj.s;
|
|
this.opacity = obj.o;
|
|
this.opacity = obj.o;
|
|
|
|
+ })
|
|
|
|
+ .onComplete((obj) => {
|
|
|
|
+ this.prev_scale = this.scale = 1;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
this.tween.easing(Tween.Easing.Quadratic.InOut).start();
|
|
this.tween.easing(Tween.Easing.Quadratic.InOut).start();
|
|
@@ -506,6 +558,19 @@ export default {
|
|
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.paper_objects.position = this.pos;
|
|
|
|
+
|
|
|
|
+ // contours
|
|
|
|
+ if (!this.isFocused()){
|
|
|
|
+ this.paper_objects.children['contours'].fillColor = "rgba(255,255,255,0.3)";
|
|
|
|
+ }else{
|
|
|
|
+ this.paper_objects.children['contours'].fillColor = "rgba(255,255,255,0.8)";
|
|
|
|
+ if (this.isHover) {
|
|
|
|
+ this.paper_objects.children['contours'].strokeColor = "#01ffe2";
|
|
|
|
+ }else{
|
|
|
|
+ this.paper_objects.children['contours'].strokeColor = "#000";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
this.draw()
|
|
this.draw()
|
|
},
|
|
},
|
|
draw() {
|
|
draw() {
|
|
@@ -533,8 +598,10 @@ export default {
|
|
// contours
|
|
// contours
|
|
if (!this.opened
|
|
if (!this.opened
|
|
|| (this.opened && this.map_mode !== "puissancedagir" && this.map_mode !== "doleancer")) {
|
|
|| (this.opened && this.map_mode !== "puissancedagir" && this.map_mode !== "doleancer")) {
|
|
- this.drawContour();
|
|
|
|
- }
|
|
|
|
|
|
+ this.paper_objects.children['contours'].visible = true;
|
|
|
|
+ } else {
|
|
|
|
+ this.paper_objects.children['contours'].visible = false;
|
|
|
|
+ }
|
|
|
|
|
|
// map mode puissance d'agir
|
|
// map mode puissance d'agir
|
|
if (this.concernement.has_puissancedagir && this.map_mode === "puissancedagir") {
|
|
if (this.concernement.has_puissancedagir && this.map_mode === "puissancedagir") {
|
|
@@ -951,29 +1018,6 @@ export default {
|
|
},
|
|
},
|
|
drawContour(){
|
|
drawContour(){
|
|
if (this.salientPoints.length > 3) {
|
|
if (this.salientPoints.length > 3) {
|
|
- var fillStyle;
|
|
|
|
- let strokeStyle = "#000";
|
|
|
|
- if (!this.isFocused()){
|
|
|
|
- fillStyle = "rgba(255,255,255,0.3)";
|
|
|
|
- }else{
|
|
|
|
- fillStyle = "rgba(255,255,255,0.8)"
|
|
|
|
- if (this.isHover) {
|
|
|
|
- strokeStyle = "#01ffe2";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- this.ctx.beginPath();
|
|
|
|
- this.ctx.lineWidth = 1;
|
|
|
|
- this.ctx.strokeStyle = strokeStyle;
|
|
|
|
- this.ctx.fillStyle = fillStyle;
|
|
|
|
- let gap = 1;//1.15;
|
|
|
|
- this.ctx.moveTo(this.pos.x+this.salientPoints[0].pos.x*this.scale*gap, this.pos.y+this.salientPoints[0].pos.y*this.scale*gap)
|
|
|
|
- for (let j = 1; j < this.salientPoints.length; j++) {
|
|
|
|
- this.ctx.lineTo(this.pos.x+this.salientPoints[j].pos.x*this.scale*gap, this.pos.y+this.salientPoints[j].pos.y*this.scale*gap)
|
|
|
|
- }
|
|
|
|
- this.ctx.lineTo(this.pos.x+this.salientPoints[0].pos.x*this.scale*gap, this.pos.y+this.salientPoints[0].pos.y*this.scale*gap)
|
|
|
|
- this.ctx.fill();
|
|
|
|
- this.ctx.stroke();
|
|
|
|
-
|
|
|
|
// // test draw contour from body part
|
|
// // test draw contour from body part
|
|
// for (let i = 0; i < this.body.parts.length; i++) {
|
|
// for (let i = 0; i < this.body.parts.length; i++) {
|
|
// if (this.body.parts[i].item_type === 'concernement-contours'){
|
|
// if (this.body.parts[i].item_type === 'concernement-contours'){
|
|
@@ -1004,7 +1048,7 @@ export default {
|
|
|
|
|
|
// // }
|
|
// // }
|
|
// }
|
|
// }
|
|
- // }
|
|
|
|
|
|
+ //
|
|
}
|
|
}
|
|
},
|
|
},
|
|
isFocused(){
|
|
isFocused(){
|