diff --git a/DiesalTools-2.0/DiesalTools-2.0.lua b/DiesalTools-2.0/DiesalTools-2.0.lua index 6b97eae..4f26f0c 100644 --- a/DiesalTools-2.0/DiesalTools-2.0.lua +++ b/DiesalTools-2.0/DiesalTools-2.0.lua @@ -19,15 +19,15 @@ local CreateFrame, UIParent, GetCursorPosition = CreateFrame, UIParent, GetCurso local GetScreenWidth, GetScreenHeight = GetScreenWidth, GetScreenHeight -- ~~| Locals |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ local escapeSequences = { - ["\a"] = "\\a", -- Bell - ["\b"] = "\\b", -- Backspace - ["\t"] = "\\t", -- Horizontal tab - ["\n"] = "\\n", -- Newline - ["\v"] = "\\v", -- Vertical tab - ["\f"] = "\\f", -- Form feed - ["\r"] = "\\r", -- Carriage return + ["\a"] = "\\a", -- Bell + ["\b"] = "\\b", -- Backspace + ["\t"] = "\\t", -- Horizontal tab + ["\n"] = "\\n", -- Newline + ["\v"] = "\\v", -- Vertical tab + ["\f"] = "\\f", -- Form feed + ["\r"] = "\\r", -- Carriage return ["\\"] = "\\\\", -- Backslash - ['"'] = '\\"', -- Quotation mark + ['"'] = '\\"', -- Quotation mark ["|"] = "||", } local lua_keywords = { @@ -77,20 +77,17 @@ local function GetCaller(level) -- Blizzard Sandbox local match, _, file, line = trace:find("^.*\\(.-):(%d+)") if match then - return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, - colors.orange) + return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, colors.orange) end -- PQI DataFile local match, _, file, line = trace:find('^%[string "[%s%-]*(.-%.lua).-"%]:(%d+)') if match then - return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, - colors.orange) + return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, colors.orange) end -- PQR Ability code local match, _, file, line = trace:find('^%[string "(.-)"%]:(%d+)') if match then - return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, - colors.orange) + return format("%s[%s%s: %s%s%s]|r", colors.orange, colors.yellow, file, colors.lightyellow, line, colors.orange) end end return format("%s[%sUnknown Caller%s]|r", colors.orange, colors.red, colors.orange) @@ -128,8 +125,7 @@ function DiesalTools.GetColor(value) if type(value) == "table" and #value >= 3 then return value[1] / 255, value[2] / 255, value[3] / 255 elseif type(value) == "string" then - return tonumber(sub(value, 1, 2), 16) / 255, tonumber(sub(value, 3, 4), 16) / 255, - tonumber(sub(value, 5, 6), 16) / 255 + return tonumber(sub(value, 1, 2), 16) / 255, tonumber(sub(value, 3, 4), 16) / 255, tonumber(sub(value, 5, 6), 16) / 255 end end @@ -141,8 +137,7 @@ function DiesalTools.Stack() for trace in stack:gmatch("(.-)\n") do local match, _, file, line, func = trace:find("^.*\\(.-):(%d+).-`(.*)'$") if match then - print(format("%s[%s%s: %s%s%s] %sfunction|r %s|r", colors.orange, colors.yellow, file, colors.lightyellow, - line, colors.orange, colors.blue, func)) + print(format("%s[%s%s: %s%s%s] %sfunction|r %s|r", colors.orange, colors.yellow, file, colors.lightyellow, line, colors.orange, colors.blue, func)) end end print("|r--------------------------------------------------------------------------------") @@ -264,11 +259,9 @@ function DiesalTools.TintColor(color, percent, to, from) if to == "rgb255" then return round((255 - r) * percent + r), round((255 - g) * percent + g), round((255 - b) * percent + b) elseif to == "rgb1" then - return round(((255 - r) * percent + r) / 255), round(((255 - g) * percent + g) / 255), - round(((255 - b) * percent + b) / 255) + return round(((255 - r) * percent + r) / 255), round(((255 - g) * percent + g) / 255), round(((255 - b) * percent + b) / 255) elseif to == "hex" then - return format("%02x%02x%02x", round((255 - r) * percent + r), round((255 - g) * percent + g), - round((255 - b) * percent + b)) + return format("%02x%02x%02x", round((255 - r) * percent + r), round((255 - g) * percent + g), round((255 - b) * percent + b)) end -- return format("%02x%02x%02x", round((255-r)*percent+r), round((255-g)*percent+g), round((255-b)*percent+b) ) end @@ -303,11 +296,9 @@ function DiesalTools.MixColors(color1, color2, percent, to, from) if to == "rgb255" then return round((r2 - r1) * percent) + r1, round((g2 - g1) * percent) + g1, round((b2 - b1) * percent) + b1 elseif to == "rgb1" then - return round(((r2 - r1) * percent + r1) / 255), round(((g2 - g1) * percent + g1) / 255), - round(((b2 - b1) * percent + b1) / 255) + return round(((r2 - r1) * percent + r1) / 255), round(((g2 - g1) * percent + g1) / 255), round(((b2 - b1) * percent + b1) / 255) elseif to == "hex" then - return format("%02x%02x%02x", round((r2 - r1) * percent) + r1, round((g2 - g1) * percent) + g1, - round((b2 - b1) * percent) + b1) + return format("%02x%02x%02x", round((r2 - r1) * percent) + r1, round((g2 - g1) * percent) + g1, round((b2 - b1) * percent) + b1) end end @@ -382,8 +373,7 @@ function DiesalTools.GetIconCoords(column, row, size, textureWidth, textureHeigh size = size or 16 textureWidth = textureWidth or 128 textureHeight = textureHeight or 16 - return (column * size - size) / textureWidth, (column * size) / textureWidth, (row * size - size) / textureHeight, - (row * size) / textureHeight + return (column * size - size) / textureWidth, (column * size) / textureWidth, (row * size - size) / textureHeight, (row * size) / textureHeight end -- | String Tools |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -489,8 +479,8 @@ local function impl(t, cat, visited) if k_type ~= "number" -- non-string non-number or k >= next_i - or k < 1 -- integer key in hash part of the table - or k % 1 ~= 0 -- non-integer key + or k < 1 -- integer key in hash part of the table + or k % 1 ~= 0 -- non-integer key then if need_comma then cat(",") @@ -619,3 +609,31 @@ function DiesalTools.Unpack(t) end return unpack(table) end + +---@param zoomPercent number +---@param width number +---@param height number +---@param xOffset? number +---@param yOffset? number +---@return number, number, number, number, number, number, number, number +function DiesalTools.GetTexCoord(zoomPercent, width, height, xOffset, yOffset) + xOffset = xOffset or 0 + yOffset = yOffset or 0 + local textureWidth = 1 - 0.5 * zoomPercent + local aspectRatio = width == 0 or height == 0 and 1 or width / height + ---@type table + local currentCoord = {} + currentCoord[1], currentCoord[2], currentCoord[3], currentCoord[4], currentCoord[5], currentCoord[6], currentCoord[7], currentCoord[8] = 0, 0, 0, 1, 1, 0, 1, 1 + + local xRatio = aspectRatio < 1 and aspectRatio or 1 + local yRatio = aspectRatio > 1 and 1 / aspectRatio or 1 + for i, coord in ipairs(currentCoord) do + if i % 2 == 1 then + currentCoord[i] = (coord - 0.5) * textureWidth * xRatio + 0.5 - xOffset + else + currentCoord[i] = (coord - 0.5) * textureWidth * yRatio + 0.5 - yOffset + end + end + + return unpack(currentCoord) +end