fix: vector mixin was broked
This commit is contained in:
parent
0de58ff338
commit
14d07c195c
|
@ -3,7 +3,7 @@ import {Mixin, Property} from '@avocado/mixins'
|
|||
import {Vector} from '@avocado/math'
|
||||
|
||||
export function VectorMixin(
|
||||
vector = 'vector',
|
||||
vectorKey = 'vector',
|
||||
x = 'x',
|
||||
y = 'y',
|
||||
meta = {},
|
||||
|
@ -19,11 +19,13 @@ export function VectorMixin(
|
|||
return Vector.equals(l, r);
|
||||
},
|
||||
get: function() {
|
||||
return [
|
||||
this[x],
|
||||
this[y],
|
||||
];
|
||||
const vector = this[meta.transformProperty(vectorKey)];
|
||||
if (!vector) {
|
||||
return [0, 0];
|
||||
}
|
||||
return [vector[0], vector[1]];
|
||||
},
|
||||
transformProperty: (key) => `${key}_PRIVATE_PROPERTY`,
|
||||
...meta,
|
||||
};
|
||||
meta.set = meta.set || function(vector) {
|
||||
|
@ -35,28 +37,28 @@ export function VectorMixin(
|
|||
meta.emit.call(this, `${y}Changed`, this[vector][1], vector[1]);
|
||||
}
|
||||
}
|
||||
this[vector] = [vector[0], vector[1]];
|
||||
this[meta.transformProperty(vectorKey)] = [vector[0], vector[1]];
|
||||
}
|
||||
const decorate = compose(
|
||||
Property(vector, meta),
|
||||
Property(vectorKey, meta),
|
||||
);
|
||||
return (Superclass) => {
|
||||
return class Vector extends decorate(Superclass) {
|
||||
|
||||
get [x]() {
|
||||
return this[vector][0];
|
||||
return this[vectorKey][0];
|
||||
}
|
||||
|
||||
set [x](x) {
|
||||
this[vector] = [x, this[vector][1]];
|
||||
this[vectorKey] = [x, this[vectorKey][1]];
|
||||
}
|
||||
|
||||
get [y]() {
|
||||
return this[vector][1];
|
||||
return this[vectorKey][1];
|
||||
}
|
||||
|
||||
set [y](y) {
|
||||
this[vector] = [this[vector][0], y];
|
||||
this[vectorKey] = [this[vectorKey][0], y];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user