Advertisement
Guest User

Lighting Settings Loader

a guest
Jul 28th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. --   ATTRIBUTE LOADER   --
  2. -- BY: PERSONIFIEDPIZZA --
  3.  
  4. local PROPERTIES_LIST = {
  5.     Lighting = {"Ambient", "Archivable", "Brightness", "ClockTime", "ColorShift_Bottom", "ColorShift_Top", "ExposureCompensation", "FogColor", "FogEnd", "FogStart", "GeographicLatitude", "GlobalShadows", "Name", "OutdoorAmbient", "Outlines", "Parent", "TimeOfDay"};
  6. }
  7.  
  8. local STOREABLE_PROPERTIES = {
  9.     "string";
  10.     "boolean";
  11.     "number";
  12.     "UDim";
  13.     "UDim2",
  14.     "BrickColor";
  15.     "Color3";
  16.     "Vector2";
  17.     "Vector3";
  18.     "NumberSequence";
  19.     "ColorSequence";
  20.     "NumberRange";
  21.     "Rect";
  22. }
  23.  
  24. local function store(instance)
  25.     local newConfig = Instance.new("Configuration")
  26.     local className = instance.ClassName
  27.     newConfig.Name = className.."Configurations"
  28.     newConfig:SetAttribute("ClassName", className)
  29.     for _, propertyName in ipairs(PROPERTIES_LIST[className]) do
  30.         local propertyValue = instance[propertyName]
  31.         local propertyType = typeof(propertyValue)
  32.         if table.find(STOREABLE_PROPERTIES, propertyType) then
  33.             newConfig:SetAttribute(propertyName, propertyValue)
  34.         elseif propertyType == "EnumItem" then
  35.             newConfig:SetAttribute(propertyName, propertyValue.Value)
  36.         end
  37.     end
  38.  
  39.     return newConfig
  40. end
  41.  
  42. local function apply(instance, config)
  43.     local attributes = config:GetAttributes()
  44.     local attributeClassName = attributes["ClassName"]
  45.     if attributeClassName ~= instance.ClassName then
  46.         warn("Can't apply configuration to the wrong class! ["..instance.ClassName..","..attributeClassName.."]")
  47.         return
  48.     end
  49.     attributes["ClassName"] = nil
  50.     for attributeName, attributeValue in pairs(attributes) do
  51.         instance[attributeName] = attributeValue
  52.     end
  53. end
  54.  
  55.  
  56. --   LIGHTING CONFIGURATIONS LOADER   --
  57. --        BY: PERSONIFIEDPIZZA        --
  58.  
  59. local Lighting = game:GetService("Lighting")
  60. local Selection = game:GetService("Selection")
  61. local ChangeHistoryService = game:GetService("ChangeHistoryService")
  62.  
  63. local function storeLightingConfiguration()
  64.     ChangeHistoryService:SetWaypoint("Storing LightingConfiguration")
  65.     local config = store(Lighting)
  66.     local folder = Lighting:FindFirstChild("LightingConfigurations")
  67.     if not folder then
  68.         folder = Instance.new("Folder")
  69.         folder.Name = "LightingConfigurations"
  70.         folder.Parent = Lighting
  71.     end
  72.     config.Parent = folder
  73.     Selection:Set({config})
  74.     ChangeHistoryService:SetWaypoint("Stored LightingConfiguration")
  75. end
  76.  
  77. local function isLightingConfiguration(instance)
  78.     local classNameAttribute = instance:GetAttribute("ClassName")
  79.     if classNameAttribute and (classNameAttribute == "Lighting") and (instance:IsA("Configuration")) then
  80.         return true
  81.     end
  82. end
  83.  
  84. local function tryLightingConfiguration()
  85.     local selected = Selection:Get()
  86.     local config
  87.     for _, instance in ipairs(selected) do
  88.         if isLightingConfiguration(instance) then
  89.             config = instance
  90.             Selection:Set({instance})
  91.             break
  92.         end
  93.     end
  94.     if config then
  95.         ChangeHistoryService:SetWaypoint("Applying LightingConfiguration")
  96.         apply(Lighting, config)
  97.         ChangeHistoryService:SetWaypoint("Applied LightingConfiguration")
  98.         return true
  99.     end
  100. end
  101.  
  102. local function applyLightingConfiguration()
  103.     local success = tryLightingConfiguration()
  104.     if success then
  105.         return true
  106.     end
  107.     print("Select a LightingConfiguration!")
  108.     Selection.SelectionChanged:Wait()
  109.     local success = tryLightingConfiguration()
  110.     if success then
  111.         return true
  112.     end
  113.     print("No LightingConfiguration selected!")
  114. end
  115.  
  116.  
  117. --   LIGHTING CONFIGURATIONS PLUGIN   --
  118. --        BY: PERSONIFIEDPIZZA        --
  119.  
  120. local toolbar = plugin:CreateToolbar("Lighting Configurations")
  121. local storeButton = toolbar:CreateButton("Store Configuration", "Stores current Configuration in Lighting", "http://www.roblox.com/asset/?id=7167747940")
  122. local applyButton = toolbar:CreateButton("Apply Configuration", "Applys selected Configuration to Lighting", "http://www.roblox.com/asset/?id=7167748754")
  123.  
  124. storeButton.ClickableWhenViewportHidden = true
  125. applyButton.ClickableWhenViewportHidden = true
  126.  
  127. local storeButtonClickId = 0
  128. storeButton.Click:Connect(function()
  129.     storeButtonClickId += 1
  130.     local myClickId = storeButtonClickId
  131.     storeLightingConfiguration()
  132.     wait(0.1)
  133.     if myClickId == storeButtonClickId then
  134.         storeButton:SetActive(false)
  135.     end
  136. end)
  137.  
  138. local applyButtonClickId = 0
  139. applyButton.Click:Connect(function()
  140.     applyButtonClickId += 1
  141.     local myClickId = applyButtonClickId
  142.     applyLightingConfiguration()
  143.     wait(0.1)
  144.     if myClickId == applyButtonClickId then
  145.         storeButton:SetActive(false)
  146.     end
  147. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement