diff options
Diffstat (limited to 'honey/ecs/script.lua')
-rw-r--r-- | honey/ecs/script.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/honey/ecs/script.lua b/honey/ecs/script.lua index 46af4fa..a9b7644 100644 --- a/honey/ecs/script.lua +++ b/honey/ecs/script.lua @@ -1,3 +1,5 @@ +local glfw = honey.glfw + local ecs = require 'honey.ecs.ecs' local node = require 'honey.ecs.node' @@ -27,6 +29,26 @@ dispatch = function(db, msg, data) end end +--===== bind window events to script handlers =====-- + +bindEvents = function(window, db) + glfw.SetFramebufferSizeCallback(window, function(w, width, height) + dispatch(db, "onFramebufferSize", {window=w, width=width, height=height}) + end) + + glfw.SetKeyCallback(window, function(w, key, scancode, action, mods) + dispatch(db, "onKey", {window=w, key=key, scancode=scancode, action=action, mods=mods}) + end) + + glfw.SetCursorPosCallback(window, function(w, xpos, ypos) + dispatch(db, "onCursorPos", {window=w, xpos=xpos, ypos=ypos}) + end) + + glfw.SetMouseButtonCallback(window, function(w, button, action, mods) + dispatch(db, "onMouseButton", {window=w, button=button, action=action, mods=mods}) + end) +end + --===== script system =====-- local script = ecs.System("script", function(db, dt, params) |