silphius/app/ecs/components/direction.js

19 lines
534 B
JavaScript
Raw Normal View History

2024-06-26 21:08:09 -05:00
import Component from '@/ecs/component.js';
2024-07-24 09:28:35 -05:00
import {HALF_PI, TAU} from '@/util/math.js';
2024-06-26 21:08:09 -05:00
export default class Direction extends Component {
2024-07-24 09:28:35 -05:00
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);
}
};
}
2024-06-26 21:08:09 -05:00
static properties = {
2024-07-24 09:28:35 -05:00
direction: {defaultValue: HALF_PI, type: 'float32'},
2024-06-26 21:08:09 -05:00
};
}