mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-10-19 03:32:41 +00:00
Character Select v1.6.1
This commit is contained in:
parent
49d736d3cb
commit
ce2a0c40c4
8 changed files with 636 additions and 378 deletions
|
@ -1,7 +1,3 @@
|
|||
----------------------
|
||||
-- Global Functions --
|
||||
----------------------
|
||||
|
||||
local saveableCharacters = {
|
||||
["1"] = true,
|
||||
["2"] = true,
|
||||
|
@ -41,6 +37,10 @@ local saveableCharacters = {
|
|||
["z"] = true,
|
||||
["_"] = true,
|
||||
["-"] = true,
|
||||
["."] = true,
|
||||
|
||||
-- Replace with Underscore
|
||||
[" "] = false,
|
||||
}
|
||||
|
||||
function string_underscore_to_space(string)
|
||||
|
@ -62,25 +62,32 @@ function string_space_to_underscore(string)
|
|||
local c = string:sub(i,i)
|
||||
if saveableCharacters[string.lower(c)] then
|
||||
s = s .. c
|
||||
else
|
||||
elseif saveableCharacters[string.lower(c)] ~= nil then
|
||||
s = s .. "_"
|
||||
end
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
function version_coop_dx()
|
||||
if SM64COOPDX_VERSION then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
function string_split(s)
|
||||
local result = {}
|
||||
for match in (s):gmatch(string.format("[^%s]+", " ")) do
|
||||
table.insert(result, match)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
client_is_coop_dx = get_coop_compatibility_enabled ~= nil -- Checks if Client is DX
|
||||
-- network_is_coop_dx = SM64COOPDX_VERSION ~= nil -- Checks if Coop Compatibility is Off (As of now unused)
|
||||
|
||||
ommActive = false
|
||||
for i in pairs(gActiveMods) do
|
||||
local name = gActiveMods[i].name
|
||||
if (name:find("OMM Rebirth")) then
|
||||
ommActive = true
|
||||
end
|
||||
end
|
||||
|
||||
----------------------
|
||||
-- Global Variables --
|
||||
----------------------
|
||||
|
||||
modVersion = "1.5.3"
|
||||
modVersion = "1.6"
|
||||
|
||||
allowMenu = {}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,116 +1,155 @@
|
|||
|
||||
--- @class CharacterTable
|
||||
--- @field public name string
|
||||
--- @field public saveName string
|
||||
--- @field public description table
|
||||
--- @field public credit string
|
||||
--- @field public color Color
|
||||
--- @field public model ModelExtendedId|integer
|
||||
--- @field public forceChar CharacterType
|
||||
--- @field public lifeIcon TextureInfo
|
||||
--- @field public camScale integer
|
||||
|
||||
local characterVoices = {}
|
||||
|
||||
local TEX_UNKNOWN_CHAR = get_texture_info("unknown-icon")
|
||||
local saveNameTable = {}
|
||||
|
||||
local E_MODEL_ARMATURE = smlua_model_util_get_id("armature_geo")
|
||||
|
||||
local table_insert = table.insert
|
||||
local type = type
|
||||
|
||||
local function split_text_into_lines(text)
|
||||
local words = {}
|
||||
for word in text:gmatch("%S+") do
|
||||
table.insert(words, word)
|
||||
end
|
||||
|
||||
local lines = {}
|
||||
local currentLine = ""
|
||||
for i, word in ipairs(words) do
|
||||
local measuredWidth = djui_hud_measure_text(currentLine .. " " .. word)*0.3
|
||||
if measuredWidth <= 100 then
|
||||
currentLine = currentLine .. " " .. word
|
||||
else
|
||||
table.insert(lines, currentLine)
|
||||
currentLine = word
|
||||
end
|
||||
end
|
||||
table.insert(lines, currentLine) -- add the last line
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
---------
|
||||
-- API --
|
||||
---------
|
||||
|
||||
---@param name string|nil Underscores turn into Spaces
|
||||
---@param description table|nil {"string"}
|
||||
---@param description table|string|nil {"string"}
|
||||
---@param credit string|nil
|
||||
---@param color Color|nil {r, g, b}
|
||||
---@param modelInfo ModelExtendedId|table|nil Use smlua_model_util_get_id()
|
||||
---@param modelInfo ModelExtendedId|integer|nil Use smlua_model_util_get_id()
|
||||
---@param forceChar CharacterType|nil CT_MARIO, CT_LUIGI, CT_TOAD, CT_WALUIGI, CT_WARIO
|
||||
---@param lifeIcon TextureInfo|nil Use get_texture_info()
|
||||
---@param camScale integer|nil Zooms the camera based on a multiplier (Default 1.0)
|
||||
---@return integer
|
||||
local character_add = function(name, description, credit, color, modelInfo, forceChar, lifeIcon)
|
||||
local function character_add(name, description, credit, color, modelInfo, forceChar, lifeIcon, camScale)
|
||||
if type(description) == "string" then
|
||||
description = split_text_into_lines(description)
|
||||
end
|
||||
table_insert(characterTable, {
|
||||
name = name and string_space_to_underscore(name) or "Untitled",
|
||||
name = name and name or "Untitled",
|
||||
saveName = name and string_space_to_underscore(name) or "Untitled",
|
||||
description = description and description or {"No description has been provided"},
|
||||
credit = credit and credit or "Unknown",
|
||||
color = color and color or {r = 255, g = 255, b = 255},
|
||||
model = modelInfo and (type(modelInfo) == "table" and modelInfo[1] or modelInfo) or E_MODEL_ARMATURE,
|
||||
capModels = type(modelInfo) == "table" and modelInfo[2] or nil,
|
||||
model = modelInfo and modelInfo or E_MODEL_ARMATURE,
|
||||
forceChar = forceChar and forceChar or CT_MARIO,
|
||||
lifeIcon = lifeIcon and lifeIcon or TEX_UNKNOWN_CHAR,
|
||||
lifeIcon = lifeIcon and lifeIcon or nil,
|
||||
camScale = camScale and camScale or 1
|
||||
})
|
||||
saveNameTable[#characterTable] = characterTable[#characterTable].saveName
|
||||
return #characterTable
|
||||
end
|
||||
|
||||
---@param charNum integer Use _G.charSelect.character_get_number_from_string() or _G.charSelect.character_add()'s return value
|
||||
---@param name string|nil Underscores turn into Spaces
|
||||
---@param description table|nil {"string"}
|
||||
---@param description table|string|nil {"string"}
|
||||
---@param credit string|nil
|
||||
---@param color Color|nil {r, g, b}
|
||||
---@param modelInfo ModelExtendedId|integer|table|nil Use smlua_model_util_get_id()
|
||||
---@param modelInfo ModelExtendedId|integer|nil Use smlua_model_util_get_id()
|
||||
---@param forceChar CharacterType|nil CT_MARIO, CT_LUIGI, CT_TOAD, CT_WALUIGI, CT_WARIO
|
||||
---@param lifeIcon TextureInfo|nil Use get_texture_info()
|
||||
local character_edit = function(charNum, name, description, credit, color, modelInfo, forceChar, lifeIcon)
|
||||
---@param camScale integer|nil Zooms the camera based on a multiplier (Default 1.0)
|
||||
local function character_edit(charNum, name, description, credit, color, modelInfo, forceChar, lifeIcon, camScale)
|
||||
if type(description) == "string" then
|
||||
description = split_text_into_lines(description)
|
||||
end
|
||||
characterTable[charNum] = characterTable[charNum] and {
|
||||
name = name and string_space_to_underscore(name) or characterTable[charNum].name,
|
||||
name = name and name or characterTable[charNum].name,
|
||||
saveName = saveNameTable[charNum],
|
||||
description = description and description or characterTable[charNum].description,
|
||||
credit = credit and credit or characterTable[charNum].credit,
|
||||
color = color and color or characterTable[charNum].color,
|
||||
model = modelInfo and (type(modelInfo) == "table" and modelInfo[1] or modelInfo) or characterTable[charNum].model,
|
||||
capModels = type(modelInfo) == "table" and modelInfo[2] or characterTable[charNum].capModels,
|
||||
model = modelInfo and modelInfo or characterTable[charNum].model,
|
||||
forceChar = forceChar and forceChar or characterTable[charNum].forceChar,
|
||||
lifeIcon = lifeIcon and lifeIcon or characterTable[charNum].lifeIcon,
|
||||
camScale = camScale and camScale or 1
|
||||
} or nil
|
||||
end
|
||||
|
||||
---@param modelInfo ModelExtendedId|integer
|
||||
---@param clips table
|
||||
local character_add_voice = function(modelInfo, clips)
|
||||
local function character_add_voice(modelInfo, clips)
|
||||
characterVoices[modelInfo] = clips
|
||||
end
|
||||
|
||||
---@return table
|
||||
local character_get_current_table = function ()
|
||||
---@param modelInfo ModelExtendedId|integer
|
||||
---@param caps table
|
||||
local function character_add_caps(modelInfo, caps)
|
||||
characterCaps[modelInfo] = caps
|
||||
end
|
||||
|
||||
---@return CharacterTable
|
||||
local function character_get_current_table()
|
||||
return characterTable[currChar]
|
||||
end
|
||||
|
||||
local character_get_current_model_number = function ()
|
||||
local function character_get_current_model_number()
|
||||
return currChar
|
||||
end
|
||||
|
||||
---@param name string
|
||||
local character_get_number_from_string = function (name)
|
||||
local function character_get_number_from_string(name)
|
||||
for i = 2, #characterTable do
|
||||
if characterTable[i].name == name or characterTable[i].name == string_space_to_underscore(name) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
|
||||
---@param m MarioState
|
||||
local character_get_voice = function (m)
|
||||
local function character_get_voice(m)
|
||||
return characterVoices[gPlayerSyncTable[m.playerIndex].modelId]
|
||||
end
|
||||
|
||||
local version_get = function ()
|
||||
local function version_get()
|
||||
return modVersion
|
||||
end
|
||||
|
||||
local is_menu_open = function ()
|
||||
local function is_menu_open()
|
||||
return menuAndTransition
|
||||
end
|
||||
|
||||
local hook_allow_menu_open = function (func)
|
||||
table.insert(allowMenu, func)
|
||||
local function hook_allow_menu_open(func)
|
||||
table_insert(allowMenu, func)
|
||||
end
|
||||
|
||||
local is_options_open = function ()
|
||||
local function is_options_open()
|
||||
return options
|
||||
end
|
||||
|
||||
local optionTableRef = {
|
||||
openInputs = 1,
|
||||
menuColor = 2,
|
||||
anims = 3,
|
||||
inputLatency = 4,
|
||||
localModels = 5,
|
||||
prefToDefault = 6,
|
||||
}
|
||||
|
||||
local controller = {
|
||||
buttonDown = 0,
|
||||
buttonPressed = 0,
|
||||
|
@ -124,7 +163,7 @@ local controller = {
|
|||
}
|
||||
|
||||
---@param tableNum integer
|
||||
local get_status = function (tableNum)
|
||||
local function get_status(tableNum)
|
||||
return optionTable[tableNum].toggle
|
||||
end
|
||||
|
||||
|
@ -133,6 +172,7 @@ _G.charSelect = {
|
|||
character_add = character_add,
|
||||
character_edit = character_edit,
|
||||
character_add_voice = character_add_voice,
|
||||
character_add_caps = character_add_caps,
|
||||
character_get_current_table = character_get_current_table,
|
||||
character_get_current_model_number = character_get_current_model_number,
|
||||
character_get_number_from_string = character_get_number_from_string,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 384 B |
Binary file not shown.
|
@ -79,7 +79,7 @@ end
|
|||
|
||||
--- @param m MarioState
|
||||
local function custom_character_sound(m, characterSound)
|
||||
if is_game_paused() then return end
|
||||
if is_game_paused() or optionTable[optionTableRef.localVoices].toggle == 0 then return end
|
||||
if characterSound == CHAR_SOUND_SNORING3 then return 0 end
|
||||
if characterSound == CHAR_SOUND_HAHA and m.hurtCounter > 0 then return 0 end
|
||||
|
||||
|
@ -96,7 +96,7 @@ local SLEEP_TALK_END = SLEEP_TALK_START + SLEEP_TALK_SNORES
|
|||
|
||||
--- @param m MarioState
|
||||
local function custom_character_snore(m)
|
||||
if is_game_paused() then return end
|
||||
if is_game_paused() or optionTable[optionTableRef.localVoices].toggle == 0 then return end
|
||||
if gCustomVoiceSamplesBackup[m.playerIndex] ~= nil and not (gCustomVoiceSamples[m.playerIndex] == false) then
|
||||
if gCustomVoiceSamples[m.playerIndex].loaded then
|
||||
audio_sample_destroy(gCustomVoiceSamples[m.playerIndex])
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue