|
@@ -19,10 +19,10 @@
|
|
// } from "matter-js";
|
|
// } from "matter-js";
|
|
|
|
|
|
import Matter from "matter-js";
|
|
import Matter from "matter-js";
|
|
-
|
|
|
|
import MatterAttractors from "matter-attractors";
|
|
import MatterAttractors from "matter-attractors";
|
|
// Matter.use(MatterAttractors);
|
|
// Matter.use(MatterAttractors);
|
|
|
|
|
|
|
|
+import { easeInOutQuad, easeInOutQuart } from 'easing-utils';
|
|
|
|
|
|
import { mapState, mapActions } from 'pinia'
|
|
import { mapState, mapActions } from 'pinia'
|
|
import { ConcernementsStore } from '@/stores/concernements'
|
|
import { ConcernementsStore } from '@/stores/concernements'
|
|
@@ -42,12 +42,12 @@ export default {
|
|
time: 0,
|
|
time: 0,
|
|
salientPoints: [],
|
|
salientPoints: [],
|
|
scale: 1,
|
|
scale: 1,
|
|
- oldScale: 1,
|
|
|
|
|
|
+ anim: null,
|
|
// matter
|
|
// matter
|
|
body: null
|
|
body: null
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- props: ['concernement'],
|
|
|
|
|
|
+ props: ['concernement', 'opened'],
|
|
computed: {
|
|
computed: {
|
|
...mapState(ConcernementsStore,['concernementsByID'])
|
|
...mapState(ConcernementsStore,['concernementsByID'])
|
|
},
|
|
},
|
|
@@ -75,6 +75,29 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
deep: true
|
|
deep: true
|
|
|
|
+ },
|
|
|
|
+ opened: {
|
|
|
|
+ handler (n, o) {
|
|
|
|
+ if(n){
|
|
|
|
+ // opened
|
|
|
|
+ this.anim = {
|
|
|
|
+ init: this.scale,
|
|
|
|
+ target: 5, //target scale
|
|
|
|
+ start: Date.now(),
|
|
|
|
+ duration: 1000 // ms
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ // closed
|
|
|
|
+ this.anim = {
|
|
|
|
+ init: this.scale,
|
|
|
|
+ target: 1, //target scale
|
|
|
|
+ start: Date.now(),
|
|
|
|
+ duration: 1000 // ms
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log(`watch opened ${this.concernement.id}`, n, o, this.anim);
|
|
|
|
+ },
|
|
|
|
+ deep: true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -117,12 +140,13 @@ export default {
|
|
});
|
|
});
|
|
// console.log('concernementItem mass', this.body.mass);
|
|
// console.log('concernementItem mass', this.body.mass);
|
|
Matter.Composite.add(this.matterEngine.world, this.body);
|
|
Matter.Composite.add(this.matterEngine.world, this.body);
|
|
|
|
+ console.log('concernement body', this.body);
|
|
}
|
|
}
|
|
|
|
|
|
// // listen for animate event dispatched from parent
|
|
// // listen for animate event dispatched from parent
|
|
// this.canvas.addEventListener('animate', this.animate)
|
|
// this.canvas.addEventListener('animate', this.animate)
|
|
// listen for afterUpdate event from Matter.Engine object
|
|
// listen for afterUpdate event from Matter.Engine object
|
|
- Matter.Events.on(this.matterEngine, "afterUpdate", this.animate)
|
|
|
|
|
|
+ Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate)
|
|
},
|
|
},
|
|
parsePoints (){
|
|
parsePoints (){
|
|
// converts data (menace/maintien, actuel/future, prise) into atcual position x,y
|
|
// converts data (menace/maintien, actuel/future, prise) into atcual position x,y
|
|
@@ -187,29 +211,48 @@ export default {
|
|
}
|
|
}
|
|
// console.log(`this.salientPoints ${this.concernement.id}`, this.salientPoints);
|
|
// console.log(`this.salientPoints ${this.concernement.id}`, this.salientPoints);
|
|
},
|
|
},
|
|
- animate (event) {
|
|
|
|
- if (this.ctx) {
|
|
|
|
- this.pos = this.body.position;
|
|
|
|
|
|
+ scaleBody(scale){
|
|
|
|
+ // scale vertices
|
|
|
|
+ Matter.Vertices.scale(this.body.parts[0].vertices, scale, scale);
|
|
|
|
+ // update properties
|
|
|
|
+ // this.body.parts[0].axes = Matter.Axes.fromVertices(this.body.parts[0].vertices);
|
|
|
|
+ // update bounds
|
|
|
|
+ // Matter.Bounds.update(this.body.parts[0].bounds, this.body.parts[0].vertices, this.body.velocity);
|
|
|
|
+ this.body.circleRadius *= scale;
|
|
|
|
+ },
|
|
|
|
+ onAfterEngineUpdate (event) {
|
|
|
|
+
|
|
|
|
+ if (this.anim) {
|
|
|
|
+ let time = Date.now() - this.anim.start; // get time elapsed since anime start
|
|
|
|
+ if (time <= this.anim.duration) {
|
|
|
|
+ let ease = easeInOutQuart(time / this.anim.duration); // get the easing factor
|
|
|
|
+ let scale = this.anim.init < this.anim.target
|
|
|
|
+ ? this.anim.init + this.anim.target * ease
|
|
|
|
+ : this.anim.init + (this.anim.target - this.anim.init) * ease; // get the current eased scale
|
|
|
|
+ // // https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
|
|
+ // // revert to the original size (by reverting the previous scale)
|
|
|
|
+ Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
|
|
|
|
+ // this.scaleBody(1 / this.scale)
|
|
|
|
+ // // then scale again to new scale
|
|
|
|
+ Matter.Body.scale(this.body, scale, scale)
|
|
|
|
+ // this.scaleBody(scale);
|
|
|
|
+ // record new scale
|
|
|
|
+ this.scale = scale;
|
|
|
|
+ }else{
|
|
|
|
+ this.anim = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
},
|
|
},
|
|
render() {
|
|
render() {
|
|
// console.log('render()', this.ctx);
|
|
// console.log('render()', this.ctx);
|
|
-
|
|
|
|
|
|
+
|
|
if (!this.ctx) return;
|
|
if (!this.ctx) return;
|
|
|
|
|
|
- this.scale = this.concernement.opened ? 5 : 1;
|
|
|
|
-
|
|
|
|
- if (this.scale !== this.oldScale) {
|
|
|
|
- // https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
|
|
|
|
- // revert to the original size (by reverting the previous scale)
|
|
|
|
- Matter.Body.scale(this.body, 1 / this.oldScale, 1 / this.oldScale)
|
|
|
|
- // then scale again
|
|
|
|
- Matter.Body.scale(this.body, this.scale, this.scale)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ this.pos = this.body.position;
|
|
|
|
+
|
|
// exterieur circle
|
|
// exterieur circle
|
|
this.ctx.beginPath();
|
|
this.ctx.beginPath();
|
|
this.ctx.lineWidth = 0.5;
|
|
this.ctx.lineWidth = 0.5;
|
|
@@ -256,8 +299,8 @@ export default {
|
|
this.ctx.fillStyle = "#000";
|
|
this.ctx.fillStyle = "#000";
|
|
this.ctx.fillText(this.concernement.id, this.pos.x, this.pos.y)
|
|
this.ctx.fillText(this.concernement.id, this.pos.x, this.pos.y)
|
|
this.ctx.fill();
|
|
this.ctx.fill();
|
|
-
|
|
|
|
- this.oldScale = this.scale;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|