local Settings={}

function Settings.new()

  local parameter={["game"]={}}
  
  -- Some are still unused
  
  parameter.game.vsync={arg=1}
  parameter.game.aa={arg=1}
  parameter.game.window={arg=true}
  parameter.game.resolution={m=true,arg1=640,arg2=460}
  parameter.game.resauto={arg=false} -- ignore custom res and select the best
  parameter.game.stretch={arg=false} -- remove black borders
  parameter.game.borderless={arg=false}
  parameter.game.fullscreen={arg=false}
  
  parameter.game.bgm={arg=75}
  parameter.game.sfx={arg=100}
  
  -- Slow but elegant way to change settings

  function parameter.change(name,arg1,arg2)
    
    for i in pairs(parameter.game) do

      if i==name and parameter.game[i].m==true then
      
        parameter.game[i].arg1=arg1
        parameter.game[i].arg2=arg2
        break
      
      elseif i==name then
      
        parameter.game[i].arg=arg1
        break
      
      end
      
    end
    
    return -1
  
  end
  
  -- Resolution shits, don't touch
  
  function parameter.apply()
    
    local s
    
    if parameter.game.stretch.arg or Global.OS=="NX" then -- For the Nintendo Switch support
    
      s="stretched"
    
    else
    
      s="normal"
    
    end
    
    if parameter.game.resauto.arg then
    
      Push.setupScreen(Global.maxresx,Global.maxresy,{upscale=s})
      love.window.updateMode({minwidth=Global.maxresx/1.55,minheight=Global.maxresy/1.55,resizable=true,vsync=parameter.game.vsync.arg,borderless=parameter.game.borderless.arg,fullscreen=parameter.game.fullscreen.arg,fullscreentype="desktop"})
      Push.resize(love.graphics.getDimensions())
    
    else
    
      love.window.updateMode({minwidth=Global.maxresx/1.55,minheight=Global.maxresy/1.55,resizable=true,vsync=parameter.game.vsync.arg,borderless=parameter.game.borderless.arg,fullscreen=parameter.game.fullscreen.arg})
      Push.setupScreen(parameter.game.resolution.arg1,parameter.game.resolution.arg2,{upscale=s})
    
    end
    
    Global.scalex,Global.scaley=Push.getWidth()/(Global.maxresx/Global.scale),Push.getHeight()/(Global.maxresy/Global.scale)
  
  end
  
  -- Like the input system
  
  function parameter.savetofile(file)
  
    File.ectotoml(parameter.game,file)
  
  end
  
  function parameter.getfromfile(file)
  
    parameter.game=File.dcfromtoml(file)
  
  end
  
  return parameter

end

return Settings
