More Improvements / New Features
+ Added mulit prop table feature on module:class.make() + Added setting defualt properties on imported class object + Added unmount method on mount object
This commit is contained in:
parent
86497c9b03
commit
2cc19c094b
8 changed files with 78 additions and 18 deletions
|
|
@ -5,7 +5,7 @@ function module.init(shared)
|
||||||
local bind = shared.event.bind;
|
local bind = shared.event.bind;
|
||||||
local addObject = shared.store.addObject;
|
local addObject = shared.store.addObject;
|
||||||
|
|
||||||
function new.make(ClassName,prop)
|
function new.make(ClassName,...)
|
||||||
-- make thing
|
-- make thing
|
||||||
local item;
|
local item;
|
||||||
local classOfClassName = type(ClassName);
|
local classOfClassName = type(ClassName);
|
||||||
|
|
@ -23,16 +23,18 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set property and adding child and binding functions
|
-- set property and adding child and binding functions
|
||||||
for index,value in pairs(prop) do
|
for _,prop in pairs({...}) do
|
||||||
local valueType = typeof(value);
|
for index,value in pairs(prop) do
|
||||||
local indexType = typeof(index);
|
local valueType = typeof(value);
|
||||||
|
local indexType = typeof(index);
|
||||||
|
|
||||||
-- child
|
-- child
|
||||||
if indexType ~= "string" then -- object
|
if indexType ~= "string" then -- object
|
||||||
value.Parent = item;
|
value.Parent = item;
|
||||||
elseif valueType == "function" and bind(value) then -- connect event
|
elseif valueType == "function" and bind(value) then -- connect event
|
||||||
elseif indexType == "string" then
|
elseif indexType == "string" then
|
||||||
new[index] = value; -- set property
|
new[index] = value; -- set property
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return item;
|
return item;
|
||||||
|
|
@ -40,7 +42,7 @@ function module.init(shared)
|
||||||
local make = new.make;
|
local make = new.make;
|
||||||
|
|
||||||
function new.import(ClassName) -- make new quad class object
|
function new.import(ClassName) -- make new quad class object
|
||||||
local this = {styles = {}};
|
local this = {};
|
||||||
setmetatable(this,{
|
setmetatable(this,{
|
||||||
__call = function (self,prop)
|
__call = function (self,prop)
|
||||||
if type(prop) == "string" then
|
if type(prop) == "string" then
|
||||||
|
|
@ -52,7 +54,7 @@ function module.init(shared)
|
||||||
return item;
|
return item;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
return make(ClassName,prop);
|
return make(ClassName,prop,this);
|
||||||
end;
|
end;
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -61,7 +63,7 @@ function module.init(shared)
|
||||||
-- set module calling function
|
-- set module calling function
|
||||||
setmetatable(new,{
|
setmetatable(new,{
|
||||||
__call = function (self,...)
|
__call = function (self,...)
|
||||||
return self.import(...);
|
return new.import(...);
|
||||||
end;
|
end;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
1
src/dump.lua
Normal file
1
src/dump.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
-- we should add dumping gui to xml feature
|
||||||
|
|
@ -26,7 +26,7 @@ frame{
|
||||||
require = require(script.require);
|
require = require(script.require);
|
||||||
local event = require("event");
|
local event = require("event");
|
||||||
local store = require("store");
|
local store = require("store");
|
||||||
local style = require("style");
|
--local style = require("style");
|
||||||
local class = require("class");
|
local class = require("class");
|
||||||
local mount = require("mount");
|
local mount = require("mount");
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ function module.init()
|
||||||
|
|
||||||
this.event = event.init(this);
|
this.event = event.init(this);
|
||||||
this.store = store.init(this);
|
this.store = store.init(this);
|
||||||
this.style = style.init(this);
|
--this.style = style.init(this);
|
||||||
this.class = class.init(this);
|
this.class = class.init(this);
|
||||||
this.mount = mount.init(this);
|
this.mount = mount.init(this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,33 @@ local module = {};
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
|
|
||||||
|
local mount = {};
|
||||||
|
mount.__index = mount;
|
||||||
|
function mount:unmount()
|
||||||
|
local this = self.this;
|
||||||
|
local typeThis = type(this);
|
||||||
|
if typeThis == "userdata" then
|
||||||
|
this:Destroy();
|
||||||
|
elseif typeThis == "table" then
|
||||||
|
pcall(function()
|
||||||
|
this.Parent = nil;
|
||||||
|
end);
|
||||||
|
local destroyThis = this.Destroy;
|
||||||
|
if destroyThis then
|
||||||
|
pcall(destroyThis);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- we should add plugin support
|
-- we should add plugin support
|
||||||
function new.mount(to,this)
|
function new.mount(to,this)
|
||||||
this.Parent = to;
|
this.Parent = to;
|
||||||
|
return setmetatable({to = to,this = this},mount);
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(new,{
|
setmetatable(new,{
|
||||||
__call = function (self,...)
|
__call = function (self,...)
|
||||||
self.mount(...);
|
return new.mount(...);
|
||||||
end;
|
end;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,18 @@ this feature should be upgraded
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local insert = table.insert;
|
local insert = table.insert;
|
||||||
|
local remove = table.remove;
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
local items = shared.items;
|
local items = shared.items;
|
||||||
|
|
||||||
local objSpace = {};
|
local objSpace = {};
|
||||||
function objSpace:each(func)
|
function objSpace:each(func)
|
||||||
|
for i,v in ipairs(self) do
|
||||||
|
coroutine.resume(coroutine.create(func),i,v);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function objSpace:eachSync(func)
|
||||||
for i,v in ipairs(self) do
|
for i,v in ipairs(self) do
|
||||||
local ret = func(i,v);
|
local ret = func(i,v);
|
||||||
if ret then
|
if ret then
|
||||||
|
|
@ -20,10 +26,24 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function objSpace:remove(indexOrItem)
|
||||||
|
local thisType = type(indexOrItem);
|
||||||
|
if thisType == "number" then
|
||||||
|
remove(self,indexOrItem);
|
||||||
|
else
|
||||||
|
for i,v in pairs(self) do
|
||||||
|
if v == indexOrItem then
|
||||||
|
remove(self,i);
|
||||||
|
break;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function new.getObjects(id)
|
function new.getObjects(id)
|
||||||
return items[id];
|
return items[id];
|
||||||
end
|
end
|
||||||
|
-- TODO: if item is exist already, ignore this call
|
||||||
function new.addObject(id,object)
|
function new.addObject(id,object)
|
||||||
local array = items[id];
|
local array = items[id];
|
||||||
if not array then
|
if not array then
|
||||||
|
|
|
||||||
0
src/tween.lua
Normal file
0
src/tween.lua
Normal file
10
test.lua
10
test.lua
|
|
@ -5,10 +5,12 @@ local gui = script.Parent;
|
||||||
local class = render.class;
|
local class = render.class;
|
||||||
local mount = render.mount;
|
local mount = render.mount;
|
||||||
local store = render.store;
|
local store = render.store;
|
||||||
local style = render.style;
|
|
||||||
|
|
||||||
local frame = class "Frame";
|
local frame = class "Frame";
|
||||||
local text = class "TextLabel";
|
local text = class.import "TextLabel";
|
||||||
|
text.style = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
mount(gui,frame "testFrame" {
|
mount(gui,frame "testFrame" {
|
||||||
text "texts" {
|
text "texts" {
|
||||||
|
|
@ -25,6 +27,10 @@ mount(gui,frame "testFrame" {
|
||||||
store.getObjects("texts"):each(function(index,this)
|
store.getObjects("texts"):each(function(index,this)
|
||||||
this.Text = "이렇게 모든 택스트를 한꺼번에 바꿀 수도 있습니다";
|
this.Text = "이렇게 모든 택스트를 한꺼번에 바꿀 수도 있습니다";
|
||||||
end);
|
end);
|
||||||
|
store.getObject("texts"):eachSync(function(index,this)
|
||||||
|
this.Text = "또한, 기본적으로 Aync 를 이용하기 때문에 순차적인 실행이 필요한 경우 Sync 를 붇여야합니다";
|
||||||
|
end);
|
||||||
|
|
||||||
|
|
||||||
do local this = store.getObjects("testFrame")[1];
|
do local this = store.getObjects("testFrame")[1];
|
||||||
spawn(function ()
|
spawn(function ()
|
||||||
|
|
|
||||||
12
test.project.json
Normal file
12
test.project.json
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"name": "Plugin",
|
||||||
|
"tree": {
|
||||||
|
"StarterGui": {
|
||||||
|
"$className": "StarterGui",
|
||||||
|
"testGUI": {
|
||||||
|
"$className": "ScreenGui",
|
||||||
|
"$path": "src"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue