Skip to content

Commit f499662

Browse files
committed
Various changes
- added `/:paletteSlug/:resolution` functionality for localhost testing - created `currFile.sublayers` for *things that should zoom with the canvas layers* - `currFile.layers` now solely contains the canvas layers - added `getProjectData` to `FileManager`'s exported methods --- - added `FileManager.localStorageSave` (it's basically just: localStorage.setItem("lpe-cache",FileManager.getProjectData())) - added `FileManager.localStorageCheck` (it's basically just: `!!localStorage.getItem("lpe-cache")`) - added `FileManager.localStorageLoad` (it's basically just: `return localStorage.getItem("lpe-cache")`) - added `FileManager.localStorageReset` (for debugging purity) --- - calling `FileManager.localStorageSave()` on mouse up (we should stress test this) --- - changed lpe file format to `{canvasWidth:number,canvasHeight:number,selectedLayer:number,colors:[],layers:[]}` - added backward compatibility for the old lpe file format --- - added some canvas utility functions in `canvas_util` - added Unsettled's color similarity utility functions in `color_util2` --- - html boilerplate - wang tiles - - POC - tiny text boilerplate - POC - tiny text font scraper --- - WIP - added two optional url route parameters `/:paletteSlug/:resolution/:prefillWidth/:prefillBinaryStr` - WIP POC - hbs_parser.js (outputs tree data about hbs file relationships)
1 parent 4029985 commit f499662

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2391
-393
lines changed

css/_canvas.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
height: 400px;
2525
position: fixed;
2626
display: none;
27-
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.64);
2827
background-color: transparent;
2928
}
3029

3130
#checkerboard {
3231
z-index: 1;
32+
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.64);
3333
}
3434

3535
#pixel-canvas {

hbs_parser.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const HANDLEBARS = require('handlebars');
4+
const sass = require('sass');
5+
6+
const result = sass.compile('./css/pixel-editor.scss');
7+
fs.writeFileSync("./css/pixel-editor.css",result.css);
8+
9+
// fs.readFile('/css/pixel-editor.scss', function(err, scssFile) {
10+
// compiler.compile(scssFile.toString(), function(err, css) {
11+
// });
12+
// });
13+
14+
const hbsArr = [
15+
...fs.readdirSync("./views/").filter(n=>n.slice(-3)==="hbs").map(n=>"./views/" + n),
16+
...fs.readdirSync("./views/components/").filter(n=>n.slice(-3)==="hbs").map(n=>"./views/components/" + n),
17+
...fs.readdirSync("./views/logs/").filter(n=>n.slice(-3)==="hbs").map(n=>"./views/logs/" + n),
18+
...fs.readdirSync("./views/popups/").filter(n=>n.slice(-3)==="hbs").map(n=>"./views/popups/" + n),
19+
];
20+
const HBS_STR_MAP = {};
21+
const HBS_SPEC_MAP = {};
22+
const HBS_TEMPLATE_MAP = {};
23+
const HBS_META_DATA = hbsArr.reduce((r,filePath,i)=>{
24+
25+
const fileStr = fs.readFileSync(filePath,"utf8");
26+
const sp0 = fileStr.split("{{> ").slice(1);
27+
const partialArr = sp0.map(n=>n.split("}}")[0]);
28+
const sp1 = fileStr.split("{{").slice(1);
29+
30+
if(sp0.length || sp1.length) {
31+
const dblCurlsArr = sp1.map(n=>n.split("}}")[0]);
32+
33+
HBS_STR_MAP[filePath] = fileStr;
34+
35+
HBS_SPEC_MAP[filePath] = HANDLEBARS.precompile(fileStr);
36+
// HBS_TEMPLATE_MAP[filePath] = HANDLEBARS.template(HBS_SPEC_MAP[filePath]);
37+
38+
r[filePath] = {
39+
fileStr,
40+
filePath,
41+
dblCurlsArr,
42+
partialArr
43+
};
44+
}
45+
46+
return r;
47+
},{});
48+
49+
fs.writeFileSync(
50+
"./js/HBS_META_DATA.js",
51+
"const HBS_META_DATA = " + JSON.stringify(HBS_META_DATA,null,4)
52+
);

images/icons_14x14.png

1.92 KB
Loading

images/le_button_18x19.png

301 Bytes
Loading

images/lospec_mock1.png

48 KB
Loading

images/lospec_mock2.png

9.56 KB
Loading

images/rotate_test_8x8_x16.png

859 Bytes
Loading

images/sked_tree_32x32.png

872 Bytes
Loading

images/sked_x1.png

23 KB
Loading

images/sked_x10.png

89.1 KB
Loading

images/test_8x8.png

149 Bytes
Loading

images/wang_tilesets_32x32.png

1.98 KB
Loading

js/Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Color {
3030
this.hsv = Color.rgbToHsv(this.rgb);
3131
break;
3232
default:
33-
console.error("Unsupported color mode " + fmt);
33+
//console.error("Unsupported color mode " + fmt);
3434
break;
3535
}
3636
}

js/ColorModule.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ColorModule = (() => {
5757
if (newColorHex == colors[i].jscolor.toString()) {
5858
//if the color isnt the one that has the picker currently open
5959
if (!colors[i].parentElement.classList.contains('jscolor-active')) {
60-
//console.log('%cColor is duplicate', colorCheckingStyle);
60+
//////console.log('%cColor is duplicate', colorCheckingStyle);
6161

6262
//show the duplicate color warning
6363
duplicateColorWarning.style.visibility = 'visible';
@@ -251,7 +251,7 @@ const ColorModule = (() => {
251251

252252
//loop through colors
253253
for (var i = 0; i < colors.length; i++) {
254-
//console.log(color,'=',colors[i].jscolor.toString());
254+
//////console.log(color,'=',colors[i].jscolor.toString());
255255

256256
if (color == colors[i].jscolor.toString()) {
257257
//set color to the color button
@@ -346,7 +346,7 @@ const ColorModule = (() => {
346346
* @param {*} paletteColors The colours of the palette
347347
*/
348348
function createColorPalette(paletteColors) {
349-
console.log("creating palette");
349+
////console.log("creating palette");
350350
//remove current palette
351351
while (colorsMenu.childElementCount > 1)
352352
colorsMenu.children[0].remove();
@@ -358,7 +358,7 @@ const ColorModule = (() => {
358358
for (var i = 0; i < paletteColors.length; i++) {
359359
var newColor = new Color("hex", paletteColors[i]);
360360
var newColorElement = ColorModule.addColor(newColor.hex);
361-
361+
////console.log('newColor.hex === ',newColor.hex);
362362
var newColRgb = newColor.rgb;
363363

364364
var lightestColorRgb = lightestColor.rgb;
@@ -382,6 +382,8 @@ const ColorModule = (() => {
382382

383383
//set as current color
384384
updateCurrentColor(darkestColor.hex);
385+
386+
////console.log('getCurrentPalette() === ',getCurrentPalette());
385387
}
386388

387389
/** Creates the palette with the colours used in all the layers
@@ -421,7 +423,7 @@ const ColorModule = (() => {
421423
//create palette from colors array
422424
createColorPalette(colorPaletteArray);
423425

424-
console.log("Done 2");
426+
////console.log("Done 2");
425427
}
426428

427429
function updateCurrentColor(color, refLayer) {

js/ColorPicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ const ColorPicker = (() => {
696696
}
697697
break;
698698
default:
699-
console.log("How did you select the " + currentPickingMode + ", hackerman?");
699+
////console.log("How did you select the " + currentPickingMode + ", hackerman?");
700700
break;
701701
}
702702

js/Dialogue.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Dialogue = (() => {
55
let currentOpenDialogue = "";
66
let dialogueOpen = true;
77

8-
const popUpContainer = document.getElementById("pop-up-container");
8+
const popUpContainer = document.getElementById("pop-up-container") ?? document.createElement("div");
99
const cancelButtons = popUpContainer.getElementsByClassName('close-button');
1010

1111
Events.onCustom("esc-pressed", closeDialogue);
@@ -31,6 +31,9 @@ const Dialogue = (() => {
3131
* @param {*} trackEvent Should I track the GA event?
3232
*/
3333
function showDialogue (dialogueName, trackEvent) {
34+
35+
36+
3437
if (typeof trackEvent === 'undefined') trackEvent = true;
3538

3639
// Updating currently open dialogue
@@ -83,4 +86,4 @@ const Dialogue = (() => {
8386
}
8487
})();
8588

86-
console.log("Dialog: " + Dialogue);
89+
////console.log("Dialog: " + Dialogue);

js/EditorState.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ const EditorState = (() => {
99
return pixelEditorMode;
1010
}
1111

12-
function switchMode(newMode) {
13-
if (!firstFile && newMode == "Basic" && !confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
12+
function switchMode(newMode, skipConfirm = false) {
13+
////console.trace();
14+
const switchText = 'Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?';
15+
if (!firstFile && newMode == "Basic" && !skipConfirm && !confirm(switchText)) {
1416
return;
1517
}
1618
//switch to advanced mode

js/Events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ const Events = (() => {
100100
*/
101101
function on(event, elementId, functionCallback, ...args) {
102102
//if element provided is string, get the actual element
103+
if(!elementId)return;
103104
const element = Util.getElement(elementId);
104-
105+
if(!element)return;
105106
element.addEventListener(event,
106107
function (e) {
107108
functionCallback(...args, e);

js/File.js

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ class File {
22
// Canvas, canvas state
33
canvasSize = [];
44
zoom = 7;
5-
canvasView = document.getElementById("canvas-view");
5+
canvasView = document.getElementById("canvas-view") ?? document.createElement("canvas");
66
inited = false;
77

88
// Layers
99
layers = [];
10+
sublayers = [];
1011
currentLayer = undefined;
1112
VFXLayer = undefined;
1213
TMPLayer = undefined;
@@ -129,11 +130,9 @@ class File {
129130

130131
// Save all imageDatas
131132
for (let i=0; i<currFile.layers.length; i++) {
132-
if (currFile.layers[i].hasCanvas()) {
133-
imageDatas.push(currFile.layers[i].context.getImageData(
134-
0, 0, currFile.canvasSize[0], currFile.canvasSize[1])
135-
);
136-
}
133+
imageDatas.push(currFile.layers[i].context.getImageData(
134+
0, 0, currFile.canvasSize[0], currFile.canvasSize[1])
135+
);
137136
}
138137

139138
// Saving the history only if I'm not already undoing or redoing
@@ -154,16 +153,20 @@ class File {
154153
currFile.canvasSize[1] = parseInt(currFile.canvasSize[1]) +
155154
this.rcBorders.top + this.rcBorders.bottom;
156155

157-
console.trace();
158-
console.log(currFile.canvasSize);
156+
////console.trace();
157+
////console.log(currFile.canvasSize);
159158

160159
// Resize the canvases
161160
for (let i=0; i<currFile.layers.length; i++) {
162161
currFile.layers[i].canvas.width = currFile.canvasSize[0];
163162
currFile.layers[i].canvas.height = currFile.canvasSize[1];
164-
165163
currFile.layers[i].resize();
166164
}
165+
for (let i=0; i<currFile.sublayers.length; i++) {
166+
currFile.sublayers[i].canvas.width = currFile.canvasSize[0];
167+
currFile.sublayers[i].canvas.height = currFile.canvasSize[1];
168+
currFile.sublayers[i].resize();
169+
}
167170

168171
// Regenerate the checkerboard
169172
currFile.checkerBoard.fillCheckerboard();
@@ -213,16 +216,14 @@ class File {
213216

214217
// Putting all the data for each layer with the right offsets (decided by the pivot)
215218
for (let i=0; i<currFile.layers.length; i++) {
216-
if (currFile.layers[i].hasCanvas()) {
217-
if (customData == undefined) {
218-
currFile.layers[i].context.putImageData(imageDatas[copiedDataIndex], leftOffset, topOffset);
219-
}
220-
else {
221-
currFile.layers[i].context.putImageData(customData[copiedDataIndex], 0, 0);
222-
}
223-
currFile.layers[i].updateLayerPreview();
224-
copiedDataIndex++;
219+
if (customData == undefined) {
220+
currFile.layers[i].context.putImageData(imageDatas[copiedDataIndex], leftOffset, topOffset);
221+
}
222+
else {
223+
currFile.layers[i].context.putImageData(customData[copiedDataIndex], 0, 0);
225224
}
225+
currFile.layers[i].updateLayerPreview();
226+
copiedDataIndex++;
226227
}
227228

228229
Dialogue.closeDialogue();
@@ -246,7 +247,7 @@ class File {
246247
this.rcPivot = "topleft";
247248

248249
// Computing the min and max coordinates in which there's a non empty pixel
249-
for (let i=1; i<currFile.layers.length - nAppLayers; i++) {
250+
for (let i=0; i<currFile.layers.length; i++) {
250251
let imageData = currFile.layers[i].context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
251252
let pixelPosition;
252253

@@ -291,12 +292,10 @@ class File {
291292

292293
// Saving the data
293294
for (let i=0; i<currFile.layers.length; i++) {
294-
if (currFile.layers[i].hasCanvas()) {
295-
imageDatas.push(currFile.layers[i].context.getImageData(minX - 1, currFile.layers[i].canvasSize[1] - maxY, maxX-minX + 1, maxY-minY + 1));
296-
}
295+
imageDatas.push(currFile.layers[i].context.getImageData(minX - 1, currFile.layers[i].canvasSize[1] - maxY, maxX-minX + 1, maxY-minY + 1));
297296
}
298297

299-
//console.log("sx: " + borders.left + "dx: " + borders.right + "top: " + borders.top + "btm: " + borders.bottom);
298+
//////console.log("sx: " + borders.left + "dx: " + borders.right + "top: " + borders.top + "btm: " + borders.bottom);
300299

301300
document.getElementById("rc-border-left").value = this.rcBorders.left;
302301
document.getElementById("rc-border-right").value = this.rcBorders.right;
@@ -430,11 +429,9 @@ class File {
430429

431430
// Get all the image datas
432431
for (let i=0; i<currFile.layers.length; i++) {
433-
if (currFile.layers[i].hasCanvas()) {
434-
rsImageDatas.push(currFile.layers[i].context.getImageData(
435-
0, 0, currFile.canvasSize[0], currFile.canvasSize[1])
436-
);
437-
}
432+
rsImageDatas.push(currFile.layers[i].context.getImageData(
433+
0, 0, currFile.canvasSize[0], currFile.canvasSize[1])
434+
);
438435
}
439436

440437
// event is null when the user is undoing
@@ -450,13 +447,11 @@ class File {
450447

451448
// Put the image datas on the new canvases
452449
for (let i=0; i<currFile.layers.length; i++) {
453-
if (currFile.layers[i].hasCanvas()) {
454-
currFile.layers[i].context.putImageData(
455-
this.resizeImageData(rsImageDatas[layerIndex], newWidth, newHeight, this.currentAlgo), 0, 0
456-
);
457-
currFile.layers[i].updateLayerPreview();
458-
layerIndex++;
459-
}
450+
currFile.layers[i].context.putImageData(
451+
this.resizeImageData(rsImageDatas[layerIndex], newWidth, newHeight, this.currentAlgo), 0, 0
452+
);
453+
currFile.layers[i].updateLayerPreview();
454+
layerIndex++;
460455
}
461456

462457
// Updating start values when I finish scaling the sprite

0 commit comments

Comments
 (0)