package electrosphere.entity.types.foliage;

import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.IdleTree;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.game.collision.PhysicsUtils;
import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.data.foliage.type.FoliageType;
import electrosphere.game.data.foliage.type.PhysicsObject;
import electrosphere.main.Globals;
import electrosphere.renderer.ActorUtils;
import java.util.List;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.joml.Vector4f;

/**
 *
 * @author amaterasu
 */
public class FoliageUtils {
    
    
    public static Entity spawnBasicFoliage(String type){
        FoliageType rawType = Globals.gameConfigCurrent.getFoliageMap().getFoliage(type);
        Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
//        if(rawType.getPhysicsObjects() != null){
//            List<PhysicsObject> physicsObjects = rawType.getPhysicsObjects();
//            for(PhysicsObject physicsTemplate : physicsObjects){
//                switch(physicsTemplate.getType()){
//                    case "CYLINDER":
////                        Matrix4f rotationTransform = new Matrix4f().rotate(rotation);
////                        Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(physicsTemplate.(),physicsTemplate.getPositionY(),physicsTemplate.getPositionZ(),1.0f));
////                        Vector3f cubePosition = new Vector3f(position).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z);
////                        Quaternionf cubeRotation = new Quaternionf(rotation).mul(new Quaternionf(physicsTemplate.getRotationX(),template.getRotationY(),physicsTemplate.getRotationZ(),physicsTemplate.getRotationW())).normalize();
//                        CollisionObjUtils.attachCollisionCube(new Vector3f(1,1,1), position, rotation, rVal);
//                        break;
//                }
//            }
//        }
        for(String token : rawType.getTokens()){
            switch(token){
                case "BLENDER_TRANSFORM":
                    ActorUtils.applyBlenderTransformer(rVal);
                    break;
                case "BLENDER_ROTATION":
                    ActorUtils.applyBlenderRotation(rVal);
                    break;
                case "PARTICLE_SPAWNER":
                    
                    break;
            }
        }
        //idle tree & generic stuff all creatures have
//        rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal));
//        Globals.entityManager.registerCreatureEntity(rVal);
        rVal.putData(EntityDataStrings.FOLIAGE_IS_FOLIAGE, true);
        rVal.putData(EntityDataStrings.FOLIAGE_TYPE, type);
        return rVal;
    }
    
    
}
