Skip to content

Commit

Permalink
get cup id from file header instead of file name
Browse files Browse the repository at this point in the history
  • Loading branch information
raicool committed Aug 15, 2023
1 parent 62386fc commit c07f14d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
26 changes: 14 additions & 12 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ int app::update()
void app::open_spotpass_file()
{
const char* file_dir = open_file();
uint8_t cup = filename_to_cup(std::filesystem::path(file_dir).filename().string().c_str());

spotpass* new_spotpass = new spotpass();
uint8_t cup = new_spotpass->load(file_dir);

LOG_DEBUG("Cup = {}, file = {}", cup, std::filesystem::path(file_dir).filename().string().c_str());

if (cup >= 0 && cup <= 8)
{
if (spotpass_files[cup]) delete spotpass_files[cup];
spotpass_files[cup] = new spotpass();
spotpass_files[cup]->load(file_dir);
spotpass_files[cup]->cup_id = cup;
if (spotpass_files[cup - 1]) delete spotpass_files[cup - 1];
spotpass_files[cup - 1] = new_spotpass;
}
else
{
Expand All @@ -67,20 +69,20 @@ void app::open_spotpass_folder()
{
auto file_name = file.path().filename();

cup = filename_to_cup(file_name.string().c_str());
spotpass* new_spotpass = new spotpass();
cup = new_spotpass->load(file.path().string().c_str());

LOG_DEBUG("Cup = {}, file = {}", cup, file_name.string().c_str());

if (cup >= 0 && cup <= 8)
if (cup >= 1 && cup <= 8)
{
if (spotpass_files[cup]) delete spotpass_files[cup];
spotpass_files[cup] = new spotpass();
spotpass_files[cup]->load(file.path().string().c_str());
spotpass_files[cup]->cup_id = cup;
if (spotpass_files[cup - 1]) delete spotpass_files[cup - 1];
spotpass_files[cup - 1] = new_spotpass;
}
}
}

app::~app()
{
for (int i = 0; i < 8; i++) delete spotpass_files[i];
for (int i = 0; i < 8; i++) if (spotpass_files[i]) delete spotpass_files[i];
}
2 changes: 1 addition & 1 deletion src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct app
window sdlwindow;
texture texture_manager;

spotpass* spotpass_files[9]{ nullptr }; // 8 file managers for 8 different spotpass cups
spotpass* spotpass_files[8]{ nullptr }; // 8 file managers for 8 different spotpass cups

void open_spotpass_file();
void open_spotpass_folder();
Expand Down
28 changes: 18 additions & 10 deletions src/common/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,42 @@
// stores where each course is inside of cup file
static const uint8_t cup_course_index[] =
{
2, // 0
4, // 1
3, // 2
2, // 3

1, // 4
4, // 5
3, // 6
1, // 7

1, // 8
4, // 9
2, // 10
3, // 11

1, // 12
4, // 13
2, // 14
3, // 15

3, // 16
1, // 17
4, // 18
3, // 19

2, // 0
4, // 1
3, // 2
2, // 3

4, // 20
3, // 21
2, // 22
4, // 23

2, // 24
3, // 25
1, // 26
1, // 27

1, // 28
2, // 29
2, // 30
Expand All @@ -41,11 +49,11 @@ static const uint8_t cup_course_index[] =
// course id for every course in each cup
static const uint8_t cup_courses[8][4] =
{
{ 26, 29, 19, 20 }, // Shell Cup
{ 4, 3, 2, 5 }, // Mushroom Cup
{ 8, 0, 15, 1 }, // Flower Cup
{ 12, 14, 6, 9 }, // Star Cup
{ 7, 10, 11, 13 }, // Special Cup
{ 26, 29, 19, 20 }, // Shell Cup
{ 28, 30, 16, 23 }, // Banana Cup
{ 27, 22, 25, 18 }, // Leaf Cup
{ 17, 24, 21, 31 } // Lightning Cup
Expand Down Expand Up @@ -96,11 +104,11 @@ static const char* course_name[] =

static const char* cup_name[] =
{
"Shell Cup", // 0
"Mushroom Cup", // 1
"Flower Cup", // 2
"Star Cup", // 3
"Special Cup", // 4
"Mushroom Cup", // 0
"Flower Cup", // 1
"Star Cup", // 2
"Special Cup", // 3
"Shell Cup", // 4
"Banana Cup", // 5
"Leaf Cup", // 6
"Lightning Cup" // 7
Expand Down
12 changes: 6 additions & 6 deletions src/core/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void panel::render()

if (ImGui::BeginMenu("Windows"))
{
ImGui::CheckboxFlags("Cups List", &panel_flags, panels::PANEL_CUPS_LIST);
ImGui::CheckboxFlags("Cups List", &panel_flags, panels::PANEL_CUPS_LIST);
ImGui::CheckboxFlags("Ghost List", &panel_flags, panels::PANEL_GHOST_LIST);
ImGui::EndMenu();
}
Expand All @@ -63,7 +63,7 @@ void panel::render()
if (ImGui::BeginTabItem(cup_name[i]))
{
is_cup_selected = true;
cup = i;
cup = app_ptr->spotpass_files[i]->cup_id;

items[0] = (char*)course_name[cup_courses[i][0]];
items[1] = (char*)course_name[cup_courses[i][1]];
Expand All @@ -80,13 +80,13 @@ void panel::render()
static int idx = 0;
if (is_cup_selected)
{
if (ImGui::ListBox("Courses", &idx, items, 4, 4)) course = cup_courses[cup][idx];
if (ImGui::ListBox("Courses", &idx, items, 4, 4)) course = cup_courses[cup - 1][idx];

ImGui::NewLine(); ImGui::Separator(); ImGui::NewLine();

if (ImGui::Button("Add Ghost"))
{
if (app_ptr->spotpass_files[cup]->add_ghost(open_file()) == false)
if (app_ptr->spotpass_files[cup - 1]->add_ghost(open_file()) == false)
{
ImGui::PushID("Load Failed");
ImGui::OpenPopup("Load Failed");
Expand Down Expand Up @@ -121,9 +121,9 @@ void panel::render()

if (ImGui::Begin("Ghost", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDecoration))
{
if (app_ptr->spotpass_files[cup])
if (app_ptr->spotpass_files[cup - 1])
{
spotpass& current_cup = *app_ptr->spotpass_files[cup];
spotpass& current_cup = *app_ptr->spotpass_files[cup - 1];

ImGui::Spacing();

Expand Down
4 changes: 3 additions & 1 deletion src/file/spotpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uint8_t spotpass::load(const char* dir)
{
uint32_t offset = 0;
uint32_t u32buffer = 0;
uint8_t buffer = 0;
uint8_t buffer = 0;

file_directory = dir;

Expand All @@ -35,6 +35,8 @@ uint8_t spotpass::load(const char* dir)
ghosts.reserve(80);
ghost_count = 0;

bin_read<uint8_t>(&cup_id, spotpass_data, 0x2f);

for (int i = 0; i < 80; i++)
{
// each ghost inside of a spotpass file have a padding size of 0x2898
Expand Down

0 comments on commit c07f14d

Please sign in to comment.