Skip to content

Commit

Permalink
make profile storage selection smart
Browse files Browse the repository at this point in the history
  • Loading branch information
devsarim committed Jan 23, 2024
1 parent 294cf12 commit 3b10aff
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/SaveMenu/Save.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local CollectionService = game:GetService("CollectionService")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")

Expand Down Expand Up @@ -31,6 +32,29 @@ local function createProfile()
return profileFolder
end

local function determineParent()
local parentCounts = {}

for _, profile in CollectionService:GetTagged("LightingProfile") do
if not parentCounts[profile.Parent] then
parentCounts[profile.Parent] = 1
else
parentCounts[profile.Parent] += 1
end
end

local highestCount = 0
local commonParent = ServerStorage

for parent, count in parentCounts do
if count > highestCount then
commonParent = parent
end
end

return commonParent
end

return function(props)
local textBox = props.textBoxRef:getValue()

Expand All @@ -53,7 +77,7 @@ return function(props)
local profile = createProfile()
profile.Name = profileName
profile:AddTag("LightingProfile")
profile.Parent = ServerStorage
profile.Parent = determineParent()

ChangeHistoryService:SetWaypoint("Create lighting profile")
end,
Expand Down

0 comments on commit 3b10aff

Please sign in to comment.