tangled
alpha
login
or
join now
kris.darkworld.download
/
block-game
0
fork
atom
Minecraft-like Roblox block game
rblx.games/135624152691584
roblox
roblox-game
rojo
0
fork
atom
overview
issues
pulls
pipelines
placement: fix selection box
kris.darkworld.download
2 months ago
3221d755
2381fa12
+39
-10
1 changed file
expand all
collapse all
unified
split
src
ReplicatedStorage
Shared
PlacementManager.lua
+39
-10
src/ReplicatedStorage/Shared/PlacementManager.lua
···
26
26
raycastParams.FilterType = Enum.RaycastFilterType.Include
27
27
raycastParams.IgnoreWater = true
28
28
29
29
+
local Mouse: Mouse = nil
30
30
+
local lastNormalId: Enum.NormalId? = nil
31
31
+
local lastRaycastFailure: string? = nil
32
32
+
local lastSelectedChunkKey: string? = nil
33
33
+
local lastSelectedBlockKey: string? = nil
34
34
+
local BREAK_ROLLBACK_TIMEOUT = 0.6
35
35
+
local pendingBreaks = {}
36
36
+
local clearSelection
37
37
+
29
38
if _G.__BLOCKSCRAFT_PLACEMENT_MANAGER then
30
39
return _G.__BLOCKSCRAFT_PLACEMENT_MANAGER
31
40
end
···
35
44
PlacementManager.SelectionBox.Name = "$SelectionBox"..(game:GetService("RunService"):IsServer() and "_SERVER" or "")
36
45
PlacementManager.SelectionBox.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
37
46
PlacementManager.SelectionBox.Adornee = nil
47
47
+
PlacementManager.SelectionBox:GetPropertyChangedSignal("Adornee"):Connect(function()
48
48
+
local adornee = PlacementManager.SelectionBox.Adornee
49
49
+
if not adornee then
50
50
+
return
51
51
+
end
52
52
+
adornee.AncestryChanged:Connect(function(_, parent)
53
53
+
if not parent then
54
54
+
clearSelection("adornee destroyed")
55
55
+
end
56
56
+
end)
57
57
+
end)
38
58
39
59
-- Trash method TODO: Fix this
40
60
local function findChunkFolderFromDescendant(inst: Instance): Instance?
···
71
91
return chunkInst:FindFirstChild(blockName)
72
92
end
73
93
74
74
-
local function clearSelection(reason: string?)
94
94
+
clearSelection = function(reason: string?)
75
95
PlacementManager.SelectionBox.Adornee = nil
76
96
PlacementManager.SelectionBox.Parent = nil
77
97
lastNormalId = nil
98
98
+
lastSelectedChunkKey = nil
99
99
+
lastSelectedBlockKey = nil
78
100
if reason then
79
101
lastRaycastFailure = reason
80
102
end
···
105
127
return nil, nil
106
128
end
107
129
108
108
-
local Mouse: Mouse = nil
109
109
-
local lastNormalId: Enum.NormalId? = nil
110
110
-
local BREAK_ROLLBACK_TIMEOUT = 0.6
111
111
-
local pendingBreaks = {}
112
112
-
local lastRaycastFailure: string? = nil
113
130
local function vectorToNormalId(normal: Vector3): Enum.NormalId
114
131
local ax, ay, az = math.abs(normal.X), math.abs(normal.Y), math.abs(normal.Z)
115
132
if ax >= ay and ax >= az then
···
324
341
script.RaycastResult.Value = nil
325
342
return
326
343
end
344
344
+
local chunkKey = makeChunkKey(chunkCoords.X, chunkCoords.Y, chunkCoords.Z)
345
345
+
local blockKey = makeBlockKey(blockCoords.X, blockCoords.Y, blockCoords.Z)
346
346
+
347
347
+
-- block is being optimistically broken, do not highlight it
348
348
+
if getPendingBreak(chunkKey, blockKey) then
349
349
+
clearSelection("block pending break")
350
350
+
script.RaycastResult.Value = nil
351
351
+
return
352
352
+
end
327
353
328
354
-- hide selection if block no longer exists (air/removed)
329
355
local chunk = ChunkManager:GetChunk(chunkCoords.X, chunkCoords.Y, chunkCoords.Z)
···
341
367
end
342
368
343
369
lastRaycastFailure = nil
344
344
-
setSelection(blockInstance, PlacementManager.ChunkFolder)
370
370
+
if lastSelectedChunkKey ~= chunkKey or lastSelectedBlockKey ~= blockKey then
371
371
+
setSelection(blockInstance, PlacementManager.ChunkFolder)
372
372
+
lastSelectedChunkKey = chunkKey
373
373
+
lastSelectedBlockKey = blockKey
374
374
+
end
345
375
script.RaycastResult.Value = objLookingAt
346
376
lastNormalId = vectorToNormalId(result.Normal)
347
377
debugPlacementLog(
···
520
550
local selectedPart = PlacementManager:RaycastGetResult()
521
551
--print(selectedPart and selectedPart:GetFullName() or nil)
522
552
if selectedPart == nil then
523
523
-
PlacementManager.SelectionBox.Adornee = nil
553
553
+
clearSelection()
524
554
script.RaycastResult.Value = nil
525
525
-
lastNormalId = nil
526
555
debugPlacementLog("[PLACE][CLIENT][TARGET]", "no selectedPart after raycast", lastRaycastFailure)
527
556
return nil
528
557
end
···
624
653
PlacementManager:Raycast()
625
654
end)
626
655
if not a then
627
627
-
PlacementManager.SelectionBox.Adornee = nil
656
656
+
clearSelection("raycast error")
628
657
script.RaycastResult.Value = nil
629
658
end
630
659
end)