Spaces:
Paused
Paused
Update src/containers/custom-procedures.jsx
Browse files
src/containers/custom-procedures.jsx
CHANGED
|
@@ -5,31 +5,14 @@ import React from 'react';
|
|
| 5 |
import CustomProceduresComponent from '../components/custom-procedures/custom-procedures.jsx';
|
| 6 |
import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks';
|
| 7 |
import {connect} from 'react-redux';
|
| 8 |
-
import Color from './custom-procedures-util/color.js';
|
| 9 |
|
| 10 |
-
|
| 11 |
-
const rgb = Color.hexToRgb(hex);
|
| 12 |
-
const hsv = Color.rgbToHsv(rgb);
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
// so we can avoid adding red to them
|
| 20 |
-
if (!(hsv.h === 0 && hsv.s === 0)) {
|
| 21 |
-
hsv.s += percentage * hsv.v;
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
// make sure values arent invalid
|
| 25 |
-
if (hsv.v > 1) hsv.v = 1;
|
| 26 |
-
if (hsv.v < 0) hsv.v = 0;
|
| 27 |
-
|
| 28 |
-
if (hsv.s > 1) hsv.s = 1;
|
| 29 |
-
if (hsv.s < 0) hsv.s = 0;
|
| 30 |
-
|
| 31 |
-
const newRgb = Color.hsvToRgb(hsv);
|
| 32 |
-
return Color.rgbToHex(newRgb);
|
| 33 |
}
|
| 34 |
|
| 35 |
class CustomProcedures extends React.Component {
|
|
@@ -74,7 +57,7 @@ class CustomProcedures extends React.Component {
|
|
| 74 |
);
|
| 75 |
|
| 76 |
// @todo This is a hack to make there be no toolbox.
|
| 77 |
-
|
| 78 |
const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
|
| 79 |
ScratchBlocks.Blocks.defaultToolbox = null;
|
| 80 |
this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
|
|
@@ -216,8 +199,8 @@ class CustomProcedures extends React.Component {
|
|
| 216 |
const newColor = element.target.value;
|
| 217 |
this.mutationRoot.setColor(
|
| 218 |
newColor,
|
| 219 |
-
|
| 220 |
-
|
| 221 |
);
|
| 222 |
this.setState({blockColor: newColor});
|
| 223 |
}
|
|
|
|
| 5 |
import CustomProceduresComponent from '../components/custom-procedures/custom-procedures.jsx';
|
| 6 |
import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks';
|
| 7 |
import {connect} from 'react-redux';
|
|
|
|
| 8 |
|
| 9 |
+
let ScratchBlocks; // defined later
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
function darkenColor(hex, amt) {
|
| 12 |
+
const Color = ScratchBlocks.goog.color;
|
| 13 |
+
return Color.rgbArrayToHex(Color.darken(
|
| 14 |
+
Color.hexToRgb(hex), amt
|
| 15 |
+
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
class CustomProcedures extends React.Component {
|
|
|
|
| 57 |
);
|
| 58 |
|
| 59 |
// @todo This is a hack to make there be no toolbox.
|
| 60 |
+
ScratchBlocks = LazyScratchBlocks.get();
|
| 61 |
const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
|
| 62 |
ScratchBlocks.Blocks.defaultToolbox = null;
|
| 63 |
this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
|
|
|
|
| 199 |
const newColor = element.target.value;
|
| 200 |
this.mutationRoot.setColor(
|
| 201 |
newColor,
|
| 202 |
+
darkenColor(newColor, 0.1),
|
| 203 |
+
darkenColor(newColor, 0.2)
|
| 204 |
);
|
| 205 |
this.setState({blockColor: newColor});
|
| 206 |
}
|