Merge branch 'port-to-gamecore' of Project-Radiance/sonic-radiance into master
This commit is contained in:
commit
8b8dec8c5b
27 changed files with 261 additions and 43 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 --
|
||||
|
|
|
@ -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)
|
||||
|
|
65
sonic-radiance.love/core/modules/assets/texture.lua
Normal file
65
sonic-radiance.love/core/modules/assets/texture.lua
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue