Clean up terrain plugin scripts

This commit is contained in:
Lewin Kelly 2024-03-22 20:50:20 +00:00
parent 759056c0da
commit b01af4131b
9 changed files with 102 additions and 79 deletions

View File

@ -249,7 +249,7 @@ end
-- Show the highlighter.
function Highlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace.
self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end
-- Update where the highlighter is displayed.
@ -971,7 +971,7 @@ function GenerateTerrain()
-- Clean up the progress bar.
UnloadProgressBar()
--Generate Terrain End
game:GetService("ChangeHistoryService"):SetWaypoint "Generate"
ChangeHistoryService:SetWaypoint "Generate"
end
local ConfirmationPopup
@ -1018,7 +1018,7 @@ function ClearTerrain()
--Erase Terrain End
UnloadProgressBar()
game:GetService("ChangeHistoryService"):SetWaypoint "Reset"
ChangeHistoryService:SetWaypoint "Reset"
end
-- Function used by the clear button. Prompts the user first.

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -153,7 +156,7 @@ function MouseHighlighter.Create(mouseUse)
-- NOTE:
-- Change this gui to be the one you want to use.
highlighter.selectionBox.Parent = game:GetService "CoreGui"
highlighter.selectionBox.Parent = CoreGui
local vectorPos = Vector3.new(position.x, position.y, position.z)
local cellPos = WorldToCellPreferEmpty(c, vectorPos)
@ -206,7 +209,7 @@ end
-- Show the highlighter.
function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace.
self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end
-- Create the mouse movement highlighter.
@ -243,7 +246,7 @@ end
--screengui
local g = Instance.new "ScreenGui"
g.Name = "BuilderGui"
g.Parent = game:GetService "CoreGui"
g.Parent = CoreGui
-- UI gui load. Required for sliders.
local RbxGui = LoadLibrary "RbxGui"
@ -359,7 +362,7 @@ function onClicked(mouseC)
end
-- Mark undo point.
game:GetService("ChangeHistoryService"):SetWaypoint "Builder"
ChangeHistoryService:SetWaypoint "Builder"
UpdatePosition(mouseC.Hit)
end

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
-----------------
--DEFAULT VALUES-
-----------------
@ -163,7 +166,7 @@ end
-- Show the highlighter.
function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace.
self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end
-- Create the mouse movement highlighter.
@ -261,7 +264,7 @@ function onClicked(mouse2)
SetCell(c, x, y, z, 0, 0, 0)
-- Mark undo point.
game:GetService("ChangeHistoryService"):SetWaypoint "Remover"
ChangeHistoryService:SetWaypoint "Remover"
UpdatePosition(mouse2.Hit)

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -62,6 +65,39 @@ local elevationOptions = {
-- What color to use for the mouse highlighter.
local mouseHighlightColor = BrickColor.new "Lime green"
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)
--
-- vectorPos - End point of the line.
--
-- Return:
-- success - Value is true if there was a plane intersection, false if not.
-- cellPos - Value is the terrain cell intersection point if there is one, vectorPos if there isn't.
local function PlaneIntersection(vectorPos)
local currCamera = game.Workspace.CurrentCamera
local startPos = Vector3.new(
currCamera.CoordinateFrame.p.X,
currCamera.CoordinateFrame.p.Y,
currCamera.CoordinateFrame.p.Z
)
local endPos = Vector3.new(vectorPos.X, vectorPos.Y, vectorPos.Z)
local normal = Vector3.new(0, 1, 0)
local p3 = Vector3.new(0, 0, 0)
local startEndDot = normal:Dot(endPos - startPos)
local cellPos = vectorPos
local success = false
if startEndDot ~= 0 then
local t = normal:Dot(p3 - startPos) / startEndDot
if t >= 0 and t <= 1 then
local intersection = ((endPos - startPos) * t) + startPos
cellPos = c:WorldToCell(intersection)
success = true
end
end
return success, cellPos
end
-- Used to create a highlighter that follows the mouse.
-- It is a class mouse highlighter. To use, call MouseHighlighter.Create(mouse) where mouse is the mouse to track.
local MouseHighlighter = {}
@ -118,39 +154,6 @@ function MouseHighlighter.Create(mouseUse)
mouseH.TargetFilter = highlighter.selectionPart
setmetatable(highlighter, MouseHighlighter)
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)
--
-- vectorPos - End point of the line.
--
-- Return:
-- success - Value is true if there was a plane intersection, false if not.
-- cellPos - Value is the terrain cell intersection point if there is one, vectorPos if there isn't.
local function PlaneIntersection(vectorPos)
local currCamera = game.Workspace.CurrentCamera
local startPos = Vector3.new(
currCamera.CoordinateFrame.p.X,
currCamera.CoordinateFrame.p.Y,
currCamera.CoordinateFrame.p.Z
)
local endPos = Vector3.new(vectorPos.X, vectorPos.Y, vectorPos.Z)
local normal = Vector3.new(0, 1, 0)
local p3 = Vector3.new(0, 0, 0)
local startEndDot = normal:Dot(endPos - startPos)
local cellPos = vectorPos
local success = false
if startEndDot ~= 0 then
local t = normal:Dot(p3 - startPos) / startEndDot
if t >= 0 and t <= 1 then
local intersection = ((endPos - startPos) * t) + startPos
cellPos = c:WorldToCell(intersection)
success = true
end
end
return success, cellPos
end
-- Update where the highlighter is displayed.
-- position - Where to display the highlighter, in world space.
function UpdatePosition(position)
@ -160,7 +163,7 @@ function MouseHighlighter.Create(mouseUse)
-- NOTE:
-- Change this gui to be the one you want to use.
highlighter.selectionBox.Parent = game:GetService "CoreGui"
highlighter.selectionBox.Parent = CoreGui
local vectorPos = Vector3.new(position.x, position.y, position.z)
local cellPos = WorldToCellPreferEmpty(c, vectorPos)
@ -213,7 +216,7 @@ end
-- Show the highlighter.
function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace.
self.selectionBox.Parent = CoreGui-- This will make it not show up in workspace.
end
-- Create the mouse movement highlighter.
@ -225,7 +228,7 @@ local mouseHighlighter = MouseHighlighter.Create(mouse)
--screengui
local g = Instance.new "ScreenGui"
g.Name = "ElevationGui"
g.Parent = game:GetService "CoreGui"
g.Parent = CoreGui
-- UI gui load. Required for sliders.
local RbxGui = LoadLibrary "RbxGui"
@ -364,7 +367,8 @@ local slopeLabel = CreateStandardLabel(
"",
elevationFrame
)
local _, slopeSliderPosition = CreateStandardSlider(
local _, slopeSliderPosition
_, slopeSliderPosition = CreateStandardSlider(
"slopeSliderGui",
UDim2.new(0, 1, 0, 67),
UDim2.new(0, 10, 0.5, -2),
@ -435,6 +439,9 @@ end
local height
local oldheightmap = {}
local heightmap = {}
--elevates terrain at point (x, y, z) in cluster c
--within radius r1 from x, z the elevation should become y + d
--from radius r1 to r2 the elevation should be a gradient
@ -547,6 +554,8 @@ end
-- return math.sqrt(math.pow(dist(x1, z1, x2, z2), 2) + math.pow(math.abs(y2 - y1) * 100 / d, 2))
-- end
local mousedown = false
-- Run when the mouse gets clicked. If the click is on terrain, then it will be used as the starting point of the elevation area.
function onClicked(mouse2)
if on then
@ -594,7 +603,7 @@ function onClicked(mouse2)
-- Hide the selection area while dragging.
mouseHighlighter:DisablePreview()
local mousedown = true
mousedown = true
local originalY = mouse2.Y
local prevY = originalY
local d = 0
@ -618,7 +627,7 @@ function onClicked(mouse2)
end
wait(0)
end
game:GetService("ChangeHistoryService"):SetWaypoint "Elevation"
ChangeHistoryService:SetWaypoint "Elevation"
end
end

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -65,7 +68,7 @@ mouse.Button1Up:connect(function()
brushheight = nil
enablePreview()
updatePreviewSelection(mouse.Hit)
game:GetService("ChangeHistoryService"):SetWaypoint "Brush"
ChangeHistoryService:SetWaypoint "Brush"
end)
mouse.Move:connect(function()
mouseMoved()
@ -541,7 +544,7 @@ end
--screengui
local g = Instance.new "ScreenGui"
g.Name = "TerrainBrushGui"
g.Parent = game:GetService "CoreGui"
g.Parent = CoreGui
brushDragBar, elevationFrame, elevationHelpFrame, elevationCloseEvent =
RbxGui.CreatePluginFrame(

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -131,7 +134,7 @@ function onClicked(mouseC)
makeCrater(x, y, z, r, d)
debounce = false
game:GetService("ChangeHistoryService"):SetWaypoint "Crater"
ChangeHistoryService:SetWaypoint "Crater"
end
end
@ -171,7 +174,7 @@ local RbxGui = LoadLibrary "RbxGui"
--screengui
local g = Instance.new "ScreenGui"
g.Name = "CraterGui"
g.Parent = game:GetService "CoreGui"
g.Parent = CoreGui
craterDragBar, craterFrame, craterHelpFrame, craterCloseEvent =
RbxGui.CreatePluginFrame(

View File

@ -2,6 +2,8 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
---------------
--PLUGIN SETUP-
---------------
@ -184,7 +186,7 @@ function makePath(px1, pz1, px2, pz2, ph, pp)
end
end
game:GetService("ChangeHistoryService"):SetWaypoint "Roads"
ChangeHistoryService:SetWaypoint "Roads"
end
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -282,16 +285,13 @@ function getSquare(cellPos, setCells)
-- local tempCellPos = Vector3.new(x, y, z)
local oldMaterial, oldType, oldOrientation = GetCell(c, x, y, z)
if oldMaterial.Value > 0 then
table.insert(
setCells,
{
xPos = x,
yPos = y,
zPos = z,
theType = oldType,
orientation = oldOrientation,
}
)
table.insert(setCells, {
xPos = x,
yPos = y,
zPos = z,
theType = oldType,
orientation = oldOrientation,
})
end
end
end
@ -315,16 +315,13 @@ function getCircular(cellPos, setCells)
local oldMaterial, oldType, oldOrientation =
GetCell(c, x, y, z)
if oldMaterial.Value > 0 then
table.insert(
setCells,
{
xPos = x,
yPos = y,
zPos = z,
theType = oldType,
orientation = oldOrientation,
}
)
table.insert(setCells, {
xPos = x,
yPos = y,
zPos = z,
theType = oldType,
orientation = oldOrientation,
})
end
end
end
@ -543,7 +540,7 @@ function mouseUp(_)
setPositionDirectionality()
end
game:GetService("ChangeHistoryService"):SetWaypoint "MaterialPaint"
ChangeHistoryService:SetWaypoint "MaterialPaint"
lastLastCell = nil
lastCell = nil
@ -725,7 +722,7 @@ end
--screengui
local g = Instance.new "ScreenGui"
g.Name = "MaterialPainterGui"
g.Parent = game:GetService "CoreGui"
g.Parent = CoreGui
dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame(
"Material Brush",

View File

@ -2,6 +2,10 @@ while game == nil do
wait(1 / 30)
end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local ContentProvider = game:GetService "ContentProvider"
local CoreGui = game:GetService "CoreGui"
---------------
--PLUGIN SETUP-
---------------
@ -67,8 +71,7 @@ local currentMaterial = 1
-- load our libraries
local RbxGui = LoadLibrary "RbxGui"
-- local RbxUtil = LoadLibrary "RbxUtility"
game:GetService("ContentProvider")
:Preload "http://banland.xyz/asset/?id=82741829"
ContentProvider:Preload "http://banland.xyz/asset/?id=82741829"
------------------------- OBJECT DEFINITIONS ---------------------
@ -510,7 +513,7 @@ local floodFill = function(x, y, z)
LoadProgressBar "Processing"
breadthFill(x, y, z)
UnloadProgressBar()
game:GetService("ChangeHistoryService"):SetWaypoint "FloodFill"
ChangeHistoryService:SetWaypoint "FloodFill"
end
-- Function used when we try and flood fill. Prompts the user first.
@ -843,7 +846,7 @@ mouseHighlighter.OnClicked = mouseUp
------
screenGui = Instance.new "ScreenGui"
screenGui.Name = "FloodFillGui"
screenGui.Parent = game:GetService "CoreGui"
screenGui.Parent = CoreGui
local containerFrame
dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame(