support for custom slot

This commit is contained in:
Der_Floh 2026-06-28 10:28:25 +02:00
parent f1388c5a35
commit 4018fe5498
3 changed files with 21 additions and 13 deletions

View File

@ -153,27 +153,35 @@ bool sky_portal::remove_skylander(u8 sky_num)
return false;
}
u8 sky_portal::load_skylander(u8* buf, fs::file in_file)
u8 sky_portal::load_skylander(u8* buf, fs::file in_file, int requested_slot)
{
std::lock_guard lock(sky_mutex);
const u32 sky_serial = read_from_ptr<le_t<u32>>(buf);
u8 found_slot = 0xFF;
// mimics spot retaining on the portal
for (u8 i = 0; i < 8; i++)
if (requested_slot >= 0 && requested_slot <= 7)
{
if ((skylanders[i].status & 1) == 0)
if ((skylanders[requested_slot].status & 1) == 0)
found_slot = static_cast<u8>(requested_slot);
}
else
{
// mimics spot retaining on the portal
for (u8 i = 0; i < 8; i++)
{
if (skylanders[i].last_id == sky_serial)
if ((skylanders[i].status & 1) == 0)
{
found_slot = i;
break;
}
if (skylanders[i].last_id == sky_serial)
{
found_slot = i;
break;
}
if (i < found_slot)
{
found_slot = i;
if (i < found_slot)
{
found_slot = i;
}
}
}
}

View File

@ -26,7 +26,7 @@ public:
void write_block(u8 sky_num, u8 block, const u8* to_write_buf, u8* reply_buf);
bool remove_skylander(u8 sky_num);
u8 load_skylander(u8* buf, fs::file in_file);
u8 load_skylander(u8* buf, fs::file in_file, int requested_slot = -1);
void get_figure_info(u8 sky_num, u8& out_status, u16& out_id, u16& out_variant);
protected:

View File

@ -39,7 +39,7 @@ static std::string handle_load(int slot, const std::string& path)
if (sky_file.read(buf.data(), buf.size()) != buf.size())
return "error file too small\n";
const u8 result = g_skyportal.load_skylander(buf.data(), std::move(sky_file));
const u8 result = g_skyportal.load_skylander(buf.data(), std::move(sky_file), slot);
if (result == 0xFF)
return "error no free slot\n";