Skip to content

Commit a238fb1

Browse files
Fixed #43, #41, #37 and #35
1 parent dfa9810 commit a238fb1

7 files changed

+117
-65
lines changed

js/ColorModule.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const ColorModule = (() => {
101101
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
102102

103103
//set current color
104-
updateCurrentColor(e.target.style.backgroundColor);
104+
updateCurrentColor(Color.cssToHex(e.target.style.backgroundColor));
105105

106106
//make color selected
107107
e.target.parentElement.classList.add('selected');
@@ -136,8 +136,6 @@ const ColorModule = (() => {
136136

137137
//show color picker
138138
addedColor.firstElementChild.jscolor.show();
139-
console.log('showing picker');
140-
141139
//hide edit button
142140
addedColor.lastChild.classList.add('hidden');
143141
}
@@ -427,6 +425,9 @@ const ColorModule = (() => {
427425
}
428426

429427
function updateCurrentColor(color, refLayer) {
428+
if (color[0] != '#')
429+
color = '#' + color;
430+
430431
if (refLayer)
431432
color = refLayer.context.fillStyle;
432433

js/Input.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Input = (() => {
22
let dragging = false;
33
let currentMouseEvent = undefined;
4+
let lastMouseTarget = undefined;
45
let spacePressed = false;
56
let altPressed = false;
67
let ctrlPressed = false;
@@ -19,6 +20,7 @@ const Input = (() => {
1920
Events.on("mouseup", window, onMouseUp);
2021

2122
function onMouseDown(event) {
23+
lastMouseTarget = event.target;
2224
currentMouseEvent = event;
2325
dragging = true;
2426

@@ -154,6 +156,10 @@ const Input = (() => {
154156
case 32:
155157
spacePressed = true;
156158
break;
159+
case 46:
160+
console.log("Pressed del");
161+
Events.emit("del");
162+
break;
157163
}
158164
}
159165
}
@@ -178,12 +184,17 @@ const Input = (() => {
178184
return spacePressed;
179185
}
180186

187+
function getLastTarget() {
188+
return lastMouseTarget;
189+
}
190+
181191
return {
182192
isDragging,
183193
getCurrMouseEvent,
184194
getCursorPosition,
185195
isAltPressed,
186196
isCtrlPressed,
187-
isSpacePressed
197+
isSpacePressed,
198+
getLastTarget
188199
}
189200
})();

js/LayerList.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ const LayerList = (() => {
345345
// Merging all the layer but the last one
346346
for (let i=0; i<visibleLayers.length - 1; i++) {
347347
nToFlatten++;
348-
console.log(visibleLayers[i].menuEntry.nextElementSibling);
348+
349349
new HistoryState().FlattenTwoVisibles(
350350
visibleLayers[i + 1].context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]),
351351
visibleLayers[i].menuEntry.nextElementSibling,
352-
layers.indexOf(visibleLayers[i]),
352+
currFile.layers.indexOf(visibleLayers[i]),
353353
visibleLayers[i], visibleLayers[i + 1]
354354
);
355355

js/layers/Layer.js

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Layer {
5050
if (this.menuEntry !== undefined) {
5151
this.name = this.menuEntry.getElementsByTagName("p")[0].innerHTML;
5252
this.menuEntry.id = "layer" + id;
53+
5354
this.menuEntry.onmouseover = () => this.hover();
5455
this.menuEntry.onmouseout = () => this.unhover();
5556
this.menuEntry.onclick = () => this.selectLayer();
@@ -63,6 +64,8 @@ class Layer {
6364
this.menuEntry.addEventListener("dragleave", this.layerDragLeave, false);
6465
this.menuEntry.addEventListener("dragend", this.layerDragEnd, false);
6566

67+
Events.onCustom("del", this.tryDelete.bind(this));
68+
6669
this.menuEntry.getElementsByTagName("canvas")[0].getContext('2d').imageSmoothingEnabled = false;
6770
}
6871

@@ -73,6 +76,12 @@ class Layer {
7376
return this.menuEntry != null;
7477
}
7578

79+
tryDelete() {
80+
if (Input.getLastTarget() != this.menuEntry && Input.getLastTarget().parentElement != this.menuEntry)
81+
return;
82+
LayerList.deleteLayer();
83+
}
84+
7685
// Initializes the canvas
7786
initialize() {
7887
//resize canvas

js/layers/PixelGrid.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class PixelGrid extends Layer {
33
// Start colour of the pixel grid (can be changed in the preferences)
44
pixelGridColor = "#000000";
55
// Distance between one line and another in HTML pixels
6-
lineDistance = 11;
6+
lineDistance = 10;
77
// The grid is not visible by default
88
pixelGridVisible = false;
99
// The grid is enabled, but is disabled in order to save performance with big sprites
@@ -82,6 +82,8 @@ class PixelGrid extends Layer {
8282

8383
this.context.strokeStyle = Settings.getCurrSettings().pixelGridColour;
8484

85+
console.log("Line ditance: " + this.lineDistance)
86+
8587
// OPTIMIZABLE, could probably be a bit more elegant
8688
// Draw horizontal lines
8789
for (let i=0; i<this.canvas.width / Math.round(this.lineDistance); i++) {

package-lock.json

+48-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json.bak

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "pixel-editor",
3+
"version": "1.0.0",
4+
"description": "Online pixel art creation tool",
5+
"main": "build.js",
6+
"scripts": {
7+
"build": "node ./build.js ./build",
8+
"serve": "node ./server.js ./build 3000",
9+
"test": "npm run build && npm run serve",
10+
"hot": "concurrently \"nodemon --exec npm test\" \"await tcp localhost:3000 && open-cli http://localhost:3000\"",
11+
"hot:reload": "cross-env RELOAD=yes npm run hot"
12+
},
13+
"author": "Lospec",
14+
"license": "ISC",
15+
"nodemonConfig": {
16+
"ext": "js,hbs,scss",
17+
"ignore": "build/"
18+
},
19+
"dependencies": {
20+
"concurrently": "^6.0.2",
21+
"express": "^4.16.4",
22+
"fs-extra": "^7.0.1",
23+
"gulp": "^4.0.2",
24+
"gulp-hb": "^8.0.0",
25+
"gulp-include": "^2.3.1",
26+
"gulp-rename": "^2.0.0",
27+
"gulp-sass": "^7.0",
28+
"handlebars-helper-svg": "^2.0.2",
29+
"nodemon": "^2.0.7",
30+
"open": "^8.0.6",
31+
"open-cli": "^6.0.1",
32+
"sass": "^1.17.3"
33+
},
34+
"devDependencies": {
35+
"cross-env": "7.0.3",
36+
"reload": "^3.2.0",
37+
"wait-cli": "^1.0.0"
38+
}
39+
}

0 commit comments

Comments
 (0)