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