Merged the two create functions

This commit is contained in:
unsettledgames 2021-07-15 16:33:26 +02:00
parent eada155375
commit 4f4091ebb3
8 changed files with 20 additions and 80 deletions

View File

@ -48,7 +48,7 @@ const Dialogue = (() => {
}
//track google event
if (trackEvent)
if (trackEvent && typeof ga !== 'undefined')
ga('send', 'event', 'Palette Editor Dialogue', dialogueName); /*global ga*/
}

View File

@ -8,10 +8,7 @@ function create(isSplash) {
var width = Util.getValue('size-width' + splashPostfix);
var height = Util.getValue('size-height' + splashPostfix);
// If I'm creating from the splash screen, I use the splashMode variable
var mode = isSplash ? splashMode : pixelEditorMode;
newPixel(width, height, mode);
newPixel(width, height);
// If I'm not creating from the splash page, then this is not the first project I've created
if (!isSplash)
@ -23,8 +20,8 @@ function create(isSplash) {
selectedPalette = 'none';
//track google event
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
if (typeof ga !== 'undefined')
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
//reset new form
Util.setValue('size-width', 64);
@ -37,63 +34,9 @@ function create(isSplash) {
/** Triggered when the "Create" button in the new pixel dialogue is pressed
*
*/
Input.on('click', 'create-button', function (){
// Getting the values of the form
var width = Util.getValue('size-width');
var height = Util.getValue('size-height');
// Creating a new pixel with those properties
if(pixelEditorMode == "Basic")
newPixel(width, height, "Advanced");
else
newPixel(width, height, "Basic");
document.getElementById('new-pixel-warning').style.display = 'block';
//get selected palette name
var selectedPalette = Util.getText('palette-button');
if (selectedPalette == 'Choose a palette...')
selectedPalette = 'none';
//track google event
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
//reset new form
Util.setValue('size-width', 64);
Util.setValue('size-height', 64);
Util.setText('palette-button', 'Choose a palette...');
Util.setText('preset-button', 'Choose a preset...');
});
Input.on('click', 'create-button', create, false);
/** Triggered when the "Create" button in the splash page is pressed
*
*/
Input.on('click', 'create-button-splash', function (){
// Getting the values of the form
var width = Util.getValue('size-width-splash');
var height = Util.getValue('size-height-splash');
var mode = pixelEditorMode;
if (mode == 'Advanced')
mode = "Basic";
else
mode = "Advanced";
// Creating a new pixel with those properties
newPixel(width, height, mode);
//track google event
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
document.getElementById('new-pixel-warning').style.display = 'block';
// Resetting the new pixel values
selectedPalette = 'none';
//reset new pixel form
Util.setValue('size-width-splash', 64);
Util.setValue('size-height-splash', 64);
Util.setText('palette-button', 'Choose a palette...');
Util.setText('preset-button', 'Choose a preset...');
});
Input.on('click', 'create-button-splash', create, true);

View File

@ -1,3 +1,6 @@
var pixelEditorMode = "Basic";
switchMode(pixelEditorMode);
let modes = {
'Basic' : {
description: 'Basic mode is perfect if you want to create simple sprites or try out palettes.'
@ -13,7 +16,7 @@ Input.on('click', 'switch-editor-mode-splash', function (e) {
function switchMode(newMode) {
//switch to advanced mode
if (newMode == 'Advanced') {
if (newMode == 'Advanced' && pixelEditorMode == 'Basic') {
// Switch to advanced ez pez lemon squez
document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode';
// Show the layer menus
@ -64,8 +67,6 @@ function switchMode(newMode) {
}
function toggleMode() {
console.log("From " + pixelEditorMode);
if (pixelEditorMode == 'Advanced')
switchMode('Basic');
else

View File

@ -49,7 +49,8 @@ for (var i = 1; i < mainMenuItems.length; i++) {
linkHolder.download = fileName;
linkHolder.click();
ga('send', 'event', 'Pixel Editor Save', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/
if (typeof ga !== 'undefined')
ga('send', 'event', 'Pixel Editor Save', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/
break;
case 'Open':
@ -117,7 +118,8 @@ for (var i = 1; i < mainMenuItems.length; i++) {
exportCanvas.remove();
//track google event
ga('send', 'event', 'Pixel Editor Export', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/
if (typeof ga !== 'undefined')
ga('send', 'event', 'Pixel Editor Export', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/
}
break;

View File

@ -38,7 +38,8 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
createPaletteFromLayers();
//track google event
ga('send', 'event', 'Pixel Editor Load', colorPalette.length, this.width+'/'+this.height); /*global ga*/
if (typeof ga !== 'undefined')
ga('send', 'event', 'Pixel Editor Load', colorPalette.length, this.width+'/'+this.height); /*global ga*/
};
img.src = e.target.result;

View File

@ -4,13 +4,9 @@ let firstPixel = true;
*
* @param {*} width Start width of the canvas
* @param {*} height Start height of the canvas
* @param {*} editorMode The editor mode chosen by the user (advanced or basic)
* @param {*} fileContent If fileContent != null, then the newPixel is being called from the open menu
*/
function newPixel (width, height, editorMode, fileContent = null) {
// Saving the editor mode
pixelEditorMode = editorMode;
function newPixel (width, height, fileContent = null) {
// The palette is empty, at the beginning
ColorModule.currentPalette.length = 0;
@ -208,5 +204,5 @@ function newFromTemplate(preset, x, y) {
x = presetProperties.width;
y = presetProperties.height;
}
newPixel(x, y, pixelEditorMode == 'Advanced' ? 'Basic' : 'Advanced');
newPixel(x, y);
}

View File

@ -4,7 +4,6 @@ var zoom = 7;
var dragging = false;
var lastMouseClickPos = [0,0];
var documentCreated = false;
var pixelEditorMode = "Basic";
//common elements
var brushPreview = document.getElementById("brush-preview");

View File

@ -1,5 +1,6 @@
/**utilities**/
//=include lib/cookies.js
//=include _jscolor.js
//=include _pixelEditorUtility.js
//=include lib/sortable.js
//=include Util.js
@ -14,7 +15,6 @@
//=include _settings.js
/**dropdown formatting**/
//=include _editorMode.js
//=include _presets.js
//=include _palettes.js
@ -38,6 +38,7 @@
//=include _colorPicker.js
//=include _paletteBlock.js
//=include SplashPage.js
//=include _editorMode.js
/**load file**/
//=include _loadImage.js
@ -60,9 +61,6 @@
//=include _onLoad.js
//=include _onbeforeunload.js
/**libraries**/
//=include _jscolor.js
/**feature toggles**/
//=include _featureToggles.js