diff --git a/sonic-radiance.love/core/debug.lua b/sonic-radiance.love/core/debug.lua index 9a85811..fe6076d 100644 --- a/sonic-radiance.love/core/debug.lua +++ b/sonic-radiance.love/core/debug.lua @@ -23,7 +23,8 @@ local DebugSystem = Object:extend() -local lovebird = require("libs.lovebird") +local cwd = (...):gsub('%.debug$', '') .. "." +local lovebird = require(cwd .. "libs.lovebird") function DebugSystem:new(controller, active) self.controller = controller diff --git a/sonic-radiance.love/core/init.lua b/sonic-radiance.love/core/init.lua index 63bba08..101f49c 100644 --- a/sonic-radiance.love/core/init.lua +++ b/sonic-radiance.love/core/init.lua @@ -23,15 +23,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] +local cwd = (...):gsub('%.init$', '') .. "." + +-- GLOBAL UTILS/FUNCTION LOADING +-- Load in the global namespace utilities that'll need to be reusable everywhere +-- in the game + +Object = require(cwd .. "libs.classic") +utils = require(cwd .. "utils") + local CoreSystem = Object:extend() -local DebugSystem = require "core.debug" +local DebugSystem = require(cwd .. "debug") -local Options = require "core.options" -local Input = require "core.input" -local Screen = require "core.screen" -local Lang = require "core.lang" -local SceneManager= require "core.scenemanager" +local Options = require(cwd .. "options") +local Input = require(cwd .. "input") +local Screen = require(cwd .. "screen") +local Lang = require(cwd .. "lang") +local SceneManager = require(cwd .. "scenemanager") function CoreSystem:new() self.debug = DebugSystem(self) diff --git a/sonic-radiance.love/core/input.lua b/sonic-radiance.love/core/input.lua index 7513d25..578c05b 100644 --- a/sonic-radiance.love/core/input.lua +++ b/sonic-radiance.love/core/input.lua @@ -26,7 +26,7 @@ local InputManager = Object:extend() function InputManager:new(controller) self.controller = controller - self.data = self.controller.options.data.input[1] + self.data = self.controller.options:getPlayerInputData(1) self.keys = self:getKeyList() self.fakekeys = self:getKeyList() diff --git a/sonic-radiance.love/core/lang.lua b/sonic-radiance.love/core/lang.lua index 1144806..6c6a69f 100644 --- a/sonic-radiance.love/core/lang.lua +++ b/sonic-radiance.love/core/lang.lua @@ -23,11 +23,22 @@ ]] local LanguageManager = Object:extend() -local langs = require "datas.languages" function LanguageManager:new(controller) self.controller = controller self:setLang(self.controller.options.data.language) + self:getTranslationData() +end + +function LanguageManager:getTranslationData() + local _path = "datas/languages/init.lua" + local fileinfo = love.filesystem.getInfo(_path) + + if fileinfo ~= nil then + self.datas = require "datas.languages" + else + self.datas = nil + end end function LanguageManager:getStringList(library, file) diff --git a/sonic-radiance.love/libs/binser.lua b/sonic-radiance.love/core/libs/binser.lua similarity index 100% rename from sonic-radiance.love/libs/binser.lua rename to sonic-radiance.love/core/libs/binser.lua diff --git a/sonic-radiance.love/libs/classic.lua b/sonic-radiance.love/core/libs/classic.lua similarity index 100% rename from sonic-radiance.love/libs/classic.lua rename to sonic-radiance.love/core/libs/classic.lua diff --git a/sonic-radiance.love/libs/cscreen.lua b/sonic-radiance.love/core/libs/cscreen.lua similarity index 100% rename from sonic-radiance.love/libs/cscreen.lua rename to sonic-radiance.love/core/libs/cscreen.lua diff --git a/sonic-radiance.love/libs/lovebird.lua b/sonic-radiance.love/core/libs/lovebird.lua similarity index 100% rename from sonic-radiance.love/libs/lovebird.lua rename to sonic-radiance.love/core/libs/lovebird.lua diff --git a/sonic-radiance.love/core/modules/assets/animator.lua b/sonic-radiance.love/core/modules/assets/animator.lua index 7bce90c..716263c 100644 --- a/sonic-radiance.love/core/modules/assets/animator.lua +++ b/sonic-radiance.love/core/modules/assets/animator.lua @@ -77,6 +77,10 @@ function Animator:draw(x, y, r, sx, sy, ox, oy, kx, ky) self.sprite:drawFrame(self.frame, x, y, r, sx, sy, ox, oy, kx, ky) end +function Animator:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) + self.sprite:drawFrameMask(self.frame, x, y, r, sx, sy, ox, oy, kx, ky) +end + function Animator:changeAnimation(name, restart) -- Force restart if animation name is different if (self.currentAnimation ~= name) then diff --git a/sonic-radiance.love/core/modules/assets/autotile.lua b/sonic-radiance.love/core/modules/assets/autotile.lua index 4104303..0cfaf6d 100644 --- a/sonic-radiance.love/core/modules/assets/autotile.lua +++ b/sonic-radiance.love/core/modules/assets/autotile.lua @@ -23,7 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -local Tileset = require "core.modules.assets.tileset" +local cwd = (...):gsub('%.autotile$', '') .. "." +local Tileset = require(cwd .. "tileset") local Autotile = Object:extend() function Autotile:new(filepath) diff --git a/sonic-radiance.love/core/modules/assets/imagefonts.lua b/sonic-radiance.love/core/modules/assets/imagefonts.lua index 16e0b7a..3cf2c1b 100644 --- a/sonic-radiance.love/core/modules/assets/imagefonts.lua +++ b/sonic-radiance.love/core/modules/assets/imagefonts.lua @@ -1,4 +1,5 @@ -local Font = require "core.modules.assets.fonts" +local cwd = (...):gsub('%.imagefonts$', '') .. "." +local Font = require(cwd.. "fonts") local ImageFont = Font:extend() function ImageFont:new(filename, extraspacing) diff --git a/sonic-radiance.love/core/modules/assets/init.lua b/sonic-radiance.love/core/modules/assets/init.lua index b6e11dc..5fe379f 100644 --- a/sonic-radiance.love/core/modules/assets/init.lua +++ b/sonic-radiance.love/core/modules/assets/init.lua @@ -24,13 +24,17 @@ local Assets = Object:extend() -local Sprite = require "core.modules.assets.sprites" -local Font = require "core.modules.assets.fonts" -local ImageFont = require "core.modules.assets.imagefonts" +local cwd = (...):gsub('%.init$', '') .. "." -local Tileset = require "core.modules.assets.tileset" -local Autotile = require "core.modules.assets.autotile" -local Background = require "core.modules.assets.background" +local Texture = require(cwd .. "texture") + +local Sprite = require(cwd .. "sprites") +local Font = require(cwd .. "fonts") +local ImageFont = require(cwd .. "imagefonts") + +local Tileset = require(cwd .. "tileset") +local Autotile = require(cwd .. "autotile") +local Background = require(cwd .. "background") function Assets:new() @@ -121,11 +125,11 @@ end -- Background -- function Assets:addImage(name, filename) - self.images[name] = love.graphics.newImage(filename) + self.images[name] = Texture(filename) end function Assets:drawImage(name, x, y, r, sx, sy, ox, oy, kx, ky) - love.graphics.draw(self.images[name], x, y, r, sx, sy, ox, oy, kx, ky) + self.images[name]:draw(x, y, r, sx, sy, ox, oy, kx, ky) end -- Images -- diff --git a/sonic-radiance.love/core/modules/assets/sprites.lua b/sonic-radiance.love/core/modules/assets/sprites.lua index 326db34..0749b63 100644 --- a/sonic-radiance.love/core/modules/assets/sprites.lua +++ b/sonic-radiance.love/core/modules/assets/sprites.lua @@ -24,8 +24,10 @@ ]] local Sprite = Object:extend() -local Animator = require("core.modules.assets.animator") -local Tileset = require("core.modules.assets.tileset") +local cwd = (...):gsub('%.sprites$', '') .. "." + +local Animator = require(cwd .. "animator") +local Tileset = require(cwd .. "tileset") function Sprite:new(filepath) self.tileset = Tileset(filepath) @@ -66,10 +68,18 @@ function Sprite:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky) self.animator:draw(x, y, r, sx, sy, ox, oy, kx, ky) end +function Sprite:drawAnimationMask(x, y, r, sx, sy, ox, oy, kx, ky) + self.animator:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) +end + function Sprite:drawFrame(frame, x, y, r, sx, sy, ox, oy, kx, ky) self.tileset:drawTile(frame, x, y, r, sx, sy, ox, oy, kx, ky) end +function Sprite:drawFrameMask(frame, x, y, r, sx, sy, ox, oy, kx, ky) + self.tileset:drawTileMask(frame, x, y, r, sx, sy, ox, oy, kx, ky) +end + function Sprite:drawPart(x, y, w, h, r, sx, sy, ox, oy, kx, ky) local w = math.floor(w) local h = math.floor(h) diff --git a/sonic-radiance.love/core/modules/assets/texture.lua b/sonic-radiance.love/core/modules/assets/texture.lua new file mode 100644 index 0000000..63313d9 --- /dev/null +++ b/sonic-radiance.love/core/modules/assets/texture.lua @@ -0,0 +1,65 @@ +-- assets/texture :: the texture object, essentially used to be able to draw easily +-- the mask of the texture (used for stuff like flashing sprite, etc) + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + + +local Texture = Object:extend() + +local function getMask(x, y, r, g, b, a) + -- template for defining your own pixel mapping function + -- perform computations giving the new values for r, g, b and a + -- ... + return 1, 1, 1, a +end + +function Texture:new(filename) + self.imageData = love.image.newImageData(filename) + + local maskData = self.imageData:clone() + maskData:mapPixel( getMask ) + + self.image = love.graphics.newImage( self.imageData ) + self.mask = love.graphics.newImage( maskData ) +end + +function Texture:getDimensions() + return self.image:getDimensions() +end + +function Texture:draw(x, y, r, sx, sy, ox, oy, kx, ky) + love.graphics.draw(self.image, x, y, r, sx, sy, ox, oy, kx, ky) +end + +function Texture:drawQuad(quad, x, y, r, sx, sy, ox, oy, kx, ky) + love.graphics.draw(self.image, quad, x, y, r, sx, sy, ox, oy, kx, ky) +end + +function Texture:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) + love.graphics.draw(self.mask, x, y, r, sx, sy, ox, oy, kx, ky) +end + +function Texture:drawMaskQuad(quad, x, y, r, sx, sy, ox, oy, kx, ky) + love.graphics.draw(self.mask, quad, x, y, r, sx, sy, ox, oy, kx, ky) +end + +return Texture diff --git a/sonic-radiance.love/core/modules/assets/tileset.lua b/sonic-radiance.love/core/modules/assets/tileset.lua index c86aa44..40ae249 100644 --- a/sonic-radiance.love/core/modules/assets/tileset.lua +++ b/sonic-radiance.love/core/modules/assets/tileset.lua @@ -27,9 +27,12 @@ ]] local Tileset = Object:extend() +local cwd = (...):gsub('%.tileset$', '') .. "." + +local Texture = require(cwd .. "texture") function Tileset:new(filepath) - self.texture = love.graphics.newImage(filepath .. ".png") + self.texture = Texture(filepath .. ".png") local data = require(filepath) self.metadata = data.metadata @@ -79,11 +82,21 @@ end function Tileset:drawTile_Grid(i, j, x, y, r, sx, sy, ox, oy, kx, ky) local tileID = self:getTileID_Grid(i, j) - love.graphics.draw(self.texture, self.quads[tileID], x, y, r, sx, sy, ox, oy, kx, ky) + self.texture:drawQuad(self.quads[tileID], x, y, r, sx, sy, ox, oy, kx, ky) end function Tileset:drawTile(id, x, y, r, sx, sy, ox, oy, kx, ky) - love.graphics.draw(self.texture, self.quads[id], x, y, r, sx, sy, ox, oy, kx, ky) + self.texture:drawQuad(self.quads[id], x, y, r, sx, sy, ox, oy, kx, ky) end +function Tileset:drawTileMask_Grid(i, j, x, y, r, sx, sy, ox, oy, kx, ky) + local tileID = self:getTileID_Grid(i, j) + self.texture:drawMaskQuad(self.quads[tileID], x, y, r, sx, sy, ox, oy, kx, ky) +end + +function Tileset:drawTileMask(id, x, y, r, sx, sy, ox, oy, kx, ky) + self.texture:drawMaskQuad(self.quads[id], x, y, r, sx, sy, ox, oy, kx, ky) +end + + return Tileset diff --git a/sonic-radiance.love/core/modules/menusystem/init.lua b/sonic-radiance.love/core/modules/menusystem/init.lua index db5ee4d..6078277 100644 --- a/sonic-radiance.love/core/modules/menusystem/init.lua +++ b/sonic-radiance.love/core/modules/menusystem/init.lua @@ -46,9 +46,22 @@ function MenuSystem:update(dt) end +function MenuSystem:switchMenu(menu) + for k,v in pairs(self.menus) do + if k == menu then + v:getFocus() + v:setVisibility(true) + v.isActive = true + else + v:setVisibility(false) + v.isActive = false + end + end +end + function MenuSystem:setAllMenuVisibility(visibility) for k,v in pairs(self.menus) do - v.isVisible = visibility + v:setVisibility(visibility) end end @@ -93,10 +106,26 @@ function MenuSystem:mousepressed( x, y, button, istouch ) end end -function MenuSystem:draw(dt) -- On dessine les entitées +function MenuSystem:getDrawList() + local drawList = {} for k,v in pairs(self.menus) do - if (v.isVisible) then - v:draw(dt) + local drawObject = {} + drawObject.name = k + drawObject.depth = v.depth + table.insert(drawList, drawObject) + end + table.sort(drawList, function(a,b) return a.depth > b.depth end) + + return drawList +end + +function MenuSystem:draw(dt) -- On dessine les entitées + self.drawList = self:getDrawList() + + for i,v in ipairs(self.drawList) do + local v2 = self.menus[v.name] + if (v2.isVisible) then + v2:draw(dt) end end diff --git a/sonic-radiance.love/core/modules/menusystem/parent.lua b/sonic-radiance.love/core/modules/menusystem/parent.lua index a6bb2a5..b9f6135 100644 --- a/sonic-radiance.love/core/modules/menusystem/parent.lua +++ b/sonic-radiance.love/core/modules/menusystem/parent.lua @@ -19,6 +19,9 @@ function Menu:new(menusystem, name, x, y, w, h) self.isDestroyed = false self.isVisible = true self.isActive = true + self.isLocked = false + + self.depth = 0 self.sound = {} self.sound.asset = nil @@ -27,6 +30,18 @@ function Menu:new(menusystem, name, x, y, w, h) self:register() end +function Menu:setDepth(depth) + self.depth = depth or 0 +end + +function Menu:setVisibility(visibility) + if self.isLocked == false then + self.isVisible = visibility + else + self.isVisible = true + end +end + function Menu:getFocus() self.menusystem.focusedMenu = self.name end diff --git a/sonic-radiance.love/core/modules/scenes.lua b/sonic-radiance.love/core/modules/scenes.lua index c87f29e..60f378c 100644 --- a/sonic-radiance.love/core/modules/scenes.lua +++ b/sonic-radiance.love/core/modules/scenes.lua @@ -22,9 +22,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] +local cwd = (...):gsub('%.scenes$', '') .. "." + local Scene = Object:extend() -local Assets = require "core.modules.assets" -local MenuSystem = require "core.modules.menusystem" +local Assets = require(cwd .. "assets") +local MenuSystem = require(cwd .. "menusystem") function Scene:new() self.mouse = {} @@ -33,10 +35,12 @@ function Scene:new() self.assets = Assets() self.menusystem = MenuSystem() self.keys = core.input:getKeyList() + + self:register() end function Scene:register() - core.scenemanager.currentScene = self + core.scenemanager:setScene(self) end function Scene:update(dt) diff --git a/sonic-radiance.love/core/options.lua b/sonic-radiance.love/core/options.lua index 57111c9..c83a333 100644 --- a/sonic-radiance.love/core/options.lua +++ b/sonic-radiance.love/core/options.lua @@ -24,7 +24,8 @@ local OptionsManager = Object:extend() -local binser = require "libs.binser" +local cwd = (...):gsub('%.options$', '') .. "." +local binser = require(cwd .. "libs.binser") function OptionsManager:new() -- We begin by creating an empty data table before reading the data. @@ -42,7 +43,7 @@ function OptionsManager:reset() self.data.video.fullscreen = false -- We load the default files - self.data.input = require "datas.inputs" + self.data.input = self:getInputDefaultData() -- TODO: have a way to auto-load a language according to the OS ? self.data.language = "en" @@ -66,6 +67,31 @@ function OptionsManager:getFile(absolute) return filepath end +function OptionsManager:getInputDefaultData() + local _path = "datas/inputs.lua" + local datas = {} + local fileinfo = love.filesystem.getInfo(_path) + + if fileinfo ~= nil then + datas = require "datas.inputs" + else + datas = {} + end + + return datas +end + +function OptionsManager:getPlayerInputData(id) + local _playerInputData = self.data.input[id] + + if _playerInputData == nil then + _playerInputData = {} + _playerInputData.keys = {} + end + + return _playerInputData +end + function OptionsManager:write() local data = self:getData() diff --git a/sonic-radiance.love/core/scenemanager.lua b/sonic-radiance.love/core/scenemanager.lua index 5d403ca..008d0a2 100644 --- a/sonic-radiance.love/core/scenemanager.lua +++ b/sonic-radiance.love/core/scenemanager.lua @@ -28,6 +28,28 @@ local SceneManager = Object:extend() function SceneManager:new(controller) self.controller = controller self.currentScene = nil + + self.storage = {} +end + +function SceneManager:setScene(scene) + self.currentScene = scene +end + +function SceneManager:storeCurrentScene(name) + self.storage[name] = self.currentScene +end + +function SceneManager:setStoredScene(name) + local storedScene = self.storage[name] + if storedScene ~= nil then + self.currentScene = storedScene + self.storage[name] = nil + end +end + +function SceneManager:clearStorage() + self.storage = {} end function SceneManager:update(dt) @@ -42,15 +64,19 @@ function SceneManager:update(dt) end function SceneManager:mousemoved(x, y, dx, dy) - self.currentScene.mouse.x, - self.currentScene.mouse.y = x, y - self.currentScene:mousemoved(x, y, dx, dy) - self.currentScene.menusystem:mousemoved(x, y, dx, dy) + if (self.currentScene ~= nil) then + self.currentScene.mouse.x, + self.currentScene.mouse.y = x, y + self.currentScene:mousemoved(x, y, dx, dy) + self.currentScene.menusystem:mousemoved(x, y, dx, dy) + end end function SceneManager:mousepressed( x, y, button, istouch ) - self.currentScene:mousepressed( x, y, button, istouch ) - self.currentScene.menusystem:mousepressed( x, y, button, istouch ) + if (self.currentScene ~= nil) then + self.currentScene:mousepressed( x, y, button, istouch ) + self.currentScene.menusystem:mousepressed( x, y, button, istouch ) + end end function SceneManager:clearScene() diff --git a/sonic-radiance.love/core/screen.lua b/sonic-radiance.love/core/screen.lua index 4e962a8..24a3c4b 100644 --- a/sonic-radiance.love/core/screen.lua +++ b/sonic-radiance.love/core/screen.lua @@ -24,7 +24,8 @@ local ScreenManager = Object:extend() -local CScreen = require "libs.cscreen" +local cwd = (...):gsub('%.screen$', '') .. "." +local CScreen = require(cwd .. "libs.cscreen") function ScreenManager:new(controller) self.controller = controller diff --git a/sonic-radiance.love/libs/loveutils/filesystem.lua b/sonic-radiance.love/core/utils/filesystem.lua similarity index 100% rename from sonic-radiance.love/libs/loveutils/filesystem.lua rename to sonic-radiance.love/core/utils/filesystem.lua diff --git a/sonic-radiance.love/libs/loveutils/graphics.lua b/sonic-radiance.love/core/utils/graphics.lua similarity index 100% rename from sonic-radiance.love/libs/loveutils/graphics.lua rename to sonic-radiance.love/core/utils/graphics.lua diff --git a/sonic-radiance.love/libs/loveutils/init.lua b/sonic-radiance.love/core/utils/init.lua similarity index 100% rename from sonic-radiance.love/libs/loveutils/init.lua rename to sonic-radiance.love/core/utils/init.lua diff --git a/sonic-radiance.love/libs/loveutils/math.lua b/sonic-radiance.love/core/utils/math.lua similarity index 100% rename from sonic-radiance.love/libs/loveutils/math.lua rename to sonic-radiance.love/core/utils/math.lua diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 91476ef..bb4bee7 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -26,7 +26,7 @@ local Game = Object:extend() local Characters = require "game.characters" -local binser = require "libs.binser" +local binser = require "core.libs.binser" function Game:new() self.slot = -1 diff --git a/sonic-radiance.love/main.lua b/sonic-radiance.love/main.lua index 8837a3a..a565372 100644 --- a/sonic-radiance.love/main.lua +++ b/sonic-radiance.love/main.lua @@ -21,8 +21,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -utils = require "libs.loveutils" -Object = require "libs.classic" Core = require "core" Game = require "game"