From cdf3f99705c6c6981a867671c4fac5eb9bee7c11 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sun, 3 Apr 2016 00:27:15 -0700 Subject: [PATCH] added element load call (yay\!) --- demo/pop/elements/window.lua | 7 ++----- demo/pop/init.lua | 3 +++ lib/pop/elements/window.lua | 7 ++----- lib/pop/init.lua | 3 +++ src/pop/elements/window.moon | 14 ++++++++------ src/pop/init.moon | 4 ++++ 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/demo/pop/elements/window.lua b/demo/pop/elements/window.lua index 16f26ad..173471f 100644 --- a/demo/pop/elements/window.lua +++ b/demo/pop/elements/window.lua @@ -25,17 +25,14 @@ do print(" assuming LÖVE version > 0.10.1 (there may be bugs)") end end -local pop_ref = nil +local pop_ref = false local window do local _class_0 local _parent_0 = element local _base_0 = { - wrap = function(pop) + load = function(pop) pop_ref = pop - return function(...) - return pop.create("window", ...) - end end, debugDraw = function(self) graphics.setLineWidth(0.5) diff --git a/demo/pop/init.lua b/demo/pop/init.lua index c2dff1a..fc09351 100644 --- a/demo/pop/init.lua +++ b/demo/pop/init.lua @@ -28,6 +28,9 @@ pop.load = function() end local name = elements[i]:sub(1, -5) pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name)) + if pop.elements[name].load then + pop.elements[name].load(pop) + end print("element loaded: \"" .. tostring(name) .. "\"") if not (pop[name]) then if pop.elements[name].wrap then diff --git a/lib/pop/elements/window.lua b/lib/pop/elements/window.lua index 16f26ad..173471f 100644 --- a/lib/pop/elements/window.lua +++ b/lib/pop/elements/window.lua @@ -25,17 +25,14 @@ do print(" assuming LÖVE version > 0.10.1 (there may be bugs)") end end -local pop_ref = nil +local pop_ref = false local window do local _class_0 local _parent_0 = element local _base_0 = { - wrap = function(pop) + load = function(pop) pop_ref = pop - return function(...) - return pop.create("window", ...) - end end, debugDraw = function(self) graphics.setLineWidth(0.5) diff --git a/lib/pop/init.lua b/lib/pop/init.lua index c2dff1a..fc09351 100644 --- a/lib/pop/init.lua +++ b/lib/pop/init.lua @@ -28,6 +28,9 @@ pop.load = function() end local name = elements[i]:sub(1, -5) pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name)) + if pop.elements[name].load then + pop.elements[name].load(pop) + end print("element loaded: \"" .. tostring(name) .. "\"") if not (pop[name]) then if pop.elements[name].wrap then diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index 291d107..3c2ea26 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -22,14 +22,16 @@ do print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}" print " assuming LÖVE version > 0.10.1 (there may be bugs)" --- a reference to pop is needed for windows, this is obtained using the wrap function when it is loaded -pop_ref = nil -- yes, this is convoluted and probably needs a re-design +pop_ref = false -- reference to pop, loaded by pop.load! class window extends element - wrap: (pop) -> - pop_ref = pop -- set our reference to pop (needed for mouse handling) - return (...) -> -- standard wrapper, nothing special needed - return pop.create("window", ...) + load: (pop) -> + pop_ref = pop + + --wrap: (pop) -> + -- pop_ref = pop -- set our reference to pop (needed for mouse handling) + -- return (...) -> -- standard wrapper, nothing special needed + -- return pop.create("window", ...) new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => super parent diff --git a/src/pop/init.moon b/src/pop/init.moon index 53ee4a1..4ebe1ae 100644 --- a/src/pop/init.moon +++ b/src/pop/init.moon @@ -28,6 +28,10 @@ pop.load = -> -- load into pop.elements table name = elements[i]\sub 1, -5 pop.elements[name] = require "#{path}/elements/#{name}" + + if pop.elements[name].load + pop.elements[name].load pop + print "element loaded: \"#{name}\"" -- create pop.element() wrapper if possible