forked from google/blockly-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure to remove Closure’s base.js
Soy now doesn’t rely on Closure. Neither does Blockly.
- Loading branch information
1 parent
53a52ab
commit 05df43d
Showing
11 changed files
with
7,569 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Blockly Games: Music | ||
* Visual Blocks Editor | ||
* | ||
* Copyright 2016 Google Inc. | ||
* https://github.com/google/blockly-games | ||
|
@@ -18,51 +18,53 @@ | |
*/ | ||
|
||
/** | ||
* @fileoverview Music pitch input field. | ||
* @fileoverview Music pitch input field. Borrowed from Blockly Games. | ||
* @author [email protected] (Neil Fraser) | ||
* @author [email protected] (Sam El-Husseini) | ||
*/ | ||
'use strict'; | ||
|
||
goog.provide('Blockly.FieldPitch'); | ||
goog.provide('CustomFields.FieldPitch'); | ||
|
||
goog.require('Blockly.FieldTextInput'); | ||
goog.require('Blockly.utils.math'); | ||
goog.require('Blockly.utils.object'); | ||
|
||
var CustomFields = CustomFields || {}; | ||
|
||
/** | ||
* Class for an editable pitch field. | ||
* @param {string} text The initial content of the field. | ||
* @extends {Blockly.FieldTextInput} | ||
* @constructor | ||
*/ | ||
Blockly.FieldPitch = function(text) { | ||
Blockly.FieldPitch.superClass_.constructor.call(this, text); | ||
CustomFields.FieldPitch = function(text) { | ||
CustomFields.FieldPitch.superClass_.constructor.call(this, text); | ||
}; | ||
goog.inherits(Blockly.FieldPitch, Blockly.FieldTextInput); | ||
Blockly.utils.object.inherits(CustomFields.FieldPitch, Blockly.FieldTextInput); | ||
|
||
/** | ||
* Construct a FieldPitch from a JSON arg object. | ||
* @param {!Object} options A JSON object with options (pitch). | ||
* @return {!Blockly.FieldPitch} The new field instance. | ||
* @return {!CustomFields.FieldPitch} The new field instance. | ||
* @package | ||
* @nocollapse | ||
*/ | ||
Blockly.FieldPitch.fromJson = function(options) { | ||
return new Blockly.FieldPitch(options['pitch']); | ||
CustomFields.FieldPitch.fromJson = function(options) { | ||
return new CustomFields.FieldPitch(options['pitch']); | ||
}; | ||
|
||
/** | ||
* All notes available for the picker. | ||
*/ | ||
Blockly.FieldPitch.NOTES = 'C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4'.split(/ /); | ||
CustomFields.FieldPitch.NOTES = 'C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4'.split(/ /); | ||
|
||
/** | ||
* Show the inline free-text editor on top of the text and the note picker. | ||
* @private | ||
*/ | ||
Blockly.FieldPitch.prototype.showEditor_ = function() { | ||
Blockly.FieldPitch.superClass_.showEditor_.call(this); | ||
CustomFields.FieldPitch.prototype.showEditor_ = function() { | ||
CustomFields.FieldPitch.superClass_.showEditor_.call(this); | ||
|
||
var div = Blockly.WidgetDiv.DIV; | ||
if (!div.firstChild) { | ||
|
@@ -99,7 +101,7 @@ Blockly.FieldPitch.prototype.showEditor_ = function() { | |
* @return {!Element} The newly created pitch picker. | ||
* @private | ||
*/ | ||
Blockly.FieldPitch.prototype.dropdownCreate_ = function() { | ||
CustomFields.FieldPitch.prototype.dropdownCreate_ = function() { | ||
this.imageElement_ = document.createElement('div'); | ||
this.imageElement_.id = 'notePicker'; | ||
|
||
|
@@ -110,7 +112,7 @@ Blockly.FieldPitch.prototype.dropdownCreate_ = function() { | |
* Dispose of events belonging to the pitch editor. | ||
* @private | ||
*/ | ||
Blockly.FieldPitch.prototype.dropdownDispose_ = function() { | ||
CustomFields.FieldPitch.prototype.dropdownDispose_ = function() { | ||
Blockly.unbindEvent_(this.clickWrapper_); | ||
Blockly.unbindEvent_(this.moveWrapper_); | ||
}; | ||
|
@@ -119,7 +121,7 @@ Blockly.FieldPitch.prototype.dropdownDispose_ = function() { | |
* Hide the editor. | ||
* @private | ||
*/ | ||
Blockly.FieldPitch.prototype.hide_ = function() { | ||
CustomFields.FieldPitch.prototype.hide_ = function() { | ||
Blockly.WidgetDiv.hide(); | ||
Blockly.DropDownDiv.hideWithoutAnimation(); | ||
}; | ||
|
@@ -128,7 +130,7 @@ Blockly.FieldPitch.prototype.hide_ = function() { | |
* Set the note to match the mouse's position. | ||
* @param {!Event} e Mouse move event. | ||
*/ | ||
Blockly.FieldPitch.prototype.onMouseMove = function(e) { | ||
CustomFields.FieldPitch.prototype.onMouseMove = function(e) { | ||
var bBox = this.imageElement_.getBoundingClientRect(); | ||
var dy = e.clientY - bBox.top; | ||
var note = Blockly.utils.math.clamp(Math.round(13.5 - dy / 7.5), 0, 12); | ||
|
@@ -141,18 +143,18 @@ Blockly.FieldPitch.prototype.onMouseMove = function(e) { | |
* @param {number|string} value The provided value. | ||
* @return {string|undefined} The respective note, or undefined if invalid. | ||
*/ | ||
Blockly.FieldPitch.prototype.valueToNote = function(value) { | ||
return Blockly.FieldPitch.NOTES[Number(value)]; | ||
CustomFields.FieldPitch.prototype.valueToNote = function(value) { | ||
return CustomFields.FieldPitch.NOTES[Number(value)]; | ||
}; | ||
|
||
/** | ||
* Convert the human-readable text (C3-A4) to machine-readable value (0-12). | ||
* @param {string} text The provided note. | ||
* @return {number|undefined} The respective value, or undefined if invalid. | ||
*/ | ||
Blockly.FieldPitch.prototype.noteToValue = function(text) { | ||
CustomFields.FieldPitch.prototype.noteToValue = function(text) { | ||
var normalizedText = text.trim().toUpperCase(); | ||
var i = Blockly.FieldPitch.NOTES.indexOf(normalizedText); | ||
var i = CustomFields.FieldPitch.NOTES.indexOf(normalizedText); | ||
return i > -1 ? i : undefined; | ||
}; | ||
|
||
|
@@ -162,9 +164,9 @@ Blockly.FieldPitch.prototype.noteToValue = function(text) { | |
* the super class will handle it, likely a string cast of value. | ||
* @protected | ||
*/ | ||
Blockly.FieldPitch.prototype.getText_ = function() { | ||
CustomFields.FieldPitch.prototype.getText_ = function() { | ||
if (this.isBeingEdited_) { | ||
return Blockly.FieldPitch.superClass_.getText_.call(this); | ||
return CustomFields.FieldPitch.superClass_.getText_.call(this); | ||
} | ||
return this.valueToNote(this.getValue()) || null; | ||
}; | ||
|
@@ -174,7 +176,7 @@ Blockly.FieldPitch.prototype.getText_ = function() { | |
* @param {*} value The value stored in this field. | ||
* @returns {string} The text to show on the HTML input. | ||
*/ | ||
Blockly.FieldPitch.prototype.getEditorText_ = function(value) { | ||
CustomFields.FieldPitch.prototype.getEditorText_ = function(value) { | ||
return this.valueToNote(value); | ||
}; | ||
|
||
|
@@ -184,7 +186,7 @@ Blockly.FieldPitch.prototype.getEditorText_ = function(value) { | |
* @param {string} text Text received from the HTML input. | ||
* @returns {*} The value to store. | ||
*/ | ||
Blockly.FieldPitch.prototype.getValueFromEditorText_ = function(text) { | ||
CustomFields.FieldPitch.prototype.getValueFromEditorText_ = function(text) { | ||
return this.noteToValue(text); | ||
}; | ||
|
||
|
@@ -193,16 +195,16 @@ Blockly.FieldPitch.prototype.getValueFromEditorText_ = function(text) { | |
* @private | ||
* @override | ||
*/ | ||
Blockly.FieldPitch.prototype.render_ = function() { | ||
Blockly.FieldPitch.superClass_.render_.call(this); | ||
CustomFields.FieldPitch.prototype.render_ = function() { | ||
CustomFields.FieldPitch.superClass_.render_.call(this); | ||
this.updateGraph_(); | ||
}; | ||
|
||
/** | ||
* Redraw the note picker with the current note. | ||
* @private | ||
*/ | ||
Blockly.FieldPitch.prototype.updateGraph_ = function() { | ||
CustomFields.FieldPitch.prototype.updateGraph_ = function() { | ||
if (!this.imageElement_) { | ||
return; | ||
} | ||
|
@@ -215,7 +217,7 @@ Blockly.FieldPitch.prototype.updateGraph_ = function() { | |
* @param {*} opt_newValue The input value. | ||
* @return {*} A valid value, or null if invalid. | ||
*/ | ||
Blockly.FieldPitch.prototype.doClassValidation_ = function(opt_newValue) { | ||
CustomFields.FieldPitch.prototype.doClassValidation_ = function(opt_newValue) { | ||
if (opt_newValue === null || opt_newValue === undefined) { | ||
return null; | ||
} | ||
|
@@ -226,4 +228,4 @@ Blockly.FieldPitch.prototype.doClassValidation_ = function(opt_newValue) { | |
return null; | ||
}; | ||
|
||
Blockly.fieldRegistry.register('field_pitch', Blockly.FieldPitch); | ||
Blockly.fieldRegistry.register('field_pitch', CustomFields.FieldPitch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.