Skip to content

Commit 1f820fd

Browse files
committed
ported to static site, removed _ext folder, split hbs files into partials
1 parent 1e3549b commit 1f820fd

Some content is hidden

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

86 files changed

+1212
-986
lines changed

build.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const fs = require('fs');
22
const path = require('path');
33
const gulp = require('gulp');
44
const include = require('gulp-include');
5-
const hb = require('gulp-hb');
5+
const handlebars = require('gulp-hb');
66
const sass = require('gulp-sass');
77
const rename = require('gulp-rename');
88

9-
const hb_svg = require('handlebars-helper-svg');
9+
//const hb_svg = require('handlebars-helper-svg');
1010

1111
const BUILDDIR = process.argv[2] || './build/';
1212

@@ -30,7 +30,6 @@ function copy_logs() {
3030
function render_js(){
3131
gulp.src('./js/*.js')
3232
.pipe(include({includePaths: [
33-
'_ext/scripts',
3433
'js',
3534
'!js/_*.js',
3635
]}))
@@ -41,16 +40,18 @@ function render_js(){
4140

4241
function render_css(){
4342
gulp.src('css/*.scss')
44-
.pipe(sass({includePaths: ['css', '_ext/sass', '_ext/modules/css']}))
43+
.pipe(sass({includePaths: ['css']}))
4544
.pipe(gulp.dest(BUILDDIR));
4645
}
4746

4847
function compile_page(){
4948
gulp.src(path.join('./views/index.hbs'))
50-
.pipe(hb({encoding: 'utf8'})
51-
.partials('./_ext/modules/_*.hbs')
52-
.helpers({ svg: hb_svg })
53-
.helpers('./_ext/modules/hbs/helpers/**/*.js')
49+
.pipe(include({includePaths: ['/svg']}))
50+
51+
.pipe(handlebars({encoding: 'utf8', debug: true, bustCache: true})
52+
.partials('./views/[!index]*.hbs')
53+
//.helpers({ svg: hb_svg })
54+
.helpers('./helpers/**/*.js')
5455
.data({
5556
projectSlug: 'pixel-editor',
5657
title: 'Lospec Pixel Editor',
File renamed without changes.

css/pixel-editor.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ svg {
296296
}
297297

298298
.drawingCanvas {
299-
cursor: url('/pixel-art-where-to-start/pencil-tool-cursor.png');
299+
cursor: url('/pixel-editor/pencil-tool-cursor.png');
300300

301301
border: solid 1px #fff;
302302
image-rendering: optimizeSpeed;

helpers/svg.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const fs = require("fs");
2+
const handlebars = require("handlebars");
3+
const ltx = require("ltx");
4+
const resolve = require("resolve");
5+
6+
const path = "../svg/";
7+
const nameToModule = {};
8+
const cache = {};
9+
10+
module.exports = function (name, opts) {
11+
name = path + name;
12+
13+
const mod =
14+
nameToModule[name] ||
15+
(nameToModule[name] = resolve.sync(name, {
16+
extensions: [".svg"],
17+
}));
18+
19+
const content =
20+
cache[name] || (cache[name] = fs.readFileSync(mod, "utf-8"));
21+
22+
const svg = parse(content);
23+
24+
Object.assign(svg.attrs, opts.hash);
25+
26+
return new handlebars.SafeString(svg.root().toString());
27+
};
28+
29+
module.exports.cache = cache;
30+
31+
function parse(xml, mod) {
32+
const svg = ltx.parse(xml);
33+
if (svg.name != "svg") {
34+
throw new TypeError("Input must be an SVG");
35+
}
36+
37+
delete svg.attrs.xmlns;
38+
delete svg.attrs["xmlns:xlink"];
39+
40+
return svg;
41+
}

js/_logs.js

-15
This file was deleted.

js/_newPixel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function newPixel (width, height, editorMode, fileContent = null) {
103103

104104
// If the user selected a palette and isn't opening a file, I load the selected palette
105105
if (selectedPalette != 'Choose a palette...' && fileContent == null) {
106-
106+
console.log('HELO', selectedPalette, palettes[selectedPalette])
107107
//if this palette isnt the one specified in the url, then reset the url
108108
if (!palettes[selectedPalette].specified)
109109
history.pushState(null, null, '/pixel-editor');

js/_onLoad.js

+59-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
1+
2+
3+
4+
15
//when the page is done loading, you can get ready to start
26
window.onload = function () {
37

48
featureToggles.onLoad();
59

610
currentTool.updateCursor();
11+
12+
//check if there are any url parameters
13+
if (window.location.pathname.replace('/pixel-editor/','').length <= 1) {
14+
console.log('no url parameters were found');
15+
16+
//show splash screen
17+
showDialogue('splash', false);
18+
}
19+
20+
//url parameters were specified
21+
else {
22+
console.log('loading preset from url parameters', window.location.pathname);
23+
24+
let args = window.location.pathname.split('/');
25+
let paletteSlug = args[2];
26+
let dimentions = args[3];
27+
28+
//fetch palette via lospec palette API
29+
fetch('https://lospec.com/palette-list/'+paletteSlug+'.json')
30+
.then(response => response.json())
31+
.then(data => {
32+
//palette loaded successfully
33+
console.log('loaded palette', data);
34+
palettes[paletteSlug] = data;
35+
palettes[paletteSlug].specified = true;
36+
37+
//refresh list of palettes
38+
document.getElementById('palette-menu-splash').refresh();
739

8-
//if the user specified dimensions
9-
if (specifiedDimentions) {
10-
//create a new pixel
11-
newPixel(getValue('size-width'), getValue('size-height'), getValue('editor-mode'));
12-
} else {
13-
//otherwise show the new pixel dialog
14-
showDialogue('splash', false);
15-
}
40+
//if the dimentions were specified
41+
if (dimentions && dimentions.length >= 3 && dimentions.includes('x')) {
42+
let width = dimentions.split('x')[0];
43+
let height = dimentions.split('x')[1];
44+
45+
console.log('dimentions were specified',width,'x',height)
46+
47+
//firstPixel = false;
1648

49+
//create new document
50+
newPixel(width, height, getValue('editor-mode'));
51+
}
52+
53+
//dimentions were not specified -- show splash screen with palette preselected
54+
else {
55+
//show splash
56+
showDialogue('new-pixel', false);
57+
}
58+
59+
})
60+
//error fetching url (either palette doesn't exist, or lospec is down)
61+
.catch((error) => {
62+
console.warn('failed to load palette "'+paletteSlug+'"', error);
63+
64+
//proceed to splash screen
65+
showDialogue('splash', false);
66+
});
67+
}
1768
};

js/_palettes.js

+100-37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
2+
palettes = {
3+
"Endesga 32": {
4+
colors: "be4a2f,d77643,ead4aa,e4a672,b86f50,733e39,3e2731,a22633,e43b44,f77622,feae34,fee761,63c74d,3e8948,265c42,193c3e,124e89,0099db,2ce8f5,ffffff,c0cbdc,8b9bb4,5a6988,3a4466,262b44,181425,ff0044,68386c,b55088,f6757a,e8b796,c28569".split(
5+
","
6+
),
7+
},
8+
9+
"Resurrect 64": {
10+
colors: "2e222f,3e3546,625565,966c6c,ab947a,694f62,7f708a,9babb2,c7dcd0,ffffff,6e2727,b33831,ea4f36,f57d4a,ae2334,e83b3b,fb6b1d,f79617,f9c22b,7a3045,9e4539,cd683d,e6904e,fbb954,4c3e24,676633,a2a947,d5e04b,fbff86,165a4c,239063,1ebc73,91db69,cddf6c,313638,374e4a,547e64,92a984,b2ba90,0b5e65,0b8a8f,0eaf9b,30e1b9,8ff8e2,323353,484a77,4d65b4,4d9be6,8fd3ff,45293f,6b3e75,905ea9,a884f3,eaaded,753c54,a24b6f,cf657f,ed8099,831c5d,c32454,f04f78,f68181,fca790,fdcbb0".split(
11+
","
12+
),
13+
},
14+
15+
"AAP-64": {
16+
colors: "060608,141013,3b1725,73172d,b4202a,df3e23,fa6a0a,f9a31b,ffd541,fffc40,d6f264,9cdb43,59c135,14a02e,1a7a3e,24523b,122020,143464,285cc4,249fde,20d6c7,a6fcdb,ffffff,fef3c0,fad6b8,f5a097,e86a73,bc4a9b,793a80,403353,242234,221c1a,322b28,71413b,bb7547,dba463,f4d29c,dae0ea,b3b9d1,8b93af,6d758d,4a5462,333941,422433,5b3138,8e5252,ba756a,e9b5a3,e3e6ff,b9bffb,849be4,588dbe,477d85,23674e,328464,5daf8d,92dcba,cdf7e2,e4d2aa,c7b08b,a08662,796755,5a4e44,423934".split(
17+
","
18+
),
19+
},
20+
21+
"Zughy 32": {
22+
colors: "472d3c,5e3643,7a444a,a05b53,bf7958,eea160,f4cca1,b6d53c,71aa34,397b44,3c5956,302c2e,5a5353,7d7071,a0938e,cfc6b8,dff6f5,8aebf1,28ccdf,3978a8,394778,39314b,564064,8e478c,cd6093,ffaeb6,f4b41b,f47e1b,e6482e,a93b3b,827094,4f546b".split(
23+
","
24+
),
25+
},
26+
27+
Journey: {
28+
colors: "050914,110524,3b063a,691749,9c3247,d46453,f5a15d,ffcf8e,ff7a7d,ff417d,d61a88,94007a,42004e,220029,100726,25082c,3d1132,73263d,bd4035,ed7b39,ffb84a,fff540,c6d831,77b02a,429058,2c645e,153c4a,052137,0e0421,0c0b42,032769,144491,488bd4,78d7ff,b0fff1,faffff,c7d4e1,928fb8,5b537d,392946,24142c,0e0f2c,132243,1a466b,10908e,28c074,3dff6e,f8ffb8,f0c297,cf968c,8f5765,52294b,0f022e,35003b,64004c,9b0e3e,d41e3c,ed4c40,ff9757,d4662f,9c341a,691b22,450c28,2d002e".split(
29+
","
30+
),
31+
},
32+
33+
Vinik24: {
34+
colors: "000000,6f6776,9a9a97,c5ccb8,8b5580,c38890,a593a5,666092,9a4f50,c28d75,7ca1c0,416aa3,8d6268,be955c,68aca9,387080,6e6962,93a167,6eaa78,557064,9d9f7f,7e9e99,5d6872,433455".split(
35+
","
36+
),
37+
},
38+
39+
"Sweetie 16": {
40+
colors: "1a1c2c,5d275d,b13e53,ef7d57,ffcd75,a7f070,38b764,257179,29366f,3b5dc9,41a6f6,73eff7,f4f4f4,94b0c2,566c86,333c57".split(
41+
","
42+
),
43+
},
44+
45+
Lospec500: {
46+
colors: "10121c,2c1e31,6b2643,ac2847,ec273f,94493a,de5d3a,e98537,f3a833,4d3533,6e4c30,a26d3f,ce9248,dab163,e8d282,f7f3b7,1e4044,006554,26854c,5ab552,9de64e,008b8b,62a477,a6cb96,d3eed3,3e3b65,3859b3,3388de,36c5f4,6dead6,5e5b8c,8c78a5,b0a7b8,deceed,9a4d76,c878af,cc99ff,fa6e79,ffa2ac,ffd1d5,f6e8e0,ffffff".split(
47+
","
48+
),
49+
},
50+
};
51+
palettes["Commodore 64"] = {"name":"Commodore 64","author":"","colors":["000000","626262","898989","adadad","ffffff","9f4e44","cb7e75","6d5412","a1683c","c9d487","9ae29b","5cab5e","6abfc6","887ecb","50459b","a057a3"]};
52+
palettes["PICO-8"] = {"name":"PICO-8","author":"","colors":["000000","1D2B53","7E2553","008751","AB5236","5F574F","C2C3C7","FFF1E8","FF004D","FFA300","FFEC27","00E436","29ADFF","83769C","FF77A8","FFCCAA"]};
53+
palettes["Gameboy Color"] = {"name":"Nintendo Gameboy (Black Zero)","author":"","colors":["2e463d","385d49","577b46","7e8416"]};
54+
55+
56+
157
//populate palettes list in new pixel menu
258
(() => {
359
const palettesMenu = document.getElementById('palette-menu');
@@ -9,43 +65,50 @@
965
const loadPaletteButton = document.getElementById('load-palette-button');
1066
const loadPaletteButtonSplash = document.getElementById('load-palette-button-splash');
1167

12-
Object.keys(palettes).forEach((paletteName,) => {
13-
14-
const button = document.createElement('button');
15-
button.appendChild(document.createTextNode(paletteName));
16-
17-
//if the palette was specified by the user, change the dropdown to it
18-
if (palettes[paletteName].specified) {
19-
Util.setText('palette-button', paletteName);
20-
Util.setText('palette-button-splash', paletteName)
21-
//Show empty palette option
22-
noPaletteButton.style.display = 'block';
23-
}
24-
25-
const buttonEvent = () => {
26-
//hide the dropdown menu
27-
Util.deselect('palette-menu');
28-
Util.deselect('palette-button');
29-
Util.deselect('palette-menu-splash');
30-
Util.deselect('palette-button-splash');
31-
32-
//show empty palette option
33-
noPaletteButton.style.display = 'block';
34-
35-
//set the text of the dropdown to the newly selected preset
36-
Util.setText('palette-button', paletteName);
37-
Util.setText('palette-button-splash', paletteName);
38-
}
39-
40-
// Making a copy for the splash page too
41-
const copyButton = button.cloneNode(true);
42-
copyButton.addEventListener('click', buttonEvent);
43-
button.addEventListener('click', buttonEvent);
44-
45-
// Appending it to the splash palette menu
46-
splashPalettes.appendChild(copyButton);
47-
palettesMenu.appendChild(button);
48-
});
68+
splashPalettes.refresh = function () {
69+
splashPalettes.innerHTML = '';
70+
palettesMenu.innerHTML = '';
71+
72+
Object.keys(palettes).forEach((paletteName,) => {
73+
74+
const button = document.createElement('button');
75+
button.appendChild(document.createTextNode(paletteName));
76+
77+
//if the palette was specified by the user, change the dropdown to it
78+
if (palettes[paletteName].specified) {
79+
Util.setText('palette-button', paletteName);
80+
Util.setText('palette-button-splash', paletteName)
81+
//Show empty palette option
82+
noPaletteButton.style.display = 'block';
83+
}
84+
85+
const buttonEvent = () => {
86+
//hide the dropdown menu
87+
Util.deselect('palette-menu');
88+
Util.deselect('palette-button');
89+
Util.deselect('palette-menu-splash');
90+
Util.deselect('palette-button-splash');
91+
92+
//show empty palette option
93+
noPaletteButton.style.display = 'block';
94+
95+
//set the text of the dropdown to the newly selected preset
96+
Util.setText('palette-button', paletteName);
97+
Util.setText('palette-button-splash', paletteName);
98+
}
99+
100+
// Making a copy for the splash page too
101+
const copyButton = button.cloneNode(true);
102+
copyButton.addEventListener('click', buttonEvent);
103+
button.addEventListener('click', buttonEvent);
104+
105+
// Appending it to the splash palette menu
106+
splashPalettes.appendChild(copyButton);
107+
palettesMenu.appendChild(button);
108+
});
109+
}
110+
111+
splashPalettes.refresh();
49112

50113

51114
const loadPaletteButtonEvent = () => {

js/_splashPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ let coverImage = document.getElementById('editor-logo');
1818
let authorLink = coverImage.getElementsByTagName('a')[0];
1919
let chosenImage = images[Math.round(Math.random() * (images.length - 1))];
2020

21-
coverImage.style.backgroundImage = 'url("/pixel-editor/' + chosenImage.path + '.png")';
21+
coverImage.style.backgroundImage = 'url("' + chosenImage.path + '.png")';
2222
authorLink.setAttribute('href', chosenImage.link);
2323
authorLink.innerHTML = 'Art by ' + chosenImage.author;

js/_variables.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var canvasSize;
33
var zoom = 7;
44
var dragging = false;
55
var lastMouseClickPos = [0,0];
6-
var dialogueOpen = false;
6+
var dialogueOpen = true;
77
var documentCreated = false;
88
var pixelEditorMode = "Advanced";
99

js/checkCompatibilityPixelEditor.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function closeCompatibilityWarning() {
2+
document.getElementById("compatibility-warning").style.visibility = "hidden";
3+
}
4+
5+
//check browser/version
6+
if (
7+
(bowser.firefox && bowser.version >= 28) ||
8+
(bowser.chrome && bowser.version >= 29) ||
9+
(!bowser.mobile && !bowser.tablet)
10+
)
11+
console.log("compatibility check passed");
12+
13+
14+
//show warning
15+
else document.getElementById("compatibility-warning").style.visibility = "visible";
File renamed without changes.

js/sortable.js js/lib/sortable.js

File renamed without changes.

0 commit comments

Comments
 (0)