import ScillaComponent from 'components/base/ScillaComponent';
import { Transform, TextRenderer } from 'scilla-components/src';
import { Entity } from 'scilla/src';

export const setX = (entity: Entity, x) => {
    entity.getComponent(Transform).position.x = x;
}
export const setRotation = (entity: Entity, x) => {
    entity.getComponent(Transform).rotation=x;
}
export const getRotation = (entity: Entity) => {
    return entity.getComponent(Transform).rotation
}

export const setAlpha = (val: Entity | ScillaComponent, alpha: number) => {
    if (val instanceof Entity) {
        val.getComponent(Transform).alpha = alpha;
    } else if (val instanceof ScillaComponent) {
        val.entity.getComponent(Transform).alpha = alpha;
    }
}

export const setScale = (val: Entity | ScillaComponent, sacle) => {
    if (val instanceof Entity) {
        val.getComponent(Transform).scale.x = sacle;
        val.getComponent(Transform).scale.y = sacle;
    }
    else if (val instanceof ScillaComponent) {
        val.entity.getComponent(Transform).scale.x = sacle;
        val.entity.getComponent(Transform).scale.y = sacle;
    }
}

export const setText = (entity: Entity, text: string) => {
    entity.getComponent(TextRenderer).text = text + '';
}

export const getScale = (val: Entity | ScillaComponent) => {
    if (val instanceof Entity) {
        return val.getComponent(Transform).scale;
    }
    else if (val instanceof ScillaComponent) {
        return val.getComponent(Transform).scale;
    }
}

export const setY = (entity: Entity, y) => {
    entity.getComponent(Transform).position.y = y;
}
export const getX = (val: Entity | ScillaComponent) => {
    let entity: Entity;
    if (val instanceof Entity)
        entity = val;
    else
        entity = val.entity;
    return entity.getComponent(Transform).position.x
}

export const getY = (val: Entity | ScillaComponent) => {
    let entity: Entity;
    if (val instanceof Entity)
        entity = val;
    else
        entity = val.entity;
    return entity.getComponent(Transform).position.y
}

export const setXY = (val: Entity | ScillaComponent, x, y) => {
    let entity: Entity;
    if (val instanceof Entity)
        entity = val;
    else
        entity = val.entity;
    setX(entity, x);
    setY(entity, y);
}