Minor improvements

This commit is contained in:
qfx 2020-02-14 02:05:13 +02:00
parent 630694ee2b
commit 90ba400380
3 changed files with 26 additions and 13 deletions

View File

@ -1,6 +1,6 @@
return { return {
HOTSWAP = true, --Turns on hotswap, disable this once it's deployed HOTSWAP = true, --Turns on hotswap, disable this once it's deployed
AUTO_RUN = false, --Replaces the default love.run AUTO_RUN = true, --Replaces the default love.run
DEBUG = true, --Reserved for later DEBUG = true, --Reserved for later
PURE_G = true, --whether to set HeliumLoader global PURE_G = true, --whether to set HeliumLoader global
} }

View File

@ -20,7 +20,7 @@ function context:bubbleUpdate()
self.element.settings.pendingUpdate = true self.element.settings.pendingUpdate = true
self.element.settings.needsRendering = true self.element.settings.needsRendering = true
if self.parentCtx then if self.parentCtx and self.parentCtx~=self then
self.parentCtx:bubbleUpdate() self.parentCtx:bubbleUpdate()
end end
end end
@ -68,10 +68,9 @@ setmetatable(element,{
__call = function(cls, ...) __call = function(cls, ...)
local self local self
local func, loader, w, h, param = ... local func, loader, w, h, param = ...
if type(func)=='function' then
self = setmetatable({}, element) self = setmetatable({}, element)
self.parentFunc = func self.parentFunc = func
end
if loader then if loader then
local function f(newFunc) local function f(newFunc)
@ -171,11 +170,16 @@ function element:reLoader(newFunc)
self.inputContext:destroy() self.inputContext:destroy()
self.parentFunc = newFunc self.parentFunc = newFunc
if type(self.parentFunc)=='function' then
self.renderer = self.parentFunc(self.parameters,self.state,self.view) self.renderer = self.parentFunc(self.parameters,self.state,self.view)
self.context:bubbleUpdate() else
self.renderer = self.parentFunc
end
self.context:unset() self.context:unset()
self.inputContext:unset() self.inputContext:unset()
self.context:bubbleUpdate()
end end
local newCanvas,newQuad = love.graphics.newCanvas,love.graphics.newQuad local newCanvas,newQuad = love.graphics.newCanvas,love.graphics.newQuad

View File

@ -7,6 +7,7 @@ local input={
activeEvents = {} activeEvents = {}
} }
local dummyfunc = function() end
---@class subscription ---@class subscription
local subscription = {} local subscription = {}
subscription.__index = subscription subscription.__index = subscription
@ -58,8 +59,9 @@ function context:set()
end end
function context:update() function context:update()
for i, sub in ipairs(self.subs) do for i, sub in ipairs(self.subs) do
sub:contextUpdate(self.absX,self.absY) sub:contextUpdate(self.absX,self.absY,self)
end end
end end
@ -91,11 +93,16 @@ end
function subscription.create(x, y, w, h, eventType, callback, doff) function subscription.create(x, y, w, h, eventType, callback, doff)
local sub local sub
if activeContext then if activeContext then
local wratio = w/activeContext.elem.view.w
local hratio = h/activeContext.elem.view.h
sub = setmetatable({ sub = setmetatable({
x = activeContext.absX + x, x = activeContext.absX + x,
y = activeContext.absY + y, y = activeContext.absY + y,
w = w, w = w,
h = h, h = h,
wratio = wratio,
hratio = hratio,
ix = x, ix = x,
iy = y, iy = y,
eventType = eventType, eventType = eventType,
@ -138,9 +145,11 @@ function subscription:destroy()
self.active = false self.active = false
end end
function subscription:contextUpdate(absX, absY) function subscription:contextUpdate(absX, absY,activeContext)
self.x = absX + self.ix self.x = absX + self.ix
self.y = absY + self.iy self.y = absY + self.iy
self.w = activeContext.elem.view.w * self.wratio
self.h = activeContext.elem.view.h * self.hratio
end end
function subscription:update(x, y, w, h) function subscription:update(x, y, w, h)
@ -248,7 +257,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
local succ = sub:checkInside(x, y) local succ = sub:checkInside(x, y)
if succ and sub.active then if succ and sub.active then
sub.cleanUp = sub:emit(x, y, btn) sub.cleanUp = sub:emit(x, y, btn) or dummyfunc
sub.currentEvent = true sub.currentEvent = true
captured = true captured = true
end end
@ -308,7 +317,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
local succ = sub:checkInside(x, y) local succ = sub:checkInside(x, y)
if sub.active and not sub.currentEvent and succ then if sub.active and not sub.currentEvent and succ then
sub.cleanUp = sub:emit(x, y) sub.cleanUp = sub:emit(x, y) or dummyfunc
sub.currentEvent = true sub.currentEvent = true
captured = true captured = true
elseif sub.currentEvent and not succ then elseif sub.currentEvent and not succ then
@ -326,7 +335,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
for index, sub in ipairs(input.subscriptions.dragged) do for index, sub in ipairs(input.subscriptions.dragged) do
if sub.active and sub.currentEvent then if sub.active and sub.currentEvent then
if not sub.cleanUp then if not sub.cleanUp then
sub.cleanUp = sub:emit(x, y, dx, dy) sub.cleanUp = sub:emit(x, y, dx, dy) or dummyfunc
else else
sub:emit(x, y, dx, dy) sub:emit(x, y, dx, dy)
end end