import { Component, Entity } from "../core/world";
import { component } from "../utils/decorators";

@component({ variables: ['x', 'y', 'z'] })
export class Position extends Component<{ x: number, y: number, z: number }> {
    constructor(x = 0, y = 0, z = 0) {
        super({ x, y, z });
    }

    get x() {
        return this.state.x;
    }
    get y() {
        return this.state.y;
    }
    get z() {
        return this.state.z;
    }
    set x(x: number) {
        this.state.x = x;
    }
    set y(y: number) {
        this.state.y = y;
    }
    set z(z: number) {
        this.state.z = z;
    }
}

export const getPosition = (entity?: Entity, key?: string) => entity?.get(Position, key)?.state;
