gamecore: better comments and organization
This commit is contained in:
parent
65010fae16
commit
1061e4822f
6 changed files with 76 additions and 8 deletions
|
@ -42,6 +42,9 @@ local Screen = require(cwd .. "screen")
|
||||||
local Lang = require(cwd .. "lang")
|
local Lang = require(cwd .. "lang")
|
||||||
local SceneManager = require(cwd .. "scenemanager")
|
local SceneManager = require(cwd .. "scenemanager")
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the core object
|
||||||
|
|
||||||
function CoreSystem:new()
|
function CoreSystem:new()
|
||||||
self.debug = DebugSystem(self)
|
self.debug = DebugSystem(self)
|
||||||
self.options = Options(self)
|
self.options = Options(self)
|
||||||
|
@ -50,6 +53,9 @@ function CoreSystem:new()
|
||||||
self.scenemanager = SceneManager(self)
|
self.scenemanager = SceneManager(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Initialize and configure the core object
|
||||||
|
|
||||||
function CoreSystem:mousemoved(x, y, dx, dy)
|
function CoreSystem:mousemoved(x, y, dx, dy)
|
||||||
local x, y = self.screen:project(x, y)
|
local x, y = self.screen:project(x, y)
|
||||||
local dx, dy = self.screen:project(dx, dy)
|
local dx, dy = self.screen:project(dx, dy)
|
||||||
|
@ -61,6 +67,9 @@ function CoreSystem:mousepressed( x, y, button, istouch )
|
||||||
self.scenemanager:mousepressed( x, y, button, istouch )
|
self.scenemanager:mousepressed( x, y, button, istouch )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Load every sytem every update functions of the scene and objects
|
||||||
|
|
||||||
function CoreSystem:update(dt)
|
function CoreSystem:update(dt)
|
||||||
self.debug:update(dt)
|
self.debug:update(dt)
|
||||||
self.input:update(dt)
|
self.input:update(dt)
|
||||||
|
@ -68,10 +77,16 @@ function CoreSystem:update(dt)
|
||||||
self.scenemanager:update(dt)
|
self.scenemanager:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw the whole game
|
||||||
|
|
||||||
function CoreSystem:draw()
|
function CoreSystem:draw()
|
||||||
self.scenemanager:draw()
|
self.scenemanager:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- EXIT FUNCTIONS
|
||||||
|
-- Quit the game
|
||||||
|
|
||||||
function CoreSystem:exit()
|
function CoreSystem:exit()
|
||||||
self.options:save()
|
self.options:save()
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
local InputManager = Object:extend()
|
local InputManager = Object:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the controller system
|
||||||
|
|
||||||
function InputManager:new(controller)
|
function InputManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.data = self.controller.options:getInputData()
|
self.data = self.controller.options:getInputData()
|
||||||
|
@ -38,6 +41,9 @@ function InputManager:initKeys()
|
||||||
self.fakesources = self:getSources()
|
self.fakesources = self:getSources()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- Get functions from the controller object
|
||||||
|
|
||||||
function InputManager:isDown(sourceid, padkey)
|
function InputManager:isDown(sourceid, padkey)
|
||||||
local isdown = false
|
local isdown = false
|
||||||
|
|
||||||
|
@ -84,6 +90,9 @@ function InputManager:getKey(sourceid, padkey)
|
||||||
return key
|
return key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- KEY MANAGEMENT FUNCTIONS
|
||||||
|
-- Manage pressed keys
|
||||||
|
|
||||||
function InputManager:flushKeys()
|
function InputManager:flushKeys()
|
||||||
for i,v in ipairs(self.sources) do
|
for i,v in ipairs(self.sources) do
|
||||||
self:flushSourceKeys(sourceid)
|
self:flushSourceKeys(sourceid)
|
||||||
|
@ -129,6 +138,9 @@ function InputManager:checkKeys(sourceid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Check every step pressed keys
|
||||||
|
|
||||||
function InputManager:update(dt)
|
function InputManager:update(dt)
|
||||||
for i,v in ipairs(self.sources) do
|
for i,v in ipairs(self.sources) do
|
||||||
self:checkKeys(i)
|
self:checkKeys(i)
|
||||||
|
|
|
@ -24,12 +24,23 @@
|
||||||
|
|
||||||
local LanguageManager = Object:extend()
|
local LanguageManager = Object:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the translation system
|
||||||
|
|
||||||
function LanguageManager:new(controller)
|
function LanguageManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self:setLang(self.controller.options.data.language)
|
self:setLang(self.controller.options.data.language)
|
||||||
self:getTranslationData()
|
self:getTranslationData()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function LanguageManager:setLang(lang)
|
||||||
|
self.controller.options.data.language = lang
|
||||||
|
self.lang = self.controller.options.data.language
|
||||||
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- Get informations from the translation manager
|
||||||
|
|
||||||
function LanguageManager:getTranslationData()
|
function LanguageManager:getTranslationData()
|
||||||
local _path = "datas/languages/init.lua"
|
local _path = "datas/languages/init.lua"
|
||||||
local fileinfo = love.filesystem.getInfo(_path)
|
local fileinfo = love.filesystem.getInfo(_path)
|
||||||
|
@ -55,9 +66,4 @@ function LanguageManager:getCurrentLangName()
|
||||||
return langnames[self.lang]
|
return langnames[self.lang]
|
||||||
end
|
end
|
||||||
|
|
||||||
function LanguageManager:setLang(lang)
|
|
||||||
self.controller.options.data.language = lang
|
|
||||||
self.lang = self.controller.options.data.language
|
|
||||||
end
|
|
||||||
|
|
||||||
return LanguageManager
|
return LanguageManager
|
||||||
|
|
|
@ -27,6 +27,9 @@ local OptionsManager = Object:extend()
|
||||||
local cwd = (...):gsub('%.options$', '') .. "."
|
local cwd = (...):gsub('%.options$', '') .. "."
|
||||||
local binser = require(cwd .. "libs.binser")
|
local binser = require(cwd .. "libs.binser")
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the game options
|
||||||
|
|
||||||
function OptionsManager:new()
|
function OptionsManager:new()
|
||||||
-- We begin by creating an empty data table before reading the data.
|
-- We begin by creating an empty data table before reading the data.
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
@ -53,6 +56,9 @@ function OptionsManager:reset()
|
||||||
self.data.audio.sfx = 100
|
self.data.audio.sfx = 100
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- Get informations from the option managers
|
||||||
|
|
||||||
function OptionsManager:getFile(absolute)
|
function OptionsManager:getFile(absolute)
|
||||||
local dir = ""
|
local dir = ""
|
||||||
if absolute then
|
if absolute then
|
||||||
|
@ -96,6 +102,11 @@ function OptionsManager:getInputData()
|
||||||
return self.data.input
|
return self.data.input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DATA HANDLING FUNCTIONS
|
||||||
|
-- Save and get data from the savefile
|
||||||
|
|
||||||
|
-- FIXME: maybe subclass a special module for that ?
|
||||||
|
|
||||||
function OptionsManager:write()
|
function OptionsManager:write()
|
||||||
local data = self:getData()
|
local data = self:getData()
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
|
|
||||||
local SceneManager = Object:extend()
|
local SceneManager = Object:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the scene manager
|
||||||
|
|
||||||
function SceneManager:new(controller)
|
function SceneManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.currentScene = nil
|
self.currentScene = nil
|
||||||
|
@ -52,6 +55,13 @@ function SceneManager:clearStorage()
|
||||||
self.storage = {}
|
self.storage = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function SceneManager:clearScene()
|
||||||
|
self.currentScene = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the current scene and its subobjects
|
||||||
|
|
||||||
function SceneManager:update(dt)
|
function SceneManager:update(dt)
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
self.currentScene:setKeys()
|
self.currentScene:setKeys()
|
||||||
|
@ -61,6 +71,9 @@ function SceneManager:update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Send pointer data to the scene
|
||||||
|
|
||||||
function SceneManager:mousemoved(x, y, dx, dy)
|
function SceneManager:mousemoved(x, y, dx, dy)
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
self.currentScene.mouse.x,
|
self.currentScene.mouse.x,
|
||||||
|
@ -77,9 +90,8 @@ function SceneManager:mousepressed( x, y, button, istouch )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function SceneManager:clearScene()
|
-- DRAW FUNCTIONS
|
||||||
self.currentScene = nil
|
-- Draw the current scene
|
||||||
end
|
|
||||||
|
|
||||||
function SceneManager:draw()
|
function SceneManager:draw()
|
||||||
self.controller.screen:apply()
|
self.controller.screen:apply()
|
||||||
|
|
|
@ -27,6 +27,9 @@ local ScreenManager = Object:extend()
|
||||||
local cwd = (...):gsub('%.screen$', '') .. "."
|
local cwd = (...):gsub('%.screen$', '') .. "."
|
||||||
local CScreen = require(cwd .. "libs.cscreen")
|
local CScreen = require(cwd .. "libs.cscreen")
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the screen manager
|
||||||
|
|
||||||
function ScreenManager:new(controller)
|
function ScreenManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.data = self.controller.options.data.video
|
self.data = self.controller.options.data.video
|
||||||
|
@ -52,6 +55,9 @@ function ScreenManager:applySettings()
|
||||||
CScreen.update(width, height)
|
CScreen.update(width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- POINTER FUNCTIONS
|
||||||
|
-- Translate the pointer according to the screen coordinates
|
||||||
|
|
||||||
function ScreenManager:project(x, y)
|
function ScreenManager:project(x, y)
|
||||||
return CScreen.project(x, y)
|
return CScreen.project(x, y)
|
||||||
end
|
end
|
||||||
|
@ -60,10 +66,16 @@ function ScreenManager:getMousePosition()
|
||||||
return CScreen.project(love.mouse.getX(), love.mouse.getY())
|
return CScreen.project(love.mouse.getX(), love.mouse.getY())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- Get screen informations
|
||||||
|
|
||||||
function ScreenManager:getDimensions()
|
function ScreenManager:getDimensions()
|
||||||
return self.width, self.height
|
return self.width, self.height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Apply draw functions to the scene
|
||||||
|
|
||||||
function ScreenManager:apply()
|
function ScreenManager:apply()
|
||||||
CScreen.apply()
|
CScreen.apply()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue