mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-28 23:13:02 +00:00
Make mods strip hex codes when doing sorting
This commit is contained in:
parent
b0e76a699c
commit
b6df4176f4
3 changed files with 57 additions and 33 deletions
|
@ -53,6 +53,39 @@ static u8 read_value(const char* data) {
|
|||
return MIN(strtol(data, NULL, 0), 255);
|
||||
}
|
||||
|
||||
static void player_palettes_sort_characters(void) {
|
||||
struct PresetPalette charPresetPalettes[MAX_PRESET_PALETTES] = { 0 };
|
||||
u8 charPresetPaletteCount = 0;
|
||||
|
||||
// copy character palettes first
|
||||
for (int c = 0; c < CT_MAX; c++) { // heh, c++
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) {
|
||||
charPresetPalettes[charPresetPaletteCount++] = gPresetPalettes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy remaining palettes
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
bool isCharPalette = false;
|
||||
for (int c = 0; c < CT_MAX; c++) { // heh, c++
|
||||
if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) {
|
||||
isCharPalette = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isCharPalette) {
|
||||
charPresetPalettes[charPresetPaletteCount++] = gPresetPalettes[i];
|
||||
}
|
||||
}
|
||||
|
||||
// finally, write to gPresetPalettes
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
gPresetPalettes[i] = charPresetPalettes[i];
|
||||
}
|
||||
}
|
||||
|
||||
void player_palettes_read(const char* palettesPath, bool appendPalettes) {
|
||||
// construct lang path
|
||||
char lpath[SYS_MAX_PATH] = "";
|
||||
|
@ -116,36 +149,7 @@ void player_palettes_read(const char* palettesPath, bool appendPalettes) {
|
|||
|
||||
// this should mean we are in the exe path's palette dir
|
||||
if (appendPalettes) {
|
||||
struct PresetPalette characterPresetPalettes[MAX_PRESET_PALETTES] = { 0 };
|
||||
u8 characterPresetPaletteCount = 0;
|
||||
|
||||
// copy character palettes first
|
||||
for (int c = 0; c < CT_MAX; c++) { // heh, c++
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) {
|
||||
characterPresetPalettes[characterPresetPaletteCount++] = gPresetPalettes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy remaining palettes
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
bool isCharacterPalette = false;
|
||||
for (int c = 0; c < CT_MAX; c++) { // heh, c++
|
||||
if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) {
|
||||
isCharacterPalette = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isCharacterPalette) {
|
||||
characterPresetPalettes[characterPresetPaletteCount++] = gPresetPalettes[i];
|
||||
}
|
||||
}
|
||||
|
||||
// finally, write to gPresetPalettes
|
||||
for (int i = 0; i < gPresetPaletteCount; i++) {
|
||||
gPresetPalettes[i] = characterPresetPalettes[i];
|
||||
}
|
||||
player_palettes_sort_characters();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1750,10 +1750,11 @@ char* remove_color_codes(const char* str) {
|
|||
char* result = strdup(str);
|
||||
char* startColor;
|
||||
while ((startColor = strstr(result, "\\#"))) {
|
||||
char* endColor = strstr(startColor, "\\");
|
||||
char* endColor = strstr(startColor + 2, "\\");
|
||||
if (endColor) {
|
||||
memmove(startColor, endColor + 1, strlen(endColor));
|
||||
memmove(startColor, endColor + 1, strlen(endColor + 1) + 1);
|
||||
} else {
|
||||
*startColor = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,21 @@ void mods_activate(struct Mods* mods) {
|
|||
mod_cache_save();
|
||||
}
|
||||
|
||||
static char* mods_remove_color_codes(const char* str) {
|
||||
char* result = strdup(str);
|
||||
char* startColor;
|
||||
while ((startColor = strstr(result, "\\#"))) {
|
||||
char* endColor = strstr(startColor + 2, "\\");
|
||||
if (endColor) {
|
||||
memmove(startColor, endColor + 1, strlen(endColor + 1) + 1);
|
||||
} else {
|
||||
*startColor = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void mods_sort(struct Mods* mods) {
|
||||
if (mods->entryCount <= 1) {
|
||||
return;
|
||||
|
@ -184,11 +199,15 @@ static void mods_sort(struct Mods* mods) {
|
|||
struct Mod* mod = mods->entries[i];
|
||||
for (s32 j = 0; j < i; ++j) {
|
||||
struct Mod* mod2 = mods->entries[j];
|
||||
if (strcmp(mod->name, mod2->name) < 0) {
|
||||
char* name = mods_remove_color_codes(mod->name);
|
||||
char* name2 = mods_remove_color_codes(mod2->name);
|
||||
if (strcmp(name, name2) < 0) {
|
||||
mods->entries[i] = mod2;
|
||||
mods->entries[j] = mod;
|
||||
mod = mods->entries[i];
|
||||
}
|
||||
free(name);
|
||||
free(name2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue