Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / scenes / GameScene.java
package gameEngine.scenes;

import gameEngine.entites.EditorEntity;
import gameEngine.entites.Entity;
import gameEngine.entites.GameObject;
import gameEngine.entites.editorComponents.EntityView;
import gameEngine.entites.gameComponents.*;

import java.util.HashMap;

import static org.lwjgl.opengl.GL11.glClearColor;

public class GameScene extends Scene {

    public GameScene(){
        System.out.println("Active Game scene");
        glClearColor(1, 1, 1, 0);
    }

    public GameScene(HashMap<String, EditorEntity> editorEntities) {
        for(EditorEntity editorEntity : editorEntities.values()){
            if(editorEntity.getEditorComponent(EntityView.class) != null) addNewObject(editorEntity);
        }
        System.out.println("Active Game scene");
        glClearColor(1, 1, 1, 0);
    }

    public void addNewObject(EditorEntity editorObject) {
        enqueueTask(() -> addNewGameObject(editorObject));
    }


    private GameObject createGameObject(){
        int entitiesLength = entities.size();
        String newId = Integer.toString(entitiesLength);
        GameObject gameObject = new GameObject(newId);
        addEntity(newId, gameObject);
        return gameObject;
    }

    private void addNewGameObject(EditorEntity editorEntity) {
        GameObject object = createGameObject();
        object.transform.setPosition(editorEntity.transform.position.x, editorEntity.transform.position.y,0);

        for(EditorEntity.Connectiontype connectionType: editorEntity.ComponentConnections) {
            if(connectionType == EditorEntity.Connectiontype.Mesh){
                object.addComponent(new Mesh(object, Mesh.MeshType.SPRITE, "GameEngine/resources/0.png"));
            }
            if(connectionType == EditorEntity.Connectiontype.MoveImage){
                object.addComponent(new MoveImage(object));
            }
        }
    }

    @Override
    public void update(float dt) {
        changeScene(0, dt);    //Editorシーンへの以降処理
        for (Entity entity : entities.values()) {
            if (entity instanceof GameObject gameObject) {
                if(gameObject.getComponent(TextMesh.class) != null) continue;
                gameObject.updateComponents();
            }
        }
    }
}