• Я зарабатываю 100 000 RUB / месяц на этом сайте!

    А знаешь как? Я всего-лишь публикую (создаю темы), а админ мне платит. Трачу деньги на мороженое, робуксы и сервера в Minecraft. А ещё на паль из Китая. 

    Хочешь так же? Пиши и узнавай условия: https://t.me/alex_redact
    Реклама: https://t.me/yougame_official

LUA скрипт Icon Library — Experiment

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
29 Ноя 2022
Сообщения
22
Реакции
4
Icon Library Release

Hey everyone,

I’m excited to share my Icon Library, a project I built mainly for fun and learning.
The code isn’t perfect — in fact, it’s garbage and trash — but it works! It’s an early, experimental release with a solid base to build on.

What to expect:
  • A collection of useful icons included by default
  • Basic rendering and layout functionality
  • An old version focused on testing and exploration

What’s coming next?
  • Custom menu modifications
  • Seamless FontAwesome icon rendering (WIP)
  • Improved performance and code quality

Included Icons:
star
heart
globe
file
cutted_star
zoom
checkmark
heart_unfilled
brokenheart
down_arrows
left_arrow
right_arrow
up_arrow
down_arrow
curt_left
curt_right
curt_up
curt_down
message
power
palette
house
pencil
thumbs up
clock
lock_up

Lua Source Code:

code_language.lua:
Expand Collapse Copy
-- WARNING: This code is garbage and trash, but hey, it works!

libraries = {} do
    libraries.list = {
        "gamesense/http",
        "gamesense/base64"
    }

    for _, v in pairs(libraries.list) do
        local lib = require(v) or error("failed to load library: "..v.."!")
        local trimmed = v:match("gamesense/(.+)$")
        if trimmed then
            _G[trimmed] = lib
        else
            _G[lib] = lib
        end
    end
end

local icon_map = {}
local custom_icons = {}
local is_loaded = false
local load_callbacks = {}
local pending_requests = {}
local icon_library = {}

local menu_c = ui.reference("misc", "settings", "menu color")

local function rgba_to_hex(r, g, b, a)
    return string.format("%02X%02X%02X%02X", r, g, b, a or 255)
end

local function safe_eval_lua_code(code)
    local env = {}
    local chunk, err = load(code, "Icons.lua", "t", env)
    if not chunk then return nil, err end
    local ok, result = pcall(chunk)
    if not ok then return nil, result end
    if type(result) == "table" then
        return result
    elseif type(env.Icons) == "table" then
        return env.Icons
    else
        return nil, "No valid icon table returned or defined"
    end
end

local function load_icons()
    http.get("https://raw.githubusercontent.com/antihookuser/Library-Icons/main/Icons.lua", function(success, response)
        if not success then
            client.error_log("[icon_library] Failed to fetch icons - Server maintenance!")
            return
        end
        local icons, err = safe_eval_lua_code(response.body)
        if not icons then
            client.error_log("[icon_library] Failed to parse icon file: " .. tostring(err))
            return
        end
        for name, icon in pairs(icons) do
            icon_map[name:lower()] = icon
        end
        is_loaded = true
        for _, cb in ipairs(load_callbacks) do cb() end
        for _, cb in ipairs(pending_requests) do cb() end
        load_callbacks = {}
        pending_requests = {}
    end)
end

local function render_icon(icon)
    return (icon and icon ~= "") and icon or "?"
end

local function get_icon(item)
    if type(item) ~= "string" then
        client.error_log("[icon_library] Invalid icon name: " .. tostring(item))
        return render_icon("")
    end

    local icon = custom_icons[item:lower()] or icon_map[item:lower()]
    if icon == "" then icon = "❤" end

    if not icon then
        client.error_log("[icon_library] Icon '" .. item .. "' not found.")
    end

    return render_icon(icon or "")
end

icon_library.get_icon = get_icon

function icon_library.add_custom_icon(name, icon)
    if type(name) == "string" and type(icon) == "string" then
        custom_icons[name:lower()] = icon
    end
end

function icon_library.remove_custom_icon(name)
    custom_icons[name:lower()] = nil
end

function icon_library.clear_custom_icons()
    custom_icons = {}
end

function icon_library.reload_icons()
    is_loaded = false
    icon_map = {}
    load_icons()
end

function icon_library.list_icons()
    if not is_loaded then return {} end
    local keys = {}
    for key in pairs(icon_map) do
        table.insert(keys, key)
    end
    return keys
end

function icon_library.has_icon(name)
    return type(name) == "string" and (custom_icons[name:lower()] or icon_map[name:lower()]) ~= nil
end

function icon_library.filter_icons_by_prefix(prefix)
    local results = {}
    if type(prefix) ~= "string" then return results end
    local all = icon_library.get_all_icons()
    for name, icon in pairs(all) do
        if name:sub(1, #prefix):lower() == prefix:lower() then
            results[name] = icon
        end
    end
    return results
end

function icon_library.count()
    local total = 0
    for _ in pairs(icon_map) do total = total + 1 end
    for _ in pairs(custom_icons) do total = total + 1 end
    return total
end

function icon_library.get_all_icons()
    local merged = {}
    for k, v in pairs(icon_map) do merged[k] = v end
    for k, v in pairs(custom_icons) do merged[k] = v end
    return merged
end

function icon_library.on_ready(callback)
    if is_loaded then
        callback()
    else
        table.insert(load_callbacks, callback)
    end
end

function icon_library.get_colored_icon_label(icon_name, text)
    local icon = icon_library.get_icon(icon_name)
    local r, g, b, a = ui.get(menu_c)
    local menu_hex = rgba_to_hex(r, g, b, a)
    return ("\a%s%s \aFFFFFFFF%s"):format(menu_hex, icon, text or "")
end

load_icons()

return icon_library

Example usage:

code_language.lua:
Expand Collapse Copy
local icon_library = require("icon_library")

icon_library.on_ready(function()
    ui.new_label("Config", "Lua", icon_library.get_icon("heart") .. " Icon")
    -- or
    ui.new_label("Config", "Lua", icon_library.get_colored_icon_label("heart", "Heart Label"))
end)

Important:
This release is mainly for those interested in experimenting or learning from the code. Please don’t use it in production without reviewing and improving it.

If you want to contribute or have suggestions, feel free to reach out!

Thanks for checking it out!

Hazey

Contact me!

@hazeybosu
 
Последнее редактирование:
you can just parse
Пожалуйста, авторизуйтесь для просмотра ссылки.
, but its boring time wasting
 
bump, will be updating this source and adding more icons
 
Назад
Сверху Снизу