refactoring: replaced global var opened by opened_concernement

This commit is contained in:
2023-06-26 12:26:16 +02:00
parent 36275fb9f3
commit 45cd0341fe
5 changed files with 33 additions and 28 deletions

View File

@@ -70,7 +70,7 @@ export default {
computed: {
...mapState(ConcernementsStore,['map_mode']),
...mapState(ConcernementsStore,['concernementsByID']),
...mapState(ConcernementsStore,['opened']),
...mapState(ConcernementsStore,['opened_concernement']),
...mapState(ConcernementsStore,['opened_entite_id']),
...mapState(CommonStore,['hover_elmt'])
},
@@ -136,7 +136,7 @@ export default {
map_mode: {
handler (n, o) {
console.log('watch map_mode', o, n);
if (n === 'terraindevie' && !this.opened) {
if (n === 'terraindevie' && !this.opened_concernement) {
this.applyShuffleForces(); // apply a little force to check the map when returning to terrain de vie
}
},
@@ -1545,7 +1545,7 @@ export default {
initPaperEvents(){
this.paper_objects.onMouseEnter = function(event){
if (!this.opened && this.isFocused()) { // only if no concernement is opened and is this focused
if (!this.opened_concernement && this.isFocused()) { // only if no concernement is opened and is this focused
this.setHoverElmt({
type: 'concernement',
id: this.id
@@ -1555,7 +1555,7 @@ export default {
}.bind(this);
this.paper_objects.onMouseLeave = function(event){
if (!this.opened && this.isFocused()) { // only if no concernement is opened
if (!this.opened_concernement && this.isFocused()) { // only if no concernement is opened
this.resetHoverElmt();
document.body.style.cursor = "auto";
}
@@ -1614,7 +1614,7 @@ export default {
this.paper_objects.onClick = function(event){
console.log('paper concernement onClick');
if (!this.is_opened) {
if (!this.opened) {
if (!this.opened_concernement) {
console.log(`Open me ${this.id}`);
// open/close all concernements
this.openCloseConcernements(this.id)
@@ -1651,7 +1651,7 @@ export default {
this.$router.push({
name: 'concernement',
hash: `#${this.map_mode}`,
params: {id: this.opened.id, eid: result.item.item_id}
params: {id: this.opened_concernement.id, eid: result.item.item_id}
});
} else {
// otherwise we close the entite and come back to the concernement
@@ -1760,8 +1760,8 @@ export default {
this.tween.update();
}
if (this.opened) {
if (this.opened.id !== this.id) {
if (this.opened_concernement) {
if (this.opened_concernement.id !== this.id) {
this.pushAside()
}
} else {
@@ -1786,13 +1786,19 @@ export default {
}
},
pushAside(){
// INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
// 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
let dir = this.pos.x > this.canvas.width/2 ? 1 : -1; // get the direction to the closest side
let dist = (dir < 0 ? this.pos.x : this.canvas.width - this.pos.x); // get the distance from the side
let ori_pos = {x:this.canvas.width/2, y:this.body.position.y};
// let minp = 0;
// let maxp = this.canvas.width / 2;
// let dist = (dir < 0 ? this.pos.x : this.canvas.width - this.pos.x); // get the distance from the side
let x_force = Math.pow(dist/700,100) * dir;
let ori_pos = {x:this.canvas.width/2, y:this.body.position.y};
Matter.Body.applyForce(
this.body,

View File

@@ -48,7 +48,7 @@ export default {
...mapState(ConcernementsStore,['map_mode']),
...mapState(ConcernementsStore,['concernements']),
...mapState(ConcernementsStore,['concernementsByID']),
...mapState(ConcernementsStore,['opened']),
// ...mapState(ConcernementsStore,['opened_concernement']),
...mapState(CommonStore,['hover_elmt'])
},
created() {