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",
|
||||
"tree": {
|
||||
"$properties": {
|
||||
"Name": "Quad"
|
||||
},
|
||||
"$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)
|
||||
end
|
||||
-- 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;
|
||||
end);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ local tonumber = tonumber
|
|||
local remove = table.remove
|
||||
local insert = table.insert
|
||||
local find = table.find
|
||||
local floor = math.floor
|
||||
|
||||
local script = script
|
||||
local EasingFunctions = require(script and script.EasingFunctions or "EasingFunctions")
|
||||
|
|
@ -60,16 +61,17 @@ module.EasingFunction = module.EasingFunctions
|
|||
-- Lerp 함수
|
||||
------------------------------------
|
||||
-- 이중 선형, Alpha 를 받아서 값을 구해옴
|
||||
function Lerp(start,goal,alpha)
|
||||
return start + ((goal - start) * alpha)
|
||||
local function Lerp(start,goal,alpha)
|
||||
if alpha == 1 then return goal end
|
||||
if alpha == 0 then return start end
|
||||
return start + ((goal - start) * alpha)
|
||||
end
|
||||
|
||||
-- 기본적으로 로블록스에 있는 클래스중, + - * / 과 같은 연산자 처리 메타 인덱스가 있는것들
|
||||
local DefaultItems = {
|
||||
-- 기본적으로 로블록스가 Lerp 를 지원하는 Class
|
||||
local DefaultLerpableItems = {
|
||||
["Vector2"] = true;
|
||||
["Vector3"] = true;
|
||||
["CFrame" ] = true;
|
||||
["number" ] = true;
|
||||
}
|
||||
|
||||
-- 예전 값,목표 값,알파를 주고 각각 해당하는 속성에 입력해줌
|
||||
|
|
@ -87,7 +89,9 @@ function LerpProperties(Item,Old,New,Alpha,Setter)
|
|||
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)
|
||||
elseif Type == "UDim2" then
|
||||
Value = UDim2.new(
|
||||
|
|
@ -98,14 +102,14 @@ function LerpProperties(Item,Old,New,Alpha,Setter)
|
|||
)
|
||||
elseif Type == "UDim" then
|
||||
Value = UDim.new(
|
||||
Lerp(OldValue.Scale ,NewValue.Scale ),
|
||||
Lerp(OldValue.Offset,NewValue.Offset)
|
||||
Lerp(OldValue.Scale ,NewValue.Scale ,Alpha),
|
||||
Lerp(OldValue.Offset,NewValue.Offset,Alpha)
|
||||
)
|
||||
elseif Type == "Color3" then
|
||||
Value = Color3.fromRGB(
|
||||
Lerp(OldValue.r*255,NewValue.r*255),
|
||||
Lerp(OldValue.g*255,NewValue.g*255),
|
||||
Lerp(OldValue.b*255,NewValue.b*255)
|
||||
Lerp(floor(OldValue.r*255),floor(NewValue.r*255) ,Alpha),
|
||||
Lerp(floor(OldValue.g*255),floor(NewValue.g*255),Alpha),
|
||||
Lerp(floor(OldValue.b*255),floor(NewValue.b*255) ,Alpha)
|
||||
)
|
||||
else
|
||||
error(
|
||||
|
|
@ -230,6 +234,10 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
|||
local Now = clock()
|
||||
local Index = 1 - (EndTime - Now) / Time
|
||||
local Alpha = Direction == "Out" and Easing(Index) or (1 - Easing(1 - Index))
|
||||
if Now >= EndTime then
|
||||
Index = 1
|
||||
Alpha = 1
|
||||
end
|
||||
|
||||
-- 속성 Lerp 수행
|
||||
LerpProperties(
|
||||
|
|
@ -247,7 +255,7 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
|||
end
|
||||
|
||||
-- 끝남
|
||||
if Now >= EndTime then
|
||||
if Index == 1 then
|
||||
for Property,_ in pairs(Properties) do
|
||||
ItemPlayIndex[Property] = 0
|
||||
end
|
||||
|
|
@ -267,18 +275,18 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
|||
if CallBack then
|
||||
for FncIndex,Fnc in pairs(CallBack) do
|
||||
if FncIndex == "*" then
|
||||
Fnc(Index,Alpha)
|
||||
Fnc(Index,Alpha,Item)
|
||||
else
|
||||
local num = tonumber(FncIndex)
|
||||
if num then
|
||||
if num <= Index then
|
||||
Fnc(Alpha)
|
||||
Fnc(Alpha,Item)
|
||||
CallBack[FncIndex] = nil
|
||||
end
|
||||
else
|
||||
local alphaNum = tonumber(FncIndex:match"~([%d.]+)")
|
||||
if alphaNum <= Alpha then
|
||||
Fnc(Index)
|
||||
Fnc(Index,Item)
|
||||
CallBack[FncIndex] = nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ this feature should be upgraded
|
|||
local wrap = coroutine.wrap;
|
||||
local insert = table.insert;
|
||||
local remove = table.remove;
|
||||
local gmatch = string.gmatch;
|
||||
local gsub = string.gsub;
|
||||
|
||||
local function catch(...)
|
||||
local passed,err = pcall(...);
|
||||
|
|
@ -26,21 +28,25 @@ function module.init(shared)
|
|||
local items = shared.items;
|
||||
|
||||
-- id space (array of object)
|
||||
local objSpaceClass = {__type = "quad_objspace"};
|
||||
function objSpaceClass:each(func)
|
||||
for i,v in ipairs(self) do
|
||||
wrap(catch)(func,i,v);
|
||||
local objectListClass = {__type = "quad_objectlist"};
|
||||
function objectListClass:each(func)
|
||||
local index = 1;
|
||||
for i,v in pairs(self) do
|
||||
wrap(catch)(func,index,v);
|
||||
index = index + 1;
|
||||
end
|
||||
end
|
||||
function objSpaceClass:eachSync(func)
|
||||
for i,v in ipairs(self) do
|
||||
local ret = func(i,v);
|
||||
function objectListClass:eachSync(func)
|
||||
local index = 1;
|
||||
for _,v in pairs(self) do
|
||||
local ret = func(index,v);
|
||||
index = index + 1;
|
||||
if ret then
|
||||
break;
|
||||
end
|
||||
end
|
||||
end
|
||||
function objSpaceClass:remove(indexOrItem)
|
||||
function objectListClass:remove(indexOrItem)
|
||||
local thisType = type(indexOrItem);
|
||||
if thisType == "number" then
|
||||
remove(self,indexOrItem);
|
||||
|
|
@ -53,35 +59,43 @@ function module.init(shared)
|
|||
end
|
||||
end
|
||||
end
|
||||
function objSpaceClass.__new()
|
||||
return setmetatable({},objSpaceClass);
|
||||
function objectListClass:isEmpty()
|
||||
if next(self) then return true; end
|
||||
return false;
|
||||
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)
|
||||
this[key] = value;
|
||||
end);
|
||||
end
|
||||
objSpaceClass.__mode = "kv"; -- week link for gc
|
||||
objSpaceClass.__index = objSpaceClass;
|
||||
objectListClass.__mode = "kv"; -- week link for gc
|
||||
objectListClass.__index = objectListClass;
|
||||
|
||||
-- get object array with id (objSpace)
|
||||
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
|
||||
-- get first object with id (not array)
|
||||
function new.getObject(id)
|
||||
local item = items[id];
|
||||
return item and item[1];
|
||||
return item and item[next(item)];
|
||||
end
|
||||
--TODO: if item is exist already, ignore this call
|
||||
-- adding object with id
|
||||
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
|
||||
id = id:gsub("^ +",""):gsub(" +$","");
|
||||
id = gsub(gsub(id,"^ +","")," +$","");
|
||||
local array = items[id];
|
||||
if not array then
|
||||
array = objSpaceClass.__new();
|
||||
array = objectListClass.__new();
|
||||
items[id] = array;
|
||||
end
|
||||
insert(array, object);
|
||||
|
|
|
|||
Loading…
Reference in a new issue