mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 20:40:39 +00:00
Use implicit return where possible
This commit is contained in:
parent
b7c98bf27b
commit
7ecea310c7
12 changed files with 78 additions and 119 deletions
|
|
@ -23,6 +23,7 @@
|
|||
},
|
||||
|
||||
"rules": {
|
||||
"arrow-body-style": ["error", "as-needed"],
|
||||
"arrow-parens": "error",
|
||||
"arrow-spacing": "error",
|
||||
"block-scoped-var": "warn",
|
||||
|
|
|
|||
|
|
@ -89,14 +89,12 @@ export function toggleShuffle(mediaPlayer) {
|
|||
export function setSkinFromFile(skinFile) {
|
||||
return (dispatch) => {
|
||||
dispatch({type: 'START_LOADING'});
|
||||
skinParser(skinFile).then((skinData) => {
|
||||
return dispatch({
|
||||
type: 'SET_SKIN_DATA',
|
||||
skinImages: skinData.images,
|
||||
skinColors: skinData.colors,
|
||||
skinPlaylistStyle: skinData.playlistStyle
|
||||
});
|
||||
});
|
||||
skinParser(skinFile).then((skinData) => dispatch({
|
||||
type: 'SET_SKIN_DATA',
|
||||
skinImages: skinData.images,
|
||||
skinColors: skinData.colors,
|
||||
skinPlaylistStyle: skinData.playlistStyle
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -117,13 +115,11 @@ export function openFileDialog(winamp) {
|
|||
|
||||
export function setEqBand(mediaPlayer, band, value) {
|
||||
mediaPlayer.setEqBand(band, value);
|
||||
return (dispatch) => {
|
||||
return dispatch({
|
||||
type: 'SET_BAND_VALUE',
|
||||
band,
|
||||
value
|
||||
});
|
||||
};
|
||||
return (dispatch) => dispatch({
|
||||
type: 'SET_BAND_VALUE',
|
||||
band,
|
||||
value
|
||||
});
|
||||
}
|
||||
|
||||
function _setEqTo(mediaPlayer, value) {
|
||||
|
|
@ -154,11 +150,9 @@ export function setEqToMin(mediaPlayer) {
|
|||
|
||||
export function setPreamp(mediaPlayer, value) {
|
||||
mediaPlayer.setPreamp(value);
|
||||
return (dispatch) => {
|
||||
return dispatch({
|
||||
type: 'SET_BAND_VALUE',
|
||||
band: 'preamp',
|
||||
value
|
||||
});
|
||||
};
|
||||
return (dispatch) => dispatch({
|
||||
type: 'SET_BAND_VALUE',
|
||||
band: 'preamp',
|
||||
value
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ module.exports = (props) => {
|
|||
const text = `${props.children}`;
|
||||
const chars = text.split('');
|
||||
return <div {...props}>
|
||||
{chars.map((character, index) => {
|
||||
return <Character key={index + character}>{character}</Character>;
|
||||
})};
|
||||
{chars.map((character, index) => <Character key={index + character}>{character}</Character>)};
|
||||
</div>;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ import EqGraph from './EqGraph.jsx';
|
|||
|
||||
import '../../css/equalizer-window.css';
|
||||
|
||||
const bandClassName = (band) => {
|
||||
return `band-${band}`;
|
||||
};
|
||||
const bandClassName = (band) => `band-${band}`;
|
||||
|
||||
class EqualizerWindow extends React.Component {
|
||||
constructor(props) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ import {connect} from 'react-redux';
|
|||
import CharacterString from './CharacterString.jsx';
|
||||
|
||||
|
||||
const Kbps = (props) => {
|
||||
return <CharacterString id='kbps'>
|
||||
{props.kbps}
|
||||
</CharacterString>;
|
||||
};
|
||||
const Kbps = (props) => <CharacterString id='kbps'>
|
||||
{props.kbps}
|
||||
</CharacterString>;
|
||||
|
||||
module.exports = connect((state) => state.media)(Kbps);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ import {connect} from 'react-redux';
|
|||
import CharacterString from './CharacterString.jsx';
|
||||
|
||||
|
||||
const Khz = (props) => {
|
||||
return <CharacterString id='khz'>
|
||||
{props.khz}
|
||||
</CharacterString>;
|
||||
};
|
||||
const Khz = (props) => <CharacterString id='khz'>
|
||||
{props.khz}
|
||||
</CharacterString>;
|
||||
|
||||
module.exports = connect((state) => state.media)(Khz);
|
||||
|
|
|
|||
|
|
@ -20,13 +20,9 @@ const getPositionText = (duration, seekToPercent) => {
|
|||
return `Seek to: ${newElapsedStr}/${durationStr} (${seekToPercent}%)`;
|
||||
};
|
||||
|
||||
const getMediaText = (name, duration) => {
|
||||
return `${name} (${getTimeStr(duration)}) *** `;
|
||||
};
|
||||
const getMediaText = (name, duration) => `${name} (${getTimeStr(duration)}) *** `;
|
||||
|
||||
const getDoubleSizeModeText = (enabled) => {
|
||||
return `${enabled ? 'Disable' : 'Enable'} doublesize mode`;
|
||||
};
|
||||
const getDoubleSizeModeText = (enabled) => `${enabled ? 'Disable' : 'Enable'} doublesize mode`;
|
||||
|
||||
const isLong = (text) => text.length > 30;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,9 @@ import {connect} from 'react-redux';
|
|||
import classnames from 'classnames';
|
||||
|
||||
|
||||
const MonoStereo = (props) => {
|
||||
return <div className='mono-stereo'>
|
||||
<div id='stereo' className={classnames({selected: props.channels === 2})} />
|
||||
<div id='mono' className={classnames({selected: props.channels === 1})} />
|
||||
</div>;
|
||||
};
|
||||
const MonoStereo = (props) => <div className='mono-stereo'>
|
||||
<div id='stereo' className={classnames({selected: props.channels === 2})} />
|
||||
<div id='mono' className={classnames({selected: props.channels === 1})} />
|
||||
</div>;
|
||||
|
||||
module.exports = connect((state) => state.media)(MonoStereo);
|
||||
|
|
|
|||
|
|
@ -145,9 +145,7 @@ Object.keys(FONT_LOOKUP).forEach((character) => {
|
|||
});
|
||||
|
||||
|
||||
const numExIsUsed = (skinImages) => {
|
||||
return !!skinImages.DIGIT_0_EX;
|
||||
};
|
||||
const numExIsUsed = (skinImages) => !!skinImages.DIGIT_0_EX;
|
||||
|
||||
const Skin = (props) => {
|
||||
if (!props.skinImages) {
|
||||
|
|
|
|||
100
js/skinParser.js
100
js/skinParser.js
|
|
@ -2,16 +2,12 @@ import SKIN_SPRITES from './skinSprites';
|
|||
import JSZip from '../node_modules/jszip/dist/jszip'; // Hack
|
||||
import {parseViscolors, parseIni} from './utils';
|
||||
|
||||
const bmpUriFromFile = (file) => {
|
||||
return `data:image/bmp;base64,${btoa(file.asBinary())}`;
|
||||
};
|
||||
const bmpUriFromFile = (file) => `data:image/bmp;base64,${btoa(file.asBinary())}`;
|
||||
|
||||
// "Promisify" processBuffer
|
||||
const getBufferFromFile = (file) => {
|
||||
return new Promise((resolve) => {
|
||||
file.processBuffer(resolve);
|
||||
});
|
||||
};
|
||||
const getBufferFromFile = (file) => new Promise((resolve) => {
|
||||
file.processBuffer(resolve);
|
||||
});
|
||||
|
||||
const getZipFromBuffer = (buffer) => new JSZip(buffer);
|
||||
|
||||
|
|
@ -24,59 +20,51 @@ const getSpriteSheetFilesFromZip = (zip) => {
|
|||
};
|
||||
|
||||
// Extract the CSS rules for a given file, and add them to the object
|
||||
const extractCss = (spriteObj) => {
|
||||
return new Promise((resolve) => {
|
||||
const uri = bmpUriFromFile(spriteObj.file);
|
||||
const img = new Image();
|
||||
const extractCss = (spriteObj) => new Promise((resolve) => {
|
||||
const uri = bmpUriFromFile(spriteObj.file);
|
||||
const img = new Image();
|
||||
|
||||
img.onload = () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
const images = {};
|
||||
spriteObj.sprites.forEach((sprite) => {
|
||||
canvas.height = sprite.height;
|
||||
canvas.width = sprite.width;
|
||||
img.onload = () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
const images = {};
|
||||
spriteObj.sprites.forEach((sprite) => {
|
||||
canvas.height = sprite.height;
|
||||
canvas.width = sprite.width;
|
||||
|
||||
const context = canvas.getContext('2d');
|
||||
context.drawImage(img, -sprite.x, -sprite.y);
|
||||
const image = canvas.toDataURL();
|
||||
if (sprite.name) {
|
||||
images[sprite.name] = image;
|
||||
}
|
||||
});
|
||||
resolve({...spriteObj, images});
|
||||
};
|
||||
img.src = uri;
|
||||
});
|
||||
};
|
||||
const context = canvas.getContext('2d');
|
||||
context.drawImage(img, -sprite.x, -sprite.y);
|
||||
const image = canvas.toDataURL();
|
||||
if (sprite.name) {
|
||||
images[sprite.name] = image;
|
||||
}
|
||||
});
|
||||
resolve({...spriteObj, images});
|
||||
};
|
||||
img.src = uri;
|
||||
});
|
||||
|
||||
// Extract the color data from a VISCOLOR.TXT file and add it to the object
|
||||
const extractColors = (spriteObj) => {
|
||||
return {
|
||||
...spriteObj,
|
||||
colors: parseViscolors(spriteObj.file.asText())
|
||||
};
|
||||
};
|
||||
const extractColors = (spriteObj) => ({
|
||||
...spriteObj,
|
||||
colors: parseViscolors(spriteObj.file.asText())
|
||||
});
|
||||
|
||||
// Extract the color data from a VISCOLOR.TXT file and add it to the object
|
||||
const extractPlaylistStyle = (spriteObj) => {
|
||||
return {
|
||||
...spriteObj,
|
||||
playlistStyle: parseIni(spriteObj.file.asText())
|
||||
};
|
||||
};
|
||||
const extractPlaylistStyle = (spriteObj) => ({
|
||||
...spriteObj,
|
||||
playlistStyle: parseIni(spriteObj.file.asText())
|
||||
});
|
||||
|
||||
const getSkinDataFromFiles = (spriteObjs) => {
|
||||
return Promise.all(spriteObjs.map((spriteObj) => {
|
||||
switch (spriteObj.name) {
|
||||
case 'VISCOLOR':
|
||||
return extractColors(spriteObj);
|
||||
case 'PLEDIT.TXT':
|
||||
return extractPlaylistStyle(spriteObj);
|
||||
default:
|
||||
return extractCss(spriteObj);
|
||||
}
|
||||
}));
|
||||
};
|
||||
const getSkinDataFromFiles = (spriteObjs) => Promise.all(spriteObjs.map((spriteObj) => {
|
||||
switch (spriteObj.name) {
|
||||
case 'VISCOLOR':
|
||||
return extractColors(spriteObj);
|
||||
case 'PLEDIT.TXT':
|
||||
return extractPlaylistStyle(spriteObj);
|
||||
default:
|
||||
return extractCss(spriteObj);
|
||||
}
|
||||
}));
|
||||
|
||||
const collectCssAndColors = (spriteObjs) => {
|
||||
let images = {};
|
||||
|
|
@ -102,12 +90,10 @@ const collectCssAndColors = (spriteObjs) => {
|
|||
};
|
||||
|
||||
// A promise that, given a File object, returns a skin style object
|
||||
const parseSkin = (file) => {
|
||||
return getBufferFromFile(file)
|
||||
const parseSkin = (file) => getBufferFromFile(file)
|
||||
.then(getZipFromBuffer)
|
||||
.then(getSpriteSheetFilesFromZip)
|
||||
.then(getSkinDataFromFiles)
|
||||
.then(collectCssAndColors);
|
||||
};
|
||||
|
||||
module.exports = parseSkin;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,10 @@ export const right = (box) => box.x + box.width;
|
|||
export const near = (a, b) => Math.abs(a - b) < SNAP_DISTANCE;
|
||||
|
||||
// http://stackoverflow.com/a/3269471/1263117
|
||||
export const overlapX = (a, b) => {
|
||||
return left(a) <= right(b) + SNAP_DISTANCE &&
|
||||
export const overlapX = (a, b) => left(a) <= right(b) + SNAP_DISTANCE &&
|
||||
left(b) <= right(a) + SNAP_DISTANCE;
|
||||
};
|
||||
export const overlapY = (a, b) => {
|
||||
return top(a) <= bottom(b) + SNAP_DISTANCE &&
|
||||
export const overlapY = (a, b) => top(a) <= bottom(b) + SNAP_DISTANCE &&
|
||||
top(b) <= bottom(a) + SNAP_DISTANCE;
|
||||
};
|
||||
|
||||
export const snap = (boxA, boxB) => {
|
||||
let x, y;
|
||||
|
|
|
|||
|
|
@ -52,9 +52,7 @@ const parseIni = (text) => {
|
|||
return data;
|
||||
};
|
||||
|
||||
const clamp = (value, min, max) => {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
};
|
||||
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
||||
|
||||
module.exports = {
|
||||
getTimeObj,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue