Reorganized code and assets.

This commit is contained in:
2025-10-05 15:24:48 -04:00
parent 7f8d79e00f
commit 03b5d1dafb
23 changed files with 57 additions and 23 deletions

35
src/utils/asset.lua Normal file
View File

@@ -0,0 +1,35 @@
------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local make_class = require 'src.utils.classes'
------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------
local Asset = make_class()
------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------
function Asset:_init()
end
function Asset:load()
end
function Asset:unload()
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return Asset

View File

@@ -1,112 +0,0 @@
------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local love = require 'love'
local make_class = require 'src.utils.classes'
------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------
local Fader = make_class()
------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------
function Fader:_init()
self.t = 0.0
self.step = 0
self.done = true
self.reverse = false
self.callback = nil
end
function Fader:_reset()
self.t = 0
self.step = 0
self.done = false
end
function Fader:fade_in(callback)
self:_reset()
self.reverse = true
self.callback = callback
end
function Fader:fade_out(callback)
self:_reset()
self.reverse = false
self.callback = callback
end
function Fader:update(dt)
-- While the fader is active.
if not self.done then
-- Update the internal timer.
self.t = self.t + dt
-- Advance the fade if enough time has passed.
if self.t >= 0.009 then
self.step = self.step + 1
self.t = 0.0
end
-- Mark as done when all fade tiles have been shown/hidden.
if self.step > 175 then
self.done = true
-- Execute the callback if any.
if self.callback ~= nil then
self.callback()
self.callback = nil
end
end
end
end
function Fader:draw()
local c = 1
-- Set the render color to black.
love.graphics.setColor(0, 0, 0)
-- For every fader tile.
for i = 0, 16 do
for j = 0, 10 do
-- Check if this is a fade in or fade out.
if not self.reverse then
-- If it's a fade out then draw black tiles until c.
if c <= self.step then
love.graphics.rectangle('fill', 20 * i, 20 * j, 20, 20)
end
else
-- If it's a fade in then draw black tiles with indices higher than c.
if c > self.step then
love.graphics.rectangle('fill', 20 * i, 20 * j, 20, 20)
end
end
-- Advance to the next tile to show/hide.
c = c + 1
end
end
-- Reset the render color to white.
love.graphics.setColor()
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return Fader

View File

@@ -1,106 +0,0 @@
------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local love = require 'love'
local make_class = require 'src.utils.classes'
------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------
-- SoundEffect is a simple wrapper around Löve's Source class to allow for
-- easy loading/unloading and automatically hecking if a sound effect is valid
-- before using it.
local SoundEffect = make_class()
------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------
function SoundEffect:_init(file_name)
self.file_name = file_name
end
function SoundEffect:load()
self.sfx = love.audio.newSource(self.file_name)
end
function SoundEffect:unload()
if self:isPlaying() then self:stop() end
self.sfx = nil
end
function SoundEffect:setVolume(volume)
if self.sfx ~= nil then self.sfx:setVolume(volume) end
end
function SoundEffect:setPitch(pitch)
if self.sfx ~= nil then self.sfx:setPitch(pitch) end
end
function SoundEffect:setLooping(enable)
if self.sfx ~= nil then self.sfx:setLooping(enable) end
end
function SoundEffect:getDuration()
if self.sfx ~= nil then
return self.sfx:getDuration()
else
return nil
end
end
function SoundEffect:isPlaying()
return self.sfx ~= nil and self.sfx:isPlaying()
end
function SoundEffect:isPaused()
return self.sfx ~= nil and self.sfx:isPaused()
end
function SoundEffect:isStopped()
return self.sfx ~= nil and self.sfx:isStopped()
end
function SoundEffect:tell()
if self.sfx ~= nil then
return self.sfx:tell()
else
return nil
end
end
function SoundEffect:play()
if self.sfx ~= nil then self.sfx:play() end
end
function SoundEffect:pause()
if self.sfx ~= nil then self.sfx:pause() end
end
function SoundEffect:stop()
if self.sfx ~= nil then self.sfx:stop() end
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return SoundEffect