Add a none option to the simulator for the color sensor and colorEnumPicker extension (#1018)
* Update colorGrid.ts * Update ns.ts Added option to select emptiness (nothing) for the colorEnumPicker block. * set-new-names-for-color-cells Set new names for colored cells that pops up when hovering over an element. So the user will understand the color. * Update sim/visuals/controls/colorGrid.ts Co-authored-by: Joey Wunderlich <jwunderl@users.noreply.github.com> --------- Co-authored-by: Joey Wunderlich <jwunderl@users.noreply.github.com>
This commit is contained in:
@ -5,10 +5,14 @@ export interface FieldColorEnumOptions extends pxtblockly.FieldColourNumberOptio
|
||||
}
|
||||
|
||||
export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Blockly.FieldCustom {
|
||||
|
||||
public isFieldCustom_ = true;
|
||||
private paramsData: any[];
|
||||
|
||||
constructor(text: string, params: FieldColorEnumOptions, opt_validator?: Function) {
|
||||
super(text, params, opt_validator);
|
||||
|
||||
this.paramsData = params["data"];
|
||||
}
|
||||
|
||||
mapColour(enumString: string) {
|
||||
@ -33,11 +37,21 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Block
|
||||
case 'ColorSensorColor.Red': return '#f12a21';
|
||||
case 'ColorSensorColor.White': return '#ffffff';
|
||||
case 'ColorSensorColor.Brown': return '#6c2d00';
|
||||
case 'ColorSensorColor.None': return '#dfe6e9'; // Grey
|
||||
case 'ColorSensorColor.None': return '#dfe6e9';
|
||||
default: return colorString;
|
||||
}
|
||||
}
|
||||
|
||||
showEditor_() {
|
||||
super.showEditor_();
|
||||
const colorCells = document.querySelectorAll('.legoColorPicker td');
|
||||
colorCells.forEach((cell) => {
|
||||
const titleName = this.mapColour(cell.getAttribute("title"));
|
||||
const index = this.paramsData.findIndex(item => item[1] === titleName);
|
||||
cell.setAttribute("title", this.paramsData[index][0]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current colour.
|
||||
* @param {boolean} opt_asHex optional field if the returned value should be a hex
|
||||
|
Reference in New Issue
Block a user