package org.hirw.game;

import lombok.Getter;
import lombok.Setter;

public class SplashScene extends Scene {
  @Getter public final SceneType SCENE_TYPE = SceneType.SPLASH;

  @Getter @Setter private Mesh screenCover;
  @Getter @Setter private FaderShader screenCoverFaderShader;
  @Getter @Setter private Mesh logo;

  public SplashScene() {
    super(SceneType.SPLASH);
  }

  public void init() {
    createScreenCover();
    createLogo();
  }

  public void update() {
    getLogo().draw();
    getScreenCoverFaderShader().update();
    getScreenCover().draw();
  }

  private void createScreenCover() {
    FaderShader faderShader = new FaderShader();
    faderShader.init();
    Mesh screenCover = new Mesh(faderShader, screenCoverRectVertices, screenCoverRectElements);
    screenCover.init();
    setScreenCoverFaderShader(faderShader);
    setScreenCover(screenCover);
  }

  private void createLogo() {
    Shader texturedShader = new Shader("assets/shaders/texture");
    texturedShader.init();
    Texture logoTexture = new Texture(225, 225, "assets/textures/plink.png");
    Texture flameTexture = new Texture(2500, 2500, "assets/textures/flames.png");
    logoTexture.init();
    flameTexture.init();
    Mesh logoMesh =
        new TexturedMesh(
            texturedShader,
            new Texture[] {logoTexture, flameTexture},
            logoRectVertices,
            screenCoverRectElements);
    logoMesh.init();
    setLogo(logoMesh);
  }

  private static final float[] screenCoverRectVertices = {
    1.0f, 1.0f, 0.0f, /*            */ 0.0f, 0.0f, 0.0f, 0.0f, // 0 Top Right
    1.0f, -1.0f, 0.0f, /*           */ 0.0f, 0.0f, 0.0f, 0.0f, // 1 Bottom Right
    -1.0f, -1.0f, 0.0f, /*          */ 0.0f, 0.0f, 0.0f, 0.0f, // 2 Bottom Left
    -1.0f, 1.0f, 0.0f, /*           */ 0.0f, 0.0f, 0.0f, 0.0f, // 3 Top Left
  };

  private static final int[] screenCoverRectElements = {
    0, 1, 3,
    1, 2, 3
  };

  private static final float[] logoRectVertices = {
    0.1f, 0.1f, 0.0f, /*       */ 0.0f, 0.0f, 0.0f, 0.0f, /*    */ 1.0f, 1.0f, //   0 Top Right
    0.1f, -0.1f, 0.0f, /*      */ 0.0f, 0.0f, 0.0f, 0.0f, /*    */ 1.0f, 0.0f, //  1 Bottom Right
    -0.1f, -0.1f, 0.0f, /*     */ 0.0f, 0.0f, 0.0f, 0.0f, /*    */ 0.0f, 0.0f, // 2 Bottom Left
    -0.1f, 0.1f, 0.0f, /*      */ 0.0f, 0.0f, 0.0f, 0.0f, /*    */ 0.0f, 1.0f, //  3 Top Left
  };
}
