feat: Position.tile
This commit is contained in:
parent
931a6c0e81
commit
35515f5345
|
@ -1,4 +1,29 @@
|
||||||
export default {
|
import Schema from '@/ecs/schema.js';
|
||||||
x: {type: 'float32'},
|
|
||||||
y: {type: 'float32'},
|
export default function(Component) {
|
||||||
};
|
return class Wielder extends Component {
|
||||||
|
instanceFromSchema() {
|
||||||
|
const Instance = super.instanceFromSchema();
|
||||||
|
const Component = this;
|
||||||
|
Object.defineProperty(Instance.prototype, 'tile', {
|
||||||
|
get: function () {
|
||||||
|
const {TileLayers} = Component.ecs.get(1);
|
||||||
|
const {Position: {x, y}} = Component.ecs.get(this.entity);
|
||||||
|
const {tileSize} = TileLayers.layers[0];
|
||||||
|
return {
|
||||||
|
x: (x - (x % tileSize.x)) / tileSize.x,
|
||||||
|
y: (y - (y % tileSize.y)) / tileSize.y,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
static schema = new Schema({
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
x: {type: 'float32'},
|
||||||
|
y: {type: 'float32'},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user