--[[ 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 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 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) end return Config