Skip to content

Commit

Permalink
Restructure to remove Closure’s base.js
Browse files Browse the repository at this point in the history
Soy now doesn’t rely on Closure.
Neither does Blockly.
  • Loading branch information
NeilFraser committed Sep 13, 2019
1 parent 53a52ab commit 05df43d
Show file tree
Hide file tree
Showing 11 changed files with 7,569 additions and 74 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ appengine/*/generated/
appengine/*/*/generated/
appengine/third-party/
json/keys.json
third-party/*
!third-party/soundfonts/
third-party-downloads/*

*.komodoproject
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ALL_JSON = {./,index,puzzle,maze,bird,turtle,movie,music,pond/docs,pond,pond/tut
ALL_TEMPLATES = appengine/template.soy,appengine/index/template.soy,appengine/puzzle/template.soy,appengine/maze/template.soy,appengine/bird/template.soy,appengine/turtle/template.soy,appengine/movie/template.soy,appengine/music/template.soy,appengine/pond/docs/template.soy,appengine/pond/template.soy,appengine/pond/tutor/template.soy,appengine/pond/duck/template.soy,appengine/gallery/template.soy

APP_ENGINE_THIRD_PARTY = appengine/third-party
SOY_COMPILER = java -jar third-party/SoyToJsSrcCompiler.jar --shouldProvideRequireSoyNamespaces --isUsingIjData
SOY_EXTRACTOR = java -jar third-party/SoyMsgExtractor.jar
SOY_COMPILER = java -jar third-party-downloads/SoyToJsSrcCompiler.jar --shouldProvideRequireSoyNamespaces --isUsingIjData
SOY_EXTRACTOR = java -jar third-party-downloads/SoyMsgExtractor.jar

REQUIRED_BINS = svn unzip wget java python sed

Expand Down Expand Up @@ -139,12 +139,12 @@ languages: soy-to-json
deps:
$(foreach bin,$(REQUIRED_BINS),\
$(if $(shell command -v $(bin) 2> /dev/null),$(info Found `$(bin)`),$(error Please install `$(bin)`)))
@# All following commands are in third-party, use backslashes to keep them on the same line as the cd command.
cd third-party; \
mkdir -p third-party-downloads
@# All following commands are in third-party-downloads, use backslashes to keep them on the same line as the cd command.
cd third-party-downloads; \
svn checkout https://github.com/google/closure-library/trunk/closure/bin/build build; \
wget -N https://dl.google.com/closure-templates/closure-templates-for-javascript-latest.zip; \
unzip -o closure-templates-for-javascript-latest.zip SoyToJsSrcCompiler.jar; \
unzip -o closure-templates-for-javascript-latest.zip -d ../$(APP_ENGINE_THIRD_PARTY) soyutils_usegoog.js; \
wget -N https://dl.google.com/closure-templates/closure-templates-msg-extractor-latest.zip; \
unzip -o closure-templates-msg-extractor-latest.zip SoyMsgExtractor.jar; \
wget -N https://dl.google.com/closure-compiler/compiler-latest.zip; \
Expand All @@ -153,23 +153,27 @@ deps:
chmod +x build/closurebuilder.py

mkdir -p $(APP_ENGINE_THIRD_PARTY)
svn checkout https://github.com/google/closure-library/trunk/closure/goog/ $(APP_ENGINE_THIRD_PARTY)/goog
svn checkout https://github.com/google/closure-library/trunk/third_party/closure/goog/ $(APP_ENGINE_THIRD_PARTY)/third_party_goog
svn checkout https://github.com/ajaxorg/ace-builds/trunk/src-min-noconflict/ $(APP_ENGINE_THIRD_PARTY)/ace
svn checkout https://github.com/google/blockly/branches/develop/ $(APP_ENGINE_THIRD_PARTY)/blockly
svn checkout --force https://github.com/ajaxorg/ace-builds/trunk/src-min-noconflict/ $(APP_ENGINE_THIRD_PARTY)/ace
mkdir -p $(APP_ENGINE_THIRD_PARTY)/blockly
svn checkout https://github.com/google/blockly/branches/develop/blocks $(APP_ENGINE_THIRD_PARTY)/blockly/blocks
svn checkout https://github.com/google/blockly/branches/develop/core $(APP_ENGINE_THIRD_PARTY)/blockly/core
svn checkout https://github.com/google/blockly/branches/develop/externs $(APP_ENGINE_THIRD_PARTY)/blockly/externs
svn checkout https://github.com/google/blockly/branches/develop/generators $(APP_ENGINE_THIRD_PARTY)/blockly/generators
svn checkout https://github.com/google/blockly/branches/develop/media $(APP_ENGINE_THIRD_PARTY)/blockly/media
svn checkout https://github.com/google/blockly/branches/develop/msg $(APP_ENGINE_THIRD_PARTY)/blockly/msg
svn checkout https://github.com/CreateJS/SoundJS/trunk/lib/ $(APP_ENGINE_THIRD_PARTY)/SoundJS
cp third-party/base.js $(APP_ENGINE_THIRD_PARTY)/
cp third-party/soyutils.js $(APP_ENGINE_THIRD_PARTY)/
cp -R third-party/soundfonts $(APP_ENGINE_THIRD_PARTY)/

@# messages.js confuses the compiler by also providing "Blockly.Msg.en".
rm $(APP_ENGINE_THIRD_PARTY)/blockly/msg/messages.js
@# Blockly includes a Closure stub that confuses the compiler by also providing "goog".
rm -r $(APP_ENGINE_THIRD_PARTY)/blockly/closure
@# Blockly's date field needs Closure. But we don't use it.
rm -r $(APP_ENGINE_THIRD_PARTY)/blockly/core/field_date.js

svn checkout https://github.com/NeilFraser/JS-Interpreter/trunk/ $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter
@# Remove @license tag so compiler will strip Google's license.
sed 's/@license//' $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter/interpreter.js > $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter/interpreter_.js
@# Compile JS-Interpreter using SIMPLE_OPTIMIZATIONS because the Music game needs to mess with the stack.
java -jar third-party/closure-compiler.jar\
java -jar third-party-downloads/closure-compiler.jar\
--language_out ECMASCRIPT5_STRICT\
--js $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter/acorn.js\
--js $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter/interpreter_.js\
Expand All @@ -183,11 +187,8 @@ clean-languages:
rm -f json/keys.json

clean-deps:
mv third-party/soundfonts third-party-soundfonts
rm -rf $(APP_ENGINE_THIRD_PARTY)
rm -rf third-party
mkdir -p third-party
mv third-party-soundfonts third-party/soundfonts
rm -rf third-party-downloads

# Prevent non-traditional rules from exiting with no changes.
.PHONY: deps
6 changes: 0 additions & 6 deletions appengine/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,12 @@ skip_files:
- ^\w+/sources/.*$
- ^third-party/ace/snippets/.*$
- ^third-party/blockly/\.github/.*$
- ^third-party/blockly/appengine/.*$
- ^third-party/blockly/demos/.*$
- ^third-party/blockly/externs/.*$
- ^third-party/blockly/generators/dart.*$
- ^third-party/blockly/generators/lua.*$
- ^third-party/blockly/generators/php.*$
- ^third-party/blockly/generators/python.*$
- ^third-party/blockly/i18n/.*$
- ^third-party/blockly/local_build/.*$
- ^third-party/blockly/msg/json/.*$
- ^third-party/blockly/tests/.*$
- ^third-party/blockly/theme_scripts/.*$
- ^third-party/blockly/\w*\.\w+$
- ^third-party/JS-Interpreter/demos.*$
- ^third-party/third_party_goog/.*$
Expand Down
4 changes: 2 additions & 2 deletions appengine/music/js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ goog.require('Blockly.Constants.Loops');
goog.require('Blockly.Constants.Math');
goog.require('Blockly.Blocks.procedures');
goog.require('Blockly.Constants.Variables');
goog.require('Blockly.FieldPitch');
goog.require('Blockly.JavaScript');
goog.require('Blockly.JavaScript.lists');
goog.require('Blockly.JavaScript.logic');
Expand All @@ -41,6 +40,7 @@ goog.require('Blockly.JavaScript.math');
goog.require('Blockly.JavaScript.procedures');
goog.require('Blockly.JavaScript.variables');
goog.require('BlocklyGames');
goog.require('CustomFields.FieldPitch');


/**
Expand All @@ -55,7 +55,7 @@ Blockly.Blocks['music_pitch'] = {
*/
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldPitch('7'), 'PITCH');
.appendField(new CustomFields.FieldPitch('7'), 'PITCH');
this.setOutput(true, 'Number');
this.setColour(Blockly.Msg['MATH_HUE']);
this.setTooltip(BlocklyGames.getMsg('Music_pitchTooltip'));
Expand Down
60 changes: 31 additions & 29 deletions appengine/music/js/field_pitch.js
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
Expand All @@ -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) {
Expand Down Expand Up @@ -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';

Expand All @@ -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_);
};
Expand All @@ -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();
};
Expand All @@ -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);
Expand All @@ -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;
};

Expand All @@ -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;
};
Expand All @@ -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);
};

Expand All @@ -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);
};

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
6 changes: 3 additions & 3 deletions appengine/music/js/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ Music.init = function() {
'flute', 'banjo', 'guitar', 'choir'];
var sounds = [];
for (var i = 0; i < instruments.length; i++) {
for (var j = 0; j < Blockly.FieldPitch.NOTES.length; j++) {
for (var j = 0; j < CustomFields.FieldPitch.NOTES.length; j++) {
sounds.push({'src': instruments[i] + '/' +
Blockly.FieldPitch.NOTES[j] + '.mp3',
CustomFields.FieldPitch.NOTES[j] + '.mp3',
id: instruments[i] + j});
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ Music.drawNote = function(i, time, pitch, duration, className) {
img.style.top = top + 'px';
img.style.left = left + 'px';
if (pitch != Music.REST) {
img.title = Blockly.FieldPitch.NOTES[pitch];
img.title = CustomFields.FieldPitch.NOTES[pitch];
}
musicContainer.appendChild(img);
if (!className) {
Expand Down
Loading

0 comments on commit 05df43d

Please sign in to comment.