Вопрос [NL] Load function

Начинающий
Статус
Оффлайн
Регистрация
30 Апр 2022
Сообщения
194
Реакции[?]
8
Поинты[?]
1K
Объясните пожалуйста как зафиксить load


code_language.lua:
local menu = ui.create("Main")

local switch = menu:switch("1")

local base64 = require("neverlose/base64")
local clipboard = require("neverlose/clipboard")


sidebar_selection = ui.get_style("Switch Active")
sidebar_color = sidebar_selection:to_hex()

copy = ui.get_icon("copy")
paste = ui.get_icon("paste")
globe = ui.get_icon("globe")

local andr = {}
local andr = {
    functions = {},
    globals = {},
}

configs_list = menu:list("Currently loaded:")

andr.functions.get_config_from_elements = {
    ----------------------------
    switch,
}


configname = menu:input("Name","Write cfg name here!")


function get_neverlose_path()
    return common.get_game_directory():sub(1, -5) .. "nl\\"
end

files.create_folder("nl\\MyConfigsTest")

files.default_path = get_neverlose_path().."MyConfigsTest\\"

files.configs_path = files.default_path.. "\\presets.json"

presets = {
    names = {},
    values = {}
}

local configs = {main = {names = presets.names, values = presets.values}}

on_load = function()
    if files.read(files.configs_path) == nil then
        files.write(files.configs_path, json.stringify(configs.main))
    end

end

on_load()

parse = function()
    local list = json.parse(files.read(files.configs_path))
    local addition_item = configname:get();

    presets.names = list.names
    presets.values = list.values
    if presets.names == addition_item then
        return
        print_raw("sdfgnikhsdbfg")
    elseif #presets.names ~= 0 then
        configs_list:update(presets.names)
    end
    

end

parse()

config_update = function()
    configs.main.names = presets.names;
    configs.main.values = presets.values;
    files.write(files.configs_path, (json.stringify(configs.main)))
    
end

config_update()


update_list_empty = function()
 

    if #presets.names == 0 then
        configs_list:update({"\a777777FFEmpty config list."})
    end
end

update_list_empty()

create = function()
    local config = configs_list:get()
    local cur_list = configs_list:list();
    local addition_item = configname:get();

    andr.config = {}
    for i = 1, #andr.config do
        print(andr.config[i])
        andr.config[i] = nil
    end
    update_list_empty()
    for i = 1, #andr.functions.get_config_from_elements do
        andr.config[i] = andr.functions.get_config_from_elements[i]:get()
    end

    cur_list[#cur_list+1] = addition_item;
    local json_config = json.stringify(andr.config)
    local encoded_config = base64.encode(json_config)
    parse()
    table.insert(presets.names, addition_item)
    table.insert(presets.values, encoded_config)
    config_update()

    
    configs_list:update(cur_list);

end

savebutton = menu:button("\a".. sidebar_color ..""..ui.get_icon("plus") .."\aFFFFFFFF  Create", create, true)

load = function()

    local config = configs_list:get()
    local config_writed = files.read(files.configs_path)

    local to_parse = json.parse(files.read(files.configs_path))


    for k, v in ipairs(to_parse) do

        for i = 1, #andr.globals.config do
            andr.functions.get_config_from_elements[i]:set(andr.globals.config[i])
        end

    end

    
end

loadbutton = menu:button("\a".. sidebar_color ..""..ui.get_icon("check") .."\aFFFFFFFF  Load", load, true)


local function delete_function()
    local cur_list = configs_list:list();
    local deletion_item = configs_list:get();
    
    parse()
    table.remove(cur_list, deletion_item);
    table.remove(presets.names, configs_list:get());
    table.remove(presets.values, configs_list:get());
    config_update()

    configs_list:update(cur_list);
end



deletebutton = menu:button("\a".. sidebar_color ..""..ui.get_icon("trash") .."\aFFFFFFFF Delete", delete_function, true)
 
Сверху Снизу