Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / EditorEntity.java
NoranekoFelician 2 days ago 1 KB ・modelファイル出力を更新
package gameEngine.entites;

import gameEngine.entites.editorComponents.EditorComponent;

import java.util.ArrayList;
import java.util.List;

public class EditorEntity extends Entity {
    public final List<EditorComponent> editorComponents = new ArrayList<>();
    public enum Connectiontype {Mesh, MoveImage, Move}
    public List<Connectiontype> ComponentConnections = new ArrayList<>();

    public EditorEntity(String eid) {
        super(eid);
    }

    public void updateComponents() {
        for (EditorComponent component : editorComponents) {
            component.update();
        }
    }

    public void addEditorComponent(EditorComponent component) {
        for (EditorComponent existingComponent : editorComponents) {
            if (existingComponent.getClass().equals(component.getClass())) {
                System.out.println("Component already exists: " + component.getClass().getSimpleName());
                return;
            }
        }
        this.editorComponents.add(component);
        System.out.println("Editor Component added: " + component.getClass().getSimpleName());
    }

    public void removeEditorComponent(EditorComponent component) {
        if (editorComponents.remove(component)) {
            System.out.println("Editor Component removed: " + component.getClass().getSimpleName());
        } else {
            System.out.println("Editor Component not found: " + component.getClass().getSimpleName());
        }
    }

    public <T extends EditorComponent> T getEditorComponent(Class<T> componentClass){
        for (EditorComponent editorComponent : editorComponents) {
            if (componentClass.isInstance(editorComponent)) {
                return componentClass.cast(editorComponent);
            }
        }
        return null;
    }

}