import { ResourceDescriptor, QueryDescriptor, Or, With } from 'thyseus';
import { GlobalTransform } from "@houseki-engine/scene";
import { Entity, Or, Query, Res, With } from "thyseus";
import { DynamicBody, KinematicBody, StaticBody, Velocity, } from "../../components";
import { PhysicsStore } from "../../resources";
export function moveRigidBodies(store: Res<PhysicsStore>, globalTransforms: Query<[
    Entity,
    GlobalTransform
], [
    Or<With<StaticBody>, Or<With<KinematicBody>, With<DynamicBody>>>
]>, velocities: Query<[
    Entity,
    Velocity
], [
    Or<With<StaticBody>, Or<With<KinematicBody>, With<DynamicBody>>>
]>) {
    // Set positions
    for (const [entity, globalTransform] of globalTransforms) {
        entity.deserialize();
        globalTransform.deserialize();
        const body = store.getRigidBody(entity.id);
        if (!body)
            continue;
        body.setTranslation(globalTransform.translation, true);
        entity.serialize();
        globalTransform.serialize();
    }
    // Set velocities
    for (const [entity, velocity] of velocities) {
        entity.deserialize();
        velocity.deserialize();
        const body = store.getRigidBody(entity.id);
        if (!body)
            continue;
        body.setLinvel(velocity, true);
        entity.serialize();
        velocity.serialize();
    }
}
moveRigidBodies.parameters = [new ResourceDescriptor(PhysicsStore), new QueryDescriptor([Entity, GlobalTransform], [new Or(new With(StaticBody), new Or(new With(KinematicBody), new With(DynamicBody)))]), new QueryDescriptor([Entity, Velocity], [new Or(new With(StaticBody), new Or(new With(KinematicBody), new With(DynamicBody)))])];
