Skip to content

Commit

Permalink
Added system sounds
Browse files Browse the repository at this point in the history
Added system sounds
Optimised the code
  • Loading branch information
Adam Bruzon committed Mar 30, 2019
1 parent 2e12675 commit e6361fd
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 45 deletions.
13 changes: 8 additions & 5 deletions src/createAllStyles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromNative } from 'sketch';
import { message } from 'sketch/ui';
import { exclamations } from './lib/Constants';

import * as Constants from './lib/Constants';
import * as Counter from './lib/Counter';
import * as Layer from './lib/Layer';
import * as SharedStyle from './lib/SharedStyle';
Expand All @@ -17,20 +17,22 @@ export default (contextNative) => {

const sharedStyles = SharedStyle.getSharedStyles(document, true);

if (selectedLayersCount === 0) {
if (selectedLayersCount == 0) {
message("No layers selected. 🤨");
NSSound.soundNamed(Constants.systemSounds.Basso).play();
return;
}

if (selectedLayersCount > 100) {
if (selectedLayersCount > 99) {
message(`You've selected ${selectedLayersCount} layers 😱 - It might take a few minutes!`);
NSSound.soundNamed(Constants.systemSounds.Blow).play();
}

setTimeout(() => {

selectedLayers.forEach(( layer ) => {

if (Layer.getLayerType(layer) === "Text") {
if (Layer.getLayerType(layer) == "Text") {

let sharedStyle = SharedStyle.getSharedTextStyleById(layer.sharedStyleId, document);

Expand Down Expand Up @@ -62,12 +64,13 @@ export default (contextNative) => {
});

message(
`${exclamations[Utils.getRandomInt(exclamations.length - 1)]}! 🙌` +
`${Constants.exclamations[Utils.getRandomInt(Constants.exclamations.length - 1)]}! 🙌` +
" | " +
`Styles created: ${Counter.getCount('created')}` +
" | " +
`Styles updated: ${Counter.getCount('updated')}`
);
NSSound.soundNamed(Constants.systemSounds.Glass).play();

}, 100);

Expand Down
11 changes: 7 additions & 4 deletions src/createShapeStyles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromNative } from 'sketch';
import { message } from 'sketch/ui';
import { exclamations } from './lib/Constants';

import * as Constants from './lib/Constants';
import * as Counter from './lib/Counter';
import * as Layer from './lib/Layer';
import * as SharedStyle from './lib/SharedStyle';
Expand All @@ -17,13 +17,15 @@ export default (contextNative) => {

const sharedStyles = SharedStyle.getSharedStyles(document, true);

if (selectedLayersCount === 0) {
if (selectedLayersCount == 0) {
message("No layers selected. 🤨");
NSSound.soundNamed(Constants.systemSounds.Basso).play();
return;
}

if (selectedLayersCount > 100) {
if (selectedLayersCount > 99) {
message(`You've selected ${selectedLayersCount} layers 😱 - It might take a few minutes!`);
NSSound.soundNamed(Constants.systemSounds.Blow).play();
}

setTimeout(() => {
Expand Down Expand Up @@ -51,14 +53,15 @@ export default (contextNative) => {
});

message(
`${exclamations[Utils.getRandomInt(exclamations.length - 1)]}! 🙌` +
`${Constants.exclamations[Utils.getRandomInt(Constants.exclamations.length - 1)]}! 🙌` +
" | " +
`Styles created: ${Counter.getCount('created')}` +
" | " +
`Styles updated: ${Counter.getCount('updated')}` +
" | " +
`Styles skipped: ${Counter.getCount('skipped')}`
);
NSSound.soundNamed(Constants.systemSounds.Glass).play();

}, 100);

Expand Down
11 changes: 7 additions & 4 deletions src/createTextStyles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromNative } from 'sketch';
import { message } from 'sketch/ui';
import { exclamations } from './lib/Constants';

import * as Constants from './lib/Constants';
import * as Counter from './lib/Counter';
import * as Layer from './lib/Layer';
import * as SharedStyle from './lib/SharedStyle';
Expand All @@ -17,13 +17,15 @@ export default (contextNative) => {

const sharedStyles = SharedStyle.getSharedStyles(document, true);

if (selectedLayersCount === 0) {
if (selectedLayersCount == 0) {
message("No layers selected. 🤨");
NSSound.soundNamed(Constants.systemSounds.Basso).play();
return;
}

if (selectedLayersCount > 100) {
if (selectedLayersCount > 99) {
message(`You've selected ${selectedLayersCount} layers 😱 - It might take a few minutes!`);
NSSound.soundNamed(Constants.systemSounds.Blow).play();
}

setTimeout(() => {
Expand Down Expand Up @@ -51,14 +53,15 @@ export default (contextNative) => {
});

message(
`${exclamations[Utils.getRandomInt(exclamations.length - 1)]}! 🙌` +
`${Constants.exclamations[Utils.getRandomInt(Constants.exclamations.length - 1)]}! 🙌` +
" | " +
`Styles created: ${Counter.getCount('created')}` +
" | " +
`Styles updated: ${Counter.getCount('updated')}` +
" | " +
`Styles skipped: ${Counter.getCount('skipped')}`
);
NSSound.soundNamed(Constants.systemSounds.Glass).play();

}, 100);

Expand Down
20 changes: 19 additions & 1 deletion src/lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ const exclamations = [
"Ziggety-damn"
];

const systemSounds = {
Basso: "Basso",
Blow: "Blow",
Bottle: "Bottle",
Frog: "Frog",
Funk: "Funk",
Glass: "Glass",
Hero: "Hero",
Morse: "Morse",
Ping: "Ping",
Pop: "Pop",
Purr: "Purr",
Sosumi: "Sosumi",
Submarine: "Submarine",
Tink: "Tink"
};

export {
exclamations
exclamations,
systemSounds
}
37 changes: 11 additions & 26 deletions src/lib/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const sortSelection = (selectedLayersNative) => {

let layer = fromNative(layerNative);

if (layer.type === "Artboard") { selected.artboards.push(layer); }
else if (layer.type === "Text") { selected.texts.push(layer); }
if (layer.type == "Artboard") { selected.artboards.push(layer); }
else if (layer.type == "Text") { selected.texts.push(layer); }
else { selected.shapes.push(layer); }

});
Expand All @@ -31,6 +31,7 @@ const sortSelection = (selectedLayersNative) => {
selectedTextCount = selected.texts.length;
selectedArtboardCount = selected.artboards.length;

selectedLayerCount = 0;
Object.keys(selected).forEach((key) => {
if (key != "artboards") { selectedLayerCount += selected[key].length; }
});
Expand All @@ -41,87 +42,71 @@ const sortSelection = (selectedLayersNative) => {

const getSelectedLayers = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedShapeCount || !selectedTextCount) {
sortSelection( selectedLayersNative );
sortSelection( contextNative.document.selectedLayers() );
}
return [].concat(selected.shapes, selected.texts);

}

const getSelectedShapes = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedShapeCount) {
return sortSelection( selectedLayersNative ).shapes;
return sortSelection( contextNative.document.selectedLayers() ).shapes;
}
return selected.shapes;

}

const getSelectedTexts = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedTextCount) {
return sortSelection( selectedLayersNative ).texts;
return sortSelection( contextNative.document.selectedLayers() ).texts;
}
return selected.texts;

}

const getSelectedArtboards = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedArtboardCount) {
sortSelection( selectedLayersNative ).artboards;
sortSelection( contextNative.document.selectedLayers() ).artboards;
}
return selected.artboards;

}

const getSelectedLayerCount = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedLayerCount) {
sortSelection( selectedLayersNative );
sortSelection( contextNative.document.selectedLayers() );
}
return selectedLayerCount;

}

const getSelectedShapeCount = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedShapeCount) {
sortSelection( selectedLayersNative );
sortSelection( contextNative.document.selectedLayers() );
}
return selectedShapeCount;

}

const getSelectedTextCount = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedTextCount) {
sortSelection( selectedLayersNative );
sortSelection( contextNative.document.selectedLayers() );
}
return selectedTextCount;

}

const getSelectedArtboardCount = (contextNative) => {

let selectedLayersNative = contextNative.document.selectedLayers();

if (!selectedArtboardCount) {
sortSelection( selectedLayersNative );
sortSelection( contextNative.document.selectedLayers() );
}
return selectedArtboardCount;

Expand Down
1 change: 0 additions & 1 deletion src/lib/SharedStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const getSharedTextStyles = (document, fromSource) => {
const getSharedStyles = (document, fromSource) => {
getSharedShapeStyles(document, fromSource);
getSharedTextStyles(document, fromSource);
console.log(sharedStyles);
return sharedStyles;
}

Expand Down
5 changes: 3 additions & 2 deletions src/removeAllShapeStyles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromNative } from 'sketch';
import { message } from 'sketch/ui';
import { exclamations } from './lib/Constants';

import * as Constants from './lib/Constants';
import * as SharedStyle from './lib/SharedStyle';
import * as Utils from './lib/Utils';

Expand All @@ -15,10 +15,11 @@ export default (contextNative) => {
SharedStyle.removeAllShapeStyles(document);

message(
`${exclamations[Utils.getRandomInt(exclamations.length - 1)]}! 🙌` +
`${Constants.exclamations[Utils.getRandomInt(Constants.exclamations.length - 1)]}! 🙌` +
" | " +
`All shape styles removed`
);
NSSound.soundNamed(Constants.systemSounds.Submarine).play();

}, 100);

Expand Down
5 changes: 3 additions & 2 deletions src/removeAllTextStyles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromNative } from 'sketch';
import { message } from 'sketch/ui';
import { exclamations } from './lib/Constants';

import * as Constants from './lib/Constants';
import * as SharedStyle from './lib/SharedStyle';
import * as Utils from './lib/Utils';

Expand All @@ -15,10 +15,11 @@ export default (contextNative) => {
SharedStyle.removeAllTextStyles(document);

message(
`${exclamations[Utils.getRandomInt(exclamations.length - 1)]}! 🙌` +
`${Constants.exclamations[Utils.getRandomInt(Constants.exclamations.length - 1)]}! 🙌` +
" | " +
`All text styles removed`
);
NSSound.soundNamed(Constants.systemSounds.Submarine).play();

}, 100);

Expand Down

0 comments on commit e6361fd

Please sign in to comment.