about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-12-24 20:00:10 -0500
committerelioat <elioat@tilde.institute>2024-12-24 20:00:10 -0500
commit899e28462fd2eb6a0443b06a6519989413b4106a (patch)
tree9c29b6d350d0903721221efcbbf6464686f78a33
parent8d8903405dc8963c71452fa4d834b0731dd4d8b9 (diff)
downloadtour-899e28462fd2eb6a0443b06a6519989413b4106a.tar.gz
*
-rw-r--r--js/pixel-art/pixel/app.js44
1 files changed, 18 insertions, 26 deletions
diff --git a/js/pixel-art/pixel/app.js b/js/pixel-art/pixel/app.js
index 33b1952..569201e 100644
--- a/js/pixel-art/pixel/app.js
+++ b/js/pixel-art/pixel/app.js
@@ -50,12 +50,6 @@ document.getElementById('newCanvasBtn').addEventListener('click', addNewCanvas);
 resizeCanvas();
 loadFromLocalStorage();
 
-function initializeApp() {
-    addNewCanvas();
-    resizeCanvas();
-    loadFromLocalStorage();
-}
-
 function addNewCanvas() {
     canvases.push({
         grid: Array(gridWidth).fill().map(() => Array(gridHeight).fill(null)),
@@ -226,41 +220,39 @@ function loadFromLocalStorage() {
     const savedData = localStorage.getItem('pixelArtConfig');
     if (savedData) {
         const gridData = JSON.parse(savedData);
-        gridWidth = gridData.gridWidth || 10;
-        gridHeight = gridData.gridHeight || 10;
+        gridWidth = gridData.gridWidth || defaultGridWidth;
+        gridHeight = gridData.gridHeight || defaultGridHeight;
         cellSize = gridData.cellSize || 16;
         colorHistory = gridData.colorHistory || [];
         currentColor = gridData.currentColor || '#000000';
-        canvases = gridData.canvases || [{ 
-            grid: Array(gridWidth).fill().map(() => Array(gridHeight).fill(null)),
-            offsetX: 0,
-            offsetY: 0
-        }];
-        
-        // Disable inputs if there are canvases
-        if (canvases.length > 0) {
-            document.getElementById('gridWidth').disabled = true;
-            document.getElementById('gridHeight').disabled = true;
-        }
+        canvases = gridData.canvases || [];
+        globalOffsetX = gridData.globalOffsetX || 0;
+        globalOffsetY = gridData.globalOffsetY || 0;
         
         document.getElementById('gridWidth').value = gridWidth;
         document.getElementById('gridHeight').value = gridHeight;
         document.getElementById('colorPicker').value = currentColor;
-        centerGrid();
-        drawGrid();
+        
         isPaletteVisible = gridData.isPaletteVisible ?? true;
         if (!isPaletteVisible) {
             palette.classList.add('hidden');
             paletteToggle.classList.add('hidden');
             paletteToggle.innerHTML = '🎨';
         }
-        globalOffsetX = gridData.globalOffsetX || 0;
-        globalOffsetY = gridData.globalOffsetY || 0;
     } else {
-        initializeGrid();
-        centerGrid();
-        drawGrid();
+        // No saved data, create default canvas
+        gridWidth = defaultGridWidth;
+        gridHeight = defaultGridHeight;
+        addNewCanvas();
     }
+    
+    // Always ensure there's at least one canvas
+    if (canvases.length === 0) {
+        addNewCanvas();
+    }
+    
+    centerGrid();
+    drawGrid();
 }
 
 function exportToPNG() {