added test file, added more feature
This commit is contained in:
parent
085d847abe
commit
86497c9b03
11 changed files with 264 additions and 69 deletions
152
build.rbxmx
152
build.rbxmx
|
|
@ -28,18 +28,22 @@ frame{
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
require = require(script.require);
|
||||||
|
local event = require("event");
|
||||||
|
local store = require("store");
|
||||||
|
local style = require("style");
|
||||||
|
local class = require("class");
|
||||||
|
local mount = require("mount");
|
||||||
|
|
||||||
function module.init()
|
function module.init()
|
||||||
local this = {items = {}};
|
local this = {items = {}};
|
||||||
|
|
||||||
local event = require(script.event).init(this); if false then event = require("src.event").init(this); end
|
this.event = event.init(this);
|
||||||
local class = require(script.class).init(this); if false then class = require("src.class").init(this); end
|
this.store = store.init(this);
|
||||||
local store = require(script.store).init(this); if false then store = require("src.store").init(this); end
|
this.style = style.init(this);
|
||||||
local style = require(script.style).init(this); if false then style = require("src.style").init(this); end
|
this.class = class.init(this);
|
||||||
|
this.mount = mount.init(this);
|
||||||
|
|
||||||
this.event = event;
|
|
||||||
this.class = class;
|
|
||||||
this.store = store;
|
|
||||||
this.style = style;
|
|
||||||
--this.makeClass = makeClass;
|
--this.makeClass = makeClass;
|
||||||
--this.tween = tween;
|
--this.tween = tween;
|
||||||
--this.plugin = plugin;
|
--this.plugin = plugin;
|
||||||
|
|
@ -51,6 +55,12 @@ return module;
|
||||||
]]></string>
|
]]></string>
|
||||||
</Properties>
|
</Properties>
|
||||||
<Item class="ModuleScript" referent="1">
|
<Item class="ModuleScript" referent="1">
|
||||||
|
<Properties>
|
||||||
|
<string name="Name">bind</string>
|
||||||
|
<string name="Source"></string>
|
||||||
|
</Properties>
|
||||||
|
</Item>
|
||||||
|
<Item class="ModuleScript" referent="2">
|
||||||
<Properties>
|
<Properties>
|
||||||
<string name="Name">class</string>
|
<string name="Name">class</string>
|
||||||
<string name="Source">local module = {};
|
<string name="Source">local module = {};
|
||||||
|
|
@ -58,21 +68,21 @@ return module;
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
local bind = shared.event.bind;
|
local bind = shared.event.bind;
|
||||||
local items = shared.items;
|
local addObject = shared.store.addObject;
|
||||||
|
|
||||||
function new.make(ClassName,prop)
|
function new.make(ClassName,prop)
|
||||||
-- make thing
|
-- make thing
|
||||||
local item;
|
local item;
|
||||||
local classOfClassName = type(ClassName);
|
local classOfClassName = type(ClassName);
|
||||||
if classOfClassName == "string" then
|
if classOfClassName == "string" then -- if classname is a string value, cdall instance.new for making new roblox instance
|
||||||
item = Instance.new(ClassName);
|
item = Instance.new(ClassName);
|
||||||
elseif classOfClassName == "function" then
|
elseif classOfClassName == "function" then -- if classname is a function value, call it for making new object (OOP object)
|
||||||
item = ClassName();
|
item = ClassName();
|
||||||
elseif classOfClassName == "table" then
|
elseif classOfClassName == "table" then -- if classname is a calss what is included new function, call it for making new object (object)
|
||||||
local func = ClassName.new or ClassName.New or ClassName.__new;
|
local func = ClassName.new or ClassName.New or ClassName.__new;
|
||||||
item = func();
|
item = func();
|
||||||
end
|
end
|
||||||
if not item then
|
if not item then -- if cannot make new object, ignore this call
|
||||||
local str = tostring(ClassName);
|
local str = tostring(ClassName);
|
||||||
print(("fail to make item '%s', did you forget to checking the class '%s' is exist?"):format(str,str));
|
print(("fail to make item '%s', did you forget to checking the class '%s' is exist?"):format(str,str));
|
||||||
end
|
end
|
||||||
|
|
@ -94,21 +104,26 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
local make = new.make;
|
local make = new.make;
|
||||||
|
|
||||||
function new.import(ClassName)
|
function new.import(ClassName) -- make new quad class object
|
||||||
return function (prop)
|
local this = {styles = {}};
|
||||||
if type(prop) == "string" then
|
setmetatable(this,{
|
||||||
local lastName = prop;
|
__call = function (self,prop)
|
||||||
return function (nprop)
|
if type(prop) == "string" then
|
||||||
nprop.Name = lastName;
|
local lastName = prop;
|
||||||
local item = make(ClassName,nprop);
|
return function (nprop)
|
||||||
items[lastName] = item;
|
nprop.Name = lastName;
|
||||||
return item;
|
local item = make(ClassName,nprop);
|
||||||
end;
|
addObject(lastName,item);
|
||||||
end
|
return item;
|
||||||
return make(ClassName,prop);
|
end;
|
||||||
end;
|
end
|
||||||
|
return make(ClassName,prop);
|
||||||
|
end;
|
||||||
|
});
|
||||||
|
return this;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set module calling function
|
||||||
setmetatable(new,{
|
setmetatable(new,{
|
||||||
__call = function (self,...)
|
__call = function (self,...)
|
||||||
return self.import(...);
|
return self.import(...);
|
||||||
|
|
@ -121,7 +136,7 @@ end
|
||||||
return module;</string>
|
return module;</string>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Item>
|
</Item>
|
||||||
<Item class="ModuleScript" referent="2">
|
<Item class="ModuleScript" referent="3">
|
||||||
<Properties>
|
<Properties>
|
||||||
<string name="Name">event</string>
|
<string name="Name">event</string>
|
||||||
<string name="Source">local module = {};
|
<string name="Source">local module = {};
|
||||||
|
|
@ -196,7 +211,68 @@ end
|
||||||
return module;</string>
|
return module;</string>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Item>
|
</Item>
|
||||||
<Item class="ModuleScript" referent="3">
|
<Item class="ModuleScript" referent="4">
|
||||||
|
<Properties>
|
||||||
|
<string name="Name">mount</string>
|
||||||
|
<string name="Source">local module = {};
|
||||||
|
|
||||||
|
function module.init(shared)
|
||||||
|
local new = {};
|
||||||
|
|
||||||
|
-- we should add plugin support
|
||||||
|
function new.mount(to,this)
|
||||||
|
this.Parent = to;
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(new,{
|
||||||
|
__call = function (self,...)
|
||||||
|
self.mount(...);
|
||||||
|
end;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new;
|
||||||
|
end
|
||||||
|
|
||||||
|
return module;</string>
|
||||||
|
</Properties>
|
||||||
|
</Item>
|
||||||
|
<Item class="ModuleScript" referent="5">
|
||||||
|
<Properties>
|
||||||
|
<string name="Name">require</string>
|
||||||
|
<string name="Source">-- remove the roblox's require system,
|
||||||
|
-- now, we can call modules with string path
|
||||||
|
|
||||||
|
if (not workspace) and (not game) and (not script) then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
return function (query)
|
||||||
|
local typeQuery = type(query);
|
||||||
|
|
||||||
|
if typeQuery == "string" then
|
||||||
|
local object = script.Parent;
|
||||||
|
query = query:gsub("/",".");
|
||||||
|
-- local index = 0;
|
||||||
|
query:gsub("[^%.]+",function (this)
|
||||||
|
-- index = index + 1;
|
||||||
|
-- if index == 1 and this == "src" then
|
||||||
|
-- return;
|
||||||
|
-- end
|
||||||
|
local lastObject = object;
|
||||||
|
object = object[this];
|
||||||
|
if not object then
|
||||||
|
object = lastObject.libs
|
||||||
|
error(("[require] : object %s was not found from this worktree, require failed"):format(query));
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
return require(object);
|
||||||
|
elseif typeQuery == "userdata" then
|
||||||
|
return require(query);
|
||||||
|
end
|
||||||
|
end;</string>
|
||||||
|
</Properties>
|
||||||
|
</Item>
|
||||||
|
<Item class="ModuleScript" referent="6">
|
||||||
<Properties>
|
<Properties>
|
||||||
<string name="Name">store</string>
|
<string name="Name">store</string>
|
||||||
<string name="Source"><![CDATA[local module = {};
|
<string name="Source"><![CDATA[local module = {};
|
||||||
|
|
@ -207,23 +283,31 @@ but, it can't allows mulit id and object
|
||||||
this feature should be upgraded
|
this feature should be upgraded
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local insert = table.insert;
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
local items = shared.items;
|
local items = shared.items;
|
||||||
|
|
||||||
function new.getObject(id)
|
function new.getObjects(id)
|
||||||
return items[id];
|
return items[id];
|
||||||
end
|
end
|
||||||
function new.setObject(id,object)
|
function new.addObject(id,object)
|
||||||
items[id] = object;
|
local array = items[id];
|
||||||
|
if not array then
|
||||||
|
array = {};
|
||||||
|
items[id] = array;
|
||||||
|
end
|
||||||
|
insert(array, object);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return new;
|
||||||
end
|
end
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
]]></string>
|
]]></string>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Item>
|
</Item>
|
||||||
<Item class="ModuleScript" referent="4">
|
<Item class="ModuleScript" referent="7">
|
||||||
<Properties>
|
<Properties>
|
||||||
<string name="Name">style</string>
|
<string name="Name">style</string>
|
||||||
<string name="Source">local module = {};
|
<string name="Source">local module = {};
|
||||||
|
|
@ -231,12 +315,10 @@ return module;
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
|
|
||||||
function shared.new()
|
function shared.new(property)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function shared.
|
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
1
build.sh
Normal file
1
build.sh
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
rojo build default.project.json -o build.rbxmx
|
||||||
0
src/bind.lua
Normal file
0
src/bind.lua
Normal file
|
|
@ -3,21 +3,21 @@ local module = {};
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
local bind = shared.event.bind;
|
local bind = shared.event.bind;
|
||||||
local items = shared.items;
|
local addObject = shared.store.addObject;
|
||||||
|
|
||||||
function new.make(ClassName,prop)
|
function new.make(ClassName,prop)
|
||||||
-- make thing
|
-- make thing
|
||||||
local item;
|
local item;
|
||||||
local classOfClassName = type(ClassName);
|
local classOfClassName = type(ClassName);
|
||||||
if classOfClassName == "string" then
|
if classOfClassName == "string" then -- if classname is a string value, cdall instance.new for making new roblox instance
|
||||||
item = Instance.new(ClassName);
|
item = Instance.new(ClassName);
|
||||||
elseif classOfClassName == "function" then
|
elseif classOfClassName == "function" then -- if classname is a function value, call it for making new object (OOP object)
|
||||||
item = ClassName();
|
item = ClassName();
|
||||||
elseif classOfClassName == "table" then
|
elseif classOfClassName == "table" then -- if classname is a calss what is included new function, call it for making new object (object)
|
||||||
local func = ClassName.new or ClassName.New or ClassName.__new;
|
local func = ClassName.new or ClassName.New or ClassName.__new;
|
||||||
item = func();
|
item = func();
|
||||||
end
|
end
|
||||||
if not item then
|
if not item then -- if cannot make new object, ignore this call
|
||||||
local str = tostring(ClassName);
|
local str = tostring(ClassName);
|
||||||
print(("fail to make item '%s', did you forget to checking the class '%s' is exist?"):format(str,str));
|
print(("fail to make item '%s', did you forget to checking the class '%s' is exist?"):format(str,str));
|
||||||
end
|
end
|
||||||
|
|
@ -29,7 +29,7 @@ function module.init(shared)
|
||||||
|
|
||||||
-- child
|
-- child
|
||||||
if indexType ~= "string" then -- object
|
if indexType ~= "string" then -- object
|
||||||
value.Parent = new;
|
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
|
||||||
|
|
@ -39,21 +39,26 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
local make = new.make;
|
local make = new.make;
|
||||||
|
|
||||||
function new.import(ClassName)
|
function new.import(ClassName) -- make new quad class object
|
||||||
return function (prop)
|
local this = {styles = {}};
|
||||||
if type(prop) == "string" then
|
setmetatable(this,{
|
||||||
local lastName = prop;
|
__call = function (self,prop)
|
||||||
return function (nprop)
|
if type(prop) == "string" then
|
||||||
nprop.Name = lastName;
|
local lastName = prop;
|
||||||
local item = make(ClassName,nprop);
|
return function (nprop)
|
||||||
items[lastName] = item;
|
nprop.Name = lastName;
|
||||||
return item;
|
local item = make(ClassName,nprop);
|
||||||
end;
|
addObject(lastName,item);
|
||||||
end
|
return item;
|
||||||
return make(ClassName,prop);
|
end;
|
||||||
end;
|
end
|
||||||
|
return make(ClassName,prop);
|
||||||
|
end;
|
||||||
|
});
|
||||||
|
return this;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set module calling function
|
||||||
setmetatable(new,{
|
setmetatable(new,{
|
||||||
__call = function (self,...)
|
__call = function (self,...)
|
||||||
return self.import(...);
|
return self.import(...);
|
||||||
|
|
|
||||||
20
src/init.lua
20
src/init.lua
|
|
@ -23,18 +23,22 @@ frame{
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
require = require(script.require);
|
||||||
|
local event = require("event");
|
||||||
|
local store = require("store");
|
||||||
|
local style = require("style");
|
||||||
|
local class = require("class");
|
||||||
|
local mount = require("mount");
|
||||||
|
|
||||||
function module.init()
|
function module.init()
|
||||||
local this = {items = {}};
|
local this = {items = {}};
|
||||||
|
|
||||||
local event = require(script.event).init(this); if false then event = require("src.event").init(this); end
|
this.event = event.init(this);
|
||||||
local class = require(script.class).init(this); if false then class = require("src.class").init(this); end
|
this.store = store.init(this);
|
||||||
local store = require(script.store).init(this); if false then store = require("src.store").init(this); end
|
this.style = style.init(this);
|
||||||
local style = require(script.style).init(this); if false then style = require("src.style").init(this); end
|
this.class = class.init(this);
|
||||||
|
this.mount = mount.init(this);
|
||||||
|
|
||||||
this.event = event;
|
|
||||||
this.class = class;
|
|
||||||
this.store = store;
|
|
||||||
this.style = style;
|
|
||||||
--this.makeClass = makeClass;
|
--this.makeClass = makeClass;
|
||||||
--this.tween = tween;
|
--this.tween = tween;
|
||||||
--this.plugin = plugin;
|
--this.plugin = plugin;
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 78746916147fc401984a1267c361a946a7784262
|
|
||||||
20
src/mount.lua
Normal file
20
src/mount.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
local module = {};
|
||||||
|
|
||||||
|
function module.init(shared)
|
||||||
|
local new = {};
|
||||||
|
|
||||||
|
-- we should add plugin support
|
||||||
|
function new.mount(to,this)
|
||||||
|
this.Parent = to;
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(new,{
|
||||||
|
__call = function (self,...)
|
||||||
|
self.mount(...);
|
||||||
|
end;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new;
|
||||||
|
end
|
||||||
|
|
||||||
|
return module;
|
||||||
31
src/require.lua
Normal file
31
src/require.lua
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
-- remove the roblox's require system,
|
||||||
|
-- now, we can call modules with string path
|
||||||
|
|
||||||
|
if (not workspace) and (not game) and (not script) then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
return function (query)
|
||||||
|
local typeQuery = type(query);
|
||||||
|
|
||||||
|
if typeQuery == "string" then
|
||||||
|
local object = script.Parent;
|
||||||
|
query = query:gsub("/",".");
|
||||||
|
-- local index = 0;
|
||||||
|
query:gsub("[^%.]+",function (this)
|
||||||
|
-- index = index + 1;
|
||||||
|
-- if index == 1 and this == "src" then
|
||||||
|
-- return;
|
||||||
|
-- end
|
||||||
|
local lastObject = object;
|
||||||
|
object = object[this];
|
||||||
|
if not object then
|
||||||
|
object = lastObject.libs
|
||||||
|
error(("[require] : object %s was not found from this worktree, require failed"):format(query));
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
return require(object);
|
||||||
|
elseif typeQuery == "userdata" then
|
||||||
|
return require(query);
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
@ -6,16 +6,34 @@ but, it can't allows mulit id and object
|
||||||
this feature should be upgraded
|
this feature should be upgraded
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local insert = table.insert;
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
local items = shared.items;
|
local items = shared.items;
|
||||||
|
|
||||||
function new.getObject(id)
|
local objSpace = {};
|
||||||
|
function objSpace:each(func)
|
||||||
|
for i,v in ipairs(self) do
|
||||||
|
local ret = func(i,v);
|
||||||
|
if ret then
|
||||||
|
break;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function new.getObjects(id)
|
||||||
return items[id];
|
return items[id];
|
||||||
end
|
end
|
||||||
function new.setObject(id,object)
|
function new.addObject(id,object)
|
||||||
items[id] = object;
|
local array = items[id];
|
||||||
|
if not array then
|
||||||
|
array = setmetatable({},{__index = objSpace});
|
||||||
|
items[id] = array;
|
||||||
|
end
|
||||||
|
insert(array, object);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return new;
|
||||||
end
|
end
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,10 @@ local module = {};
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
|
|
||||||
function shared.new()
|
function shared.new(property)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function shared.
|
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
37
test.lua
Normal file
37
test.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
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 style = render.style;
|
||||||
|
|
||||||
|
local frame = class "Frame";
|
||||||
|
local text = class "TextLabel";
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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
|
||||||
Loading…
Reference in a new issue