Compare commits

...

2 Commits

6 changed files with 156 additions and 1 deletions

View File

@@ -22,3 +22,4 @@ A dungeon crawler game made with LoveDOS for the DOSember Game Jam https://itch.
- [Concrete by Frank Baranowski](https://fontlibrary.org/en/font/concrete)
- [Nemoy by BSozoo](https://fontlibrary.org/en/font/nemoy)
- [Banana Brick by artmaker](https://fontlibrary.org/en/font/banana-brick)
- [Block Buster letters (remix) by Arvin61r58 and The Big Red Computer Club](https://openclipart.org/detail/322048/block-buster-letters-remix)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -4,6 +4,7 @@
local love = require 'love'
local game_states = require 'src.states'
local settings = require 'src.utils.settings'
local Fader = require 'src.utils.fader'
@@ -36,6 +37,9 @@ end
function love.load(args)
parse_args(args)
-- Obtain the settigns for the game.
settings:load_settings()
-- Load the assets of the intro game state.
game_states[Current_state]:load()
@@ -61,6 +65,9 @@ function love.update(dt)
if Fade.done then
game_states[Current_state]:unload(dt)
love.event.quit()
-- Save the settings before quitting just in case.
settings:load_settings()
end
else
-- If the new state exists then unload it's data and set the new state.

View File

@@ -68,7 +68,7 @@ end
function Fader:draw()
local c = 0
local c = 1
love.graphics.setColor(0, 0, 0)
for i = 0, 16 do

33
src/utils/mgclines.lua Normal file
View File

@@ -0,0 +1,33 @@
------------------------------------------------------------------------------
-- Methods
------------------------------------------------------------------------------
-- From https://stackoverflow.com/a/19327160
local function magiclines( str )
local pos
pos = 1
return function()
if not pos then return nil end
local p1, p2 = string.find( str, "\r?\n", pos )
local line
if p1 then
line = str:sub( pos, p1 - 1 )
pos = p2 + 1
else
line = str:sub( pos )
pos = nil
end
return line
end
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return magiclines

114
src/utils/settings.lua Normal file
View File

@@ -0,0 +1,114 @@
------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local love = require 'love'
local magiclines = require 'src.utils.mgclines'
------------------------------------------------------------------------------
-- Constants
------------------------------------------------------------------------------
local SETTINGS_PATH = 'settings.ini'
------------------------------------------------------------------------------
-- Module definitions
------------------------------------------------------------------------------
local settings = {
permadeath=true,
forward='w',
backward='s',
stepleft='a',
stepright='d',
turnleft='q',
turnright='e',
musicvol=75,
soundvol=100,
}
------------------------------------------------------------------------------
-- Private module methods
------------------------------------------------------------------------------
function settings:_parse_settings_str(s)
for line in magiclines(s) do
local k, v = string.match(line, '(%w+)=(.+)')
if k and v then
if self[k] ~= nil then
if v == 'true' then
if type(self[k]) ~= 'boolean' then error(string.format('Invalid value for %s in settings', k)) end
self[k] = true
elseif v == 'false' then
if type(self[k]) ~= 'boolean' then error(string.format('Invalid value for %s in settings', k)) end
self[k] = false
elseif tonumber(v) then
if type(self[k]) ~= 'number' then error(string.format('Invalid value for %s in settings', k)) end
self[k] = tonumber(v)
else
self[k] = v
end
else
error(self[k])
end
end
end
end
function settings:_get_settings_str()
local s = '[settings]\n'
for k, v in pairs(self) do
if type(v) ~= 'function' then
s = s .. string.format('%s=%s\n', k, v)
end
end
return s
end
function settings:_open_or_create()
if not love.filesystem.exists(SETTINGS_PATH) then
local setts = self:_get_settings_str()
love.filesystem.write(SETTINGS_PATH, setts)
return setts
else
if not love.filesystem.isFile(SETTINGS_PATH) then
error ("Settings path exists and isn't a file")
else
return love.filesystem.read(SETTINGS_PATH)
end
end
end
------------------------------------------------------------------------------
-- Public module methods
------------------------------------------------------------------------------
function settings:load_settings()
local s = self:_open_or_create()
self:_parse_settings_str(s)
end
function settings:save_settings()
if not love.filesystem.exists(SETTINGS_PATH) or love.filesystem.isFile(SETTINGS_PATH) then
love.filesystem.write(SETTINGS_PATH, self:_get_settings_str())
else
error("Settings path exists and isn't a file")
end
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return settings