rewrite all COMPLETELY because im suck at this shit fr 🥀🥀🥀

This commit is contained in:
neckrat 2026-01-16 14:28:56 +03:00
parent 28b0384285
commit 4883cc0e0c
14 changed files with 101 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,32 @@
--- @class Audio
--- @field musicVolume number
--- @field soundVolume number
audio = {}
audio.__index = audio
local function new(musicVolume, soundVolume) -- здесь мы должны выгружать значения из файлика с сохранением настроек
return setmetatable({
musicVolume = musicVolume,
soundVolume = soundVolume
}, audio)
end
--- @param source love.Source
function audio:play(source)
if source:getType() == "static" then
source:setVolume(self.musicVolume)
return source:play()
end
source:setVolume(self.soundVolume)
return source:play()
end
function audio:setMusicVolume(volume)
self.musicVolume = volume
end
function audio:setSoundVolume(volume)
self.soundVolume = volume
end
return { new = new }

52
lib/music.lua Normal file
View File

@ -0,0 +1,52 @@
-- --- @class Music
-- --- @field source table<string, love.Source> audio streams, that supports multitrack (kind of)
-- --- @field offset number
-- music = {}
-- music.__index = music
-- --- @param path string accepts path to dir with some music files (example: "main_ambient"; "player/theme1" and etc etc)
-- local function new(path)
-- local dir = Tree.assets.files.audio.music[path]
-- --- @type table<string, love.Source>
-- local source = {}
-- print(dir)
-- for _, v in pairs(dir) do
-- print(v.filename)
-- source[v.filename] = v.source
-- print(v.filename)
-- end
-- print('[music]: new source: ', table.concat(source, ' '))
-- return setmetatable({ source = source, offset = 0 }, music)
-- end
-- function music:update()
-- for _, v in ipairs(self.source) do
-- v:seek()
-- end
-- end
-- --- pause stemfile or music at all
-- --- @param filename? string
-- function music:pause(filename)
-- if filename then
-- self.source[filename]:pause()
-- else
-- for _, v in pairs(self.source) do
-- v:pause()
-- end
-- end
-- end
-- --- play music stemfile by his name
-- --- @param filename string
-- --- @return boolean
-- function music:play(filename)
-- print('[music]: ', table.concat(self.source, ' '))
-- self.source[filename]:seek(self.offset, "seconds")
-- return self.source[filename]:play()
-- end
-- return { new = new }

9
lib/sound.lua Normal file
View File

@ -0,0 +1,9 @@
-- --- @class Sound
-- --- @field source love.Source just a sound
-- sound = {}
-- local function new()
-- return setmetatable({}, sound)
-- end
-- return { new }

View File

@ -144,7 +144,8 @@ function attack:cast(caster, target)
AnimationNode {
function(node)
targetSprite:animate("hurt", node)
Tree.assets.files.audio.sounds.hurt:play()
-- Tree.assets.files.audio.sounds.hurt:play()
Tree.audio:play(Tree.assets.files.audio.sounds.hurt)
end
}
}

View File

@ -11,6 +11,7 @@ Tree.controls = require "lib.controls"
Tree.level = (require "lib.level.level").new("procedural", "flower_plains") -- для теста у нас только один уровень, который сразу же загружен
Tree.behaviors = (require "lib.utils.behavior_loader")("lib/character/behaviors") --- @todo написать нормальную загрузку поведений
Tree.audio = (require "lib.audio").new(1, 1)
-- Tree.behaviors.map = require "lib.character.behaviors.map"
-- Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
-- Tree.behaviors.sprite = require "lib.character.behaviors.sprite"

View File

@ -50,9 +50,9 @@ function AssetBundle.loadFile(path)
return love.graphics.newShader(path);
elseif (ext == "lua") then
return require(string.gsub(path, ".lua", ""))
elseif (ext == "mp3") and string.find(path, "sounds") then
elseif (ext == "ogg") and string.find(path, "sounds") then
return love.audio.newSource(path, 'static')
elseif (ext == "mp3") and string.find(path, "music") then
elseif (ext == "ogg") and string.find(path, "music") then
return love.audio.newSource(path, 'stream')
end
return nil

View File

@ -19,6 +19,9 @@ function love.load()
Tree.level.turnOrder:endRound()
print("Now playing:", Tree.level.turnOrder.current)
love.window.setMode(1080, 720, { resizable = true, msaa = 4, vsync = true })
-- Level1_music = (require "lib.music").new("level1/bass")
-- Level1_music:play("bass")
end
local lt = "0"