aboutsummaryrefslogtreecommitdiffstats
path: root/Gamestates/Config.lua
blob: 26033c93cbdcf819b7df77c55c797e7887fb3b28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--[[
	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 "<KEY>: <VALUE>" 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