core: add a way to get keyboard callbacks from current scene

This commit is contained in:
Kazhnuz 2019-04-14 19:45:52 +02:00
parent 1aef8ad49d
commit 324a5854b7
4 changed files with 43 additions and 2 deletions

View file

@ -36,3 +36,11 @@ end
function love.mousepressed( x, y, button, istouch )
core:mousepressed(x, y, button, istouch)
end
function love.keypressed( key, scancode, isrepeat )
core:keypressed( key, scancode, isrepeat )
end
function love.keyreleased(key)
core:keyreleased( key )
end

View file

@ -57,7 +57,7 @@ function CoreSystem:new()
end
-- MOUSE FUNCTIONS
-- Initialize and configure the core object
-- get directly the mouse when needed
function CoreSystem:mousemoved(x, y, dx, dy)
local x, y = self.screen:project(x, y)
@ -70,6 +70,17 @@ function CoreSystem:mousepressed( x, y, button, istouch )
self.scenemanager:mousepressed( x, y, button, istouch )
end
-- KEYBOARD FUNCTIONS
-- get directly the keyboard when needed
function CoreSystem:keypressed( key, scancode, isrepeat )
self.scenemanager:keypressed( key, scancode, isrepeat )
end
function CoreSystem:keyreleased( key )
self.scenemanager:keyreleased( key )
end
-- UPDATE FUNCTIONS
-- Load every sytem every update functions of the scene and objects

View file

@ -72,6 +72,17 @@ function Scene:mousepressed( x, y, button, istouch )
-- Empty function, is just here to avoid crash
end
-- KEYBOARD FUNCTIONS
-- Add send keys functions to the scene
function SceneManager:keypressed( key, scancode, isrepeat )
end
function SceneManager:keyreleased( key )
end
-- DRAW FUNCTIONS
-- Draw the scene and its content
@ -79,7 +90,7 @@ function Scene:draw()
end
-- KEYBOARD FUNCTIONS
-- INPUT FUNCTIONS
-- Handle inputs from keyboard/controllers
function Scene:setKeys()

View file

@ -90,6 +90,17 @@ function SceneManager:mousepressed( x, y, button, istouch )
end
end
-- KEYBOARD FUNCTIONS
-- Add send keys functions to the scene
function SceneManager:keypressed( key, scancode, isrepeat )
self.currentScene:keypressed( key, scancode, isrepeat )
end
function SceneManager:keyreleased( key )
self.currentScene:keyreleased( key )
end
-- DRAW FUNCTIONS
-- Draw the current scene