From 2cc19c094b587da32cb501f1a571e0c4a2f316c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=82=B4=EB=A0=A4=EC=A3=BC=EC=84=B8=EC=9A=94?= <46598063+qwreey75@users.noreply.github.com> Date: Sun, 12 Sep 2021 21:04:43 +0900 Subject: [PATCH] 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 --- src/class.lua | 28 +++++++++++++++------------- src/dump.lua | 1 + src/init.lua | 4 ++-- src/mount.lua | 21 ++++++++++++++++++++- src/store.lua | 20 ++++++++++++++++++++ src/tween.lua | 0 test.lua | 10 ++++++++-- test.project.json | 12 ++++++++++++ 8 files changed, 78 insertions(+), 18 deletions(-) create mode 100644 src/dump.lua create mode 100644 src/tween.lua create mode 100644 test.project.json diff --git a/src/class.lua b/src/class.lua index c9a6e18..75ba118 100644 --- a/src/class.lua +++ b/src/class.lua @@ -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; }); diff --git a/src/dump.lua b/src/dump.lua new file mode 100644 index 0000000..26949c6 --- /dev/null +++ b/src/dump.lua @@ -0,0 +1 @@ +-- we should add dumping gui to xml feature \ No newline at end of file diff --git a/src/init.lua b/src/init.lua index f2d2e83..0f83905 100644 --- a/src/init.lua +++ b/src/init.lua @@ -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); diff --git a/src/mount.lua b/src/mount.lua index 32a4614..36d9522 100644 --- a/src/mount.lua +++ b/src/mount.lua @@ -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; }); diff --git a/src/store.lua b/src/store.lua index 698d865..27b4686 100644 --- a/src/store.lua +++ b/src/store.lua @@ -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 diff --git a/src/tween.lua b/src/tween.lua new file mode 100644 index 0000000..e69de29 diff --git a/test.lua b/test.lua index 6ed0987..acf6bda 100644 --- a/test.lua +++ b/test.lua @@ -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 () diff --git a/test.project.json b/test.project.json new file mode 100644 index 0000000..5ad52f9 --- /dev/null +++ b/test.project.json @@ -0,0 +1,12 @@ +{ + "name": "Plugin", + "tree": { + "StarterGui": { + "$className": "StarterGui", + "testGUI": { + "$className": "ScreenGui", + "$path": "src" + } + } + } +} \ No newline at end of file