mirror of
https://github.com/isledecomp/isle.pizza.git
synced 2026-05-02 02:33:57 +00:00
Fix save editor showing wrong name for orphaned save slots
Players.gsi could fall out of sync with save files during cloud sync because the saveSlotWritten event only tracked the slot file and History.gsi for incremental upload, not Players.gsi. This caused slots without a matching Players.gsi entry to display the first player's name due to a fallback to index 0. - Track Players.gsi in saveSlotWritten handler for incremental uploads - Remove broken fallback to player index 0 in name resolution - Hide save slots with no Players.gsi entry from the save editor UI
This commit is contained in:
parent
2272835be5
commit
2f222fe42c
@ -100,6 +100,7 @@ export async function initCloudSync() {
|
|||||||
window.addEventListener('opfs-save-slot-written', (e) => {
|
window.addEventListener('opfs-save-slot-written', (e) => {
|
||||||
trackWrite(getSaveFileName(e.detail.slot));
|
trackWrite(getSaveFileName(e.detail.slot));
|
||||||
trackWrite(HISTORY_FILE);
|
trackWrite(HISTORY_FILE);
|
||||||
|
trackWrite(PLAYERS_FILE);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('opfs-save-state-changed', () => {
|
window.addEventListener('opfs-save-state-changed', () => {
|
||||||
|
|||||||
@ -126,14 +126,8 @@ export async function listSaveSlots() {
|
|||||||
// The playerId in the save file corresponds to an index in Players.gsi
|
// The playerId in the save file corresponds to an index in Players.gsi
|
||||||
// Actually, we need to match by looking at order - player names are stored
|
// Actually, we need to match by looking at order - player names are stored
|
||||||
// in order of most recently played, so we just use the index
|
// in order of most recently played, so we just use the index
|
||||||
if (playersCache && playersCache.players.length > 0) {
|
if (playersCache && i < playersCache.players.length && playersCache.players[i]) {
|
||||||
// Find player by matching the slot with Players.gsi order
|
slot.playerName = playersCache.players[i].name;
|
||||||
// For now, just use the first player if available
|
|
||||||
// In reality, we'd need to match by player_id
|
|
||||||
const playerIndex = i < playersCache.players.length ? i : 0;
|
|
||||||
if (playersCache.players[playerIndex]) {
|
|
||||||
slot.playerName = playersCache.players[playerIndex].name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -168,12 +162,8 @@ export async function loadSaveSlot(slotNumber) {
|
|||||||
const players = await loadPlayers();
|
const players = await loadPlayers();
|
||||||
|
|
||||||
let playerName = null;
|
let playerName = null;
|
||||||
if (players && players.players.length > 0) {
|
if (players && slotNumber < players.players.length && players.players[slotNumber]) {
|
||||||
// Use slot index as a simple mapping
|
playerName = players.players[slotNumber].name;
|
||||||
const playerIndex = slotNumber < players.players.length ? slotNumber : 0;
|
|
||||||
if (players.players[playerIndex]) {
|
|
||||||
playerName = players.players[playerIndex].name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -311,7 +311,7 @@
|
|||||||
{ id: Actor.LAURA, name: ActorNames[Actor.LAURA] }
|
{ id: Actor.LAURA, name: ActorNames[Actor.LAURA] }
|
||||||
];
|
];
|
||||||
|
|
||||||
$: existingSlots = slots.filter(s => s.exists);
|
$: existingSlots = slots.filter(s => s.exists && s.playerName);
|
||||||
$: currentSlot = slots.find(s => s.slotNumber === selectedSlot);
|
$: currentSlot = slots.find(s => s.slotNumber === selectedSlot);
|
||||||
|
|
||||||
// Update local state when currentSlot changes
|
// Update local state when currentSlot changes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user