sm64coopdx/mods/character-select-coop/a-utils.lua

125 lines
2.8 KiB
Lua
Raw Normal View History

2024-07-01 00:09:46 +00:00
if VERSION_NUMBER < 37 then
djui_popup_create("\n\\#FFAAAA\\Character Select requires\n CoopDX v1 or higher use!\n\nYou can find CoopDX here:\n\\#6666FF\\https://sm64coopdx.com", 5)
incompatibleClient = true
return 0
end
2024-09-01 17:44:55 +00:00
MOD_VERSION = "1.9.2"
2024-03-09 19:23:25 +00:00
ommActive = false
for i in pairs(gActiveMods) do
if gActiveMods[i].relativePath == "omm-coop" then
ommActive = true
break
end
end
-- localize functions to improve performance
local string_lower,table_insert = string.lower,table.insert
2023-12-16 18:25:28 +00:00
local saveableCharacters = {
["1"] = true,
["2"] = true,
["3"] = true,
["4"] = true,
["5"] = true,
["6"] = true,
["7"] = true,
["8"] = true,
["9"] = true,
["0"] = true,
["a"] = true,
["b"] = true,
["c"] = true,
["d"] = true,
["e"] = true,
["f"] = true,
["g"] = true,
["h"] = true,
["i"] = true,
["j"] = true,
["k"] = true,
["l"] = true,
["m"] = true,
["n"] = true,
["o"] = true,
["p"] = true,
["q"] = true,
["r"] = true,
["s"] = true,
["t"] = true,
["u"] = true,
["v"] = true,
["w"] = true,
["x"] = true,
["y"] = true,
["z"] = true,
["_"] = true,
["-"] = true,
2024-02-20 21:10:45 +00:00
["."] = true,
-- Replace with Underscore
[" "] = false,
2023-12-16 18:25:28 +00:00
}
2024-03-09 19:23:25 +00:00
--- @param string string
--- Replaces underscores in the string with spaces
2023-12-16 18:25:28 +00:00
function string_underscore_to_space(string)
2024-03-09 19:23:25 +00:00
if string == nil then return "" end
return string:gsub("_", " ")
2023-12-16 18:25:28 +00:00
end
2024-03-09 19:23:25 +00:00
--- @param string string
--- Constructs a new string but only with characters from `saveableCharacters`
--- * Spaces are the notable character that gets turned into an underscore
2023-12-16 18:25:28 +00:00
function string_space_to_underscore(string)
local s = ''
for i = 1, #string do
local c = string:sub(i,i)
2024-03-09 19:23:25 +00:00
if saveableCharacters[string_lower(c)] then
2023-12-16 18:25:28 +00:00
s = s .. c
2024-03-09 19:23:25 +00:00
elseif saveableCharacters[string_lower(c)] ~= nil then
2023-12-16 18:25:28 +00:00
s = s .. "_"
end
end
return s
end
2024-03-09 19:23:25 +00:00
--- @param string string
--- Splits a string into a table by spaces
function string_split(string)
2024-02-20 21:10:45 +00:00
local result = {}
2024-03-09 19:23:25 +00:00
for match in string:gmatch(string.format("[^%s]+", " ")) do
table_insert(result, match)
2023-12-18 22:01:33 +00:00
end
2024-02-20 21:10:45 +00:00
return result
2023-12-18 22:01:33 +00:00
end
2024-03-09 19:23:25 +00:00
--- @param param number
--- @param caseTable table
--- Switch statement function
function switch(param, caseTable)
local case = caseTable[param]
if case then return case() end
local def = caseTable['default']
return def and def() or nil
2024-02-20 21:10:45 +00:00
end
2023-12-16 18:25:28 +00:00
allowMenu = {}
2024-03-09 19:23:25 +00:00
2024-07-01 00:09:46 +00:00
renderInMenuTable = {
front = {},
back = {},
}
queueStorageFailsafe = false
charBeingSet = false
stopPalettes = false
for i in pairs(gActiveMods) do
if (gActiveMods[i].incompatible ~= nil and gActiveMods[i].incompatible:find("gamemode")) and not (gActiveMods[i].name:find("Personal Star Counter")) then
2024-07-01 00:09:46 +00:00
stopPalettes = true
end
2024-07-17 19:08:38 +00:00
end