fix: fixed atween float number issue
This commit is contained in:
parent
606a11f19b
commit
2d47b75b84
5 changed files with 102 additions and 37 deletions
|
|
@ -1,9 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Quad",
|
"name": "Quad",
|
||||||
"tree": {
|
"tree": {
|
||||||
"$properties": {
|
|
||||||
"Name": "Quad"
|
|
||||||
},
|
|
||||||
"$path": "src"
|
"$path": "src"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
45
docs/kr/index.md
Normal file
45
docs/kr/index.md
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
# Quad
|
||||||
|
|
||||||
|
## 목차
|
||||||
|
|
||||||
|
class.import
|
||||||
|
mount
|
||||||
|
event
|
||||||
|
style
|
||||||
|
store
|
||||||
|
tween
|
||||||
|
store.getStore (register)
|
||||||
|
class.extend
|
||||||
|
|
||||||
|
## 모든 문서
|
||||||
|
|
||||||
|
class
|
||||||
|
*__call*, import
|
||||||
|
*class* extend
|
||||||
|
*private* ~~make~~
|
||||||
|
|
||||||
|
event
|
||||||
|
*__call*
|
||||||
|
prop
|
||||||
|
created
|
||||||
|
createdSync
|
||||||
|
disconnecter
|
||||||
|
*private* ~~bind~~
|
||||||
|
|
||||||
|
mount
|
||||||
|
*__call* mount => mountClass|mountsClass
|
||||||
|
*class* mountClass|mountsClass
|
||||||
|
|
||||||
|
store
|
||||||
|
getObject
|
||||||
|
getObjects => objectList
|
||||||
|
addObject
|
||||||
|
*class* objectList
|
||||||
|
*class* store
|
||||||
|
|
||||||
|
style
|
||||||
|
*private* ~~parseStyles~~
|
||||||
|
*__call* new
|
||||||
|
|
||||||
|
tween (from @qwreey75:AdvancedTween)
|
||||||
|
|
@ -318,7 +318,8 @@ function module.init(shared)
|
||||||
mountfunc(self,parent)
|
mountfunc(self,parent)
|
||||||
end
|
end
|
||||||
-- prevent gc
|
-- prevent gc
|
||||||
((type(object) == "table" and object.__object) or object):GetPropertyChangedSignal "ClassName":Connect(function()
|
((type(object) == "table" and object.__object) or object)
|
||||||
|
:GetPropertyChangedSignal "ClassName":Connect(function()
|
||||||
return self;
|
return self;
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ local tonumber = tonumber
|
||||||
local remove = table.remove
|
local remove = table.remove
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
local find = table.find
|
local find = table.find
|
||||||
|
local floor = math.floor
|
||||||
|
|
||||||
local script = script
|
local script = script
|
||||||
local EasingFunctions = require(script and script.EasingFunctions or "EasingFunctions")
|
local EasingFunctions = require(script and script.EasingFunctions or "EasingFunctions")
|
||||||
|
|
@ -60,16 +61,17 @@ module.EasingFunction = module.EasingFunctions
|
||||||
-- Lerp 함수
|
-- Lerp 함수
|
||||||
------------------------------------
|
------------------------------------
|
||||||
-- 이중 선형, Alpha 를 받아서 값을 구해옴
|
-- 이중 선형, Alpha 를 받아서 값을 구해옴
|
||||||
function Lerp(start,goal,alpha)
|
local function Lerp(start,goal,alpha)
|
||||||
return start + ((goal - start) * alpha)
|
if alpha == 1 then return goal end
|
||||||
|
if alpha == 0 then return start end
|
||||||
|
return start + ((goal - start) * alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 기본적으로 로블록스에 있는 클래스중, + - * / 과 같은 연산자 처리 메타 인덱스가 있는것들
|
-- 기본적으로 로블록스가 Lerp 를 지원하는 Class
|
||||||
local DefaultItems = {
|
local DefaultLerpableItems = {
|
||||||
["Vector2"] = true;
|
["Vector2"] = true;
|
||||||
["Vector3"] = true;
|
["Vector3"] = true;
|
||||||
["CFrame" ] = true;
|
["CFrame" ] = true;
|
||||||
["number" ] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 예전 값,목표 값,알파를 주고 각각 해당하는 속성에 입력해줌
|
-- 예전 값,목표 값,알파를 주고 각각 해당하는 속성에 입력해줌
|
||||||
|
|
@ -87,7 +89,9 @@ function LerpProperties(Item,Old,New,Alpha,Setter)
|
||||||
tostring(type(NewValue))
|
tostring(type(NewValue))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elseif DefaultItems[Type] then
|
elseif DefaultLerpableItems[Type] then
|
||||||
|
Value = OldValue:Lerp(NewValue,Alpha)
|
||||||
|
elseif Type == "number" then
|
||||||
Value = Lerp(OldValue,NewValue,Alpha)
|
Value = Lerp(OldValue,NewValue,Alpha)
|
||||||
elseif Type == "UDim2" then
|
elseif Type == "UDim2" then
|
||||||
Value = UDim2.new(
|
Value = UDim2.new(
|
||||||
|
|
@ -98,14 +102,14 @@ function LerpProperties(Item,Old,New,Alpha,Setter)
|
||||||
)
|
)
|
||||||
elseif Type == "UDim" then
|
elseif Type == "UDim" then
|
||||||
Value = UDim.new(
|
Value = UDim.new(
|
||||||
Lerp(OldValue.Scale ,NewValue.Scale ),
|
Lerp(OldValue.Scale ,NewValue.Scale ,Alpha),
|
||||||
Lerp(OldValue.Offset,NewValue.Offset)
|
Lerp(OldValue.Offset,NewValue.Offset,Alpha)
|
||||||
)
|
)
|
||||||
elseif Type == "Color3" then
|
elseif Type == "Color3" then
|
||||||
Value = Color3.fromRGB(
|
Value = Color3.fromRGB(
|
||||||
Lerp(OldValue.r*255,NewValue.r*255),
|
Lerp(floor(OldValue.r*255),floor(NewValue.r*255) ,Alpha),
|
||||||
Lerp(OldValue.g*255,NewValue.g*255),
|
Lerp(floor(OldValue.g*255),floor(NewValue.g*255),Alpha),
|
||||||
Lerp(OldValue.b*255,NewValue.b*255)
|
Lerp(floor(OldValue.b*255),floor(NewValue.b*255) ,Alpha)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
error(
|
error(
|
||||||
|
|
@ -230,6 +234,10 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
||||||
local Now = clock()
|
local Now = clock()
|
||||||
local Index = 1 - (EndTime - Now) / Time
|
local Index = 1 - (EndTime - Now) / Time
|
||||||
local Alpha = Direction == "Out" and Easing(Index) or (1 - Easing(1 - Index))
|
local Alpha = Direction == "Out" and Easing(Index) or (1 - Easing(1 - Index))
|
||||||
|
if Now >= EndTime then
|
||||||
|
Index = 1
|
||||||
|
Alpha = 1
|
||||||
|
end
|
||||||
|
|
||||||
-- 속성 Lerp 수행
|
-- 속성 Lerp 수행
|
||||||
LerpProperties(
|
LerpProperties(
|
||||||
|
|
@ -247,7 +255,7 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 끝남
|
-- 끝남
|
||||||
if Now >= EndTime then
|
if Index == 1 then
|
||||||
for Property,_ in pairs(Properties) do
|
for Property,_ in pairs(Properties) do
|
||||||
ItemPlayIndex[Property] = 0
|
ItemPlayIndex[Property] = 0
|
||||||
end
|
end
|
||||||
|
|
@ -267,18 +275,18 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
||||||
if CallBack then
|
if CallBack then
|
||||||
for FncIndex,Fnc in pairs(CallBack) do
|
for FncIndex,Fnc in pairs(CallBack) do
|
||||||
if FncIndex == "*" then
|
if FncIndex == "*" then
|
||||||
Fnc(Index,Alpha)
|
Fnc(Index,Alpha,Item)
|
||||||
else
|
else
|
||||||
local num = tonumber(FncIndex)
|
local num = tonumber(FncIndex)
|
||||||
if num then
|
if num then
|
||||||
if num <= Index then
|
if num <= Index then
|
||||||
Fnc(Alpha)
|
Fnc(Alpha,Item)
|
||||||
CallBack[FncIndex] = nil
|
CallBack[FncIndex] = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local alphaNum = tonumber(FncIndex:match"~([%d.]+)")
|
local alphaNum = tonumber(FncIndex:match"~([%d.]+)")
|
||||||
if alphaNum <= Alpha then
|
if alphaNum <= Alpha then
|
||||||
Fnc(Index)
|
Fnc(Index,Item)
|
||||||
CallBack[FncIndex] = nil
|
CallBack[FncIndex] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ this feature should be upgraded
|
||||||
local wrap = coroutine.wrap;
|
local wrap = coroutine.wrap;
|
||||||
local insert = table.insert;
|
local insert = table.insert;
|
||||||
local remove = table.remove;
|
local remove = table.remove;
|
||||||
|
local gmatch = string.gmatch;
|
||||||
|
local gsub = string.gsub;
|
||||||
|
|
||||||
local function catch(...)
|
local function catch(...)
|
||||||
local passed,err = pcall(...);
|
local passed,err = pcall(...);
|
||||||
|
|
@ -26,21 +28,25 @@ function module.init(shared)
|
||||||
local items = shared.items;
|
local items = shared.items;
|
||||||
|
|
||||||
-- id space (array of object)
|
-- id space (array of object)
|
||||||
local objSpaceClass = {__type = "quad_objspace"};
|
local objectListClass = {__type = "quad_objectlist"};
|
||||||
function objSpaceClass:each(func)
|
function objectListClass:each(func)
|
||||||
for i,v in ipairs(self) do
|
local index = 1;
|
||||||
wrap(catch)(func,i,v);
|
for i,v in pairs(self) do
|
||||||
|
wrap(catch)(func,index,v);
|
||||||
|
index = index + 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function objSpaceClass:eachSync(func)
|
function objectListClass:eachSync(func)
|
||||||
for i,v in ipairs(self) do
|
local index = 1;
|
||||||
local ret = func(i,v);
|
for _,v in pairs(self) do
|
||||||
|
local ret = func(index,v);
|
||||||
|
index = index + 1;
|
||||||
if ret then
|
if ret then
|
||||||
break;
|
break;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function objSpaceClass:remove(indexOrItem)
|
function objectListClass:remove(indexOrItem)
|
||||||
local thisType = type(indexOrItem);
|
local thisType = type(indexOrItem);
|
||||||
if thisType == "number" then
|
if thisType == "number" then
|
||||||
remove(self,indexOrItem);
|
remove(self,indexOrItem);
|
||||||
|
|
@ -53,35 +59,43 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function objSpaceClass.__new()
|
function objectListClass:isEmpty()
|
||||||
return setmetatable({},objSpaceClass);
|
if next(self) then return true; end
|
||||||
|
return false;
|
||||||
end
|
end
|
||||||
function objSpaceClass:__newIndex(key,value) -- props setter
|
function objectListClass.__new()
|
||||||
|
return setmetatable({},objectListClass);
|
||||||
|
end
|
||||||
|
function objectListClass:__newIndex(key,value) -- props setter
|
||||||
self:each(function (this)
|
self:each(function (this)
|
||||||
this[key] = value;
|
this[key] = value;
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
objSpaceClass.__mode = "kv"; -- week link for gc
|
objectListClass.__mode = "kv"; -- week link for gc
|
||||||
objSpaceClass.__index = objSpaceClass;
|
objectListClass.__index = objectListClass;
|
||||||
|
|
||||||
-- get object array with id (objSpace)
|
-- get object array with id (objSpace)
|
||||||
function new.getObjects(id)
|
function new.getObjects(id)
|
||||||
return items[id];
|
local list = items[id];
|
||||||
|
if list then return list; end
|
||||||
|
list = objectListClass.__new(id);
|
||||||
|
items[id] = list;
|
||||||
|
return list;
|
||||||
end
|
end
|
||||||
-- get first object with id (not array)
|
-- get first object with id (not array)
|
||||||
function new.getObject(id)
|
function new.getObject(id)
|
||||||
local item = items[id];
|
local item = items[id];
|
||||||
return item and item[1];
|
return item and item[next(item)];
|
||||||
end
|
end
|
||||||
--TODO: if item is exist already, ignore this call
|
--TODO: if item is exist already, ignore this call
|
||||||
-- adding object with id
|
-- adding object with id
|
||||||
function new.addObject(ids,object)
|
function new.addObject(ids,object)
|
||||||
for id in ids:gmatch("[^,]+") do -- split by ,
|
for id in gmatch(ids,"[^,]+") do -- split by ,
|
||||||
-- remove trailing, heading spaces
|
-- remove trailing, heading spaces
|
||||||
id = id:gsub("^ +",""):gsub(" +$","");
|
id = gsub(gsub(id,"^ +","")," +$","");
|
||||||
local array = items[id];
|
local array = items[id];
|
||||||
if not array then
|
if not array then
|
||||||
array = objSpaceClass.__new();
|
array = objectListClass.__new();
|
||||||
items[id] = array;
|
items[id] = array;
|
||||||
end
|
end
|
||||||
insert(array, object);
|
insert(array, object);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue