--[[ Gamestates/Config.lua User defined configuration by piernov Comment: currently only used for player_name, but maybe allowing other parameters like sound or display settings will be implemented. A similar file could be used to implement an "High score" feature. ]]-- Config = {} Config.player_name = {} local Gui = require "Quickie" local Utils = require "Utils" function Config:loadUserConfig() -- Load user config file if not love.filesystem.exists("userConfig") then love.filesystem.write( "userConfig", "") -- Create the save file if it doesn't exists else for line in love.filesystem.lines("userConfig") do -- Read line by line var, arg = line:match("(.*): (.*)") -- Split following the ": " schema if var == "PLAYERNAME" then Config.player_name.text = arg -- Handle player_name end end end if not Config.player_name.text then Config.player_name.text = "BlueMind" -- Set default player_name if nothing was found in the user config file end if not Config.Mute then Config.Mute = false end end function Config:enter() Previous = "Gamestates/Menu" end function Config:update(dt) Gui.group.push{grow = "down", pos = {Utils.percentCoordinates(20, 20)}} Gui.Label{text = "Player name", size = {Utils.percentCoordinates(10, 10)}} Gui.Input{info = Config.player_name, size = {Utils.percentCoordinates(50, 10)}} if Gui.Button{text = "Save", size = {Utils.percentCoordinates(60, 10)}} then love.filesystem.write( "userConfig", "PLAYERNAME: " .. Config.player_name.text) -- Write the new name to the config file end if Config.Mute == false then if Gui.Button{text = "Mute", size = {Utils.percentCoordinates(40, 10)}} then Config.Mute = true Menu.Music:stop() end else if Gui.Button{text = "Unmute", size = {Utils.percentCoordinates(40, 10)}} then Config.Mute = false Menu.Music:play() end end if love.system.getOS() ~= "Android" then if Gui.Button{text = "Fullscreen", size = {Utils.percentCoordinates(40, 10)}} then if Config.Fullscreen == true then love.window.setFullscreen(false, "desktop") Config.Fullscreen = false else Config.Fullscreen = true love.window.setFullscreen(true, "desktop") end end end Gui.group.pop{} end -- Quickie's functions function Config:draw() Gui.core.draw() end function Config:keypressed(key, code) Gui.keyboard.pressed(key) end function love.textinput(str) Gui.keyboard.textinput(str) end -- End function Config:leave() love.keyboard.setTextInput(false) Menu.Music:stop() end return Config