Fix TypeError: customImages is not iterable
- Fixed updateImageCount() function to handle new customImages data structure
- Added compatibility for both old (array) and new (object) customImages format
- Function now properly handles { task: [], consequence: [] } structure
- Prevents TypeError when toggling image enabled/disabled states
Error was occurring when:
- User clicked checkbox to enable/disable images
- updateImageCount() tried to spread customImages as array
- But customImages was object with task/consequence properties
Fix ensures compatibility with both data formats for smooth migration.
This commit is contained in:
parent
0a7bcc91e9
commit
7597bc8eed
15
game.js
15
game.js
|
|
@ -1705,9 +1705,20 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
|||
|
||||
updateImageCount() {
|
||||
const images = this.getAllImages();
|
||||
const customImages = this.dataManager.get('customImages') || [];
|
||||
const customImages = this.dataManager.get('customImages') || { task: [], consequence: [] };
|
||||
const disabledImages = this.dataManager.get('disabledImages') || [];
|
||||
const allImages = [...images, ...customImages];
|
||||
|
||||
// Handle both old and new customImages format
|
||||
let customImagesArray = [];
|
||||
if (Array.isArray(customImages)) {
|
||||
// Old format - flat array
|
||||
customImagesArray = customImages;
|
||||
} else {
|
||||
// New format - object with task and consequence arrays
|
||||
customImagesArray = [...(customImages.task || []), ...(customImages.consequence || [])];
|
||||
}
|
||||
|
||||
const allImages = [...images, ...customImagesArray];
|
||||
|
||||
const imageCount = document.querySelector('.image-count');
|
||||
if (imageCount) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue