-
Notifications
You must be signed in to change notification settings - Fork 205
Update SaveManager.lua #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -292,28 +292,43 @@ local SaveManager = {} do | |||||||
| SaveManager.Options.SaveManager_ConfigList:SetValue(nil) | ||||||||
| end}) | ||||||||
|
|
||||||||
| local AutoloadButton | ||||||||
| AutoloadButton = section:AddButton({Title = "Set as autoload", Description = "Current autoload config: none", Callback = function() | ||||||||
| local name = SaveManager.Options.SaveManager_ConfigList.Value | ||||||||
| writefile(self.Folder .. "/settings/autoload.txt", name) | ||||||||
| AutoloadButton:SetDesc("Current autoload config: " .. name) | ||||||||
| self.Library:Notify({ | ||||||||
| Title = "Interface", | ||||||||
| Content = "Config loader", | ||||||||
| SubContent = string.format("Set %q to auto load", name), | ||||||||
| Duration = 7 | ||||||||
| }) | ||||||||
| end}) | ||||||||
| local Toggle = section:AddToggle("AutoloadToggle", { | ||||||||
| Title = "Auto Load Config", | ||||||||
| Default = false, | ||||||||
| Description = "Toggle to set/unset autoload config" | ||||||||
| }) | ||||||||
|
|
||||||||
| Toggle:OnChanged(function(state) | ||||||||
| local name = SaveManager.Options.SaveManager_ConfigList.Value | ||||||||
| local autoloadPath = self.Folder .. "/settings/autoload.txt" | ||||||||
|
|
||||||||
| if state then | ||||||||
| writefile(autoloadPath, name) | ||||||||
| self.Library:Notify({ | ||||||||
| Title = "Interface", | ||||||||
| Content = "Config loader", | ||||||||
| SubContent = string.format("Set %q to auto load", name), | ||||||||
| Duration = 7 | ||||||||
| }) | ||||||||
| else | ||||||||
| if isfile(autoloadPath) then | ||||||||
| delfile(autoloadPath) | ||||||||
| end | ||||||||
| self.Library:Notify({ | ||||||||
| Title = "Interface", | ||||||||
| Content = "Config loader", | ||||||||
| SubContent = "Autoload has been disabled", | ||||||||
| Duration = 7 | ||||||||
| }) | ||||||||
| end | ||||||||
| end) | ||||||||
|
Comment on lines
+301
to
+324
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OnChanged fires on initialization, causing unwanted notification. Based on the Consider one of these approaches: Option 1: Add a flag to suppress the initial notification: +local initializing = true
Toggle:OnChanged(function(state)
local name = SaveManager.Options.SaveManager_ConfigList.Value
local autoloadPath = self.Folder .. "/settings/autoload.txt"
if state then
writefile(autoloadPath, name)
self.Library:Notify({
Title = "Interface",
Content = "Config loader",
SubContent = string.format("Set %q to auto load", name),
Duration = 7
})
else
+ if initializing then
+ initializing = false
+ return
+ end
if isfile(autoloadPath) then
delfile(autoloadPath)
endOption 2: Initialize the toggle state based on whether |
||||||||
|
|
||||||||
| if isfile(self.Folder .. "/settings/autoload.txt") then | ||||||||
| local name = readfile(self.Folder .. "/settings/autoload.txt") | ||||||||
| AutoloadButton:SetDesc("Current autoload config: " .. name) | ||||||||
| end | ||||||||
| -- ตั้งค่าเริ่มต้นเป็นปิดไว้ก่อน | ||||||||
| Options.AutoloadToggle:SetValue(false) | ||||||||
|
Comment on lines
+295
to
+327
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Toggle state doesn't reflect actual autoload status on initialization. The toggle always starts as Consider initializing the toggle based on file existence: local Toggle = section:AddToggle("AutoloadToggle", {
Title = "Auto Load Config",
- Default = false,
+ Default = isfile(self.Folder .. "/settings/autoload.txt"),
Description = "Toggle to set/unset autoload config"
})Then register the 🤖 Prompt for AI Agents
Comment on lines
+326
to
+327
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove redundant SetValue call. Line 327 calls Apply this diff to remove the redundant call: end)
--- ตั้งค่าเริ่มต้นเป็นปิดไว้ก่อน
-Options.AutoloadToggle:SetValue(false)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| SaveManager:SetIgnoreIndexes({ "SaveManager_ConfigList", "SaveManager_ConfigName" }) | ||||||||
| end | ||||||||
|
|
||||||||
| SaveManager:BuildFolderTree() | ||||||||
| end | ||||||||
|
|
||||||||
| return SaveManager | ||||||||
| return SaveManager | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate config selection before writing to autoload.
The handler writes
nameto the autoload file without verifying that a config is actually selected. IfSaveManager_ConfigList.Valueisnilor empty, this will write invalid data toautoload.txt, causingLoadAutoloadConfig()to fail silently or load nothing.Apply this diff to add validation:
Toggle:OnChanged(function(state) local name = SaveManager.Options.SaveManager_ConfigList.Value local autoloadPath = self.Folder .. "/settings/autoload.txt" if state then + if not name or name == "" then + self.Library:Notify({ + Title = "Interface", + Content = "Config loader", + SubContent = "Please select a config first", + Duration = 7 + }) + Toggle:SetValue(false) + return + end writefile(autoloadPath, name)🤖 Prompt for AI Agents