Fix non-provided name not correctly preferring cur
| @@ -2125,7 +2125,7 @@ export async function showFontAwesomePicker(customList = null) { | |||
| 2125 | * @returns {any?} - The found character or null if not found | 2125 | * @returns {any?} - The found character or null if not found |
| 2126 | */ | 2126 | */ |
| 2127 | export function findChar({ name = null, allowAvatar = true, insensitive = true, filteredByTags = null, preferCurrentChar = true, quiet = false } = {}) { | 2127 | export function findChar({ name = null, allowAvatar = true, insensitive = true, filteredByTags = null, preferCurrentChar = true, quiet = false } = {}) { |
| 2128 | const matches = (char) => (allowAvatar && char.avatar === name) || (insensitive ? equalsIgnoreCaseAndAccents(char.name, name) : char.name === name); | 2128 | const matches = (char) => !name || (allowAvatar && char.avatar === name) || (insensitive ? equalsIgnoreCaseAndAccents(char.name, name) : char.name === name); |
| 2129 | 2129 | ||
| 2130 | // Filter characters by tags if provided | 2130 | // Filter characters by tags if provided |
| 2131 | let filteredCharacters = characters; | 2131 | let filteredCharacters = characters; |
| @@ -2145,8 +2145,8 @@ export function findChar({ name = null, allowAvatar = true, insensitive = true, | |||
| 2145 | if (preferCurrentChar) { | 2145 | if (preferCurrentChar) { |
| 2146 | const preferredCharSearch = currentChars.filter(matches); | 2146 | const preferredCharSearch = currentChars.filter(matches); |
| 2147 | if (preferredCharSearch.length > 1) { | 2147 | if (preferredCharSearch.length > 1) { |
| 2148 | if (!quiet) toastr.warning(`Multiple characters found for name "${name}" and given conditions.`); | 2148 | if (!quiet) toastr.warning('Multiple characters found for given conditions.'); |
| 2149 | else console.warn(`Multiple characters found for name "${name}". Returning the first match.`); | 2149 | else console.warn('Multiple characters found for given conditions. Returning the first match.'); |
| 2150 | } | 2150 | } |
| 2151 | if (preferredCharSearch.length) { | 2151 | if (preferredCharSearch.length) { |
| 2152 | return preferredCharSearch[0]; | 2152 | return preferredCharSearch[0]; |
| @@ -2164,8 +2164,8 @@ export function findChar({ name = null, allowAvatar = true, insensitive = true, | |||
| 2164 | // Search for matching characters by name | 2164 | // Search for matching characters by name |
| 2165 | const matchingCharacters = name ? filteredCharacters.filter(matches) : filteredCharacters; | 2165 | const matchingCharacters = name ? filteredCharacters.filter(matches) : filteredCharacters; |
| 2166 | if (matchingCharacters.length > 1) { | 2166 | if (matchingCharacters.length > 1) { |
| 2167 | if (!quiet) toastr.warning(`Multiple characters found for name "${name}" and given conditions.`); | 2167 | if (!quiet) toastr.warning('Multiple characters found for given conditions.'); |
| 2168 | else console.warn(`Multiple characters found for name "${name}". Returning the first match.`); | 2168 | else console.warn('Multiple characters found for given conditions. Returning the first match.'); |
| 2169 | } | 2169 | } |
| 2170 | 2170 | ||
| 2171 | return matchingCharacters[0] || null; | 2171 | return matchingCharacters[0] || null; |