2021-12-07 14:11:40 +03:00
|
|
|
/** EXTERNALS AND LIBRARIES **/
|
2021-07-07 00:24:20 +03:00
|
|
|
//=include lib/cookies.js
|
2021-12-06 13:26:42 +03:00
|
|
|
//=include lib/jscolor.js
|
2021-07-07 00:24:20 +03:00
|
|
|
//=include lib/sortable.js
|
2021-12-06 22:12:57 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
//=include data/consts.js
|
|
|
|
//=include data/palettes.js
|
|
|
|
|
|
|
|
/** UTILITY AND INPUT **/
|
2021-06-29 02:54:54 +03:00
|
|
|
//=include Util.js
|
2021-07-20 23:52:51 +03:00
|
|
|
//=include Events.js
|
2021-07-14 00:40:23 +03:00
|
|
|
//=include Dialogue.js
|
2021-07-14 23:20:55 +03:00
|
|
|
//=include History.js
|
2021-12-07 14:11:40 +03:00
|
|
|
//=include Settings.js
|
|
|
|
//=include EditorState.js
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** COLOR-RELATED **/
|
2021-12-06 22:12:57 +03:00
|
|
|
//=include Color.js
|
2021-12-07 14:11:40 +03:00
|
|
|
//=include ColorPicker.js
|
|
|
|
//=include PaletteBlock.js
|
2021-12-06 22:12:57 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** BASE CLASSES **/
|
2021-12-06 19:37:43 +03:00
|
|
|
//=include File.js
|
2021-11-09 01:12:51 +03:00
|
|
|
//=include Tool.js
|
2021-12-07 14:11:40 +03:00
|
|
|
//=include layers/Layer.js
|
|
|
|
|
|
|
|
/** SPECIAL LAYERS **/
|
|
|
|
//=include layers/Checkerboard.js
|
|
|
|
//=include layers/PixelGrid.js
|
2021-11-01 15:02:18 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** TOOLS **/
|
2021-12-13 00:50:21 +03:00
|
|
|
//=include tools/DrawingTool.js
|
2021-11-01 15:02:18 +03:00
|
|
|
//=include tools/ResizableTool.js
|
|
|
|
//=include tools/SelectionTool.js
|
|
|
|
|
|
|
|
//=include tools/BrushTool.js
|
|
|
|
//=include tools/EraserTool.js
|
|
|
|
//=include tools/LineTool.js
|
|
|
|
//=include tools/RectangleTool.js
|
|
|
|
//=include tools/FillTool.js
|
2022-01-08 06:45:35 +03:00
|
|
|
//=include tools/EyeDropperTool.js
|
2021-11-01 15:02:18 +03:00
|
|
|
//=include tools/PanTool.js
|
|
|
|
//=include tools/ZoomTool.js
|
|
|
|
//=include tools/RectangularSelectionTool.js
|
|
|
|
//=include tools/MoveSelectionTool.js
|
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** MODULES AND MENUS **/
|
|
|
|
//=include SplashPage.js
|
|
|
|
//=include PresetModule.js
|
|
|
|
//=include ColorModule.js
|
|
|
|
//=include ToolManager.js
|
2021-07-22 23:42:41 +03:00
|
|
|
//=include LayerList.js
|
2021-11-12 01:13:15 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** STARTUP AND FILE MANAGEMENT **/
|
2021-07-22 19:57:44 +03:00
|
|
|
//=include Startup.js
|
2021-07-15 23:21:19 +03:00
|
|
|
//=include FileManager.js
|
|
|
|
//=include TopMenuModule.js
|
2021-07-22 19:57:44 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** HTML INPUT EVENTS **/
|
2021-07-22 19:57:44 +03:00
|
|
|
//=include Input.js
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
/** IHER **/
|
2021-12-06 13:26:42 +03:00
|
|
|
//=include FeatureToggles.js
|
2021-06-29 02:54:54 +03:00
|
|
|
|
|
|
|
// Controls execution of this preset module
|
2021-07-15 23:26:08 +03:00
|
|
|
PresetModule.instrumentPresetMenu();
|
|
|
|
|
|
|
|
//when the page is done loading, you can get ready to start
|
|
|
|
window.onload = function () {
|
|
|
|
featureToggles.onLoad();
|
|
|
|
|
2021-10-27 11:02:21 +03:00
|
|
|
ToolManager.currentTool().updateCursor();
|
2021-07-15 23:26:08 +03:00
|
|
|
|
|
|
|
//check if there are any url parameters
|
|
|
|
if (window.location.pathname.replace('/pixel-editor/','').length <= 1) {
|
|
|
|
//show splash screen
|
|
|
|
Dialogue.showDialogue('splash', false);
|
|
|
|
}
|
|
|
|
//url parameters were specified
|
|
|
|
else {
|
|
|
|
let args = window.location.pathname.split('/');
|
|
|
|
let paletteSlug = args[2];
|
|
|
|
let dimentions = args[3];
|
|
|
|
|
|
|
|
//fetch palette via lospec palette API
|
|
|
|
fetch('https://lospec.com/palette-list/'+paletteSlug+'.json')
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
//palette loaded successfully
|
|
|
|
palettes[paletteSlug] = data;
|
|
|
|
palettes[paletteSlug].specified = true;
|
|
|
|
|
|
|
|
//refresh list of palettes
|
|
|
|
document.getElementById('palette-menu-splash').refresh();
|
|
|
|
|
|
|
|
//if the dimentions were specified
|
|
|
|
if (dimentions && dimentions.length >= 3 && dimentions.includes('x')) {
|
|
|
|
let width = dimentions.split('x')[0];
|
|
|
|
let height = dimentions.split('x')[1];
|
|
|
|
|
|
|
|
//create new document
|
|
|
|
Startup.newPixel(width, height);
|
|
|
|
}
|
|
|
|
//dimentions were not specified -- show splash screen with palette preselected
|
|
|
|
else {
|
|
|
|
//show splash
|
|
|
|
Dialogue.showDialogue('new-pixel', false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
//error fetching url (either palette doesn't exist, or lospec is down)
|
|
|
|
.catch((error) => {
|
|
|
|
console.warn('failed to load palette "'+paletteSlug+'"', error);
|
|
|
|
//proceed to splash screen
|
|
|
|
Dialogue.showDialogue('splash', false);
|
|
|
|
});
|
|
|
|
}
|
2021-07-19 00:17:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//prevent user from leaving page with unsaved data
|
|
|
|
window.onbeforeunload = function() {
|
2021-12-07 14:11:40 +03:00
|
|
|
if (EditorState.documentCreated)
|
2021-07-19 00:17:41 +03:00
|
|
|
return 'You will lose your pixel if it\'s not saved!';
|
|
|
|
|
|
|
|
else return;
|
2021-12-05 01:11:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Compatibility functions
|
|
|
|
function closeCompatibilityWarning() {
|
|
|
|
document.getElementById("compatibility-warning").style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
|
|
|
|
//check browser/version
|
|
|
|
if (
|
|
|
|
(bowser.firefox && bowser.version >= 28) ||
|
|
|
|
(bowser.chrome && bowser.version >= 29) ||
|
|
|
|
(!bowser.mobile && !bowser.tablet)
|
|
|
|
)
|
|
|
|
console.log("compatibility check passed");
|
|
|
|
//show warning
|
|
|
|
else document.getElementById("compatibility-warning").style.visibility = "visible";
|