diff --git a/README.md b/README.md
index 7ca320e..9920ac8 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,11 @@ The next version is mostly focused on adding missing essential features and port
Suggestions / Planned features:
-- Save project while keeping layer data
- Line tool
- Resize canvas
- Snap brush preview to pixel grid
- Move selection with arrows
+- Load palette from LPE file
- Custom color picker
- custom code without dependencies
@@ -36,7 +36,7 @@ Suggestions / Planned features:
- Another currentLayer.canvas
- Must be rescaled each zoom
-- Possibly add collaborate function using together.js
+- Possibly add collaborate function
- Bug fix
- Alt + scroll broken
diff --git a/js/_addColor.js b/js/_addColor.js
index 54f3534..d8e5b62 100644
--- a/js/_addColor.js
+++ b/js/_addColor.js
@@ -1,3 +1,5 @@
+let currentPalette = [];
+
//adds the given color to the palette
//input hex color string
//returns list item element
@@ -6,7 +8,7 @@ function addColor (newColor) {
//add # at beginning if not present
if (newColor.charAt(0) != '#')
newColor = '#' + newColor;
-
+ currentPalette.push(newColor);
//create list item
var listItem = document.createElement('li');
@@ -45,5 +47,7 @@ function addColor (newColor) {
button.parentElement.firstChild.jscolor.show();
});
+ console.log(currentPalette);
+
return listItem;
}
diff --git a/js/_colorChanged.js b/js/_colorChanged.js
index 5d8f390..c7df0ba 100644
--- a/js/_colorChanged.js
+++ b/js/_colorChanged.js
@@ -28,10 +28,11 @@ function colorChanged(e) {
var newColor = hexToRgb(e.target.value);
var oldColor = e.target.oldColor;
+ currentPalette.splice(currentPalette.indexOf("#" + newColor), 1);
+
newColor.a = 255;
//save undo state
- //saveHistoryState({type: 'colorchange', newColor: e.target.value, oldColor: rgbToHex(oldColor), canvas: context.getImageData(0, 0, canvasSize[0], canvasSize[1])});
new HistoryStateEditColor(e.target.value.toLowerCase(), rgbToHex(oldColor));
//get the currently selected color
@@ -82,7 +83,7 @@ function colorChanged(e) {
//set new old color to changed color
e.target.oldColor = newColor;
-
+ currentPalette.push('#' + newColorHex);
//if this is the current color, update the drawing color
if (e.target.colorElement.parentElement.classList.contains('selected')) {
diff --git a/js/_createColorPalette.js b/js/_createColorPalette.js
index 19e14ac..48cb71c 100644
--- a/js/_createColorPalette.js
+++ b/js/_createColorPalette.js
@@ -34,12 +34,6 @@ function createColorPalette(selectedPalette, fillBackground) {
}
- //fill bg with lightest color
- if (fillBackground) {
- currentLayer.context.fillStyle = lightestColor;
- currentLayer.context.fillRect(0, 0, canvasSize[0], canvasSize[1]);
- }
-
//set as current color
currentLayer.context.fillStyle = darkestColor;
}
diff --git a/js/_fileMenu.js b/js/_fileMenu.js
index 3183ff4..cfcb4f0 100644
--- a/js/_fileMenu.js
+++ b/js/_fileMenu.js
@@ -33,6 +33,29 @@ for (var i = 1; i < mainMenuItems.length; i++) {
//File Menu
case 'New':
showDialogue('new-pixel');
+ break;
+ case 'Save project':
+ //create name
+ var selectedPalette = getText('palette-button');
+ if (selectedPalette != 'Choose a palette...'){
+ var paletteAbbreviation = palettes[selectedPalette].abbreviation;
+ var fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]+'.lpe';
+ } else {
+ var fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.lpe';
+ selectedPalette = 'none';
+ }
+
+ //set download link
+ var linkHolder = document.getElementById('save-project-link-holder');
+ // create file content
+ var content = getProjectData();
+
+ linkHolder.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(content);
+ linkHolder.download = fileName;
+ linkHolder.click();
+
+ ga('send', 'event', 'Pixel Editor Save', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/
+
break;
case 'Open':
//if a document exists
@@ -48,9 +71,8 @@ for (var i = 1; i < mainMenuItems.length; i++) {
break;
- case 'Save as...':
+ case 'Export':
if (documentCreated) {
-
//create name
var selectedPalette = getText('palette-button');
if (selectedPalette != 'Choose a palette...'){
@@ -66,7 +88,7 @@ for (var i = 1; i < mainMenuItems.length; i++) {
// Creating a tmp canvas to flatten everything
var exportCanvas = document.createElement("canvas");
var emptyCanvas = document.createElement("canvas");
- var layersCopy = layers.slice();;
+ var layersCopy = layers.slice();
exportCanvas.width = canvasSize[0];
exportCanvas.height = canvasSize[1];
@@ -75,7 +97,7 @@ for (var i = 1; i < mainMenuItems.length; i++) {
emptyCanvas.height = canvasSize[1];
// Sorting the layers by z index
- layersCopy.sort((a, b) => (a.canvas.zIndex > b.canvas.zIndex) ? 1 : -1);
+ layersCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1);
// Merging every layer on the export canvas
for (let i=0; i Layer 0
-
+
-
+
@@ -149,8 +150,7 @@
-
Layer 0