silphius/app/ecs-components/position.js

25 lines
697 B
JavaScript
Raw Normal View History

2024-06-26 21:08:09 -05:00
import Component from '@/ecs/component.js';
2024-06-25 06:19:57 -05:00
2024-06-26 21:08:09 -05:00
export default class Position 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,
}
2024-06-25 06:19:57 -05:00
},
});
2024-06-26 21:08:09 -05:00
return Instance;
2024-06-25 06:19:57 -05:00
}
2024-06-26 21:08:09 -05:00
static properties = {
x: {type: 'float32'},
y: {type: 'float32'},
};
2024-06-25 06:19:57 -05:00
}