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

View File

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