From f3900ec0d460f395fc83366fa814e87642f93194 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:49:36 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=95=88?= =?UTF-8?q?=EC=97=90=20=EC=84=A4=EB=AA=85=EC=9D=84=20=EC=A0=81=EC=97=88?= =?UTF-8?q?=EB=8B=A4,=20=EB=82=98=EC=A4=91=EC=97=90=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=97=90=20=EB=8F=84=EC=9B=80=EC=9D=B4=20?= =?UTF-8?q?=EB=90=A0=20=EC=98=88=EC=A0=95=20=3F'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/class.lua | 39 +++++++++++++++++++++---- src/store.lua | 4 +++ src/tween.lua | 1 + test.lua | 41 --------------------------- test.project.json | 8 +++++- testScript.client.lua | 66 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 48 deletions(-) delete mode 100644 test.lua create mode 100644 testScript.client.lua diff --git a/src/class.lua b/src/class.lua index 177d127..67c66af 100644 --- a/src/class.lua +++ b/src/class.lua @@ -1,11 +1,22 @@ local module = {}; +local exportItemMeta = { + __index = function (self,key) + local methods = self.__methods; + local events = self.__events; + return (methods and methods[key]) or (events and events[key]) or (self.getters[key](self.__this)); + end; + __newindex = function (self,key,value) + self.__setters[key](self.__this,value); + end; +}; + function module.init(shared) local new = {}; local bind = shared.event.bind; local addObject = shared.store.addObject; - function new.make(ClassName,...) + function new.make(ClassName,...) -- render object -- make thing local item; local classOfClassName = type(ClassName); @@ -23,17 +34,21 @@ function module.init(shared) end -- set property and adding child and binding functions - for _,prop in pairs({...}) do + for iprop,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 + if valueType == "function" and bind(value) then -- connect event elseif indexType == "string" then - new[index] = value; -- set property + item[index] = value; -- set property + elseif indexType == "number" then -- object + if iprop == 1 then -- todo : move bindings + value.Parent = item; + else + value:Clone().Parent = item; + end end end end @@ -60,6 +75,18 @@ function module.init(shared) return this; end + function new.export(newFn,setters,getters,methods,events) -- make quad importable class + return function () + return setmetatable({ + __this = newFn(); + __setters = setters; + __getters = getters; + __methods = methods; + __events = events; + },exportItemMeta); + end; + end + -- set module calling function setmetatable(new,{ __call = function (self,...) diff --git a/src/store.lua b/src/store.lua index 27b4686..8ed6db3 100644 --- a/src/store.lua +++ b/src/store.lua @@ -43,6 +43,10 @@ function module.init(shared) function new.getObjects(id) return items[id]; end + function new.getObject(id) + local item = items[id]; + return item and item[1]; + end -- TODO: if item is exist already, ignore this call function new.addObject(id,object) local array = items[id]; diff --git a/src/tween.lua b/src/tween.lua index e69de29..b26664c 100644 --- a/src/tween.lua +++ b/src/tween.lua @@ -0,0 +1 @@ +-- this feature will depends on https://github.com/nofairTCM/AdvancedTween \ No newline at end of file diff --git a/test.lua b/test.lua deleted file mode 100644 index 2baccc7..0000000 --- a/test.lua +++ /dev/null @@ -1,41 +0,0 @@ -local quad = require(script.quad) if false then quad = require("src"); end -local render = quad.init(); -local gui = script.Parent; - -local class = render.class; -local mount = render.mount; -local store = render.store; - -local frame = class "Frame"; -local text = class.import "TextLabel"; -text.TextSize = ; - -mount(gui,frame "testFrame" { - text "texts" { - Text = "We can make ui like this"; - }; - text "texts" { - Text = "asdfasdfasdf"; - }; - text "texts" { - Text = "qweiufnwlqef"; - }; -}); - -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 () - local flip = false; - while wait(0.5) do - flip = not flip; - this.BackgroundTransparency = flip and 1 or 0; - end - end); -end diff --git a/test.project.json b/test.project.json index 5ad52f9..f0c4b51 100644 --- a/test.project.json +++ b/test.project.json @@ -1,11 +1,17 @@ { "name": "Plugin", "tree": { + "$className": "DataModel", "StarterGui": { "$className": "StarterGui", "testGUI": { "$className": "ScreenGui", - "$path": "src" + "testScript": { + "$path": "testScript.client.lua" + }, + "quad": { + "$path": "src" + } } } } diff --git a/testScript.client.lua b/testScript.client.lua new file mode 100644 index 0000000..70a0a4f --- /dev/null +++ b/testScript.client.lua @@ -0,0 +1,66 @@ +-- 이렇게 모듈을 부를 수 있다, 뒤에 if 가 붇은것은 자동완성이 뜨도록 하기 위해서 사용된다 +local quad = require(script.Parent.quad) if false then quad = require("src"); end +local render = quad.init(); +-- init 함수를 이용해 여러 스크립트가 이 모듈을 호출해도 완전히 별계의 +-- 환경에서 실행될 수 있도록 만든다, init 를 호출하면 완전히 새로운 store 와 style +-- 등을 가진 모듈을 새로 생성한다 + +-- 하위 모듈을 이렇게 부른다 +local class = render.class; +local mount = render.mount; +local store = render.store; + +-- 오브젝트를 이렇게 불러온다 +local frame = class "Frame"; -- 이렇게 원하는 오브젝트를 불러올 수 있다 +local text = class "TextLabel"; +text.TextSize = 17; -- 이렇게 오브젝트의 기본값도 정할 수 있다 +text.Size = UDim2.new(1,0,0,30); +local titleText = class "TextLabel"; +-- 당연 이렇게 똑같은 className 을 가진 오브젝트를 여러번 import 도 된다 +-- 다른 임포트에서 설정한 기본값은 여기에 적용되지 않는다 + +local gui = script.Parent; +local app = mount(gui,frame "testFrame" { -- mount 로 트리를 마운트한다, 이후 app 에서 unmount 호출가능 + Size = UDim2.fromOffset(120,60); + Position = UDim2.fromScale(0.5,0.5); + AnchorPoint = Vector2.new(0.5,0.5); + text "texts" { -- 이렇게 단순히 child 개체를 만들 수 있다 + Text = "We can make ui like this"; + }; + text "texts" { + Position = UDim2.fromOffset(0,30); + Text = "qweiufnwlqef"; + }; + titleText { -- 아이디를 명명하지 않아도 오브젝트를 바로 만들 수 있다 + Text = "test"; + }; +}); + +print(store.getObject("texts")); +-- getObject 를 호출하면 해당 id 로 명명된 오브젝트중 +-- 가장 처음으로 생성된 객체를 반환한다 +store.getObjects("texts"):each(function(index,this) + this.Text = "이렇게 모든 택스트를 한꺼번에 바꿀 수도 있습니다"; +end); +-- getObjects 를 이용하면 해당 id 로 명명된 오브젝트가 담긴 array 를 가져온다 +-- for 을 돌릴 수 있지만 each 를 이용해 async 된 작업을 수행할 수 있다 +store.getObjects("texts"):eachSync(function(index,this) + this.Text = "또한, 기본적으로 Aync 를 이용하기 때문에 순차적인 실행이 필요한 경우 Sync 를 붇여야합니다"; +end); +-- sync 를 하면 일반 스크립트를 실행하는것 처럼 순차적으로 실행되도록 만들 수도 있다 +-- 이 때 순서는 먼저 생생된 순서이다, 항상 같음을 유지한다는 보장이 없으므로 순서가 중요한경우 +-- 직접 for 을 이용해 순서 검증을 한 뒤 task 를 수행해야한다 + +-- 이렇게 어떤 오브젝트를 가지고 task 수행하는 thread 를 만들 수 있다 +do local this = store.getObject("testFrame"); + spawn(function () + local flip = false; + while wait(0.5) do + flip = not flip; + this.BackgroundTransparency = flip and 1 or 0; + end + end); +end + +app.unmount(); -- 트리의 객체들을 모두 파기한다, 플러그인에서 unload 같은곳에 쓰는 함수 +return app; \ No newline at end of file