silphius/app/ecs/components/direction.js
2024-07-24 09:28:35 -05:00

19 lines
534 B
JavaScript

import Component from '@/ecs/component.js';
import {HALF_PI, TAU} from '@/util/math.js';
export default class Direction extends Component {
instanceFromSchema() {
return class DirectionInstance extends super.instanceFromSchema() {
static quantize(d, n) {
return Math.floor(((d + (TAU / (n * 2))) % TAU) / (TAU / n));
}
quantize(n) {
return this.constructor.quantize(this.direction, n);
}
};
}
static properties = {
direction: {defaultValue: HALF_PI, type: 'float32'},
};
}