Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

[REQUEST] Add config saving and loading  #4

@SleepyLama

Description

@SleepyLama

Script
What script are you submitting a feature request for?

  • [Material Remake UI (Incredible UI you've created.)]

  • [Adding Config saving and loading]

Example :

local Toggles = {}
local Sliders = {}
local Textboxes = {}

local ConfigName = "Test"
local function saveConfig(cfgName)
    if isfile(string.format("%s.json",cfgName)) then
        local Config = game:GetService("HttpService"):JSONDecode(readfile(string.format("%s.json",cfgName)))
        local Data = {}
        table.foreach(Toggles,function(i,v)
            Data[i] = v:GetState()
        end)
        table.foreach(Sliders,function(i,v)
            Data[i] = v.Value
        end)
        table.foreach(Textboxes,function(i,v)
            Data[i] = v:GetText()
        end)
        table.foreach(Data,function(x,y)
            warn(x,y)
        end)
        writefile(string.format("%s.json",cfgName), game:GetService("HttpService"):JSONEncode(Data))
    else
        writefile(string.format("%s.json",cfgName), game:GetService("HttpService"):JSONEncode({}))
        local Config = game:GetService("HttpService"):JSONDecode(readfile(string.format("%s.json",cfgName)))
        local Data = {}
        table.foreach(Toggles,function(i,v)
            Data[i] = v:GetState()
        end)
        table.foreach(Sliders,function(i,v)
            Data[i] = v.Value
        end)
        table.foreach(Textboxes,function(i,v)
            Data[i] = v:GetText()
        end)
        table.foreach(Data,function(x,y)
            warn(x,y)
        end)
        writefile(string.format("%s.json",cfgName), game:GetService("HttpService"):JSONEncode(Data))
    end
end
local function loadConfig(cfgName)
    if isfile(string.format("%s.json",cfgName)) then
        local Config = game:GetService("HttpService"):JSONDecode(readfile(string.format("%s.json",cfgName)))
        table.foreach(Config,function(i,v)
            if typeof(v) == "boolean" then
                Toggles[i]:SetState(v)
            end
        end)
    end
end

Since its not added yet each time i want to create a toggle/textbox/slider i say

    Text = "Text Box",
    Callback = function(value)
        print(value)
    end,
    Type = "Default",
    ClearOnFocus = false
})

or

    Text = "Slider",
    Callback = function(value)
        Sliders["Slider"].Value = value
        print("Enabled:", value)
    end,
    Min = 0,
    Max = 123789,
    Def = 0
})```

or 
```Toggles["Toggle"] = MainTab.Toggle({
    Text = "Toggle",
    Callback = function(value)
        print("Enabled:", value)
    end,
    Enabled = true
})

I was unable to complete like loading the config for sliders or textboxes (because its not added as a method and rewriting the source would take too much work due to you probably updating it (because of the notify system))

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions