Build tool fixes

This commit is contained in:
CloneTrooper1019 2019-11-25 04:20:42 -06:00
parent 1ab379014b
commit 8d26a1560f
3 changed files with 37 additions and 153 deletions

View File

@ -145,7 +145,7 @@ end
local function startDraggerAction(mPart) local function startDraggerAction(mPart)
if mode == "Delete" then if mode == "Delete" then
gateway:InvokeServer("RequestDelete",mPart) gateway:InvokeServer("RequestDelete", mPart)
return return
end end
@ -166,16 +166,7 @@ local function startDraggerAction(mPart)
while down do while down do
local now = tick() local now = tick()
local joints = {}
for _,joint in pairs(mousePart:GetJoints()) do
if CollectionService:HasTag(joint, "GorillaGlue") then
joints[joint] = joint.Parent
joint.Parent = nil
end
end
--local mousePart = selection.Adornee
if down then if down then
Dragger:MouseMove(mouse.UnitRay) Dragger:MouseMove(mouse.UnitRay)
end end
@ -193,16 +184,19 @@ local function startDraggerAction(mPart)
end end
end end
for joint, parent in pairs(joints) do
joint.Parent = parent
end
RunService.Heartbeat:Wait() RunService.Heartbeat:Wait()
end end
selection.Transparency = 1 selection.Transparency = 1
gateway:InvokeServer("ClearKey", dragKey)
-- Its the servers job to deal with these, but thanks Roblox :)
for _,child in pairs(mousePart:GetChildren()) do
if child:IsA("JointInstance") then
child:Destroy()
end
end
gateway:InvokeServer("ClearKey", dragKey)
currentKey = nil currentKey = nil
end end
end end

View File

@ -38,10 +38,13 @@ submitUpdate.Parent = DraggerService
local draggerScript = script:WaitForChild("Dragger") local draggerScript = script:WaitForChild("Dragger")
local activeKeys = {} local activeKeys = {}
local playerToKey = {}
local partToKey = {}
local debounce = {} local debounce = {}
local weakTable = { __mode = 'k' }
local playerToKey = setmetatable({}, weakTable)
local partToKey = setmetatable({}, weakTable)
local SIMULATE_TAG = "SimulateAfterDrag" local SIMULATE_TAG = "SimulateAfterDrag"
local NO_BREAK_TAG = "GorillaGlue" local NO_BREAK_TAG = "GorillaGlue"
@ -55,14 +58,14 @@ local function canGiveKey(player, part)
if part.Locked then if part.Locked then
return false return false
end end
local playerHasKey = playerToKey[player] local playerHasKey = playerToKey[player]
if playerHasKey then
return false
end
local partHasKey = partToKey[part] local partHasKey = partToKey[part]
if partHasKey then
if playerHasKey or partHasKey then
return false return false
end end
return true return true
end end
@ -72,50 +75,22 @@ local function claimAssembly(player, part)
end end
end end
local function validJointsOf(part)
return coroutine.wrap(function ()
for _,joint in pairs(part:GetJoints()) do
if not CollectionService:HasTag(joint, NO_BREAK_TAG) then
coroutine.yield(joint)
end
end
end)
end
local function breakJoints(part)
for joint in validJointsOf(part) do
if not CollectionService:HasTag(joint, NO_BREAK_TAG) then
joint:Destroy()
end
end
end
local function makeJoints(part)
-- Connect this part to a nearby surface
workspace:JoinToOutsiders({part}, "Surface")
end
local function removePartKey(key) local function removePartKey(key)
local data = activeKeys[key] local data = activeKeys[key]
if data then if data then
local player = data.Player local player = data.Player
local part = data.Part
if player then if player then
playerToKey[player] = nil playerToKey[player] = nil
end end
local part = data.Part
if part then if part then
makeJoints(part) part:MakeJoints()
if CollectionService:HasTag(part, SIMULATE_TAG) then
data.Anchored = false
CollectionService:RemoveTag(part, SIMULATE_TAG)
end
part.Anchored = data.Anchored part.Anchored = data.Anchored
claimAssembly(player, part) claimAssembly(player, part)
partToKey[part] = nil partToKey[part] = nil
end end
@ -123,56 +98,6 @@ local function removePartKey(key)
end end
end end
local function restoreJointUpstream(part)
local collectedParts = {}
if part and CollectionService:HasTag(part, SIMULATE_TAG) then
CollectionService:RemoveTag(part, SIMULATE_TAG)
part.Anchored = false
makeJoints(part)
for joint in validJointsOf(part) do
local part0 = joint.Part0
local part1 = joint.Part1
if part0 and part ~= part0 then
collectedParts[part0] = true
restoreJointUpstream(part0)
end
if part1 and part ~= part1 then
collectedParts[part1] = true
restoreJointUpstream(part1)
end
end
end
return collectedParts
end
local function collapseJointUpstream(part)
if part and not (part.Locked or CollectionService:HasTag(part, SIMULATE_TAG)) then
CollectionService:AddTag(part, SIMULATE_TAG)
part.Anchored = true
for joint in validJointsOf(part) do
local part0 = joint.Part0
local part1 = joint.Part1
if part0 and part ~= part0 then
collapseJointUpstream(part0)
end
if part1 and part ~= part1 then
collapseJointUpstream(part1)
end
end
breakJoints(part)
end
end
function draggerGateway.OnServerInvoke(player, request, ...) function draggerGateway.OnServerInvoke(player, request, ...)
if request == "GetKey" then if request == "GetKey" then
local part, asClone = ... local part, asClone = ...
@ -182,7 +107,7 @@ function draggerGateway.OnServerInvoke(player, request, ...)
local newPart = part:Clone() local newPart = part:Clone()
newPart.Parent = workspace newPart.Parent = workspace
breakJoints(newPart) newPart:BreakJoints()
newPart.CFrame = CFrame.new(part.Position + Vector3.new(0, part.Size.Y, 0)) newPart.CFrame = CFrame.new(part.Position + Vector3.new(0, part.Size.Y, 0))
local copySound = Instance.new("Sound") local copySound = Instance.new("Sound")
@ -203,17 +128,9 @@ function draggerGateway.OnServerInvoke(player, request, ...)
playerToKey[player] = key playerToKey[player] = key
partToKey[part] = key partToKey[part] = key
local collected = restoreJointUpstream(part)
local anchored = part.Anchored local anchored = part.Anchored
part.Anchored = true part.Anchored = true
breakJoints(part) part:BreakJoints()
for otherPart in pairs(collected) do
if otherPart:IsGrounded() then
collapseJointUpstream(otherPart)
end
end
activeKeys[key] = activeKeys[key] =
{ {
@ -260,19 +177,12 @@ function draggerGateway.OnServerInvoke(player, request, ...)
s.Volume = 1 s.Volume = 1
s.PlayOnRemove = true s.PlayOnRemove = true
s.Parent = part s.Parent = part
local connectedParts = restoreJointUpstream(part)
part:Destroy() part:Destroy()
for otherPart in pairs(connectedParts) do
if otherPart:IsGrounded() then
collapseJointUpstream(otherPart)
end
end
end end
wait(.1) wait(.1)
debounce[player] = false debounce[player] = nil
end end
end end
end end
@ -283,6 +193,7 @@ local function onChildAdded(child)
local tool = Instance.new("Tool") local tool = Instance.new("Tool")
tool.Name = draggerTool tool.Name = draggerTool
tool.RequiresHandle = false tool.RequiresHandle = false
tool.CanBeDropped = false
local newDragger = draggerScript:Clone() local newDragger = draggerScript:Clone()
newDragger.Parent = tool newDragger.Parent = tool
@ -315,7 +226,7 @@ local function onSubmitUpdate(player, key, cframe)
if owner == player then if owner == player then
local part = keyData.Part local part = keyData.Part
if part and part:IsDescendantOf(workspace) then if part and part:IsDescendantOf(workspace) then
breakJoints(part) part:BreakJoints()
part.CFrame = cframe part.CFrame = cframe
end end
end end
@ -327,15 +238,6 @@ for _, player in pairs(game.Players:GetPlayers()) do
end end
submitUpdate.OnServerEvent:Connect(onSubmitUpdate) submitUpdate.OnServerEvent:Connect(onSubmitUpdate)
Players.PlayerAdded:Connect(onPlayerAdded) Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoved) Players.PlayerRemoving:Connect(onPlayerRemoved)
-- Garbage Collection
while wait(5) do
for part, key in pairs(partToKey) do
if not part:IsDescendantOf(workspace) then
removePartKey(key)
end
end
end

View File

@ -12,7 +12,8 @@ for _,v in ipairs(brickColors) do
oldColors[v] = true oldColors[v] = true
end end
local textureCaches = {} local textureCaches = setmetatable({}, { __mode = 'k'})
local weakValueMT = { __mode = 'v'}
local colorCaches = {} local colorCaches = {}
local char = string.char local char = string.char
@ -133,6 +134,8 @@ local function onSurfaceChanged(part, surface)
if not (texture and texture:IsA("Texture")) then if not (texture and texture:IsA("Texture")) then
texture = Instance.new("Texture") texture = Instance.new("Texture")
texture.Archivable = false
cache[surface] = texture cache[surface] = texture
texture.StudsPerTileU = 2; texture.StudsPerTileU = 2;
@ -173,20 +176,8 @@ local function onTransparencyChanged(part)
end end
end end
local function onParentChanged(part)
local texureCache = textureCaches[part]
if not part:IsDescendantOf(workspace) then
for _,tex in pairs(texureCache) do
tex:Destroy()
end
texureCache[part] = nil
end
end
local function registerPartSurfaces(part) local function registerPartSurfaces(part)
local textureCache = {} local textureCache = setmetatable({}, weakValueMT)
textureCaches[part] = textureCache textureCaches[part] = textureCache
for surface in pairs(surfaces) do for surface in pairs(surfaces) do
@ -277,8 +268,6 @@ local function onItemChanged(object, descriptor)
onTransparencyChanged(object) onTransparencyChanged(object)
elseif descriptor == "BrickColor" then elseif descriptor == "BrickColor" then
onBrickColorUpdated(object) onBrickColorUpdated(object)
elseif descriptor == "Parent" then
onParentChanged(object)
end end
end end
end end
@ -290,5 +279,4 @@ end
workspace.DescendantAdded:Connect(onDescendantAdded) workspace.DescendantAdded:Connect(onDescendantAdded)
game.ItemChanged:Connect(onItemChanged) game.ItemChanged:Connect(onItemChanged)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------