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:
살려주세요 2021-09-12 21:04:43 +09:00
parent 86497c9b03
commit 2cc19c094b
8 changed files with 78 additions and 18 deletions

View file

@ -5,7 +5,7 @@ function module.init(shared)
local bind = shared.event.bind;
local addObject = shared.store.addObject;
function new.make(ClassName,prop)
function new.make(ClassName,...)
-- make thing
local item;
local classOfClassName = type(ClassName);
@ -23,16 +23,18 @@ function module.init(shared)
end
-- set property and adding child and binding functions
for index,value in pairs(prop) do
local valueType = typeof(value);
local indexType = typeof(index);
for _,prop in pairs({...}) do
for index,value in pairs(prop) do
local valueType = typeof(value);
local indexType = typeof(index);
-- child
if indexType ~= "string" then -- object
value.Parent = item;
elseif valueType == "function" and bind(value) then -- connect event
elseif indexType == "string" then
new[index] = value; -- set property
-- child
if indexType ~= "string" then -- object
value.Parent = item;
elseif valueType == "function" and bind(value) then -- connect event
elseif indexType == "string" then
new[index] = value; -- set property
end
end
end
return item;
@ -40,7 +42,7 @@ function module.init(shared)
local make = new.make;
function new.import(ClassName) -- make new quad class object
local this = {styles = {}};
local this = {};
setmetatable(this,{
__call = function (self,prop)
if type(prop) == "string" then
@ -52,7 +54,7 @@ function module.init(shared)
return item;
end;
end
return make(ClassName,prop);
return make(ClassName,prop,this);
end;
});
return this;
@ -61,7 +63,7 @@ function module.init(shared)
-- set module calling function
setmetatable(new,{
__call = function (self,...)
return self.import(...);
return new.import(...);
end;
});

1
src/dump.lua Normal file
View file

@ -0,0 +1 @@
-- we should add dumping gui to xml feature

View file

@ -26,7 +26,7 @@ frame{
require = require(script.require);
local event = require("event");
local store = require("store");
local style = require("style");
--local style = require("style");
local class = require("class");
local mount = require("mount");
@ -35,7 +35,7 @@ function module.init()
this.event = event.init(this);
this.store = store.init(this);
this.style = style.init(this);
--this.style = style.init(this);
this.class = class.init(this);
this.mount = mount.init(this);

View file

@ -3,14 +3,33 @@ local module = {};
function module.init(shared)
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
function new.mount(to,this)
this.Parent = to;
return setmetatable({to = to,this = this},mount);
end
setmetatable(new,{
__call = function (self,...)
self.mount(...);
return new.mount(...);
end;
});

View file

@ -7,12 +7,18 @@ this feature should be upgraded
]]
local insert = table.insert;
local remove = table.remove;
function module.init(shared)
local new = {};
local items = shared.items;
local objSpace = {};
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
local ret = func(i,v);
if ret then
@ -20,10 +26,24 @@ function module.init(shared)
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)
return items[id];
end
-- TODO: if item is exist already, ignore this call
function new.addObject(id,object)
local array = items[id];
if not array then

0
src/tween.lua Normal file
View file

View file

@ -5,10 +5,12 @@ local gui = script.Parent;
local class = render.class;
local mount = render.mount;
local store = render.store;
local style = render.style;
local frame = class "Frame";
local text = class "TextLabel";
local text = class.import "TextLabel";
text.style = {
};
mount(gui,frame "testFrame" {
text "texts" {
@ -25,6 +27,10 @@ mount(gui,frame "testFrame" {
store.getObjects("texts"):each(function(index,this)
this.Text = "이렇게 모든 택스트를 한꺼번에 바꿀 수도 있습니다";
end);
store.getObject("texts"):eachSync(function(index,this)
this.Text = "또한, 기본적으로 Aync 를 이용하기 때문에 순차적인 실행이 필요한 경우 Sync 를 붇여야합니다";
end);
do local this = store.getObjects("testFrame")[1];
spawn(function ()

12
test.project.json Normal file
View file

@ -0,0 +1,12 @@
{
"name": "Plugin",
"tree": {
"StarterGui": {
"$className": "StarterGui",
"testGUI": {
"$className": "ScreenGui",
"$path": "src"
}
}
}
}