Code works but has a lot of if statements, is there a way to simplfy this somehow?
local TweenService = game:GetService("TweenService")
local BaseTweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Back, Enum.EasingDirection.In, 0, false, 0)
local BaseUpdateTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0)
local DefaultValues = {
["CanMove"] = {
["Highlight"] = {["FillColor"] = Color3.fromHex("#4fff34"), ["OutlineColor"] = Color3.new(0,0,0)},
["TileHover"] = {["Size"] = UDim2.new(8,0,4,0), ["StudsOffset"] = Vector3.new(0,6,0)},
["BackgroundFrame"] = {["BackgroundColor3"] = Color3.fromHex("#002a0c"), ["BackgroundTransparency"] = 0.7},
["CanMoveLabel"] = {["TextColor3"] = Color3.fromHex("#45ba3d"), ["Text"] = "You can move to this tile"},
["TileFunctionLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "A simple tile that doesnt do much"},
["TileNameLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "Normal Tile"},
["Tweenable"] = true
},
["CantMove"] = {
["Highlight"] = {["FillColor"] = Color3.fromHex("#ff4234"), ["OutlineColor"] = Color3.new(0,0,0)},
["TileHover"] = {["Size"] = UDim2.new(8,0,4,0), ["StudsOffset"] = Vector3.new(0,6,0)},
["BackgroundFrame"] = {["BackgroundColor3"] = Color3.fromHex("#2a0000"), ["BackgroundTransparency"] = 0.7},
["CanMoveLabel"] = {["TextColor3"] = Color3.fromHex("#ba3e3a"), ["Text"] = "You cannot move to this tile"},
["TileFunctionLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "A simple tile that doesnt do much"},
["TileNameLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "Normal Tile"} ,
["Tweenable"] = true
},
["OwnTile"] = {
["Highlight"] = {["FillColor"] = Color3.fromHex("#3cd5ff"), ["OutlineColor"] = Color3.new(0,0,0)},
["TileHover"] = {["Size"] = UDim2.new(8,0,4,0), ["StudsOffset"] = Vector3.new(0,12,0)},
["BackgroundFrame"] = {["BackgroundColor3"] = Color3.fromHex("#00264f"), ["BackgroundTransparency"] = 0.7},
["CanMoveLabel"] = {["TextColor3"] = Color3.fromHex("#5490ff"), ["Text"] = "You are on this tile"},
["TileFunctionLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "A simple tile that doesnt do much"},
["TileNameLabel"] = {["TextColor3"] = Color3.new(255,255,255), ["Text"] = "Normal Tile"} ,
["Tweenable"] = true
}
}
local TileTable = {}
local function UiItUp(Hightlight, Gui, UiTable, MoveStatus, ToUpdate)
local BaseTable = DefaultValues[MoveStatus]
local HighlightTable = UiTable.Highlight or BaseTable.Highlight
local TileHoverTable = UiTable.TileHover or BaseTable.TileHover
local BGFrameTable = UiTable.BackgroundFrame or BaseTable.BackgroundFrame
local CanMoveTable = UiTable.CanMoveLabel or BaseTable.CanMoveLabel
local TileFuncTable = UiTable.TileFunctionLabel or BaseTable.TileFunctionLabel
local TileNameTable = UiTable.TileNameLabel or BaseTable.TileNameLabel
local Tweenable = if UiTable.Tweenable ~= nil then UiTable.Tweenable else BaseTable.Tweenable
local SetTweens = {}
local UpdateTweens = {}
local BGFrame = Gui:FindFirstChild("Frame")
local CanMove = BGFrame:FindFirstChild("CanMove")
local TileFunction = BGFrame:FindFirstChild("TileFunction")
local TileName = BGFrame:FindFirstChild("TileName")
for Property, SetTo in pairs(HighlightTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(Hightlight, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
Hightlight[Property] = SetTo
end
end
for Property, SetTo in pairs(TileHoverTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(Gui, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
Gui[Property] = SetTo
end
end
for Property, SetTo in pairs(BGFrameTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(BGFrame, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
BGFrame[Property] = SetTo
end
end
for Property, SetTo in pairs(CanMoveTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(CanMove, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
CanMove[Property] = SetTo
end
end
for Property, SetTo in pairs(TileFuncTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(TileFunction, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
TileFunction[Property] = SetTo
end
end
for Property, SetTo in pairs(TileNameTable) do
if ToUpdate and Property ~= "Text" and Tweenable then
table.insert(UpdateTweens,
TweenService:Create(TileName, BaseUpdateTweenInfo, {[Property] = SetTo})
)
else
TileName[Property] = SetTo
end
end
if Tweenable then
if Tweenable and not ToUpdate then
Gui.Size = UDim2.new(0,0,0,0)
table.insert(SetTweens,
TweenService:Create(Gui, BaseTweenInfo, {Size = TileHoverTable.Size})
)
end
end
return if ToUpdate then UpdateTweens else SetTweens
end
local tUI = {
}
function tUI.SetUi(Tile, Hightlight, Gui, MoveStatus, ToUpdate)
local Tweens = UiItUp(Hightlight, Gui, TileTable[Tile.Name] or {}, MoveStatus, ToUpdate)
print(MoveStatus)
if tUI[Tile.Name] then tUI[Tile.Name](Hightlight, Gui, MoveStatus, Tile) end
return true, Tweens
end
function tUI.RainbowTile(Highlight, Gui)
--yeah
end
return tUI