package electrosphere.game.config;

import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import electrosphere.util.FileUtils;

/**
 * User-defined settings
 */
public class UserSettings {
    
    
    //
    //Gameplay settings
    //
    boolean gameplayGenerateWorld;
    int gameplayPhysicsCellRadius;
    
    
    //
    //Display settings
    //
    int displayWidth;
    int displayHeight;
    boolean displayFullscreen;
    
    
    //
    //Graphics settings
    //
    //general
    float graphicsFOV;
    //performance
    int graphicsPerformanceLODChunkRadius;
    boolean graphicsPerformanceEnableVSync;
    boolean graphicsPerformanceDrawShadows;
    boolean graphicsPerformanceOIT;
    //resolution
    int renderResolutionX;
    int renderResolutionY;
    //debug
    //debug visuals
    boolean graphicsDebugDrawCollisionSpheresClient;
    boolean graphicsDebugDrawCollisionSpheresServer;
    boolean graphicsDebugDrawPhysicsObjects;
    boolean graphicsDebugDrawMovementVectors;
    boolean graphicsDebugDrawNavmesh;
    //debug network
    boolean netRunNetMonitor;


    float graphicsViewRange;
    
    
    
    
    
    
    
    
    public boolean gameplayGenerateWorld() {
        return gameplayGenerateWorld;
    }

    public int getDisplayWidth() {
        return displayWidth;
    }

    public int getDisplayHeight() {
        return displayHeight;
    }

    public float getGraphicsFOV() {
        return graphicsFOV;
    }

    public boolean graphicsPerformanceEnableVSync() {
        return graphicsPerformanceEnableVSync;
    }

    public boolean graphicsPerformanceDrawShadows() {
        return graphicsPerformanceDrawShadows;
    }

    public boolean getGraphicsDebugDrawCollisionSpheresClient() {
        return graphicsDebugDrawCollisionSpheresClient;
    }

    public boolean getGraphicsDebugDrawCollisionSpheresServer() {
        return graphicsDebugDrawCollisionSpheresServer;
    }

    public boolean graphicsDebugDrawPhysicsObjects() {
        return graphicsDebugDrawPhysicsObjects;
    }

    public boolean graphicsDebugDrawMovementVectors() {
        return graphicsDebugDrawMovementVectors;
    }

    public int getGameplayPhysicsCellRadius() {
        return gameplayPhysicsCellRadius;
    }

    public int getGraphicsPerformanceLODChunkRadius() {
        return graphicsPerformanceLODChunkRadius;
    }

    public float getGraphicsViewDistance(){
        return graphicsViewRange;
    }

    public boolean graphicsDebugDrawNavmesh() {
        return graphicsDebugDrawNavmesh;
    }

    public boolean displayFullscreen(){
        return displayFullscreen;
    }

    public int getRenderResolutionX(){
        return renderResolutionX;
    }

    public int getRenderResolutionY(){
        return renderResolutionY;
    }

    public boolean getGraphicsPerformanceOIT(){
        return graphicsPerformanceOIT;
    }

    public boolean getNetRunNetMonitor(){
        return netRunNetMonitor;
    }
    

    public void setGraphicsDebugDrawCollisionSpheresClient(boolean draw){
        this.graphicsDebugDrawCollisionSpheresClient = draw;
    }

    public void setGraphicsDebugDrawCollisionSpheresServer(boolean draw){
        this.graphicsDebugDrawCollisionSpheresServer = draw;
    }

    public void setGraphicsDebugDrawPhysicsObjects(boolean draw){
        this.graphicsDebugDrawPhysicsObjects = draw;
    }

    public void setGraphicsDebugDrawMovementVectors(boolean draw){
        this.graphicsDebugDrawMovementVectors = draw;
    }

    public void setGraphicsDebugDrawNavmesh(boolean draw){
        this.graphicsDebugDrawNavmesh = draw;
    }

    public void setGraphicsViewRange(float range){
        graphicsViewRange = range;
    }

    public void setDisplayFullscreen(boolean fullscreen){
        this.displayFullscreen = fullscreen;
    }
    
    
    
    
    
    
    
    
    
    
    
    static UserSettings getDefault(){
        UserSettings rVal = new UserSettings();
        
        //display settings
        rVal.displayHeight = 1080;
        rVal.displayWidth = 1920;
        rVal.displayFullscreen = true;
        
        //gameplay settings
        rVal.gameplayGenerateWorld = true;
        rVal.gameplayPhysicsCellRadius = 2;
        
        //graphics settings
        rVal.graphicsDebugDrawCollisionSpheresClient = false;
        rVal.graphicsDebugDrawCollisionSpheresServer = false;
        rVal.graphicsDebugDrawMovementVectors = false;
        rVal.graphicsDebugDrawPhysicsObjects = false;
        rVal.graphicsDebugDrawNavmesh = false;
        rVal.graphicsPerformanceLODChunkRadius = 5;
        rVal.graphicsFOV = 90.0f;
        rVal.graphicsPerformanceDrawShadows = true;
        rVal.graphicsPerformanceEnableVSync = true;
        rVal.graphicsPerformanceOIT = true;
        rVal.renderResolutionX = 1920;
        rVal.renderResolutionY = 1080;

        //debug settings
        rVal.netRunNetMonitor = false;
        
        return rVal;
    }
    
    
    public static void loadUserSettings(){
        LoggerInterface.loggerStartup.INFO("Load user settings");
        Globals.userSettings = FileUtils.loadObjectFromAssetPath("/Config/settings.json", UserSettings.class);
        if(Globals.userSettings == null){
            Globals.userSettings = getDefault();
        }
        Globals.WINDOW_WIDTH = Globals.userSettings.displayWidth;
        Globals.WINDOW_HEIGHT = Globals.userSettings.displayHeight;
        Globals.verticalFOV = Globals.userSettings.graphicsFOV;
    }
    
    
    
}
