Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- print("Plugin loaded") -- vX.N
- local ChangeHistoryService = game:GetService("ChangeHistoryService")
- local GuiUtilities = require(script.Parent.StudioWidgets.GuiUtilities)
- local module = require(script.Parent.StudioWidgets.GuiUtilities)
- local LabeledCheckbox = require(script.Parent.StudioWidgets.LabeledCheckbox)
- -- note the SyncColors function is from Roblox
- local click = script.Click
- local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float ,
- false,
- true,
- 357, --float size x
- 440, -- y
- 357, -- min width
- 440) -- min height
- local widget = plugin:CreateDockWidgetPluginGui("Menu", widgetInfo)
- widget.Title = "Settings Auto-path v1"
- local mainframe = Instance.new("Frame")
- mainframe.Size = UDim2.new(1,0,1,0)
- mainframe.Parent = widget
- local function syncGuiColors(objects)
- local function setColors()
- for _, guiObject in ipairs(objects) do
- -- Sync background color
- guiObject.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
- -- Sync text color
- if guiObject:IsA("TextLabel") or guiObject:IsA("TextButton") then
- guiObject.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText)
- end
- end
- end
- -- Run 'setColors()' function to initially sync colors
- setColors()
- -- Connect 'ThemeChanged' event to the 'setColors()' function
- settings().Studio.ThemeChanged:Connect(setColors)
- end
- -- color changed this
- mainframe.Parent = widget
- local toolbar = plugin:CreateToolbar("Auto-path v1") -- shorten?
- local toggle = toolbar:CreateButton("Toggle Settings", "Toggle the Settings widget", "rbxassetid://4966899239")
- local generatePath = toolbar:CreateButton("Path", "Create automated paths", "rbxassetid://5045855755")
- toggle.Click:Connect(function()
- widget.Enabled = not widget.Enabled
- end)
- local WFCindex = LabeledCheckbox.new(
- "WFC",
- "WaitForChild() index",
- plugin:GetSetting("WFC"),
- false
- )
- WFCindex:SetValueChangedFunction(function(newValue)
- plugin:SetSetting("WFC",newValue)
- end)
- local ob = WFCindex:GetFrame()
- ob.Position = ob.Position + UDim2.new(0,1,0,18)
- ob.Parent = mainframe
- --
- local FFCindex = LabeledCheckbox.new(
- "FFC",
- "FindFirstChild() index",
- plugin:GetSetting("FFCindex"),
- false
- )
- local obk = FFCindex:GetFrame()
- obk.Position = ob.Position + UDim2.new(0, 0, 0, 60)
- obk.Parent = mainframe
- FFCindex:SetValueChangedFunction(function(newValue)
- plugin:SetSetting("FFC", newValue)
- end)
- local doubleQuote = LabeledCheckbox.new(
- "quotes",
- 'use double quotes " " ',
- plugin:GetSetting("quotes"),
- false
- )
- doubleQuote:SetValueChangedFunction(function(newValue)
- plugin:SetSetting("quotes", newValue)
- end)
- local obj = doubleQuote:GetFrame()
- obj.Position = obk.Position + UDim2.new(0, 0, 0, 60)
- obj.Parent = mainframe
- local LocalScript = LabeledCheckbox.new("local", "Local Script",
- plugin:GetSetting("local"),
- false
- )
- LocalScript:SetValueChangedFunction(function(newValue)
- plugin:SetSetting("local", newValue)
- end)
- local oba = LocalScript:GetFrame()
- oba.Position = obj.Position + UDim2.new(0, 0, 0, 60)
- oba.Parent = mainframe
- local case = LabeledCheckbox.new("case", "camelCase",
- plugin:GetSetting("case"),
- false
- )
- case:SetValueChangedFunction(function(newValue)
- plugin:SetSetting("case", newValue)
- end)
- local obg = case:GetFrame()
- obg.Position = oba.Position + UDim2.new(0, 0, 0, 60)
- obg.Parent = mainframe
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0,300,0,40)
- button.BackgroundColor3 = Color3.new(1,1,1)
- button.Position = obg.Position + UDim2.new(0, 33, 0, 104)
- button.TextScaled = true
- button.Text = "click to prepend..."
- button.Parent = mainframe
- local label = Instance.new("TextLabel")
- label.Text = "prepend to script"
- label.BackgroundTransparency = 1
- label.TextSize = 18
- label.Position = button.Position - UDim2.new(0, 50, 0, 40) -- I could've just made this before the button
- label.Size = UDim2.new(0,300,0,20)
- label.Parent = mainframe
- label.Changed:Connect(function()
- label.TextColor3 = Color3.new(1,1,1)
- end)
- syncGuiColors({mainframe})
- --------- this line marks the end of the UI territory, cross this border at your own risk
- local services = {[[ReplicatedStorage]], [[ReplicatedFirst]], [[Lighting]], [[ServerStorage]], [[ServerScriptService]],
- [[SoundService]], [[StarterGui]], [[Players]],[[ReplicatedScriptService]], [[SoundService]], [[StarterPack]], [[StarterPlayer]],
- [[Teams]], [[Chat]], [[LocalizationService]], [[TestService]]} -- RSS, welcome to the team buddy
- local chars = { "*", "&", "%", "$", "#", "@", "!", ";", "|", "/",":",")","(","[","]",
- "?", "," , "<", ">","=", "+",}
- local function CapitalizeFirst(str, bool)
- local v = {}
- for i in str:gmatch(".") do
- table.insert(v, i) -- something looks odd here
- end
- if bool then
- local SirPascalTable = {}
- for i = 1, #str do
- if i % 2 == 0 then -- even
- table.insert(SirPascalTable, v[i]:upper())
- else
- table.insert(SirPascalTable, v[i]:lower())
- end
- str = table.concat(SirPascalTable)
- end
- else
- str = v[1]:upper().. table.concat(v,"", 2)
- end
- return str
- end
- local function Refine(text)
- local t = {};
- if not text:find(" ") then return nil end
- local split = text:split(" ")
- for _, component in ipairs(split) do
- table.insert(t, (CapitalizeFirst(component, case:GetValue())))
- end
- return table.concat(t)
- end
- local function replaceChar(str)
- local temp = {}
- for x in str:gmatch(".") do -- for gaps only? previously gmatch() . for every character
- if string.find(table.concat(chars), x,1,true) then table.insert(temp, "_") -- in the future just CapitalizeSecondVariable
- else
- table.insert(temp, x)
- end
- end
- if Refine(table.concat(temp)) then return Refine(table.concat(temp)) end
- return table.concat(temp)
- end
- local function getName(item, sep)
- local v = tostring(item:GetFullName())
- local index
- if FFCindex:GetValue() then index = ":FindFirstChild("
- elseif WFCindex:GetValue() then index = ":WaitForChild("
- end
- if v:match("Workspace") then
- v = "workspace"..v:sub(10)
- end
- local split = v:split(".")[3]
- for _, x in ipairs(services) do
- if v:match(x) then
- split = v:split(".")[3] or v:split(".")[2]
- v = "game:GetService("..sep.. x .. sep ..")".. "["..sep..replaceChar(split)..sep.."]" -- game. service. etc.
- end
- end
- local tab = v:split(".")
- if not index then
- return v end
- v = tab[1] -- first item (why am I writing this, not like anyone else is going to read this right?)
- for i = 2, #tab do
- v = v..index.. sep.. tab[i].. sep..")" -- workspace:FindFirstChild("item"):FindFirstChild(obj) or WFC
- end
- return v
- end
- local function removeBracks(str)
- local count = 0
- for i in str:gmatch("%[") do
- count = count + 1
- if count>1 then return str end
- end
- local before = str:sub(1, str:find("%[")-1)
- str = str:sub(str:find("%[")+1, str:find("%]")-1)
- return {before,str}
- end
- local s
- local sep
- local tab = {}
- local created = {service = false, remote = false, assets = false, modules = false}
- local function brackCountAbove2(str)
- local count = 0
- for i in str:gmatch("%[") do
- count = count + 1
- if count>1 then return true end
- return false
- end
- end
- local function AddAfterType(key, value, TYPE)
- local temp = {}
- for x in key:gmatch(".") do
- if string.find(table.concat(chars), x,1,true) then table.insert(temp, "_") -- in the future just CapitalizeSecondVariable
- else
- table.insert(temp, x)
- end
- end
- key = table.concat(temp)
- if not s.Source:find(TYPE) then s.Source = s.Source.. "\n\n --// "..TYPE.." \n " created[TYPE] = true end
- if s.Source:find(TYPE) then
- local num,num2 = s.Source:find(TYPE)
- local sub = string.sub(s.Source,1, num2+1) -- from beginning till Type
- local rest = string.sub(s.Source, num2+1)
- if not value:match(" ") and not value:match("_") and value:match("%[") and (value:match("%"..sep)) and not brackCountAbove2(value) then
- local t = removeBracks(value)
- value = t[1]..".".. (t[2]:match("%w+"))
- end
- if TYPE == "modules" then -- this one's special
- value = "require("..value..")"
- end
- sub = sub.."\n local "..key.." = "..value -- previously sub.."\n local "..key.." = "..value
- s.Source = sub..rest
- end
- end
- local clickedByButton
- local selection = game:GetService("Selection")
- local active = true
- local done
- local function OnGenClick ()
- if FFCindex:GetValue() and WFCindex:GetValue() then return error("\n Error: Cannot use :WaitForChild() and :FindFirstChild() functions at the same time") end
- if not done then
- for _, v in ipairs(game:GetDescendants()) do
- pcall(function()
- if v.Name:match(" ") then v.Name = string.gsub(v.Name, '^%s*(.-)%s*$', '%1')
- end
- end)
- end
- -- begone yield, wait:(
- done = true
- end
- local lscript = LocalScript:GetValue()
- if lscript then s = Instance.new("LocalScript")
- else
- s = Instance.new("Script")
- end
- if doubleQuote:GetValue() then sep = '"'
- else
- sep = "'"
- end
- local function OperationForcedFineLine()
- for w in s.Source:gmatch("%w+") do
- if table.find( {"modules","assets","remotes","services"}, w) then
- local one, two = s.Source:find(w)
- s.Source = string.sub(s.Source,1, two+1).."\n".. string.sub(s.Source, two+1)
- end
- end
- end
- local function define(obj,t,v)
- if obj:IsA("RemoteEvent") then
- if not created.remote then
- s.Source = s.Source.. "\n\n --// remotes \n " created.remote = true
- AddAfterType(t,v,"remotes")
- else
- AddAfterType(t,v,"remotes")
- end
- else
- if obj:IsA("ModuleScript") then if not created.modules then s.Source = s.Source.. "\n\n --// modules \n " created.modules = true
- AddAfterType(t,v,"modules")
- else
- AddAfterType(t,v,"modules")
- end
- else
- if obj:IsA("Instance") then if not created.assets then s.Source = s.Source.. "\n\n --// assets \n " created.assets = true
- AddAfterType(t,v,"assets")
- else
- AddAfterType(t,v, "assets")
- end
- end
- end
- end
- end
- for _, obj in ipairs(selection:Get()) do
- local name = obj.Name
- if table.find(services, name) then
- if not created.service then
- s.Source = s.Source.."\n\n --// services \n"
- created.service = true
- AddAfterType(name,"game:GetService("..sep..name..sep..")" ,"services")
- else
- AddAfterType(name,"game:GetService("..sep..name..sep..")" ,"services")
- end
- -- s.Source = s.Source.. "\n local "..name.." = ".. "game:GetService("..sep..name..sep..")"
- else -- not just a service, even more ...
- local v = obj:GetFullName()
- local temp = v:split(".")
- if temp[1] == "Workspace" then temp[1] = "workspace" end
- v = temp[1] -- first item
- local t = name
- if table.find(services, temp[1] ) then v = "game:GetService(" .. sep .. v .. sep.. ")" end
- for i = 2, #temp do
- v = v.."[".. sep.. temp[i].. sep.."]" -- add function that replaces chars such as brackets with no gap or _
- end
- t = replaceChar(name)
- -- recheck for any gaps and dots
- if string.match(v, " ") then
- local a = v:split(".")
- local v = a[1]
- for i = 2, #a do
- v = v .. "[".. sep..a[i] .. sep .. "]"
- end
- if string.find(v, ".",1,true) or string.find(v, "[",1,true) then
- local a = v:split(".")
- local v = a[1]
- for i = 2, #a do
- v = v .. "[".. sep..a[i] .. sep .. "]"
- end
- for _, se in ipairs(services) do -- I know this can be minimized, but who cares while doing this in a plugin right?
- if v:match(se) then
- v = "game:GetService("..sep..se..sep..")"
- for i = 2, #a do
- v = v .. "[".. sep..a[i] .. sep .. "]"
- end
- end
- end
- end
- define(obj, t, v)
- else
- define(obj, name, (getName(obj, sep)))
- --s.Source = s.Source.. "\n local "..name.." = ".. getName(obj, sep)
- end
- end
- end
- OperationForcedFineLine()
- s.Source = "\n".. s.Source
- if not clickedByButton then s.Parent = workspace
- else
- s:Destroy()
- end
- end
- generatePath.Click:Connect(OnGenClick)
- -- after user clicks button to prepend, clear current selection and parent to next selection
- button.Activated:Connect(function()
- assert(not LocalScript:GetValue(), "\n Error: you cannot create a local script inside of a script")
- clickedByButton = true
- OnGenClick()
- selection:Set({nil})
- while true do
- wait()
- if #selection:Get()~= 0 and selection:Get()[1]:IsA("LuaSourceContainer") then selection:Get()[1].Source = s.Source..selection:Get()[1].Source break end
- end
- wait(0.11) -- some cooldown for spammers
- clickedByButton = false
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement