19 lines
534 B
JavaScript
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'},
|
|
};
|
|
}
|