From ba510b060ad474db3b0a548c7506c72e26ac68b9 Mon Sep 17 00:00:00 2001 From: Lewin Kelly Date: Thu, 11 Apr 2024 00:22:46 +0100 Subject: [PATCH] Formatting improvements to terrain plugins --- terrain plugins/00 - terrain.luau | 43 +---- terrain plugins/01 - builder.luau | 46 ++--- terrain plugins/02 - remover.luau | 234 ++++++++++++------------ terrain plugins/03 - elevation.luau | 79 ++++---- terrain plugins/04 - brush.luau | 209 +++++++++++---------- terrain plugins/06 - craters.luau | 6 +- terrain plugins/08 - roads.luau | 16 +- terrain plugins/09 - materialpaint.luau | 213 +++++++++++---------- terrain plugins/10 - stamper.luau | 4 +- terrain plugins/11 - floodfill.luau | 130 ++++++------- 10 files changed, 496 insertions(+), 484 deletions(-) diff --git a/terrain plugins/00 - terrain.luau b/terrain plugins/00 - terrain.luau index 59e7873..8a04273 100644 --- a/terrain plugins/00 - terrain.luau +++ b/terrain plugins/00 - terrain.luau @@ -33,9 +33,9 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local SetCells = c.SetCells local AutoWedge = c.AutowedgeCells @@ -130,9 +130,10 @@ local hideGenerateConformation = false --GUI- ------ --screengui -local g = Instance.new "ScreenGui" -g.Name = "TerrainCreatorGui" -g.Parent = CoreGui +local g = New "ScreenGui" { + Name = "TerrainCreatorGui", + Parent = CoreGui, +} -- UI gui load. Required for sliders. local RbxGui = LoadLibrary "RbxGui" @@ -161,7 +162,7 @@ local function helpText() TextXAlignment = Enum.TextXAlignment.Left, TextYAlignment = Enum.TextYAlignment.Top, BackgroundTransparency = 1, - TextWrap = true, + TextWrapped = true, Parent = terrainHelpFrame, } end @@ -368,30 +369,6 @@ local function CreateStandardSlider( return sliderGui, sliderPosition end --- Create a standard dropdown. Use this for all dropdowns in the popup so it is easy to standardize. --- name - What to set the text label name as. --- pos - Where to position the label. Should be of type UDim2. --- values - A table of the values that will be in the dropbox, in the order they are to be shown. --- initValue - Initial value the dropdown should be set to. --- funcOnChange - Function to run when a dropdown selection is made. --- parent - What to set the parent as. --- Return: --- dropdown - The dropdown gui. --- updateSelection - Object to use to change the current dropdown. --- function CreateStandardDropdown(name, pos, values, initValue, funcOnChange, parent) --- -- Create a dropdown selection for the modes to fill in a river --- local dropdown, updateSelection = RbxGui.CreateDropDownMenu(values, funcOnChange) --- dropdown.Name = name --- dropdown.Position = pos --- dropdown.Active = true --- dropdown.Size = UDim2.new(0, 150, 0, 32) --- dropdown.Parent = parent - --- updateSelection(initValue) - --- return dropdown, updateSelection --- end - local cancelValues = { cancelAction = false, -- Used to cancel currently occuring actions. If set to true then terrain generation will stop. progressBar = nil, -- Will store the progress bar when needed. @@ -594,7 +571,7 @@ end -- centerX, centerZ - Center coordinate of land. This doesn't take into account clipping. -- length, width - Land dimensions. local function SetCamera(centerX, centerZ, length, width, height) - local currCamera = game.Workspace.CurrentCamera + local currCamera = workspace.CurrentCamera local cameraPos = Vector3.new(0, 400, 1600) local cameraFocus = Vector3.new(0, height * 4, 0) @@ -648,8 +625,8 @@ local function GenerateTerrain() --Generate Terrain -- offset terrain additionally by whatever the smallest cell is - --xpos2 = generateOptions.xpos + game.Workspace.Terrain.MaxExtents.Min.X - --zpos2 = generateOptions.zpos + game.Workspace.Terrain.MaxExtents.Min.Z + --xpos2 = generateOptions.xpos + workspace.Terrain.MaxExtents.Min.X + --zpos2 = generateOptions.zpos + workspace.Terrain.MaxExtents.Min.Z local xpos2 = generateOptions.xpos - generateOptions.width / 2 local zpos2 = generateOptions.zpos - generateOptions.length / 2 diff --git a/terrain plugins/01 - builder.luau b/terrain plugins/01 - builder.luau index cc1477b..ee69a37 100644 --- a/terrain plugins/01 - builder.luau +++ b/terrain plugins/01 - builder.luau @@ -31,9 +31,9 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local GetCell = c.GetCell local WorldToCellPreferSolid = c.WorldToCellPreferSolid @@ -48,11 +48,12 @@ local SetWaterCell = c.SetWaterCell ----------------- -- Stores selection properties. -local selectionProps = {} -selectionProps.isWater = nil -- True if what will be built is water. -selectionProps.waterForce = nil -- Water force. -selectionProps.waterDirection = nil -- Water direction. -selectionProps.terrainMaterial = 0 -- Terrain material to use +local selectionProps = { + isWater = nil, -- True if what will be built is water. + waterForce = nil, -- Water force. + waterDirection = nil, -- Water direction. + terrainMaterial = 0, -- Terrain material to use +} -- What color to use for the mouse highlighter. local mouseHighlightColor = BrickColor.new "Lime green" @@ -125,7 +126,7 @@ function MouseHighlighter.Create(mouseUse) -- 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. function PlaneIntersection(vectorPos) - local currCamera = game.Workspace.CurrentCamera + local currCamera = workspace.CurrentCamera local startPos = Vector3.new( currCamera.CoordinateFrame.p.X, currCamera.CoordinateFrame.p.Y, @@ -249,20 +250,23 @@ end) builderHelpFrame.Size = UDim2.new(0, 160, 0, 85) -local builderHelpText = Instance.new "TextLabel" -builderHelpText.Name = "HelpText" -builderHelpText.Font = Enum.Font.ArialBold -builderHelpText.FontSize = Enum.FontSize.Size12 -builderHelpText.TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255) -builderHelpText.TextXAlignment = Enum.TextXAlignment.Left -builderHelpText.TextYAlignment = Enum.TextYAlignment.Top -builderHelpText.Position = UDim2.new(0, 4, 0, 4) -builderHelpText.Size = UDim2.new(1, -8, 0, 177) -builderHelpText.BackgroundTransparency = 1 -builderHelpText.TextWrap = true -builderHelpText.Text = [[ +local helpText = [[ Clicking terrain adds a single block into the selection box shown. The terrain material and type will be the same as the cell that was clicked on.]] -builderHelpText.Parent = builderHelpFrame + +New "TextLabel" { + Name = "HelpText", + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size12, + TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255), + TextXAlignment = Enum.TextXAlignment.Left, + TextYAlignment = Enum.TextYAlignment.Top, + Position = UDim2.new(0, 4, 0, 4), + Size = UDim2.new(1, -8, 0, 177), + BackgroundTransparency = 1, + TextWrapped = true, + Text = helpText, + Parent = builderHelpFrame, +} CreateStandardLabel( "AddText", diff --git a/terrain plugins/02 - remover.luau b/terrain plugins/02 - remover.luau index ee4c356..76de0f1 100644 --- a/terrain plugins/02 - remover.luau +++ b/terrain plugins/02 - remover.luau @@ -6,6 +6,7 @@ local ChangeHistoryService = game:GetService "ChangeHistoryService" local CoreGui = game:GetService "CoreGui" local CreateStandardLabel = require "../Modules/Terrain/CreateStandardLabel" +local New = require("../Modules/New").New ----------------- --DEFAULT VALUES- @@ -34,9 +35,9 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local GetCell = c.GetCell local WorldToCellPreferSolid = c.WorldToCellPreferSolid @@ -66,6 +67,79 @@ function MouseHighlighter.Create(mouseUse) -- Will hold a part the highlighter will be attached to. This will be moved where the mouse is. highlighter.selectionPart = nil + -- Create the part that the highlighter will be attached to. + highlighter.selectionPart = New "Part" { + Name = "SelectionPart", + Archivable = false, + Transparency = 1, + Anchored = true, + Locked = true, + CanCollide = false, + FormFactor = Enum.FormFactor.Custom, + } + + highlighter.selectionBox = New "SelectionBox" { + Archivable = false, + Color = mouseHighlightColor, + Adornee = highlighter.selectionPart, + } + mouse2.TargetFilter = highlighter.selectionPart + setmetatable(highlighter, MouseHighlighter) + + -- Update where the highlighter is displayed. + -- position - Where to display the highlighter, in world space. + function UpdatePosition(position) + if not position then + return + end + + if not mouse2.Target then + highlighter.selectionBox.Parent = nil + return + end + + -- NOTE: + -- Change this gui to be the one you want to use. + highlighter.selectionBox.Parent = CoreGui + + local vectorPos = Vector3.new(position.x, position.y, position.z) + local cellPos = WorldToCellPreferSolid(c, vectorPos) + + local regionToSelect + + local lowVec = CellCenterToWorld(c, cellPos.x, cellPos.y - 1, cellPos.z) + local highVec = + CellCenterToWorld(c, cellPos.x, cellPos.y + 1, cellPos.z) + regionToSelect = Region3.new(lowVec, highVec) + + highlighter.selectionPart.Size = regionToSelect.Size + - Vector3.new(-4, 4, -4) + highlighter.selectionPart.CFrame = regionToSelect.CFrame + + if not (highlighter.OnClicked and highlighter.mouseDown) then + return + elseif not highlighter.lastUsedPoint then + highlighter.lastUsedPoint = WorldToCellPreferSolid( + c, + Vector3.new(mouse2.Hit.x, mouse2.Hit.y, mouse2.Hit.z) + ) + else + cellPos = WorldToCellPreferSolid( + c, + Vector3.new(mouse2.Hit.x, mouse2.Hit.y, mouse2.Hit.z) + ) + + -- holdChange = cellPos - highlighter.lastUsedPoint -- ? + + -- Require terrain. + if 0 == GetCell(c, cellPos.X, cellPos.Y, cellPos.Z).Value then + return + else + highlighter.lastUsedPoint = cellPos + end + end + end + -- Function to call when the mouse has moved. Updates where to display the highlighter. local function MouseMoved() if on then @@ -85,77 +159,6 @@ function MouseHighlighter.Create(mouseUse) highlighter.mouseDown = false end) - -- Create the part that the highlighter will be attached to. - highlighter.selectionPart = Instance.new "Part" - highlighter.selectionPart.Name = "SelectionPart" - highlighter.selectionPart.Archivable = false - highlighter.selectionPart.Transparency = 1 - highlighter.selectionPart.Anchored = true - highlighter.selectionPart.Locked = true - highlighter.selectionPart.CanCollide = false - highlighter.selectionPart.FormFactor = Enum.FormFactor.Custom - - highlighter.selectionBox = Instance.new "SelectionBox" - highlighter.selectionBox.Archivable = false - highlighter.selectionBox.Color = mouseHighlightColor - highlighter.selectionBox.Adornee = highlighter.selectionPart - mouse2.TargetFilter = highlighter.selectionPart - setmetatable(highlighter, MouseHighlighter) - - -- Update where the highlighter is displayed. - -- position - Where to display the highlighter, in world space. - function UpdatePosition(position) - if not position then - return - end - - if not mouse2.Target then - highlighter.selectionBox.Parent = nil - return - end - - -- NOTE: - -- Change this gui to be the one you want to use. - highlighter.selectionBox.Parent = game:GetService "CoreGui" - - local vectorPos = Vector3.new(position.x, position.y, position.z) - local cellPos = WorldToCellPreferSolid(c, vectorPos) - - local regionToSelect - - local lowVec = CellCenterToWorld(c, cellPos.x, cellPos.y - 1, cellPos.z) - local highVec = - CellCenterToWorld(c, cellPos.x, cellPos.y + 1, cellPos.z) - regionToSelect = Region3.new(lowVec, highVec) - - highlighter.selectionPart.Size = regionToSelect.Size - - Vector3.new(-4, 4, -4) - highlighter.selectionPart.CFrame = regionToSelect.CFrame - - if nil ~= highlighter.OnClicked and highlighter.mouseDown then - if nil == highlighter.lastUsedPoint then - highlighter.lastUsedPoint = WorldToCellPreferSolid( - c, - Vector3.new(mouse2.Hit.x, mouse2.Hit.y, mouse2.Hit.z) - ) - else - cellPos = WorldToCellPreferSolid( - c, - Vector3.new(mouse2.Hit.x, mouse2.Hit.y, mouse2.Hit.z) - ) - - holdChange = cellPos - highlighter.lastUsedPoint - - -- Require terrain. - if 0 == GetCell(c, cellPos.X, cellPos.Y, cellPos.Z).Value then - return - else - highlighter.lastUsedPoint = cellPos - end - end - end - end - return highlighter end @@ -176,9 +179,10 @@ local mouseHighlighter = MouseHighlighter.Create(mouse) --GUI- ------ --screengui -local g = Instance.new "ScreenGui" -g.Name = "RemoverGui" -g.Parent = game:GetService "CoreGui" +local g = New "ScreenGui" { + Name = "RemoverGui", + Parent = CoreGui, +} -- UI gui load. Required for sliders. local RbxGui = LoadLibrary "RbxGui" @@ -202,20 +206,23 @@ end) removerHelpFrame.Size = UDim2.new(0, 160, 0, 60) -local removerHelpText = Instance.new "TextLabel" -removerHelpText.Name = "HelpText" -removerHelpText.Font = Enum.Font.ArialBold -removerHelpText.FontSize = Enum.FontSize.Size12 -removerHelpText.TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255) -removerHelpText.TextXAlignment = Enum.TextXAlignment.Left -removerHelpText.TextYAlignment = Enum.TextYAlignment.Top -removerHelpText.Position = UDim2.new(0, 4, 0, 4) -removerHelpText.Size = UDim2.new(1, -8, 0, 177) -removerHelpText.BackgroundTransparency = 1 -removerHelpText.TextWrap = true -removerHelpText.Text = [[ +local helpText = [[ Clicking terrain removes a single block at the location clicked (shown with red highlight).]] -removerHelpText.Parent = removerHelpFrame + +New "TextLabel" { + Name = "HelpText", + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size12, + TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255), + TextXAlignment = Enum.TextXAlignment.Left, + TextYAlignment = Enum.TextYAlignment.Top, + Position = UDim2.new(0, 4, 0, 4), + Size = UDim2.new(1, -8, 0, 177), + BackgroundTransparency = 1, + TextWrapped = true, + Text = helpText, + Parent = removerHelpFrame, +} CreateStandardLabel( "removeText", @@ -227,32 +234,33 @@ CreateStandardLabel( -- Function to connect to the mouse button 1 down event. This is what will run when the user clicks. -- mouse - Mouse data. -function onClicked() - if on then - local cellPos = WorldToCellPreferSolid( +local function onClicked() + if not on then + return + end + local cellPos = WorldToCellPreferSolid( + c, + Vector3.new(mouse.Hit.x, mouse.Hit.y, mouse.Hit.z) + ) + local x = cellPos.x + local y = cellPos.y + local z = cellPos.z + + SetCell(c, x, y, z, 0, 0, 0) + + -- Mark undo point. + ChangeHistoryService:SetWaypoint "Remover" + + UpdatePosition(mouse.Hit) + + if properties.autoWedgeEnabled then + AutoWedge( c, - Vector3.new(mouse.Hit.x, mouse.Hit.y, mouse.Hit.z) - ) - local x = cellPos.x - local y = cellPos.y - local z = cellPos.z - - SetCell(c, x, y, z, 0, 0, 0) - - -- Mark undo point. - ChangeHistoryService:SetWaypoint "Remover" - - UpdatePosition(mouse.Hit) - - if properties.autoWedgeEnabled then - AutoWedge( - c, - Region3int16.new( - Vector3int16.new(x - 1, y - 1, z - 1), - Vector3int16.new(x + 1, y + 1, z + 1) - ) + Region3int16.new( + Vector3int16.new(x - 1, y - 1, z - 1), + Vector3int16.new(x + 1, y + 1, z + 1) ) - end + ) end end diff --git a/terrain plugins/03 - elevation.luau b/terrain plugins/03 - elevation.luau index 5a9f1a4..616c5cd 100644 --- a/terrain plugins/03 - elevation.luau +++ b/terrain plugins/03 - elevation.luau @@ -6,6 +6,7 @@ local ChangeHistoryService = game:GetService "ChangeHistoryService" local CoreGui = game:GetService "CoreGui" local CreateStandardLabel = require "../Modules/Terrain/CreateStandardLabel" +local New = require("../Modules/New").New --------------- --PLUGIN SETUP- @@ -34,9 +35,9 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local SetWaterCell = c.SetWaterCell local GetCell = c.GetCell @@ -73,7 +74,7 @@ local mouseHighlightColor = BrickColor.new "Lime green" -- 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 currCamera = workspace.CurrentCamera local startPos = Vector3.new( currCamera.CoordinateFrame.p.X, currCamera.CoordinateFrame.p.Y, @@ -190,19 +191,20 @@ function MouseHighlighter.Create(mouseUse) end) -- Create the part that the highlighter will be attached to. - highlighter.selectionPart = Instance.new "Part" - highlighter.selectionPart.Name = "SelectionPart" - highlighter.selectionPart.Archivable = false - highlighter.selectionPart.Transparency = 1 - highlighter.selectionPart.Anchored = true - highlighter.selectionPart.Locked = true - highlighter.selectionPart.CanCollide = false - highlighter.selectionPart.FormFactor = Enum.FormFactor.Custom - - highlighter.selectionBox = Instance.new "SelectionBox" - highlighter.selectionBox.Archivable = false - highlighter.selectionBox.Color = mouseHighlightColor - highlighter.selectionBox.Adornee = highlighter.selectionPart + highlighter.selectionPart = New "Part" { + Name = "SelectionPart", + Archivable = false, + Transparency = 1, + Anchored = true, + Locked = true, + CanCollide = false, + FormFactor = Enum.FormFactor.Custom, + } + highlighter.selectionBox = New "SelectionBox" { + Archivable = false, + Color = mouseHighlightColor, + Adornee = highlighter.selectionPart, + } mouseH.TargetFilter = highlighter.selectionPart setmetatable(highlighter, MouseHighlighter) @@ -292,18 +294,7 @@ end) elevationHelpFrame.Size = UDim2.new(0, 300, 0, 130) -local elevationHelpText = Instance.new "TextLabel" -elevationHelpText.Name = "HelpText" -elevationHelpText.Font = Enum.Font.ArialBold -elevationHelpText.FontSize = Enum.FontSize.Size12 -elevationHelpText.TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255) -elevationHelpText.TextXAlignment = Enum.TextXAlignment.Left -elevationHelpText.TextYAlignment = Enum.TextYAlignment.Top -elevationHelpText.Position = UDim2.new(0, 4, 0, 4) -elevationHelpText.Size = UDim2.new(1, -8, 0, 177) -elevationHelpText.BackgroundTransparency = 1 -elevationHelpText.TextWrap = true -elevationHelpText.Text = [[ +local helpText = [[ Use to drag terrain up or down. Hold the left mouse button down and drag the mouse up or down to create a mountain or valley. Radius: @@ -311,7 +302,21 @@ The larger it is, the wider the top of the elevation will be. Slope: The larger it is, the steeper the slope.]] -elevationHelpText.Parent = elevationHelpFrame + +New "TextLabel" { + Name = "HelpText", + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size12, + TextColor3 = Color3.new(227 / 255, 227 / 255, 227 / 255), + TextXAlignment = Enum.TextXAlignment.Left, + TextYAlignment = Enum.TextYAlignment.Top, + Position = UDim2.new(0, 4, 0, 4), + Size = UDim2.new(1, -8, 0, 177), + BackgroundTransparency = 1, + TextWrapped = true, + Text = helpText, + Parent = elevationHelpFrame, +} -- Slider for controlling radius. local radiusLabel = CreateStandardLabel( @@ -418,10 +423,14 @@ 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 -function elevate(x, y, z, r1, r2, d, range) +local function dist(x1, y1, x2, y2) + return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)) +end + +-- 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 +local function elevate(x, y, z, r1, r2, d, range) for i = x - (range + 2), x + (range + 2) do if oldheightmap[i] == nil then oldheightmap[i] = {} @@ -522,10 +531,6 @@ function elevate(x, y, z, r1, r2, d, range) end end -function dist(x1, y1, x2, y2) - return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)) -end - -- function dist3d(x1, y1, z1, x2, y2, z2) -- return math.sqrt(math.pow(dist(x1, z1, x2, z2), 2) + math.pow(math.abs(y2 - y1) * 100 / d, 2)) -- end diff --git a/terrain plugins/04 - brush.luau b/terrain plugins/04 - brush.luau index 255105e..1f03b0a 100644 --- a/terrain plugins/04 - brush.luau +++ b/terrain plugins/04 - brush.luau @@ -4,6 +4,7 @@ end local ChangeHistoryService = game:GetService "ChangeHistoryService" local CoreGui = game:GetService "CoreGui" +local New = require("../Modules/New").New -- local CreateStandardLabel = require "../Modules/Terrain/CreateStandardLabel" @@ -28,10 +29,10 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -- Local function definitions -local c = game.Workspace.Terrain +local c = workspace.Terrain local GetCell = c.GetCell local SetCells = c.SetCells local AutowedgeCells = c.AutowedgeCells @@ -75,21 +76,31 @@ end) mouse.Move:connect(function() mouseMoved() end) -local selectionPart = Instance.new "Part" -selectionPart.Name = "SelectionPart" -selectionPart.Archivable = false -selectionPart.Transparency = 1 -selectionPart.Anchored = true -selectionPart.Locked = true -selectionPart.CanCollide = false -selectionPart.FormFactor = Enum.FormFactor.Custom +local selectionPart = New "Part" { + Name = "SelectionPart", + Archivable = false, + Transparency = 1, + Anchored = true, + Locked = true, + CanCollide = false, + FormFactor = Enum.FormFactor.Custom, +} -local selectionBox = Instance.new "SelectionBox" -selectionBox.Archivable = false -selectionBox.Color = BrickColor.new "Lime green" -selectionBox.Adornee = selectionPart +local selectionBox = New "SelectionBox" { + Archivable = false, + Color = BrickColor.new "Lime green", + Adornee = selectionPart, +} mouse.TargetFilter = selectionPart +function disablePreview() + selectionBox.Parent = nil +end + +function enablePreview() + selectionBox.Parent = workspace +end + ----------------------- --FUNCTION DEFINITIONS- ----------------------- @@ -113,7 +124,7 @@ function findLowestEmptyCell(x, y, z) end -- finds the lowest cell that is not filled in the radius that is currently specified -function findLowPoint(x, y, z) +local function findLowPoint(x, y, z) local lowestPoint = maxYExtents + 1 for i = -radius, radius do local zPos = z + i @@ -131,8 +142,40 @@ function findLowPoint(x, y, z) return lowestPoint end ---brushes terrain at point (x, y, z) in cluster c -function brush(x, y, z) +-- 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. +-- intersection - Value is the terrain cell intersection point if there is one, vectorPos if there isn't. +local function PlaneIntersection(vectorPos) + local currCamera = 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 + +-- brushes terrain at point (x, y, z) in cluster c +local function brush(x, y, z) if depth == 0 then return elseif depth > 0 then @@ -160,14 +203,6 @@ function brush(x, y, z) end end -function disablePreview() - selectionBox.Parent = nil -end - -function enablePreview() - selectionBox.Parent = game.Workspace -end - function updatePreviewSelection(position) if not position then return @@ -257,7 +292,7 @@ function doFillCells(position, mouseDrag, needsCellPos) local timeBetweenFills = tick() - lastCellFillTime local totalDragPixels = math.abs(mouseDrag.x) + math.abs(mouseDrag.y) local editDistance = ( - game.Workspace.CurrentCamera.CoordinateFrame.p + workspace.CurrentCamera.CoordinateFrame.p - Vector3.new(position.x, position.y, position.z) ).magnitude @@ -322,38 +357,6 @@ function mouseMoved() updatePreviewSelection(mouse.Hit) end --- 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. --- intersection - Value is the terrain cell intersection point if there is one, vectorPos if there isn't. -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 - function buttonDown() if on then local firstCellPos = WorldToCellPreferSolid( @@ -372,11 +375,10 @@ function buttonDown() Vector3.new(mouse.Hit.x, mouse.Hit.y, mouse.Hit.z) ) if not success then - if mouse.Target then - firstCellPos = solidCell - else + if not mouse.Target then return end + firstCellPos = solidCell end end @@ -515,9 +517,10 @@ end -- end --screengui -local g = Instance.new "ScreenGui" -g.Name = "TerrainBrushGui" -g.Parent = CoreGui +local g = New "ScreenGui" { + Name = "TerrainBrushGui", + Parent = CoreGui, +} local elevationFrame, elevationHelpFrame, elevationCloseEvent brushDragBar, elevationFrame, elevationHelpFrame, elevationCloseEvent = @@ -534,16 +537,8 @@ elevationCloseEvent.Event:connect(function() end) elevationHelpFrame.Size = UDim2.new(0, 200, 0, 210) -local helpText = Instance.new "TextLabel" -helpText.Font = Enum.Font.ArialBold -helpText.FontSize = Enum.FontSize.Size12 -helpText.TextColor3 = Color3.new(1, 1, 1) -helpText.BackgroundTransparency = 1 -helpText.TextWrap = true -helpText.Size = UDim2.new(1, -10, 1, -10) -helpText.Position = UDim2.new(0, 5, 0, 5) -helpText.TextXAlignment = Enum.TextXAlignment.Left -helpText.Text = + +local helpText = [[Drag the mouse by holding the left mouse button to either create or destroy terrain defined by the selection box. Radius: @@ -552,21 +547,34 @@ Half of the width of the selection box to be used. Height: How tall to make terrain from the mouse location. If this value is negative, the brush will remove terrain instead of creating terrain (indicated by the red selection box). ]] -helpText.Parent = elevationHelpFrame ---current radius display label -local radl = Instance.new "TextLabel" -radl.Position = UDim2.new(0, 0, 0, 70) -radl.Size = UDim2.new(1, 0, 0, 14) -radl.Text = "" -radl.BackgroundColor3 = Color3.new(0.4, 0.4, 0.4) -radl.TextColor3 = Color3.new(0.95, 0.95, 0.95) -radl.Font = Enum.Font.ArialBold -radl.FontSize = Enum.FontSize.Size14 -radl.TextXAlignment = Enum.TextXAlignment.Left -radl.BorderColor3 = Color3.new(0, 0, 0) -radl.BackgroundTransparency = 1 -radl.Parent = elevationFrame +New "TextLabel" { + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size12, + TextColor3 = Color3.new(1, 1, 1), + BackgroundTransparency = 1, + TextWrapped = true, + Size = UDim2.new(1, -10, 1, -10), + Position = UDim2.new(0, 5, 0, 5), + TextXAlignment = Enum.TextXAlignment.Left, + Text = helpText, + Parent = elevationHelpFrame, +} + +-- current radius display label +local radl = New "TextLabel" { + Position = UDim2.new(0, 0, 0, 70), + Size = UDim2.new(1, 0, 0, 14), + Text = "", + BackgroundColor3 = Color3.new(0.4, 0.4, 0.4), + TextColor3 = Color3.new(0.95, 0.95, 0.95), + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size14, + TextXAlignment = Enum.TextXAlignment.Left, + BorderColor3 = Color3.new(0, 0, 0), + BackgroundTransparency = 1, + Parent = elevationFrame, +} --radius slider local radSliderGui, radSliderPosition = @@ -581,18 +589,19 @@ end) radSliderPosition.Value = radius - 1 --current depth factor display label -local dfl = Instance.new "TextLabel" -dfl.Position = UDim2.new(0, 0, 0, 110) -dfl.Size = UDim2.new(1, 0, 0, 14) -dfl.Text = "" -dfl.BackgroundColor3 = Color3.new(0.4, 0.4, 0.4) -dfl.TextColor3 = Color3.new(0.95, 0.95, 0.95) -dfl.Font = Enum.Font.ArialBold -dfl.FontSize = Enum.FontSize.Size14 -dfl.BorderColor3 = Color3.new(0, 0, 0) -dfl.TextXAlignment = Enum.TextXAlignment.Left -dfl.BackgroundTransparency = 1 -dfl.Parent = elevationFrame +local dfl = New "TextLabel" { + Position = UDim2.new(0, 0, 0, 110), + Size = UDim2.new(1, 0, 0, 14), + Text = "", + BackgroundColor3 = Color3.new(0.4, 0.4, 0.4), + TextColor3 = Color3.new(0.95, 0.95, 0.95), + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size14, + BorderColor3 = Color3.new(0, 0, 0), + TextXAlignment = Enum.TextXAlignment.Left, + BackgroundTransparency = 1, + Parent = elevationFrame, +} --depth factor slider local addSliderGui, addSliderPosition = diff --git a/terrain plugins/06 - craters.luau b/terrain plugins/06 - craters.luau index 20e1a74..4984d06 100644 --- a/terrain plugins/06 - craters.luau +++ b/terrain plugins/06 - craters.luau @@ -28,10 +28,10 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -- Local function definitions -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local GetCell = c.GetCell local WorldToCellPreferSolid = c.WorldToCellPreferSolid @@ -196,7 +196,7 @@ helpText.Font = Enum.Font.ArialBold helpText.FontSize = Enum.FontSize.Size12 helpText.TextColor3 = Color3.new(1, 1, 1) helpText.BackgroundTransparency = 1 -helpText.TextWrap = true +helpText.TextWrapped = true helpText.Size = UDim2.new(1, -10, 1, -10) helpText.Position = UDim2.new(0, 5, 0, 5) helpText.TextXAlignment = Enum.TextXAlignment.Left diff --git a/terrain plugins/08 - roads.luau b/terrain plugins/08 - roads.luau index 107878f..7e8d298 100644 --- a/terrain plugins/08 - roads.luau +++ b/terrain plugins/08 - roads.luau @@ -26,10 +26,10 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" -- Local function definitions -local c = game.Workspace.Terrain +local c = workspace.Terrain local GetCell = c.GetCell local WorldToCellPreferSolid = c.WorldToCellPreferSolid local WorldToCellPreferEmpty = c.WorldToCellPreferEmpty @@ -195,7 +195,7 @@ end -- 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. function PlaneIntersection(vectorPos) - local currCamera = game.Workspace.CurrentCamera + local currCamera = workspace.CurrentCamera local startPos = Vector3.new( currCamera.CoordinateFrame.p.X, currCamera.CoordinateFrame.p.Y, @@ -260,10 +260,8 @@ mouse.Button1Down:connect(function() local celMat = GetCell(c, x, y, z) if celMat.Value > 0 then DefaultTerrainMaterial = celMat.Value - else - if 0 == DefaultTerrainMaterial then - DefaultTerrainMaterial = 1 - end + elseif 0 == DefaultTerrainMaterial then + DefaultTerrainMaterial = 1 end elseif mode == 1 then x2 = x @@ -336,7 +334,7 @@ roadTextHelper.Size = UDim2.new(1, -8, 1, -8) roadTextHelper.Position = UDim2.new(0, 4, 0, 4) roadTextHelper.TextXAlignment = Enum.TextXAlignment.Left roadTextHelper.TextYAlignment = Enum.TextYAlignment.Top -roadTextHelper.TextWrap = true +roadTextHelper.TextWrapped = true roadTextHelper.Parent = roadFrame roadHelpFrame.Size = UDim2.new(0, 200, 0, 150) @@ -345,7 +343,7 @@ helpText.Font = Enum.Font.ArialBold helpText.FontSize = Enum.FontSize.Size12 helpText.TextColor3 = Color3.new(1, 1, 1) helpText.BackgroundTransparency = 1 -helpText.TextWrap = true +helpText.TextWrapped = true helpText.Size = UDim2.new(1, -10, 1, -10) helpText.Position = UDim2.new(0, 5, 0, 5) helpText.TextXAlignment = Enum.TextXAlignment.Left diff --git a/terrain plugins/09 - materialpaint.luau b/terrain plugins/09 - materialpaint.luau index a8737a6..7ade732 100644 --- a/terrain plugins/09 - materialpaint.luau +++ b/terrain plugins/09 - materialpaint.luau @@ -5,6 +5,10 @@ end local ChangeHistoryService = game:GetService "ChangeHistoryService" local CoreGui = game:GetService "CoreGui" +local News = require "../Modules/New" +local New = News.New +local Hydrate = News.Hydrate + --------------- --PLUGIN SETUP- --------------- @@ -41,12 +45,12 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" ----------------------------- --LOCAL FUNCTION DEFINITIONS- ----------------------------- -local c = game.Workspace.Terrain +local c = workspace.Terrain local SetCell = c.SetCell local SetWaterCell = c.SetWaterCell -- local GetWaterCell = c.GetWaterCell @@ -568,14 +572,12 @@ local function setPositionDirectionality() end function mouseDown(mouseD) - if not (on and mouseD.Target == game.Workspace.Terrain) then + if not (on and mouseD.Target == workspace.Terrain) then return end dragging = true - if - not (mouseD and mouseD.Hit and mouseD.Target == game.Workspace.Terrain) - then + if not (mouseD and mouseD.Hit and mouseD.Target == workspace.Terrain) then return end @@ -605,42 +607,6 @@ function mouseUp(_) lastCell = nil end -function mouseMove(mouseM) - if not on then - return - elseif mouseM.Target == game.Workspace.Terrain then - if lastCell == WorldToCellPreferSolid(c, mouseM.Hit.p) then - return - end - updateSelection(mouseM) - local newCell = WorldToCellPreferSolid(c, mouseM.Hit.p) - - if not dragging then - return - end - -- local painting = true - paint(newCell) - if lastCell and newCell and (lastCell - newCell).magnitude > 1 then - paintBetweenPoints(lastCell, newCell) - end - lastLastCell = lastCell - lastCell = newCell - -- painting = false - else - destroySelection() - end -end - -function destroySelection() - if currSelectionUpdate then - currSelectionUpdate = nil - end - if currSelectionDestroy then - currSelectionDestroy() - currSelectionDestroy = nil - end -end - local function moveTowardsGoal(direction: string, currPos, goalPos, currCell) if currPos == goalPos then return currCell @@ -676,7 +642,7 @@ local function interpolateOneDim(direction, currPos, goalPos, currCell) return currCell end -function paintBetweenPoints(lastCellP, newCell) +local function paintBetweenPoints(lastCellP, newCell) local currCell = lastCellP while @@ -690,6 +656,42 @@ function paintBetweenPoints(lastCellP, newCell) end end +local function destroySelection() + if currSelectionUpdate then + currSelectionUpdate = nil + end + if currSelectionDestroy then + currSelectionDestroy() + currSelectionDestroy = nil + end +end + +function mouseMove(mouseM) + if not on then + return + elseif mouseM.Target == workspace.Terrain then + if lastCell == WorldToCellPreferSolid(c, mouseM.Hit.p) then + return + end + updateSelection(mouseM) + local newCell = WorldToCellPreferSolid(c, mouseM.Hit.p) + + if not dragging then + return + end + -- local painting = true + paint(newCell) + if lastCell and newCell and (lastCell - newCell).magnitude > 1 then + paintBetweenPoints(lastCell, newCell) + end + lastLastCell = lastCell + lastCell = newCell + -- painting = false + else + destroySelection() + end +end + function On() if not c then return @@ -714,9 +716,10 @@ end ------ --screengui -local g = Instance.new "ScreenGui" -g.Name = "MaterialPainterGui" -g.Parent = CoreGui +local g = New "ScreenGui" { + Name = "MaterialPainterGui", + Parent = CoreGui, +} local containerFrame dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame( @@ -738,20 +741,8 @@ end) helpFrame.Size = UDim2.new(0, 200, 0, 250) helpFrame.ZIndex = 3 -local textHelp = Instance.new "TextLabel" -textHelp.Name = "TextHelp" -textHelp.Font = Enum.Font.ArialBold -textHelp.FontSize = Enum.FontSize.Size12 -textHelp.TextColor3 = Color3.new(1, 1, 1) -textHelp.Size = UDim2.new(1, -6, 1, -6) -textHelp.Position = UDim2.new(0, 3, 0, 3) -textHelp.TextXAlignment = Enum.TextXAlignment.Left -textHelp.TextYAlignment = Enum.TextYAlignment.Top -textHelp.Position = UDim2.new(0, 4, 0, 4) -textHelp.BackgroundTransparency = 1 -textHelp.TextWrap = true -textHelp.ZIndex = 4 -textHelp.Text = + +local helpText = [[Changes existing terrain blocks to the specified material. Simply hold the mouse down and drag to 'paint' the terrain (only cells inside the selection box will be affected). Size: @@ -762,53 +753,80 @@ The shape we paint terrain with inside of our selection box. Material Selection: The terrain material we will paint.]] -textHelp.Parent = helpFrame + +New "TextLabel" { + Name = "TextHelp", + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size12, + TextColor3 = Color3.new(1, 1, 1), + Size = UDim2.new(1, -6, 1, -6), + -- Position = UDim2.new(0, 3, 0, 3), -- lellel new supremacy - Heliodex + TextXAlignment = Enum.TextXAlignment.Left, + TextYAlignment = Enum.TextYAlignment.Top, + Position = UDim2.new(0, 4, 0, 4), + BackgroundTransparency = 1, + TextWrapped = true, + ZIndex = 4, + Text = helpText, + Parent = helpFrame, +} closeEvent.Event:connect(function() Off() end) -terrainSelectorGui, terrainSelected, forceTerrainSelection = - RbxGui.CreateTerrainMaterialSelector( - UDim2.new(1, -10, 0, 184), - UDim2.new(0, 5, 1, -190) - ) -terrainSelectorGui.Parent = containerFrame -terrainSelectorGui.BackgroundTransparency = 1 -terrainSelectorGui.BorderSizePixel = 0 +terrainSelectorGui, terrainSelected = RbxGui.CreateTerrainMaterialSelector( + UDim2.new(1, -10, 0, 184), + UDim2.new(0, 5, 1, -190) +) +Hydrate(terrainSelectorGui) { + BackgroundTransparency = 1, + BorderSizePixel = 0, + Parent = containerFrame, +} terrainSelected.Event:connect(function(newMaterial) currentMaterial = newMaterial end) -- Purpose: -- Retrive the size text to display for a given radius, where 1 == 1 block and 2 == 3 blocks, etc. -function SizeText(radiusT) +local function SizeText(radiusT: number) return "Size: " .. (((radiusT - 1) * 2) + 1) end +local function makeRadiusLabel() + return New "TextLabel" { + Size = UDim2.new(1, -3, 0, 14), + TextColor3 = Color3.new(0.95, 0.95, 0.95), + Font = Enum.Font.ArialBold, + FontSize = Enum.FontSize.Size14, + BorderColor3 = Color3.new(0, 0, 0), + BackgroundTransparency = 1, + TextXAlignment = Enum.TextXAlignment.Left, + } +end + --current radius display label -radiusLabel = Instance.new "TextLabel" -radiusLabel.Name = "RadiusLabel" -radiusLabel.Position = UDim2.new(0, 10, 0, 5) -radiusLabel.Size = UDim2.new(1, -3, 0, 14) -radiusLabel.Text = SizeText(radius) -radiusLabel.TextColor3 = Color3.new(0.95, 0.95, 0.95) -radiusLabel.Font = Enum.Font.ArialBold -radiusLabel.FontSize = Enum.FontSize.Size14 -radiusLabel.BorderColor3 = Color3.new(0, 0, 0) -radiusLabel.BackgroundTransparency = 1 -radiusLabel.TextXAlignment = Enum.TextXAlignment.Left -radiusLabel.Parent = containerFrame +radiusLabel = Hydrate(makeRadiusLabel()) { + Name = "RadiusLabel", + Text = SizeText(radius), + Position = UDim2.new(0, 10, 0, 5), + Parent = containerFrame, +} --radius slider local radSliderGui, radSliderPosition = RbxGui.CreateSlider(6, 0, UDim2.new(0, 0, 0, 18)) -radSliderGui.Size = UDim2.new(1, -2, 0, 20) -radSliderGui.Position = UDim2.new(0, 0, 0, 24) -radSliderGui.Parent = containerFrame -local radBar = radSliderGui:FindFirstChild "Bar" -radBar.Size = UDim2.new(1, -20, 0, 5) -radBar.Position = UDim2.new(0, 10, 0.5, -3) +Hydrate(radSliderGui) { + Size = UDim2.new(1, -2, 0, 20), + Position = UDim2.new(0, 0, 0, 24), + Parent = containerFrame, +} +Hydrate(radSliderGui.Bar) { + Size = UDim2.new(1, -20, 0, 5), + Position = UDim2.new(0, 10, 0.5, -3), +} + radSliderPosition.Value = radius radSliderPosition.Changed:connect(function() radius = radSliderPosition.Value @@ -823,15 +841,18 @@ end local brushDropDown, forceSelection = RbxGui.CreateDropDownMenu(brushTypes, brushTypeChanged) forceSelection "Square" -brushDropDown.Size = UDim2.new(1, -10, 0.01, 25) -brushDropDown.Position = UDim2.new(0, 5, 0, 65) -brushDropDown.Parent = containerFrame -local brushLabel = radiusLabel:Clone() -brushLabel.Name = "BrushLabel" -brushLabel.Text = "Brush Type" -brushLabel.Position = UDim2.new(0, 10, 0, 50) -brushLabel.Parent = containerFrame +Hydrate(brushDropDown) { + Size = UDim2.new(1, -10, 0.01, 25), + Position = UDim2.new(0, 5, 0, 65), + Parent = containerFrame, +} +Hydrate(makeRadiusLabel()) { + Name = "BrushLabel", + Text = "Brush Type", + Position = UDim2.new(0, 10, 0, 50), + Parent = containerFrame, +} this.Deactivation:connect(function() Off() diff --git a/terrain plugins/10 - stamper.luau b/terrain plugins/10 - stamper.luau index 4287f02..269182b 100644 --- a/terrain plugins/10 - stamper.luau +++ b/terrain plugins/10 - stamper.luau @@ -36,7 +36,7 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" ----------------- --DEFAULT VALUES- @@ -375,7 +375,7 @@ function createGui() end function On() - if not game.Workspace.Terrain then + if not workspace.Terrain then return elseif this then this:Activate(true) diff --git a/terrain plugins/11 - floodfill.luau b/terrain plugins/11 - floodfill.luau index 12615c6..a414043 100644 --- a/terrain plugins/11 - floodfill.luau +++ b/terrain plugins/11 - floodfill.luau @@ -42,12 +42,12 @@ toolbarbutton.Click:connect(function() end) game:WaitForChild "Workspace" -game.Workspace:WaitForChild "Terrain" +workspace:WaitForChild "Terrain" ----------------------------- --LOCAL FUNCTION DEFINITIONS- ----------------------------- -local c = game.Workspace.Terrain +local c = workspace.Terrain -- local WorldToCellPreferSolid = c.WorldToCellPreferSolid local WorldToCellPreferEmpty = c.WorldToCellPreferEmpty local CellCenterToWorld = c.CellCenterToWorld @@ -83,44 +83,32 @@ ContentProvider:Preload "http://banland.xyz/asset?id=82741829" ------------------------- OBJECT DEFINITIONS --------------------- -- helper function for objects +local colours = { + "Bright green", + "Bright yellow", + "Bright red", + "Sand red", + "Black", + "Dark stone grey", + "Sand blue", + "Deep orange", + "Dark orange", + "Reddish brown", + "Light orange", + "Light stone grey", + "Sand green", + "Medium stone grey", + "Really red", + "Really blue", + "Bright blue", +} + local function getClosestColorToTerrainMaterial(terrainValue) - if terrainValue == 1 then - return BrickColor.new "Bright green" - elseif terrainValue == 2 then - return BrickColor.new "Bright yellow" - elseif terrainValue == 3 then - return BrickColor.new "Bright red" - elseif terrainValue == 4 then - return BrickColor.new "Sand red" - elseif terrainValue == 5 then - return BrickColor.new "Black" - elseif terrainValue == 6 then - return BrickColor.new "Dark stone grey" - elseif terrainValue == 7 then - return BrickColor.new "Sand blue" - elseif terrainValue == 8 then - return BrickColor.new "Deep orange" - elseif terrainValue == 9 then - return BrickColor.new "Dark orange" - elseif terrainValue == 10 then - return BrickColor.new "Reddish brown" - elseif terrainValue == 11 then - return BrickColor.new "Light orange" - elseif terrainValue == 12 then - return BrickColor.new "Light stone grey" - elseif terrainValue == 13 then - return BrickColor.new "Sand green" - elseif terrainValue == 14 then - return BrickColor.new "Medium stone grey" - elseif terrainValue == 15 then - return BrickColor.new "Really red" - elseif terrainValue == 16 then - return BrickColor.new "Really blue" - elseif terrainValue == 17 then - return BrickColor.new "Bright blue" - else - return BrickColor.new "Bright green" + local val = BrickColor.new(colours[terrainValue]) + if val then + return val end + return BrickColor.new "Bright green" end -- Used to create a highlighter that follows the mouse. @@ -155,32 +143,34 @@ function MouseHighlighter.Create(mouseUse) end) -- Create the part that the highlighter will be attached to. - highlighter.selectionPart = Instance.new "Part" - highlighter.selectionPart.Name = "SelectionPart" - highlighter.selectionPart.Archivable = false - highlighter.selectionPart.Transparency = 0.5 - highlighter.selectionPart.Anchored = true - highlighter.selectionPart.Locked = true - highlighter.selectionPart.CanCollide = false - highlighter.selectionPart.FormFactor = Enum.FormFactor.Custom - highlighter.selectionPart.Size = Vector3.new(4, 4, 4) - highlighter.selectionPart.BottomSurface = 0 - highlighter.selectionPart.TopSurface = 0 - highlighter.selectionPart.BrickColor = - getClosestColorToTerrainMaterial(currentMaterial) - highlighter.selectionPart.Parent = game.Workspace + highlighter.selectionPart = New "Part" { + Name = "SelectionPart", + Archivable = false, + Transparency = 0.5, + Anchored = true, + Locked = true, + CanCollide = false, + FormFactor = Enum.FormFactor.Custom, + Size = Vector3.new(4, 4, 4), + BottomSurface = 0, + TopSurface = 0, + BrickColor = getClosestColorToTerrainMaterial(currentMaterial), + Parent = workspace, + } - local billboardGui = Instance.new "BillboardGui" - billboardGui.Size = UDim2.new(5, 0, 5, 0) - billboardGui.StudsOffset = Vector3.new(0, 2.5, 0) - billboardGui.Parent = highlighter.selectionPart + local billboardGui = New "BillboardGui" { + Size = UDim2.new(5, 0, 5, 0), + StudsOffset = Vector3.new(0, 2.5, 0), + Parent = highlighter.selectionPart, + } - local imageLabel = Instance.new "ImageLabel" - imageLabel.BackgroundTransparency = 1 - imageLabel.Size = UDim2.new(1, 0, 1, 0) - imageLabel.Position = UDim2.new(-0.35, 0, -0.5, 0) - imageLabel.Image = "http://banland.xyz/asset?id=82741829" - imageLabel.Parent = billboardGui + local imageLabel = New "ImageLabel" { + BackgroundTransparency = 1, + Size = UDim2.new(1, 0, 1, 0), + Position = UDim2.new(-0.35, 0, -0.5, 0), + Image = "http://banland.xyz/asset?id=82741829", + Parent = billboardGui, + } local lastTweenChange @@ -197,7 +187,7 @@ function MouseHighlighter.Create(mouseUse) tweenDown = function() if imageLabel - and imageLabel:IsDescendantOf(game.Workspace) + and imageLabel:IsDescendantOf(workspace) and thisTweenStamp == lastTweenChange then imageLabel:TweenPosition( @@ -213,7 +203,7 @@ function MouseHighlighter.Create(mouseUse) tweenUp = function() if imageLabel - and imageLabel:IsDescendantOf(game.Workspace) + and imageLabel:IsDescendantOf(workspace) and thisTweenStamp == lastTweenChange then imageLabel:TweenPosition( @@ -249,8 +239,8 @@ function MouseHighlighter.Create(mouseUse) return end - if highlighter.selectionPart.Parent ~= game.Workspace then - highlighter.selectionPart.Parent = game.Workspace + if highlighter.selectionPart.Parent ~= workspace then + highlighter.selectionPart.Parent = workspace startTween() end @@ -327,7 +317,7 @@ end -- Show the highlighter. function MouseHighlighter:EnablePreview() - self.selectionPart.Parent = game.Workspace + self.selectionPart.Parent = workspace startTween() end @@ -401,7 +391,7 @@ function ConfirmationPopup.Create( ) ) { FontSize = Enum.FontSize.Size14, - TextWrap = true, + TextWrapped = true, Font = Enum.Font.Arial, TextXAlignment = Enum.TextXAlignment.Center, } @@ -596,7 +586,7 @@ local function ConfirmFloodFill(x, y, z) end function mouseDown(mouseD) - if on and mouseD.Target == game.Workspace.Terrain then + if on and mouseD.Target == workspace.Terrain then startCell = mouseHighlighter:GetPosition() end end @@ -824,7 +814,7 @@ Hydrate(helpFrame) { TextXAlignment = Enum.TextXAlignment.Left, TextYAlignment = Enum.TextYAlignment.Top, BackgroundTransparency = 1, - TextWrap = true, + TextWrapped = true, Text = [[ Quickly replace empty terrain cells with a selected material. Clicking the mouse will cause any empty terrain cells around the point clicked to be filled with the current material, and will also spread to surrounding empty cells (including any empty cells below, but not above).