mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 13:15:50 +00:00
* Switch git submodules to Wally packages * Update build snapshot * Add wally to foreman and use latest versions * Install packages in CI runners * Fix indents * Install packages in the correct directory * Install packages in correct dir of release action too * Remove submodules from ci checkout * Remove submodules from release checkout * Update selene with latest fix * Fix whitespace Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
60 lines
1.3 KiB
Lua
60 lines
1.3 KiB
Lua
local Rojo = script:FindFirstAncestor("Rojo")
|
|
local Packages = Rojo.Packages
|
|
|
|
local Roact = require(Packages.Roact)
|
|
local Log = require(Packages.Log)
|
|
|
|
local LERP_DATA_TYPES = {
|
|
Color3 = true,
|
|
UDim = true,
|
|
UDim2 = true,
|
|
Vector2 = true,
|
|
Vector3 = true,
|
|
}
|
|
|
|
local function fromMotor(motor)
|
|
local motorBinding, setMotorBinding = Roact.createBinding(motor:getValue())
|
|
motor:onStep(setMotorBinding)
|
|
return motorBinding
|
|
end
|
|
|
|
local function mapLerp(binding, value1, value2)
|
|
local valueType = typeof(value1)
|
|
if valueType ~= typeof(value2) then
|
|
Log.error("Type mismatch between values ({}, {}})", valueType, typeof(value2))
|
|
end
|
|
|
|
return binding:map(function(position)
|
|
if valueType == "number" then
|
|
return value1 - (value2 - value1) * position
|
|
elseif LERP_DATA_TYPES[valueType] then
|
|
return value1:lerp(value2, position)
|
|
else
|
|
Log.error("Unable to interpolate type {}", valueType)
|
|
end
|
|
end)
|
|
end
|
|
|
|
local function deriveProperty(binding, propertyName)
|
|
return binding:map(function(values)
|
|
return values[propertyName]
|
|
end)
|
|
end
|
|
|
|
local function blendAlpha(alphaValues)
|
|
local alpha = 0
|
|
|
|
for _, value in pairs(alphaValues) do
|
|
alpha = alpha + (1 - alpha) * value
|
|
end
|
|
|
|
return alpha
|
|
end
|
|
|
|
return {
|
|
fromMotor = fromMotor,
|
|
mapLerp = mapLerp,
|
|
deriveProperty = deriveProperty,
|
|
blendAlpha = blendAlpha,
|
|
}
|