soiz1 commited on
Commit
fbe84a7
·
verified ·
1 Parent(s): fa5541b

Upload 310 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
.editorconfig ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
.eslintignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *_compressed*.js
2
+ *_uncompressed*.js
3
+ /msg/*
4
+ /core/css.js
5
+ /i18n/*
6
+ /tests/jsunit/*
7
+ /tests/workspace_svg/*
8
+ /tests/blocks/*
9
+ /demos/*
10
+ /accessible/*
11
+ /appengine/*
12
+ /shim/*
13
+ /dist/*
14
+ /gh-pages/*
15
+ /webpack.config.js
16
+ /build/*
.eslintrc ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "extends": "eslint:recommended",
3
+ "rules": {
4
+ "curly": ["error", "multi-line"],
5
+ "eol-last": ["error"],
6
+ "indent": [
7
+ "error", 2, # Blockly/Google use 2-space indents
8
+ # Blockly/Google uses +4 space indents for line continuations.
9
+ {
10
+ "SwitchCase": 1,
11
+ "MemberExpression": 2,
12
+ "ObjectExpression": 1,
13
+ "FunctionDeclaration": {
14
+ "body": 1,
15
+ "parameters": 2
16
+ },
17
+ "FunctionExpression": {
18
+ "body": 1,
19
+ "parameters": 2
20
+ },
21
+ "CallExpression": {
22
+ "arguments": 2
23
+ },
24
+ # Ignore default rules for ternary expressions.
25
+ "ignoredNodes": ["ConditionalExpression"]
26
+ }
27
+ ],
28
+ "linebreak-style": ["off"],
29
+ "max-len": ["error", 120, 4],
30
+ "no-trailing-spaces": ["error", { "skipBlankLines": true }],
31
+ "no-unused-vars": [
32
+ "error",
33
+ {
34
+ "args": "after-used",
35
+ # Ignore vars starting with an underscore.
36
+ "varsIgnorePattern": "^_",
37
+ # Ignore arguments starting with an underscore.
38
+ "argsIgnorePattern": "^_"
39
+ }
40
+ ],
41
+ "no-use-before-define": ["error"],
42
+ "quotes": ["off"], # Blockly mixes single and double quotes
43
+ "semi": ["error", "always"],
44
+ "space-before-function-paren": ["error", "never"], # Blockly doesn't have space before function paren
45
+ "space-infix-ops": ["error"],
46
+ "strict": ["off"], # Blockly uses 'use strict' in files
47
+ "no-cond-assign": ["off"], # Blockly often uses cond-assignment in loops
48
+ "no-redeclare": ["off"], # Closure style allows redeclarations
49
+ "valid-jsdoc": ["error", {"requireReturn": false}],
50
+ "no-console": ["off"],
51
+ "no-constant-condition": ["off"]
52
+ },
53
+ "enviroment": "web",
54
+ "globals": {
55
+ "Blockly": true, # Blockly global
56
+ "goog": true, # goog closure libraries/includes
57
+ }
58
+ }
.github/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Expected Behavior
2
+
3
+ _Please describe what should happen_
4
+
5
+ ### Actual Behavior
6
+
7
+ _Describe what actually happens_
8
+
9
+ ### Steps to Reproduce
10
+
11
+ _Explain what someone needs to do in order to see what's described in *Actual behavior* above_
12
+
13
+ ### Operating System and Browser
14
+
15
+ _e.g. Mac OS 10.11.6 Safari 10.0_
.github/PULL_REQUEST_TEMPLATE.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Resolves
2
+
3
+ _What Github issue does this resolve (please include link)?_
4
+
5
+ ### Proposed Changes
6
+
7
+ _Describe what this Pull Request does_
8
+
9
+ ### Reason for Changes
10
+
11
+ _Explain why these changes should be made_
12
+
13
+ ### Test Coverage
14
+
15
+ _Please show how you have added tests to cover your changes_
.github/workflows/build.yml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Remote Dispatch Action Initiator
2
+ #test
3
+ on: [push]
4
+
5
+ jobs:
6
+ ping-pong:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Repository Dispatch
10
+ uses: peter-evans/[email protected]
11
+ with:
12
+ token: ${{ secrets.t }}
13
+ event-type: update
14
+ repository: PenguinMod/PenguinMod-Gui
.github/workflows/rebuild.yml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Rebuild
2
+ on:
3
+ workflow_dispatch:
4
+ push:
5
+ branches:
6
+ - develop
7
+
8
+ jobs:
9
+ rebuild:
10
+ concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
11
+ runs-on: ubuntu-22.04
12
+ steps:
13
+ - uses: actions/setup-node@v3
14
+ with:
15
+ node-version: 16
16
+ - name: Checkout
17
+ uses: actions/checkout@v3
18
+
19
+ - name: Rebuild
20
+ run: |
21
+ sudo apt install python2
22
+ npm install
23
+ npm run translate
24
+
25
+ - name: Upload built-dist
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: built-dist
29
+ path: dist
30
+ - name: Upload built-media
31
+ uses: actions/upload-artifact@v4
32
+ with:
33
+ name: built-media
34
+ path: media
35
+
36
+ - name: Checkout to develop-builds
37
+ uses: actions/checkout@v3
38
+ with:
39
+ ref: develop-builds
40
+
41
+ - name: Clear out things
42
+ run: |
43
+ rm -rf dist/*
44
+ rm -rf media/*
45
+
46
+ - name: Download built-dist
47
+ uses: actions/download-artifact@v4
48
+ with:
49
+ name: built-dist
50
+ path: dist/
51
+ - name: Download built-media
52
+ uses: actions/download-artifact@v4
53
+ with:
54
+ name: built-media
55
+ path: media/
56
+
57
+ - name: Commit
58
+ uses: EndBug/[email protected]
59
+ with:
60
+ message: "Build"
61
+ committer_name: GitHub Actions
62
+ committer_email: [email protected]
63
+
64
+ - name: Repository Dispatch
65
+ uses: peter-evans/[email protected]
66
+ with:
67
+ token: ${{ secrets.t }}
68
+ event-type: update
69
+ repository: PenguinMod/penguinmod.github.io
.gitignore ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # OSX
2
+ .DS_Store
3
+
4
+ # NPM
5
+ /node_modules
6
+ npm-*
7
+
8
+ # Localization / I18N
9
+ common.pyc
10
+ .settings
11
+ .project
12
+ *.pyc
13
+ *.komodoproject
14
+ /nbproject/private/
15
+
16
+ # Unused by scratch-blocks
17
+ dart_compressed.js
18
+ javascript_compressed.js
19
+ lua_compressed.js
20
+ php_compressed.js
21
+ python_compressed.js
22
+
23
+ # Editor
24
+ .vscode
25
+
26
+ /accessible/*
27
+ /dist
28
+ /msg/js/*
29
+ !/msg/js/en.js
30
+ /msg/json/*
31
+ !/msg/json/en.json
32
+ /blockly_compressed_horizontal.js
33
+ /blockly_compressed_vertical.js
34
+ /blockly_uncompressed_horizontal.js
35
+ /blockly_uncompressed_vertical.js
36
+ /blocks_compressed_horizontal.js
37
+ /blocks_compressed_vertical.js
38
+ /blocks_compressed.js
39
+ /gh-pages/main.js
40
+ /gh-pages/playgrounds
41
+ /gh-pages/Gemfile.lock
42
+ /gh-pages/closure-library
43
+ /gh-pages/_site
44
+ /*compiler*.jar
45
+ /local_blockly_compressed_vertical.js
46
+ /chromedriver
.gitpod.yml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # This configuration file was automatically generated by Gitpod.
2
+ # Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
3
+ # and commit this file to your remote git repository to share the goodness with others.
4
+
5
+ # Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
6
+
7
+ tasks:
8
+ - init: npm install
9
+
10
+
.npmignore ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Development files
2
+ .eslintrc
3
+ /.editorconfig
4
+ /.eslintignore
5
+ /.gitattributes
6
+ /.github
7
+ /.travis.yml
8
+ /.tx
9
+ /tests
10
+ /webpack.config.js
11
+
12
+ # Localization / I18N
13
+ common.pyc
14
+ .settings
15
+ .project
16
+ *.pyc
17
+ *.komodoproject
18
+ /nbproject/private/
19
+
20
+ /accessible/*
21
+
22
+ # Build created files
23
+ /gh-pages
24
+
25
+ # Exclude already built packages from testing with npm pack
26
+ /scratch-blocks-*.{tar,tgz}
.npmrc ADDED
@@ -0,0 +1 @@
 
 
1
+ registry=https://registry.npmjs.org/
.travis.yml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ language: node_js
2
+ node_js:
3
+ - "12"
4
+ env:
5
+ global:
6
+ - NPM_TAG=latest
7
+ - RELEASE_VERSION="0.1.0-prerelease.$(date +'%Y%m%d%H%M%S')"
8
+ addons:
9
+ chrome: stable
10
+ cache:
11
+ directories:
12
+ - node_modules
13
+
14
+ before_install:
15
+ # Symlink closure library
16
+ - ln -s $(npm root)/google-closure-library ../closure-library
17
+
18
+ before_script:
19
+ - export DISPLAY=:99.0
20
+ - tests/scripts/setup_linux_env.sh
21
+ - sleep 2
22
+ script:
23
+ - i18n/sync_translations.sh
24
+ - npm test
25
+ before_deploy:
26
+ - >
27
+ if [ -z "$BEFORE_DEPLOY_RAN" ]; then
28
+ npm --no-git-tag-version version $RELEASE_VERSION
29
+ if [[ "$TRAVIS_BRANCH" == hotfix/* ]]; then export NPM_TAG=hotfix; fi # double brackets are important for matching the wildcard
30
+ git config --global user.email $(git log --pretty=format:"%ae" -n1)
31
+ git config --global user.name $(git log --pretty=format:"%an" -n1)
32
+ export BEFORE_DEPLOY_RAN=true
33
+ fi
34
+ deploy:
35
+ - provider: npm
36
+ on:
37
+ branch:
38
+ - master
39
+ - develop
40
+ - hotfix/*
41
+ skip_cleanup: true
42
+ email: $NPM_EMAIL
43
+ api_key: $NPM_TOKEN
44
+ tag: $NPM_TAG
45
+ - provider: script
46
+ on:
47
+ all_branches: true
48
+ condition: $TRAVIS_EVENT_TYPE != cron && ! $TRAVIS_BRANCH =~ ^greenkeeper/
49
+ tags: false # Don't push tags to gh-pages
50
+ skip_cleanup: true
51
+ script: npm run --silent deploy -- -x -r https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
.tx/config ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [main]
2
+ host = https://www.transifex.com
3
+ lang_map = zh_CN:zh-cn, zh_TW:zh-tw, pt_BR:pt-br, es_419:es-419
4
+
5
+ [scratch-editor.blocks]
6
+ file_filter = msg/json/<lang>.json
7
+ source_file = msg/json/en.json
8
+ source_lang = en
9
+ type = KEYVALUEJSON
.vscode/settings.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "githubPullRequests.ignoredPullRequestBranches": [
3
+ "develop"
4
+ ]
5
+ }
LICENSE ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ <one line to give the program's name and a brief idea of what it does.>
635
+ Copyright (C) <year> <name of author>
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ <program> Copyright (C) <year> <name of author>
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <https://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <https://www.gnu.org/licenses/why-not-lgpl.html>.
README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PenguinMod-Blocks
2
+
3
+ <!-- ## Playgrounds
4
+
5
+ - **Vertical blocks**: https://turbowa arp.github.io/scratch-blocks/tests/vertical_playground_compressed.html -->
6
+
7
+ <!--
8
+ #### Scratch Blocks is a library for building creative computing interfaces.
9
+ [![Build Status](https://travis-ci.org/LLK/scratch-blocks.svg?branch=develop)](https://travis-ci.org/LLK/scratch-blocks)
10
+ [![Dependency Status](https://david-dm.org/LLK/scratch-blocks.svg)](https://david-dm.org/LLK/scratch-blocks)
11
+ [![devDependency Status](https://david-dm.org/LLK/scratch-blocks/dev-status.svg)](https://david-dm.org/LLK/scratch-blocks#info=devDependencies)
12
+ -->
13
+
14
+ ![](https://cloud.githubusercontent.com/assets/747641/15227351/c37c09da-1854-11e6-8dc7-9a298f2b1f01.jpg)
15
+
16
+ <!--
17
+ ## Introduction
18
+ Scratch Blocks is a fork of Google's [Blockly](https://github.com/google/blockly) project that provides a design specification and codebase for building creative computing interfaces. Together with the [Scratch Virtual Machine (VM)](https://github.com/LLK/scratch-vm) this codebase allows for the rapid design and development of visual programming interfaces. Unlike [Blockly](https://github.com/google/blockly), Scratch Blocks does not use [code generators](https://developers.google.com/blockly/guides/configure/web/code-generators), but rather leverages the [Scratch Virtual Machine](https://github.com/LLK/scratch-vm) to create highly dynamic, interactive programming environments.
19
+
20
+ *This project is in active development and should be considered a "developer preview" at this time.*
21
+
22
+ ## Two Types of Blocks
23
+ ![](https://cloud.githubusercontent.com/assets/747641/15255731/dad4d028-190b-11e6-9c16-8df7445adc96.png)
24
+
25
+ Scratch Blocks brings together two different programming "grammars" that the Scratch Team has designed and continued to refine over the past decade. The standard [Scratch](https://scratch.mit.edu) grammar uses blocks that snap together vertically, much like LEGO bricks. For our [ScratchJr](https://scratchjr.org) software, intended for younger children, we developed blocks that are labelled with icons rather than words, and snap together horizontally rather than vertically. We have found that the horizontal grammar is not only friendlier for beginning programmers but also better suited for devices with small screens.
26
+
27
+ ## Documentation
28
+ The "getting started" guide including [FAQ](https://scratch.mit.edu/developers#faq) and [design documentation](https://github.com/LLK/scratch-blocks/wiki/Design) can be found in the [wiki](https://github.com/LLK/scratch-blocks/wiki).
29
+
30
+ ## Donate
31
+ We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep it that way! Please consider making a [donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!
32
+ -->
TRADEMARK ADDED
@@ -0,0 +1 @@
 
 
1
+ The Scratch trademarks, including the Scratch name, logo, the Scratch Cat, Gobo, Pico, Nano, Tera and Giga graphics (the "Marks"), are property of the Massachusetts Institute of Technology (MIT). Marks may not be used to endorse or promote products derived from this software without specific prior written permission.
blocks_common/colour.js ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Colour blocks for Blockly.
23
+ * @author [email protected] (Neil Fraser)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Blocks.colour');
28
+
29
+ goog.require('Blockly.Blocks');
30
+
31
+ goog.require('Blockly.constants');
32
+
33
+ /**
34
+ * Pick a random colour.
35
+ * @return {string} #RRGGBB for random colour.
36
+ */
37
+ function randomColour() {
38
+ var num = Math.floor(Math.random() * Math.pow(2, 24));
39
+ return '#' + ('00000' + num.toString(16)).substr(-6);
40
+ }
41
+
42
+ Blockly.Blocks['colour_picker'] = {
43
+ /**
44
+ * Block for colour picker.
45
+ * @this Blockly.Block
46
+ */
47
+ init: function() {
48
+ this.jsonInit({
49
+ "message0": "%1",
50
+ "args0": [
51
+ {
52
+ "type": "field_colour_slider",
53
+ "name": "COLOUR",
54
+ "colour": randomColour()
55
+ }
56
+ ],
57
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
58
+ "output": "Colour"
59
+ });
60
+ }
61
+ };
blocks_common/custom.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @fileoverview Custom blocks for Blockly.
3
+ * @author @SharkPool-SP (SharkPool)
4
+ */
5
+ 'use strict';
6
+
7
+ goog.provide('Blockly.Blocks.customInput');
8
+
9
+ goog.require('Blockly.Blocks');
10
+
11
+ goog.require('Blockly.Colours');
12
+
13
+ goog.require('Blockly.constants');
14
+
15
+ Blockly.Blocks['customInput'] = {
16
+ /**
17
+ * Block for custom inputs.
18
+ * @this Blockly.Block
19
+ */
20
+ init: function() {
21
+ this.jsonInit({
22
+ "message0": "%1",
23
+ "args0": [
24
+ {
25
+ "type": "field_customInput",
26
+ "name": "CUSTOM"
27
+ }
28
+ ],
29
+ "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
30
+ "output": "String",
31
+ "extensions": ["colours_pen"]
32
+ });
33
+ }
34
+ };
blocks_common/math.js ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Math blocks for Blockly.
23
+ * @author [email protected] (Quynh Neutron)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Blocks.math');
28
+
29
+ goog.require('Blockly.Blocks');
30
+
31
+ goog.require('Blockly.Colours');
32
+
33
+ goog.require('Blockly.constants');
34
+
35
+ Blockly.Blocks['math_number'] = {
36
+ /**
37
+ * Block for generic numeric value.
38
+ * @this Blockly.Block
39
+ */
40
+ init: function() {
41
+ this.jsonInit({
42
+ "message0": "%1",
43
+ "args0": [
44
+ {
45
+ "type": "field_number",
46
+ "name": "NUM",
47
+ "value": "0"
48
+ }
49
+ ],
50
+ "output": "Number",
51
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
52
+ "colour": Blockly.Colours.textField,
53
+ "colourSecondary": Blockly.Colours.textField,
54
+ "colourTertiary": Blockly.Colours.textField
55
+ });
56
+ }
57
+ };
58
+
59
+ Blockly.Blocks['math_integer'] = {
60
+ /**
61
+ * Block for integer value (no decimal, + or -).
62
+ * @this Blockly.Block
63
+ */
64
+ init: function() {
65
+ this.jsonInit({
66
+ "message0": "%1",
67
+ "args0": [
68
+ {
69
+ "type": "field_number",
70
+ "name": "NUM",
71
+ "precision": 1
72
+ }
73
+ ],
74
+ "output": "Number",
75
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
76
+ "colour": Blockly.Colours.textField,
77
+ "colourSecondary": Blockly.Colours.textField,
78
+ "colourTertiary": Blockly.Colours.textField
79
+ });
80
+ }
81
+ };
82
+
83
+ Blockly.Blocks['math_whole_number'] = {
84
+ /**
85
+ * Block for whole number value, no negatives or decimals.
86
+ * @this Blockly.Block
87
+ */
88
+ init: function() {
89
+ this.jsonInit({
90
+ "message0": "%1",
91
+ "args0": [
92
+ {
93
+ "type": "field_number",
94
+ "name": "NUM",
95
+ "min": 0,
96
+ "precision": 1
97
+ }
98
+ ],
99
+ "output": "Number",
100
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
101
+ "colour": Blockly.Colours.textField,
102
+ "colourSecondary": Blockly.Colours.textField,
103
+ "colourTertiary": Blockly.Colours.textField
104
+ });
105
+ }
106
+ };
107
+
108
+ Blockly.Blocks['math_positive_number'] = {
109
+ /**
110
+ * Block for positive number value, with decimal.
111
+ * @this Blockly.Block
112
+ */
113
+ init: function() {
114
+ this.jsonInit({
115
+ "message0": "%1",
116
+ "args0": [
117
+ {
118
+ "type": "field_number",
119
+ "name": "NUM",
120
+ "min": 0
121
+ }
122
+ ],
123
+ "output": "Number",
124
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
125
+ "colour": Blockly.Colours.textField,
126
+ "colourSecondary": Blockly.Colours.textField,
127
+ "colourTertiary": Blockly.Colours.textField
128
+ });
129
+ }
130
+ };
131
+
132
+ Blockly.Blocks['math_angle'] = {
133
+ /**
134
+ * Block for angle picker.
135
+ * @this Blockly.Block
136
+ */
137
+ init: function() {
138
+ this.jsonInit({
139
+ "message0": "%1",
140
+ "args0": [
141
+ {
142
+ "type": "field_angle",
143
+ "name": "NUM",
144
+ "value": 90
145
+ }
146
+ ],
147
+ "output": "Number",
148
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
149
+ "colour": Blockly.Colours.textField,
150
+ "colourSecondary": Blockly.Colours.textField,
151
+ "colourTertiary": Blockly.Colours.textField
152
+ });
153
+ }
154
+ };
blocks_common/matrix.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Matrix blocks for Blockly.
23
+ * @author [email protected] (Kreg Hanning)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Blocks.matrix');
28
+
29
+ goog.require('Blockly.Blocks');
30
+
31
+ goog.require('Blockly.Colours');
32
+
33
+ goog.require('Blockly.constants');
34
+
35
+ Blockly.Blocks['matrix'] = {
36
+ /**
37
+ * Block for matrix value.
38
+ * @this Blockly.Block
39
+ */
40
+ init: function() {
41
+ this.jsonInit({
42
+ "message0": "%1",
43
+ "args0": [
44
+ {
45
+ "type": "field_matrix",
46
+ "name": "MATRIX"
47
+ }
48
+ ],
49
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
50
+ "output": "Number",
51
+ "extensions": ["colours_pen"]
52
+ });
53
+ }
54
+ };
blocks_common/note.js ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Note block.
23
+ * @author [email protected] (Eric Rosenbaum)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Blocks.note');
28
+
29
+ goog.require('Blockly.Blocks');
30
+
31
+ goog.require('Blockly.Colours');
32
+
33
+ goog.require('Blockly.constants');
34
+
35
+ Blockly.Blocks['note'] = {
36
+ /**
37
+ * Block for musical note value.
38
+ * @this Blockly.Block
39
+ */
40
+ init: function() {
41
+ this.jsonInit({
42
+ "message0": "%1",
43
+ "args0": [
44
+ {
45
+ "type": "field_note",
46
+ "name": "NOTE",
47
+ "value": 60
48
+ }
49
+ ],
50
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
51
+ "output": "Number",
52
+ "colour": Blockly.Colours.textField,
53
+ "colourSecondary": Blockly.Colours.textField,
54
+ "colourTertiary": Blockly.Colours.textField
55
+ });
56
+ }
57
+ };
blocks_common/polygon.js ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @fileoverview Polygon block.
3
+ * @author @RedMan13 (godslayerakp) & SharkPool
4
+ */
5
+ 'use strict';
6
+
7
+ // TODO set the default value for checkboxes so the arrow doesnt point the wrong way on duplication/flyout click
8
+
9
+ goog.provide('Blockly.Blocks.polygon');
10
+ goog.require('Blockly.Blocks');
11
+ goog.require('Blockly.Colours');
12
+ goog.require('Blockly.constants');
13
+
14
+ const getXYForPoint = (point, points, opt_offset, opt_scale) => {
15
+ const offset = Array.isArray(opt_offset)
16
+ ? opt_offset
17
+ : [0,0];
18
+ const scale = typeof opt_scale === 'number'
19
+ ? opt_scale
20
+ : 10;
21
+ const origin = 360 / points;
22
+
23
+ const dir = Blockly.utils.toRadians(((origin * point) - (origin / 2)) - 90);
24
+ const x = Math.cos(dir) * scale;
25
+ const y = Math.sin(dir) * scale;
26
+ return [x + offset[0],y + offset[1]];
27
+ }
28
+
29
+ Blockly.Blocks['polygon'] = {
30
+ /**
31
+ * Block for complex shapes.
32
+ * @this Blockly.Block
33
+ */
34
+ init: function() {
35
+ this.color = Blockly.Colours.pen.primary;
36
+ this.needsInit = true;
37
+ this.expanded = true;
38
+ this.points = 0;
39
+ this.offset = [0,0];
40
+ this.scale = 50;
41
+ this.oldConnections = {};
42
+ this.myBlocks = {};
43
+ this.initGenerate();
44
+ },
45
+ mutationToDom: function() {
46
+ const container = document.createElement('mutation');
47
+
48
+ container.setAttribute('points', JSON.stringify(this.points));
49
+ container.setAttribute('color', this.color);
50
+ container.setAttribute('midle', JSON.stringify(this.offset));
51
+ container.setAttribute('scale', JSON.stringify(this.scale));
52
+ container.setAttribute('expanded', JSON.stringify(this.expanded));
53
+ container.setAttribute('needsInit', JSON.stringify(this.needsInit));
54
+ return container;
55
+ },
56
+ domToMutation: function(xmlElement) {
57
+ const newPoints = JSON.parse(xmlElement.getAttribute('points'));
58
+ const newColor = xmlElement.getAttribute('color') || '';
59
+ const newOffset = JSON.parse(xmlElement.getAttribute('midle') || '""');
60
+ const newScale = JSON.parse(xmlElement.getAttribute('scale') || '""');
61
+ const isInit = JSON.parse(xmlElement.getAttribute('needsInit') || 'true');
62
+ const newExpanded = false;
63
+ if (newPoints !== this.points) {
64
+ this.clear();
65
+ this.points = newPoints;
66
+ if (isInit) this.initGenerate();
67
+ else this.generate();
68
+ }
69
+ if (typeof newColor === 'string') {
70
+ this.color = newColor;
71
+ }
72
+ if (newOffset && Array.isArray(newOffset)) {
73
+ this.offset = newOffset;
74
+ }
75
+ if (typeof newScale === 'number') {
76
+ this.length = newScale;
77
+ }
78
+ if (typeof newExpanded === 'boolean' && newExpanded !== this.expanded) {
79
+ this.setExpanded(newExpanded);
80
+ this.setFieldValue(newExpanded, 'button');
81
+ }
82
+ },
83
+ clear: function() {
84
+ const connections = {};
85
+ for (let point = 1; point <= this.points; point++) {
86
+ const xName = `x${point}`;
87
+ const yName = `y${point}`;
88
+ const xInput = this.getInput(xName);
89
+ const yInput = this.getInput(yName);
90
+ connections[xName] = xInput.connection.targetConnection;
91
+ connections[yName] = yInput.connection.targetConnection;
92
+ this.removeInput(xName);
93
+ this.removeInput(yName);
94
+ }
95
+
96
+ this.removeInput('buttonContainer');
97
+ this.oldConnections = connections;
98
+ },
99
+ initGenerate: function() {
100
+ this.setColour(this.color, this.color, this.color);
101
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE);
102
+ this.setOutput(true, 'math_polygon');
103
+ this.setShadow(true);
104
+
105
+ const thisBlock = this;
106
+ const button = new Blockly.FieldCheckbox(
107
+ this.expanded,
108
+ newState => {
109
+ if (this.isInFlyout) return;
110
+ this.needsInit = false;
111
+ this.generate();
112
+ this.inputList[0].setVisible(false);
113
+ this.render();
114
+ return newState;
115
+ }
116
+ )
117
+ this.appendDummyInput('buttonContainer')
118
+ .appendField(button, 'button');
119
+ this.render(true);
120
+ },
121
+ generate: function() {
122
+ const connections = this.oldConnections;
123
+ // create all the node inputs
124
+ for (let point = 1; point <= this.points; point++) {
125
+ const xName = `x${point}`;
126
+ const yName = `y${point}`;
127
+ const xInput = this.appendValueInput(xName);
128
+ const yInput = this.appendValueInput(yName);
129
+ const xConnection = xInput.connection;
130
+ const yConnection = yInput.connection;
131
+ // dispose of any free-floating blocks that where created by this block
132
+ if (this.myBlocks[xName] && !this.myBlocks[xName].outputConnection.targetConnection) {
133
+ this.myBlocks[xName].dispose();
134
+ delete this.myBlocks[xName];
135
+ }
136
+ if (this.myBlocks[yName] && !this.myBlocks[yName].outputConnection.targetConnection) {
137
+ this.myBlocks[yName].dispose();
138
+ delete this.myBlocks[yName];
139
+ }
140
+ // if this point isnt filled in, fill it in
141
+ if (!this.getInput(xName).connection.targetConnection || !this.getInput(yName).connection.targetConnection) {
142
+ const newxBlock = this.workspace.newBlock('math_number');
143
+ const newyBlock = this.workspace.newBlock('math_number');
144
+ const initialValue = getXYForPoint(point - 1, this.points, this.offset, this.scale)
145
+ newxBlock.setFieldValue(String(initialValue[0]), 'NUM');
146
+ newyBlock.setFieldValue(String(initialValue[1]), 'NUM');
147
+ newxBlock.setShadow(true);
148
+ newyBlock.setShadow(true);
149
+ newxBlock.initSvg();
150
+ newyBlock.initSvg();
151
+ newxBlock.render(true);
152
+ newyBlock.render(true);
153
+
154
+ newxBlock.outputConnection.connect(xConnection);
155
+ newyBlock.outputConnection.connect(yConnection);
156
+ this.myBlocks[xName] = newxBlock;
157
+ this.myBlocks[yName] = newyBlock;
158
+ }
159
+ // if we have a cached connection for this point then connect it
160
+ if (connections[xName] || connections[yName]) {
161
+ const xBlock = connections[xName].getSourceBlock();
162
+ const yBlock = connections[yName].getSourceBlock();
163
+ connections[xName].connect(xConnection);
164
+ connections[yName].connect(yConnection);
165
+ // re-render the blocks after connecting them
166
+ xBlock.initSvg();
167
+ yBlock.initSvg();
168
+ xBlock.render(false);
169
+ yBlock.render(false);
170
+ }
171
+ xInput.appendField('x: ');
172
+ yInput.appendField('y: ');
173
+ }
174
+
175
+ this.setColour(this.color, this.color, this.color);
176
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE);
177
+ this.setOutput(true, 'math_polygon');
178
+ this.setShadow(true);
179
+
180
+ const thisBlock = this;
181
+ const button = new Blockly.FieldCheckbox(
182
+ this.expanded,
183
+ newState => {
184
+ this.needsInit = false;
185
+ thisBlock.setExpanded(newState);
186
+ return newState;
187
+ }
188
+ )
189
+ this.appendDummyInput('buttonContainer')
190
+ .appendField(button, 'button');
191
+ this.render(true);
192
+ },
193
+ setExpanded: function(bool) {
194
+ if (this.needsInit) return;
195
+ this.expanded = bool;
196
+ for (let point = 1; point <= this.points; point++) {
197
+ const xName = `x${point}`;
198
+ const yName = `y${point}`;
199
+ const xInput = this.getInput(xName);
200
+ const yInput = this.getInput(yName);
201
+ xInput.visible_ = !bool;
202
+ xInput.setVisible(bool);
203
+ yInput.visible_ = !bool;
204
+ yInput.setVisible(bool);
205
+ }
206
+ this.initSvg();
207
+ // we dont need to re-render this block since renderChildren will render all parents aswell
208
+ this.rerenderChildBlocks();
209
+ },
210
+ rerenderChildBlocks: function() {
211
+ const renderInputs = (block) => {
212
+ const children = block.childBlocks_;
213
+ // once we hit a bottom block, rerender the whole tree
214
+ if (children.length) block.render(true);
215
+ for (var i = 0, child; child = children[i]; i++) {
216
+ child.render(false);
217
+ renderInputs(child);
218
+ }
219
+ }
220
+ renderInputs(this);
221
+ }
222
+ };
blocks_common/text.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Text blocks for Blockly.
23
+ * @author [email protected] (Neil Fraser)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Blocks.texts');
28
+
29
+ goog.require('Blockly.Blocks');
30
+
31
+ goog.require('Blockly.Colours');
32
+
33
+ goog.require('Blockly.constants');
34
+
35
+ Blockly.Blocks['text'] = {
36
+ /**
37
+ * Block for text value.
38
+ * @this Blockly.Block
39
+ */
40
+ init: function() {
41
+ this.jsonInit({
42
+ "message0": "%1",
43
+ "args0": [
44
+ {
45
+ "type": "field_input",
46
+ "name": "TEXT"
47
+ }
48
+ ],
49
+ "output": "String",
50
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
51
+ "colour": Blockly.Colours.textField,
52
+ "colourSecondary": Blockly.Colours.textField,
53
+ "colourTertiary": Blockly.Colours.textField
54
+ });
55
+ }
56
+ };
blocks_vertical/control.js ADDED
@@ -0,0 +1,1117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.control');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
28
+
29
+
30
+ Blockly.Blocks['control_forever'] = {
31
+ /**
32
+ * Block for repeat n times (external number).
33
+ * https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#5eke39
34
+ * @this Blockly.Block
35
+ */
36
+ init: function() {
37
+ this.jsonInit({
38
+ "id": "control_forever",
39
+ "message0": Blockly.Msg.CONTROL_FOREVER,
40
+ "message1": "%1", // Statement
41
+ "message2": "%1", // Icon
42
+ "lastDummyAlign2": "RIGHT",
43
+ "args1": [
44
+ {
45
+ "type": "input_statement",
46
+ "check": 'normal',
47
+ "name": "SUBSTACK"
48
+ }
49
+ ],
50
+ "args2": [
51
+ {
52
+ "type": "field_image",
53
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
54
+ "width": 24,
55
+ "height": 24,
56
+ "alt": "*",
57
+ "flip_rtl": true
58
+ }
59
+ ],
60
+ "category": Blockly.Categories.control,
61
+ "extensions": ["colours_control", "shape_end"]
62
+ });
63
+ }
64
+ };
65
+
66
+ Blockly.Blocks['control_repeat'] = {
67
+ /**
68
+ * Block for repeat n times (external number).
69
+ * https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#so57n9
70
+ * @this Blockly.Block
71
+ */
72
+ init: function() {
73
+ this.jsonInit({
74
+ "id": "control_repeat",
75
+ "message0": Blockly.Msg.CONTROL_REPEAT,
76
+ "message1": "%1", // Statement
77
+ "message2": "%1", // Icon
78
+ "lastDummyAlign2": "RIGHT",
79
+ "args0": [
80
+ {
81
+ "type": "input_value",
82
+ "name": "TIMES"
83
+ }
84
+ ],
85
+ "args1": [
86
+ {
87
+ "type": "input_statement",
88
+ "check": 'normal',
89
+ "name": "SUBSTACK"
90
+ }
91
+ ],
92
+ "args2": [
93
+ {
94
+ "type": "field_image",
95
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
96
+ "width": 24,
97
+ "height": 24,
98
+ "alt": "*",
99
+ "flip_rtl": true
100
+ }
101
+ ],
102
+ "category": Blockly.Categories.control,
103
+ "extensions": ["colours_control", "shape_statement"]
104
+ });
105
+ }
106
+ };
107
+
108
+ Blockly.Blocks['control_repeatForSeconds'] = {
109
+ /**
110
+ * pm: Block to repeat for n seconds (external number).
111
+ * @this Blockly.Block
112
+ */
113
+ init: function() {
114
+ this.jsonInit({
115
+ "id": "control_repeatForSeconds",
116
+ "message0": "repeat for %1 seconds",
117
+ "message1": "%1", // Statement
118
+ "message2": "%1", // Icon
119
+ "lastDummyAlign2": "RIGHT",
120
+ "args0": [
121
+ {
122
+ "type": "input_value",
123
+ "name": "TIMES"
124
+ }
125
+ ],
126
+ "args1": [
127
+ {
128
+ "type": "input_statement",
129
+ "check": 'normal',
130
+ "name": "SUBSTACK"
131
+ }
132
+ ],
133
+ "args2": [
134
+ {
135
+ "type": "field_image",
136
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
137
+ "width": 24,
138
+ "height": 24,
139
+ "alt": "*",
140
+ "flip_rtl": true
141
+ }
142
+ ],
143
+ "category": Blockly.Categories.control,
144
+ "extensions": ["colours_control", "shape_statement"]
145
+ });
146
+ }
147
+ };
148
+
149
+ Blockly.Blocks['control_if'] = {
150
+ /**
151
+ * Block for if-then.
152
+ * @this Blockly.Block
153
+ */
154
+ init: function() {
155
+ this.jsonInit({
156
+ "type": "control_if",
157
+ "message0": Blockly.Msg.CONTROL_IF,
158
+ "message1": "%1", // Statement
159
+ "args0": [
160
+ {
161
+ "type": "input_value",
162
+ "name": "CONDITION",
163
+ "check": "Boolean"
164
+ }
165
+ ],
166
+ "args1": [
167
+ {
168
+ "type": "input_statement",
169
+ "check": 'normal',
170
+ "name": "SUBSTACK"
171
+ }
172
+ ],
173
+ "category": Blockly.Categories.control,
174
+ "extensions": ["colours_control", "shape_statement"]
175
+ });
176
+ }
177
+ };
178
+
179
+ Blockly.Blocks['control_if_else'] = {
180
+ /**
181
+ * Block for if-else.
182
+ * @this Blockly.Block
183
+ */
184
+ init: function() {
185
+ this.jsonInit({
186
+ "type": "control_if_else",
187
+ "message0": Blockly.Msg.CONTROL_IF,
188
+ "message1": "%1",
189
+ "message2": Blockly.Msg.CONTROL_ELSE,
190
+ "message3": "%1",
191
+ "args0": [
192
+ {
193
+ "type": "input_value",
194
+ "name": "CONDITION",
195
+ "check": "Boolean"
196
+ }
197
+ ],
198
+ "args1": [
199
+ {
200
+ "type": "input_statement",
201
+ "check": 'normal',
202
+ "name": "SUBSTACK"
203
+ }
204
+ ],
205
+ "args3": [
206
+ {
207
+ "type": "input_statement",
208
+ "check": 'normal',
209
+ "name": "SUBSTACK2"
210
+ }
211
+ ],
212
+ "category": Blockly.Categories.control,
213
+ "extensions": ["colours_control", "shape_statement"]
214
+ });
215
+ }
216
+ };
217
+
218
+
219
+ Blockly.Blocks['control_try_catch'] = {
220
+ /**
221
+ * Block for try-catch.
222
+ * @this Blockly.Block
223
+ */
224
+ init: function () {
225
+ this.jsonInit({
226
+ "type": "control_try_catch",
227
+ "message0": "try to do",
228
+ "message1": "%1",
229
+ "message2": "if a block errors",
230
+ "message3": "%1",
231
+ "args1": [
232
+ {
233
+ "type": "input_statement",
234
+ "check": 'normal',
235
+ "name": "SUBSTACK"
236
+ }
237
+ ],
238
+ "args3": [
239
+ {
240
+ "type": "input_statement",
241
+ "check": 'normal',
242
+ "name": "SUBSTACK2"
243
+ }
244
+ ],
245
+ "category": Blockly.Categories.control,
246
+ "extensions": ["colours_control", "shape_statement"]
247
+ });
248
+ }
249
+ };
250
+
251
+ Blockly.Blocks['control_throw_error'] = {
252
+ init: function () {
253
+ this.jsonInit({
254
+ "message0": 'throw error %1',
255
+ "args0": [
256
+ {
257
+ "type": "input_value",
258
+ "name": "ERROR"
259
+ }
260
+ ],
261
+ "category": Blockly.Categories.control,
262
+ "extensions": ["colours_control", "shape_end"]
263
+ });
264
+ }
265
+ };
266
+
267
+ Blockly.Blocks['control_error'] = {
268
+ /**
269
+ * pm: Block to get a try catch error.
270
+ * @this Blockly.Block
271
+ */
272
+ init: function () {
273
+ this.jsonInit({
274
+ "message0": "error",
275
+ "category": Blockly.Categories.control,
276
+ "extensions": ["colours_control", "output_string"]
277
+ });
278
+ }
279
+ };
280
+
281
+ Blockly.Blocks['control_stop'] = {
282
+ /**
283
+ * Block for stop all scripts.
284
+ * @this Blockly.Block
285
+ */
286
+ init: function() {
287
+ var ALL_SCRIPTS = 'all';
288
+ var THIS_SCRIPT = 'this script';
289
+ var OTHER_SCRIPTS = 'other scripts in sprite';
290
+ var stopDropdown = new Blockly.FieldDropdown(function() {
291
+ if (this.sourceBlock_ &&
292
+ this.sourceBlock_.nextConnection &&
293
+ this.sourceBlock_.nextConnection.isConnected()) {
294
+ return [
295
+ [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
296
+ ];
297
+ }
298
+ return [[Blockly.Msg.CONTROL_STOP_ALL, ALL_SCRIPTS],
299
+ [Blockly.Msg.CONTROL_STOP_THIS, THIS_SCRIPT],
300
+ [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
301
+ ];
302
+ }, function(option) {
303
+ // Create an event group to keep field value and mutator in sync
304
+ // Return null at the end because setValue is called here already.
305
+ Blockly.Events.setGroup(true);
306
+ var oldMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
307
+ this.sourceBlock_.setNextStatement(option == OTHER_SCRIPTS, "normal");
308
+ var newMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
309
+ Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_,
310
+ 'mutation', null, oldMutation, newMutation));
311
+ this.setValue(option);
312
+ Blockly.Events.setGroup(false);
313
+ return null;
314
+ });
315
+ this.appendDummyInput()
316
+ .appendField(Blockly.Msg.CONTROL_STOP)
317
+ .appendField(stopDropdown, 'STOP_OPTION');
318
+ this.setCategory(Blockly.Categories.control);
319
+ this.setColour(Blockly.Colours.control.primary,
320
+ Blockly.Colours.control.secondary,
321
+ Blockly.Colours.control.tertiary
322
+ );
323
+ this.setPreviousStatement(true, "normal");
324
+ },
325
+ mutationToDom: function() {
326
+ var container = document.createElement('mutation');
327
+ container.setAttribute('hasnext', this.nextConnection != null);
328
+ return container;
329
+ },
330
+ domToMutation: function(xmlElement) {
331
+ var hasNext = (xmlElement.getAttribute('hasnext') == 'true');
332
+ this.setNextStatement(hasNext, "normal");
333
+ }
334
+ };
335
+
336
+ Blockly.Blocks['control_wait'] = {
337
+ /**
338
+ * Block to wait (pause) stack.
339
+ * @this Blockly.Block
340
+ */
341
+ init: function() {
342
+ this.jsonInit({
343
+ "id": "control_wait",
344
+ "message0": Blockly.Msg.CONTROL_WAIT,
345
+ "args0": [
346
+ {
347
+ "type": "input_value",
348
+ "name": "DURATION"
349
+ }
350
+ ],
351
+ "category": Blockly.Categories.control,
352
+ "extensions": ["colours_control", "shape_statement"]
353
+ });
354
+ }
355
+ };
356
+
357
+ Blockly.Blocks['control_waitsecondsoruntil'] = {
358
+ /**
359
+ * pm: Block to wait (pause) stack for a specified amount of seconds, or until a condition is met.
360
+ * @this Blockly.Block
361
+ */
362
+ init: function() {
363
+ this.jsonInit({
364
+ "id": "control_waitsecondsoruntil",
365
+ "message0": "wait %1 seconds or until %2",
366
+ "args0": [
367
+ {
368
+ "type": "input_value",
369
+ "name": "DURATION"
370
+ },
371
+ {
372
+ "type": "input_value",
373
+ "name": "CONDITION",
374
+ "check": "Boolean"
375
+ }
376
+ ],
377
+ "category": Blockly.Categories.control,
378
+ "extensions": ["colours_control", "shape_statement"]
379
+ });
380
+ }
381
+ };
382
+
383
+ Blockly.Blocks['control_waittick'] = {
384
+ /**
385
+ * pm: Block to wait (pause) stack until the next runtime tick.
386
+ * @this Blockly.Block
387
+ */
388
+ init: function() {
389
+ this.jsonInit({
390
+ "id": "control_waittick",
391
+ "message0": "wait until next tick",
392
+ "args0": [],
393
+ "category": Blockly.Categories.control,
394
+ "extensions": ["colours_control", "shape_statement"]
395
+ });
396
+ }
397
+ };
398
+
399
+ Blockly.Blocks['control_wait_until'] = {
400
+ /**
401
+ * Block to wait until a condition becomes true.
402
+ * @this Blockly.Block
403
+ */
404
+ init: function() {
405
+ this.jsonInit({
406
+ "message0": Blockly.Msg.CONTROL_WAITUNTIL,
407
+ "args0": [
408
+ {
409
+ "type": "input_value",
410
+ "name": "CONDITION",
411
+ "check": "Boolean"
412
+ }
413
+ ],
414
+ "category": Blockly.Categories.control,
415
+ "extensions": ["colours_control", "shape_statement"]
416
+ });
417
+ }
418
+ };
419
+
420
+ Blockly.Blocks['control_repeat_until'] = {
421
+ /**
422
+ * Block to repeat until a condition becomes true.
423
+ * @this Blockly.Block
424
+ */
425
+ init: function() {
426
+ this.jsonInit({
427
+ "message0": Blockly.Msg.CONTROL_REPEATUNTIL,
428
+ "message1": "%1",
429
+ "message2": "%1",
430
+ "lastDummyAlign2": "RIGHT",
431
+ "args0": [
432
+ {
433
+ "type": "input_value",
434
+ "name": "CONDITION",
435
+ "check": "Boolean"
436
+ }
437
+ ],
438
+ "args1": [
439
+ {
440
+ "type": "input_statement",
441
+ "check": 'normal',
442
+ "name": "SUBSTACK"
443
+ }
444
+ ],
445
+ "args2": [
446
+ {
447
+ "type": "field_image",
448
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
449
+ "width": 24,
450
+ "height": 24,
451
+ "alt": "*",
452
+ "flip_rtl": true
453
+ }
454
+ ],
455
+ "category": Blockly.Categories.control,
456
+ "extensions": ["colours_control", "shape_statement"]
457
+ });
458
+ }
459
+ };
460
+
461
+ Blockly.Blocks['control_while'] = {
462
+ /**
463
+ * pm: Block to repeat until a condition becomes false.
464
+ */
465
+ init: function() {
466
+ this.jsonInit({
467
+ "message0": Blockly.Msg.CONTROL_WHILE,
468
+ "message1": "%1",
469
+ "message2": "%1",
470
+ "lastDummyAlign2": "RIGHT",
471
+ "args0": [
472
+ {
473
+ "type": "input_value",
474
+ "name": "CONDITION",
475
+ "check": "Boolean"
476
+ }
477
+ ],
478
+ "args1": [
479
+ {
480
+ "type": "input_statement",
481
+ "check": 'normal',
482
+ "name": "SUBSTACK"
483
+ }
484
+ ],
485
+ "args2": [
486
+ {
487
+ "type": "field_image",
488
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
489
+ "width": 24,
490
+ "height": 24,
491
+ "alt": "*",
492
+ "flip_rtl": true
493
+ }
494
+ ],
495
+ "category": Blockly.Categories.control,
496
+ "extensions": ["colours_control", "shape_statement"]
497
+ });
498
+ }
499
+ };
500
+
501
+ Blockly.Blocks['control_for_each'] = {
502
+ /**
503
+ * pm: Block for for-each loops.
504
+ * @this Blockly.Block
505
+ */
506
+ init: function() {
507
+ this.jsonInit({
508
+ "type": "control_for_each",
509
+ "message0": Blockly.Msg.CONTROL_FOREACH,
510
+ "message1": "%1",
511
+ "message2": "%1",
512
+ "lastDummyAlign2": "RIGHT",
513
+ "args0": [
514
+ {
515
+ "type": "field_variable",
516
+ "name": "VARIABLE"
517
+ },
518
+ {
519
+ "type": "input_value",
520
+ "name": "VALUE"
521
+ }
522
+ ],
523
+ "args1": [
524
+ {
525
+ "type": "input_statement",
526
+ "check": 'normal',
527
+ "name": "SUBSTACK"
528
+ }
529
+ ],
530
+ "args2": [
531
+ {
532
+ "type": "field_image",
533
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
534
+ "width": 24,
535
+ "height": 24,
536
+ "alt": "*",
537
+ "flip_rtl": true
538
+ }
539
+ ],
540
+ "category": Blockly.Categories.control,
541
+ "extensions": ["colours_control", "shape_statement"]
542
+ });
543
+ }
544
+ };
545
+
546
+ Blockly.Blocks['control_start_as_clone'] = {
547
+ /**
548
+ * Block for "when I start as a clone" hat.
549
+ * @this Blockly.Block
550
+ */
551
+ init: function() {
552
+ this.jsonInit({
553
+ "id": "control_start_as_clone",
554
+ "message0": Blockly.Msg.CONTROL_STARTASCLONE,
555
+ "args0": [
556
+ ],
557
+ "category": Blockly.Categories.control,
558
+ "extensions": ["colours_control", "shape_hat"]
559
+ });
560
+ }
561
+ };
562
+
563
+ Blockly.Blocks['control_create_clone_of_menu'] = {
564
+ /**
565
+ * Create-clone drop-down menu.
566
+ * @this Blockly.Block
567
+ */
568
+ init: function() {
569
+ this.jsonInit({
570
+ "message0": "%1",
571
+ "args0": [
572
+ {
573
+ "type": "field_dropdown",
574
+ "name": "CLONE_OPTION",
575
+ "options": [
576
+ [Blockly.Msg.CONTROL_CREATECLONEOF_MYSELF, '_myself_']
577
+ ]
578
+ }
579
+ ],
580
+ "extensions": ["colours_control", "output_string"]
581
+ });
582
+ }
583
+ };
584
+
585
+ Blockly.Blocks['control_create_clone_of'] = {
586
+ /**
587
+ * Block for "create clone of..."
588
+ * @this Blockly.Block
589
+ */
590
+ init: function() {
591
+ this.jsonInit({
592
+ "id": "control_start_as_clone",
593
+ "message0": Blockly.Msg.CONTROL_CREATECLONEOF,
594
+ "args0": [
595
+ {
596
+ "type": "input_value",
597
+ "name": "CLONE_OPTION"
598
+ }
599
+ ],
600
+ "category": Blockly.Categories.control,
601
+ "extensions": ["colours_control", "shape_statement"]
602
+ });
603
+ }
604
+ };
605
+
606
+ Blockly.Blocks['control_delete_clones_of'] = {
607
+ /**
608
+ * pm: Block for "delete clones of..."
609
+ * @this Blockly.Block
610
+ */
611
+ init: function() {
612
+ this.jsonInit({
613
+ "id": "control_delete_clones_of",
614
+ "message0": "delete clones of %1",
615
+ "args0": [
616
+ {
617
+ "type": "input_value",
618
+ "name": "CLONE_OPTION"
619
+ }
620
+ ],
621
+ "category": Blockly.Categories.control,
622
+ "extensions": ["colours_control", "shape_statement"]
623
+ });
624
+ }
625
+ };
626
+
627
+ Blockly.Blocks['control_delete_this_clone'] = {
628
+ /**
629
+ * Block for "delete this clone."
630
+ * @this Blockly.Block
631
+ */
632
+ init: function() {
633
+ this.jsonInit({
634
+ "message0": Blockly.Msg.CONTROL_DELETETHISCLONE,
635
+ "args0": [
636
+ ],
637
+ "category": Blockly.Categories.control,
638
+ "extensions": ["colours_control", "shape_end"]
639
+ });
640
+ }
641
+ };
642
+
643
+ Blockly.Blocks['control_is_clone'] = {
644
+ /**
645
+ * pm: Block to check if a sprite is a clone.
646
+ * @this Blockly.Block
647
+ */
648
+ init: function () {
649
+ this.jsonInit({
650
+ "message0": "is clone?",
651
+ "category": Blockly.Categories.control,
652
+ "extensions": ["colours_control", "output_boolean"]
653
+ });
654
+ }
655
+ };
656
+
657
+ Blockly.Blocks['control_stop_sprite_menu'] = {
658
+ /**
659
+ * pm: Stop-sprite drop-down menu.
660
+ * @this Blockly.Block
661
+ */
662
+ init: function() {
663
+ this.jsonInit({
664
+ "message0": "%1",
665
+ "args0": [
666
+ {
667
+ "type": "field_dropdown",
668
+ "name": "STOP_OPTION",
669
+ "options": [
670
+ ["stage", '_stage_']
671
+ ]
672
+ }
673
+ ],
674
+ "extensions": ["colours_control", "output_string"]
675
+ });
676
+ }
677
+ };
678
+
679
+ Blockly.Blocks['control_stop_sprite'] = {
680
+ /**
681
+ * pm: Block for "stop (...)"
682
+ * @this Blockly.Block
683
+ */
684
+ init: function() {
685
+ this.jsonInit({
686
+ "id": "control_stop_sprite",
687
+ "message0": "stop %1",
688
+ "args0": [
689
+ {
690
+ "type": "input_value",
691
+ "name": "STOP_OPTION"
692
+ }
693
+ ],
694
+ "category": Blockly.Categories.control,
695
+ "extensions": ["colours_control", "shape_statement"]
696
+ });
697
+ }
698
+ };
699
+
700
+ Blockly.Blocks['control_run_as_sprite_menu'] = {
701
+ /**
702
+ * pm: Run-as-sprite drop-down menu.
703
+ * @this Blockly.Block
704
+ */
705
+ init: function() {
706
+ this.jsonInit({
707
+ "message0": "%1",
708
+ "args0": [
709
+ {
710
+ "type": "field_dropdown",
711
+ "name": "RUN_AS_OPTION",
712
+ "options": [
713
+ ["Stage", '_stage_']
714
+ ]
715
+ }
716
+ ],
717
+ "extensions": ["colours_control", "output_string"]
718
+ });
719
+ }
720
+ };
721
+
722
+ Blockly.Blocks['control_run_as_sprite'] = {
723
+ init: function() {
724
+ this.jsonInit({
725
+ "message0": 'as %1',
726
+ "message1": "%1",
727
+ "args0": [
728
+ {
729
+ "type": "input_value",
730
+ "name": "RUN_AS_OPTION"
731
+ }
732
+ ],
733
+ "args1": [
734
+ {
735
+ "type": "input_statement",
736
+ "check": 'normal',
737
+ "name": "SUBSTACK"
738
+ }
739
+ ],
740
+ "category": Blockly.Categories.control,
741
+ "extensions": ["colours_control", "shape_statement"]
742
+ });
743
+ }
744
+ };
745
+
746
+ Blockly.Blocks['control_inline_stack_output'] = {
747
+ /**
748
+ * pm: Block to run a stack and output a return from it.
749
+ * @this Blockly.Block
750
+ */
751
+ init: function () {
752
+ this.jsonInit({
753
+ "message0": 'inline block',
754
+ "message1": "%1",
755
+ "args1": [
756
+ {
757
+ "type": "input_statement",
758
+ "check": 'normal',
759
+ "name": "SUBSTACK"
760
+ }
761
+ ],
762
+ "category": Blockly.Categories.control,
763
+ "output": null,
764
+ "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
765
+ "extensions": ["colours_control"]
766
+ });
767
+ }
768
+ };
769
+
770
+ Blockly.Blocks['control_get_counter'] = {
771
+ /**
772
+ * pm: Block to get the counter value.
773
+ * @this Blockly.Block
774
+ */
775
+ init: function() {
776
+ this.jsonInit({
777
+ "message0": Blockly.Msg.CONTROL_COUNTER,
778
+ "category": Blockly.Categories.control,
779
+ "checkboxInFlyout": true,
780
+ "extensions": ["colours_control", "output_number"]
781
+ });
782
+ }
783
+ };
784
+
785
+ Blockly.Blocks['control_incr_counter'] = {
786
+ /**
787
+ * pm: Block to add one to the counter value.
788
+ * @this Blockly.Block
789
+ */
790
+ init: function() {
791
+ this.jsonInit({
792
+ "message0": Blockly.Msg.CONTROL_INCRCOUNTER,
793
+ "category": Blockly.Categories.control,
794
+ "extensions": ["colours_control", "shape_statement"]
795
+ });
796
+ }
797
+ };
798
+
799
+ Blockly.Blocks['control_decr_counter'] = {
800
+ /**
801
+ * pm: Block to subtract one from the counter value.
802
+ * @this Blockly.Block
803
+ */
804
+ init: function () {
805
+ this.jsonInit({
806
+ "message0": "decrement counter",
807
+ "category": Blockly.Categories.control,
808
+ "extensions": ["colours_control", "shape_statement"]
809
+ });
810
+ }
811
+ };
812
+
813
+ Blockly.Blocks['control_set_counter'] = {
814
+ /**
815
+ * pm: Block to set the counter value.
816
+ * @this Blockly.Block
817
+ */
818
+ init: function () {
819
+ this.jsonInit({
820
+ "message0": "set counter to %1",
821
+ "args0": [
822
+ {
823
+ "type": "input_value",
824
+ "name": "VALUE"
825
+ }
826
+ ],
827
+ "category": Blockly.Categories.control,
828
+ "extensions": ["colours_control", "shape_statement"]
829
+ });
830
+ }
831
+ };
832
+
833
+ Blockly.Blocks['control_clear_counter'] = {
834
+ /**
835
+ * pm: Block to clear the counter value.
836
+ * @this Blockly.Block
837
+ */
838
+ init: function() {
839
+ this.jsonInit({
840
+ "message0": Blockly.Msg.CONTROL_CLEARCOUNTER,
841
+ "category": Blockly.Categories.control,
842
+ "extensions": ["colours_control", "shape_statement"]
843
+ });
844
+ }
845
+ };
846
+
847
+ Blockly.Blocks['control_all_at_once'] = {
848
+ /**
849
+ * Block to run the contained script. This is an obsolete block that is
850
+ * implemented for compatibility with Scratch 2.0 projects. Note that
851
+ * this was originally designed to run all of the contained blocks
852
+ * (sequentially, like normal) within a single frame, but this feature
853
+ * was removed in place of custom blocks marked "run without screen
854
+ * refresh". The "all at once" block was changed to run the contained
855
+ * blocks ordinarily, functioning the same way as an "if" block with a
856
+ * reporter that is always true (e.g. "if 1 = 1"). Also note that the
857
+ * Scratch 2.0 spec for this block is "warpSpeed", but the label shows
858
+ * "all at once".
859
+ * @this Blockly.Block
860
+ */
861
+ init: function() {
862
+ this.jsonInit({
863
+ "message0": Blockly.Msg.CONTROL_ALLATONCE,
864
+ "message1": "%1", // Statement
865
+ "args1": [
866
+ {
867
+ "type": "input_statement",
868
+ "check": 'normal',
869
+ "name": "SUBSTACK"
870
+ }
871
+ ],
872
+ "category": Blockly.Categories.control,
873
+ "extensions": ["colours_control", "shape_statement"]
874
+ });
875
+ }
876
+ };
877
+
878
+ Blockly.Blocks['control_new_script'] = {
879
+ init: function () {
880
+ this.jsonInit({
881
+ "message0": "new script",
882
+ "message1": "%1", // Statement
883
+ "args1": [
884
+ {
885
+ "type": "input_statement",
886
+ "check": 'normal',
887
+ "name": "SUBSTACK"
888
+ }
889
+ ],
890
+ "category": Blockly.Categories.control,
891
+ "extensions": ["colours_control", "shape_statement"]
892
+ });
893
+ }
894
+ };
895
+
896
+ Blockly.Blocks["control_backToGreenFlag"] = {
897
+ init: function() {
898
+ this.jsonInit({
899
+ "inputsInline": true,
900
+ "message0": "run %1",
901
+ "args0": [
902
+ {
903
+ "type": "field_image",
904
+ "src": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAACJ0lEQVRIid2Uy09TQRSHv2kv1VR5hhQQqwlYGtqCmtbHokhDTNQtEVz4B/gfmBCDXoyGmLj3kbBwY2LY6MpHWJDUoBukKsTKQ6I2paWGBipCo73jBii30BpI78ZfMpkzMznznTOPAwZLbFgt/ZWY011k9gzysSdZLICStdJXkPRjSns41hcH2Y7EjmAVmESKFyjyCaPqr50AzBtWbeAsEKDE0oy7w4rnfAXNbWU0nlY40CQwmX0kY73UBr4QGw5vu5vndg31Zy6wv3OGhecZfQbrajk3Rp2zXRdCqe0Irg5o8k8w+uwWR9VLmE13eaeNgarRqtoQ4jKKdpUy+wLy+3Hg2vaAQlIsbk51ZUjNJ/n8egBv5CBan2Bf5TL1nlkafGkWYz8YeVy94bIjwHpOpTY/vs7Nc1WAHQCNr5sXTLsA/EOaNBagabph8QEyYzAA3QkZkYGeUOAVyTlWUt/I/M5gLa/GpDjYXFryuumPaCsgMWsl+ilEfLoOSQTBClBBuW2GExcXsVi9hQFSF8RWQGT8MNCLwzXAYHc2nNabbQzdu4/TH6ThpBMhbDmef1iKhRgf8iHFo/wAeEpIfUgoZ/bD9SAB1Us42MPUiJOaxhBVh5YwKYKfib3MhZtYXS5B0sl79VUhQH4Nq6vADbzqHaJTbUQn3QjKECKOlG8Iqblh7apUsFayX661gjLgH/zPgPm1PlFMQPaSHa4HTIcnSFW8LSbAcP0F3uGqEimnx6MAAAAASUVORK5CYII=",
905
+ "width": 24,
906
+ "height": 24,
907
+ "flip_rtl": false
908
+ }
909
+ ],
910
+ "category": Blockly.Categories.control,
911
+ "extensions": ["colours_control", "shape_statement"]
912
+ });
913
+ }
914
+ };
915
+
916
+ Blockly.Blocks["control_if_return_else_return"] = {
917
+ init: function() {
918
+ this.jsonInit({
919
+ "inputsInline": true,
920
+ "message0": "if %1 then %2 else %3",
921
+ "args0": [
922
+ {
923
+ "type": "input_value",
924
+ "name": "boolean",
925
+ "check": "Boolean"
926
+ },
927
+ {
928
+ "type": "input_value",
929
+ "name": "TEXT1"
930
+ },
931
+ {
932
+ "type": "input_value",
933
+ "name": "TEXT2"
934
+ }
935
+ ],
936
+ "category": Blockly.Categories.control,
937
+ "extensions": ["colours_control", "output_string"]
938
+ });
939
+ }
940
+ };
941
+
942
+ Blockly.Blocks['control_switch'] = {
943
+ init: function() {
944
+ this.jsonInit({
945
+ "message0": 'switch %1',
946
+ "message1": "%1",
947
+ "args0": [
948
+ {
949
+ "type": "input_value",
950
+ "name": "CONDITION"
951
+ }
952
+ ],
953
+ "args1": [
954
+ {
955
+ "type": "input_statement",
956
+ "name": "SUBSTACK",
957
+ "check": 'switchCase'
958
+ }
959
+ ],
960
+ "category": Blockly.Categories.control,
961
+ "extensions": ["colours_control", "shape_statement"]
962
+ });
963
+ }
964
+ };
965
+
966
+ Blockly.Blocks['control_switch_default'] = {
967
+ init: function() {
968
+ this.jsonInit({
969
+ "message0": 'switch %1',
970
+ "message1": "%1",
971
+ "message2": "default",
972
+ "message3": "%1",
973
+ "args0": [
974
+ {
975
+ "type": "input_value",
976
+ "name": "CONDITION"
977
+ }
978
+ ],
979
+ "args1": [
980
+ {
981
+ "type": "input_statement",
982
+ "name": "SUBSTACK1",
983
+ "check": 'switchCase'
984
+ }
985
+ ],
986
+ "args3": [
987
+ {
988
+ "type": "input_statement",
989
+ "check": 'normal',
990
+ "name": "SUBSTACK2"
991
+ }
992
+ ],
993
+ "category": Blockly.Categories.control,
994
+ "extensions": ["colours_control", "shape_statement"]
995
+ });
996
+ }
997
+ };
998
+
999
+ Blockly.Blocks['control_case'] = {
1000
+ init: function() {
1001
+ this.jsonInit({
1002
+ "message0": 'case %1',
1003
+ "message1": "%1",
1004
+ "args0": [
1005
+ {
1006
+ "type": "input_value",
1007
+ "name": "CONDITION"
1008
+ }
1009
+ ],
1010
+ "args1": [
1011
+ {
1012
+ "type": "input_statement",
1013
+ "check": 'normal',
1014
+ "name": "SUBSTACK"
1015
+ }
1016
+ ],
1017
+ "category": Blockly.Categories.control,
1018
+ "extensions": ["colours_control", "shape_case"]
1019
+ });
1020
+ }
1021
+ };
1022
+
1023
+ Blockly.Blocks['control_case_next'] = {
1024
+ init: function() {
1025
+ this.jsonInit({
1026
+ "message0": 'run next case when %1',
1027
+ "args0": [
1028
+ {
1029
+ "type": "input_value",
1030
+ "name": "CONDITION"
1031
+ }
1032
+ ],
1033
+ "category": Blockly.Categories.control,
1034
+ "extensions": ["colours_control", "shape_case"]
1035
+ });
1036
+ }
1037
+ };
1038
+
1039
+ Blockly.Blocks['control_exitCase'] = {
1040
+ init: function () {
1041
+ this.jsonInit({
1042
+ "message0": 'exit case %1',
1043
+ "args0": [
1044
+ {
1045
+ "type": "field_image",
1046
+ "src": Blockly.mainWorkspace.options.pathToMedia + "arrow-down.svg",
1047
+ "width": 24,
1048
+ "height": 24,
1049
+ "alt": "↓",
1050
+ "flip_rtl": true
1051
+ }
1052
+ ],
1053
+ "category": Blockly.Categories.control,
1054
+ "extensions": ["colours_control", "shape_end"]
1055
+ });
1056
+ }
1057
+ };
1058
+
1059
+ Blockly.Blocks['control_exitLoop'] = {
1060
+ init: function() {
1061
+ this.jsonInit({
1062
+ "message0": 'escape loop %1',
1063
+ "args0": [
1064
+ {
1065
+ "type": "field_image",
1066
+ "src": Blockly.mainWorkspace.options.pathToMedia + "arrow-down.svg",
1067
+ "width": 24,
1068
+ "height": 24,
1069
+ "alt": "↓",
1070
+ "flip_rtl": true
1071
+ }
1072
+ ],
1073
+ "category": Blockly.Categories.control,
1074
+ "extensions": ["colours_control", "shape_end"]
1075
+ });
1076
+ }
1077
+ };
1078
+
1079
+ Blockly.Blocks['control_continueLoop'] = {
1080
+ init: function() {
1081
+ this.jsonInit({
1082
+ "message0": 'continue loop %1',
1083
+ "args0": [
1084
+ {
1085
+ "type": "field_image",
1086
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
1087
+ "width": 24,
1088
+ "height": 24,
1089
+ "alt": "*",
1090
+ "flip_rtl": true
1091
+ }
1092
+ ],
1093
+ "category": Blockly.Categories.control,
1094
+ "extensions": ["colours_control", "shape_end"]
1095
+ });
1096
+ }
1097
+ };
1098
+
1099
+ Blockly.Blocks['control_javascript_command'] = {
1100
+ /**
1101
+ * pm: Block to run javascript code.
1102
+ * @this Blockly.Block
1103
+ */
1104
+ init: function () {
1105
+ this.jsonInit({
1106
+ "message0": "javascript %1",
1107
+ "args0": [
1108
+ {
1109
+ "type": "input_value",
1110
+ "name": "JS"
1111
+ }
1112
+ ],
1113
+ "category": Blockly.Categories.control,
1114
+ "extensions": ["colours_control", "shape_statement"]
1115
+ });
1116
+ }
1117
+ };
blocks_vertical/data.js ADDED
@@ -0,0 +1,1008 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.data');
24
+ goog.provide('Blockly.Constants.Data');
25
+
26
+ goog.require('Blockly.Blocks');
27
+ goog.require('Blockly.Colours');
28
+ goog.require('Blockly.constants');
29
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
30
+
31
+
32
+ Blockly.Blocks['data_variable'] = {
33
+ /**
34
+ * Block of Variables
35
+ * @this Blockly.Block
36
+ */
37
+ init: function() {
38
+ this.jsonInit({
39
+ "message0": "%1",
40
+ "lastDummyAlign0": "CENTRE",
41
+ "args0": [
42
+ {
43
+ "type": "field_variable_getter",
44
+ "text": "",
45
+ "name": "VARIABLE",
46
+ "variableType": ""
47
+ }
48
+ ],
49
+ "output": null,
50
+ "category": Blockly.Categories.data,
51
+ "checkboxInFlyout": true,
52
+ "extensions": ["contextMenu_getVariableBlock", "colours_data"],
53
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND
54
+ });
55
+ }
56
+ };
57
+
58
+ Blockly.Blocks['data_setvariableto'] = {
59
+ /**
60
+ * Block to set variable to a certain value
61
+ * @this Blockly.Block
62
+ */
63
+ init: function() {
64
+ this.jsonInit({
65
+ "message0": Blockly.Msg.DATA_SETVARIABLETO,
66
+ "args0": [
67
+ {
68
+ "type": "field_variable",
69
+ "name": "VARIABLE"
70
+ },
71
+ {
72
+ "type": "input_value",
73
+ "name": "VALUE"
74
+ }
75
+ ],
76
+ "category": Blockly.Categories.data,
77
+ "extensions": ["colours_data", "shape_statement"]
78
+ });
79
+ }
80
+ };
81
+
82
+ Blockly.Blocks['data_changevariableby'] = {
83
+ /**
84
+ * Block to change variable by a certain value
85
+ * @this Blockly.Block
86
+ */
87
+ init: function() {
88
+ this.jsonInit({
89
+ "message0": Blockly.Msg.DATA_CHANGEVARIABLEBY,
90
+ "args0": [
91
+ {
92
+ "type": "field_variable",
93
+ "name": "VARIABLE"
94
+ },
95
+ {
96
+ "type": "input_value",
97
+ "name": "VALUE"
98
+ }
99
+ ],
100
+ "category": Blockly.Categories.data,
101
+ "extensions": ["colours_data", "shape_statement"]
102
+ });
103
+ }
104
+ };
105
+
106
+ Blockly.Blocks['data_showvariable'] = {
107
+ /**
108
+ * Block to show a variable
109
+ * @this Blockly.Block
110
+ */
111
+ init: function() {
112
+ this.jsonInit({
113
+ "message0": Blockly.Msg.DATA_SHOWVARIABLE,
114
+ "args0": [
115
+ {
116
+ "type": "field_variable",
117
+ "name": "VARIABLE"
118
+ }
119
+ ],
120
+ "category": Blockly.Categories.data,
121
+ "colour": Blockly.Colours.data.primary,
122
+ "colourSecondary": Blockly.Colours.data.secondary,
123
+ "colourTertiary": Blockly.Colours.data.tertiary,
124
+ "extensions": ["shape_statement"]
125
+ });
126
+ }
127
+ };
128
+
129
+ Blockly.Blocks['data_hidevariable'] = {
130
+ /**
131
+ * Block to hide a variable
132
+ * @this Blockly.Block
133
+ */
134
+ init: function() {
135
+ this.jsonInit({
136
+ "message0": Blockly.Msg.DATA_HIDEVARIABLE,
137
+ "args0": [
138
+ {
139
+ "type": "field_variable",
140
+ "name": "VARIABLE"
141
+ }
142
+ ],
143
+ "category": Blockly.Categories.data,
144
+ "colour": Blockly.Colours.data.primary,
145
+ "colourSecondary": Blockly.Colours.data.secondary,
146
+ "colourTertiary": Blockly.Colours.data.tertiary,
147
+ "extensions": ["shape_statement"]
148
+ });
149
+ }
150
+ };
151
+
152
+ Blockly.Blocks['data_listcontents'] = {
153
+ /**
154
+ * List reporter.
155
+ * @this Blockly.Block
156
+ */
157
+ init: function() {
158
+ this.jsonInit({
159
+ "message0": "%1",
160
+ "args0": [
161
+ {
162
+ "type": "field_variable_getter",
163
+ "text": "",
164
+ "name": "LIST",
165
+ "variableType": Blockly.LIST_VARIABLE_TYPE
166
+ }
167
+ ],
168
+ "category": Blockly.Categories.dataLists,
169
+ "extensions": ["contextMenu_getListBlock", "colours_data_lists", "output_string"],
170
+ "checkboxInFlyout": true
171
+ });
172
+ }
173
+ };
174
+
175
+ Blockly.Blocks['data_listindexall'] = {
176
+ /**
177
+ * List index menu, with all option.
178
+ * @this Blockly.Block
179
+ */
180
+ init: function() {
181
+ this.jsonInit({
182
+ "message0": "%1",
183
+ "args0": [
184
+ {
185
+ "type": "field_numberdropdown",
186
+ "name": "INDEX",
187
+ "value": "1",
188
+ "min": 1,
189
+ "precision": 1,
190
+ "options": [
191
+ ["1", "1"],
192
+ [Blockly.Msg.DATA_INDEX_LAST, "last"],
193
+ [Blockly.Msg.DATA_INDEX_ALL, "all"]
194
+ ]
195
+ }
196
+ ],
197
+ "category": Blockly.Categories.data,
198
+ "extensions": ["colours_textfield", "output_string"]
199
+ });
200
+ }
201
+ };
202
+
203
+ Blockly.Blocks['data_listindexrandom'] = {
204
+ /**
205
+ * List index menu, with random option.
206
+ * @this Blockly.Block
207
+ */
208
+ init: function() {
209
+ this.jsonInit({
210
+ "message0": "%1",
211
+ "args0": [
212
+ {
213
+ "type": "field_numberdropdown",
214
+ "name": "INDEX",
215
+ "value": "1",
216
+ "min": 1,
217
+ "precision": 1,
218
+ "options": [
219
+ ["1", "1"],
220
+ [Blockly.Msg.DATA_INDEX_LAST, "last"],
221
+ [Blockly.Msg.DATA_INDEX_RANDOM, "random"]
222
+ ]
223
+ }
224
+ ],
225
+ "category": Blockly.Categories.data,
226
+ "extensions": ["colours_textfield", "output_string"]
227
+ });
228
+ }
229
+ };
230
+
231
+ Blockly.Blocks['data_addtolist'] = {
232
+ /**
233
+ * Block to add item to list.
234
+ * @this Blockly.Block
235
+ */
236
+ init: function() {
237
+ this.jsonInit({
238
+ "message0": Blockly.Msg.DATA_ADDTOLIST,
239
+ "args0": [
240
+ {
241
+ "type": "input_value",
242
+ "name": "ITEM"
243
+ },
244
+ {
245
+ "type": "field_variable",
246
+ "name": "LIST",
247
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
248
+ }
249
+ ],
250
+ "category": Blockly.Categories.dataLists,
251
+ "extensions": ["colours_data_lists", "shape_statement"]
252
+ });
253
+ }
254
+ };
255
+
256
+ Blockly.Blocks['data_deleteoflist'] = {
257
+ /**
258
+ * Block to delete item from list.
259
+ * @this Blockly.Block
260
+ */
261
+ init: function() {
262
+ this.jsonInit({
263
+ "message0": Blockly.Msg.DATA_DELETEOFLIST,
264
+ "args0": [
265
+ {
266
+ "type": "input_value",
267
+ "name": "INDEX"
268
+ },
269
+ {
270
+ "type": "field_variable",
271
+ "name": "LIST",
272
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
273
+ }
274
+ ],
275
+ "category": Blockly.Categories.dataLists,
276
+ "extensions": ["colours_data_lists", "shape_statement"]
277
+ });
278
+ }
279
+ };
280
+
281
+ Blockly.Blocks['data_deletealloflist'] = {
282
+ /**
283
+ * Block to delete all items from list.
284
+ * @this Blockly.Block
285
+ */
286
+ init: function() {
287
+ this.jsonInit({
288
+ "message0": Blockly.Msg.DATA_DELETEALLOFLIST,
289
+ "args0": [
290
+ {
291
+ "type": "field_variable",
292
+ "name": "LIST",
293
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
294
+ }
295
+ ],
296
+ "category": Blockly.Categories.dataLists,
297
+ "extensions": ["colours_data_lists", "shape_statement"]
298
+ });
299
+ }
300
+ };
301
+
302
+ Blockly.Blocks['data_shiftlist'] = {
303
+ /**
304
+ * Block to delete all items from list.
305
+ * @this Blockly.Block
306
+ */
307
+ init: function() {
308
+ this.jsonInit({
309
+ "message0": "shift %1 by %2",
310
+ "args0": [
311
+ {
312
+ "type": "field_variable",
313
+ "name": "LIST",
314
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
315
+ },
316
+ {
317
+ "type": "input_value",
318
+ "name": "INDEX"
319
+ }
320
+ ],
321
+ "category": Blockly.Categories.dataLists,
322
+ "extensions": ["colours_data_lists", "shape_statement"]
323
+ });
324
+ }
325
+ };
326
+
327
+ Blockly.Blocks['data_insertatlist'] = {
328
+ /**
329
+ * Block to insert item to list.
330
+ * @this Blockly.Block
331
+ */
332
+ init: function() {
333
+ this.jsonInit({
334
+ "message0": Blockly.Msg.DATA_INSERTATLIST,
335
+ "args0": [
336
+ {
337
+ "type": "input_value",
338
+ "name": "ITEM"
339
+ },
340
+ {
341
+ "type": "input_value",
342
+ "name": "INDEX"
343
+ },
344
+ {
345
+ "type": "field_variable",
346
+ "name": "LIST",
347
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
348
+ }
349
+ ],
350
+ "category": Blockly.Categories.dataLists,
351
+ "extensions": ["colours_data_lists", "shape_statement"]
352
+ });
353
+ }
354
+ };
355
+
356
+ Blockly.Blocks['data_replaceitemoflist'] = {
357
+ /**
358
+ * Block to insert item to list.
359
+ * @this Blockly.Block
360
+ */
361
+ init: function() {
362
+ this.jsonInit({
363
+ "message0": Blockly.Msg.DATA_REPLACEITEMOFLIST,
364
+ "args0": [
365
+ {
366
+ "type": "input_value",
367
+ "name": "INDEX"
368
+ },
369
+ {
370
+ "type": "field_variable",
371
+ "name": "LIST",
372
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
373
+ },
374
+ {
375
+ "type": "input_value",
376
+ "name": "ITEM"
377
+ }
378
+ ],
379
+ "category": Blockly.Categories.dataLists,
380
+ "extensions": ["colours_data_lists", "shape_statement"]
381
+ });
382
+ }
383
+ };
384
+
385
+ Blockly.Blocks['data_itemoflist'] = {
386
+ /**
387
+ * Block for reporting item of list.
388
+ * @this Blockly.Block
389
+ */
390
+ init: function() {
391
+ this.jsonInit({
392
+ "message0": Blockly.Msg.DATA_ITEMOFLIST,
393
+ "args0": [
394
+ {
395
+ "type": "input_value",
396
+ "name": "INDEX"
397
+ },
398
+ {
399
+ "type": "field_variable",
400
+ "name": "LIST",
401
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
402
+ }
403
+ ],
404
+ "output": null,
405
+ "category": Blockly.Categories.dataLists,
406
+ "extensions": ["colours_data_lists"],
407
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND
408
+ });
409
+ }
410
+ };
411
+
412
+ Blockly.Blocks['data_itemnumoflist'] = {
413
+ /**
414
+ * Block for reporting the item # of a string in a list.
415
+ * @this Blockly.Block
416
+ */
417
+ init: function() {
418
+ this.jsonInit({
419
+ "message0": Blockly.Msg.DATA_ITEMNUMOFLIST,
420
+ "args0": [
421
+ {
422
+ "type": "input_value",
423
+ "name": "ITEM"
424
+ },
425
+ {
426
+ "type": "field_variable",
427
+ "name": "LIST",
428
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
429
+ }
430
+ ],
431
+ "output": null,
432
+ "category": Blockly.Categories.dataLists,
433
+ "extensions": ["colours_data_lists"],
434
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND
435
+ });
436
+ }
437
+ };
438
+
439
+ Blockly.Blocks['data_lengthoflist'] = {
440
+ /**
441
+ * Block for reporting length of list.
442
+ * @this Blockly.Block
443
+ */
444
+ init: function() {
445
+ this.jsonInit({
446
+ "message0": Blockly.Msg.DATA_LENGTHOFLIST,
447
+ "args0": [
448
+ {
449
+ "type": "field_variable",
450
+ "name": "LIST",
451
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
452
+ }
453
+ ],
454
+ "category": Blockly.Categories.dataLists,
455
+ "extensions": ["colours_data_lists", "output_number"]
456
+ });
457
+ }
458
+ };
459
+
460
+ Blockly.Blocks['data_listcontainsitem'] = {
461
+ /**
462
+ * Block to report whether list contains item.
463
+ * @this Blockly.Block
464
+ */
465
+ init: function() {
466
+ this.jsonInit({
467
+ "message0": Blockly.Msg.DATA_LISTCONTAINSITEM,
468
+ "args0": [
469
+ {
470
+ "type": "field_variable",
471
+ "name": "LIST",
472
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
473
+ },
474
+ {
475
+ "type": "input_value",
476
+ "name": "ITEM"
477
+ }
478
+ ],
479
+ "category": Blockly.Categories.dataLists,
480
+ "extensions": ["colours_data_lists", "output_boolean"]
481
+ });
482
+ }
483
+ };
484
+
485
+ Blockly.Blocks['data_showlist'] = {
486
+ /**
487
+ * Block to show a list.
488
+ * @this Blockly.Block
489
+ */
490
+ init: function() {
491
+ this.jsonInit({
492
+ "message0": Blockly.Msg.DATA_SHOWLIST,
493
+ "args0": [
494
+ {
495
+ "type": "field_variable",
496
+ "name": "LIST",
497
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
498
+ }
499
+ ],
500
+ "category": Blockly.Categories.dataLists,
501
+ "extensions": ["colours_data_lists", "shape_statement"]
502
+ });
503
+ }
504
+ };
505
+
506
+ Blockly.Blocks['data_hidelist'] = {
507
+ /**
508
+ * Block to hide a list.
509
+ * @this Blockly.Block
510
+ */
511
+ init: function() {
512
+ this.jsonInit({
513
+ "message0": Blockly.Msg.DATA_HIDELIST,
514
+ "args0": [
515
+ {
516
+ "type": "field_variable",
517
+ "name": "LIST",
518
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
519
+ }
520
+ ],
521
+ "category": Blockly.Categories.dataLists,
522
+ "extensions": ["colours_data_lists", "shape_statement"]
523
+ });
524
+ }
525
+ };
526
+
527
+ Blockly.Blocks['data_reverselist'] = {
528
+ init: function() {
529
+ this.jsonInit({
530
+ "message0": 'reverse %1',
531
+ "args0": [
532
+ {
533
+ "type": "field_variable",
534
+ "name": "LIST",
535
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
536
+ }
537
+ ],
538
+ "category": Blockly.Categories.dataLists,
539
+ "extensions": ["colours_data_lists", "shape_statement"]
540
+ });
541
+ }
542
+ };
543
+
544
+ Blockly.Blocks['data_itemexistslist'] = {
545
+ init: function() {
546
+ this.jsonInit({
547
+ "message0": 'item %1 exists in %2 ?',
548
+ "args0": [
549
+ {
550
+ "type": "input_value",
551
+ "name": "INDEX"
552
+ },
553
+ {
554
+ "type": "field_variable",
555
+ "name": "LIST",
556
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
557
+ }
558
+ ],
559
+ "category": Blockly.Categories.dataLists,
560
+ "extensions": ["colours_data_lists", "output_boolean"]
561
+ });
562
+ }
563
+ };
564
+
565
+ Blockly.Blocks['data_listisempty'] = {
566
+ /**
567
+ * Block to hide a list.
568
+ * @this Blockly.Block
569
+ */
570
+ init: function() {
571
+ this.jsonInit({
572
+ "message0": 'is %1 empty?',
573
+ "args0": [
574
+ {
575
+ "type": "field_variable",
576
+ "name": "LIST",
577
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
578
+ }
579
+ ],
580
+ "category": Blockly.Categories.dataLists,
581
+ "extensions": ["colours_data_lists", "output_boolean"]
582
+ });
583
+ }
584
+ };
585
+
586
+ Blockly.Blocks['data_listarray'] = {
587
+ init: function() {
588
+ this.jsonInit({
589
+ "message0": 'get list %1 as an array',
590
+ "args0": [
591
+ {
592
+ "type": "field_variable",
593
+ "name": "LIST",
594
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
595
+ }
596
+ ],
597
+ "category": Blockly.Categories.dataLists,
598
+ "extensions": ["colours_data_lists", "output_string"]
599
+ });
600
+ }
601
+ };
602
+
603
+ Blockly.Blocks['data_amountinlist'] = {
604
+ init: function() {
605
+ this.jsonInit({
606
+ "message0": 'amount of %1 in %2',
607
+ "args0": [
608
+ {
609
+ "type": "input_value",
610
+ "name": "VALUE"
611
+ },
612
+ {
613
+ "type": "field_variable",
614
+ "name": "LIST",
615
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
616
+ }
617
+ ],
618
+ "category": Blockly.Categories.dataLists,
619
+ "extensions": ["colours_data_lists", "output_number"]
620
+ });
621
+ }
622
+ };
623
+
624
+ Blockly.Blocks['data_filterlistitem'] = {
625
+ init: function() {
626
+ this.jsonInit({
627
+ "message0": 'item',
628
+ "args0": [],
629
+ "category": Blockly.Categories.dataLists,
630
+ "extensions": ["colours_data_lists", "output_string"],
631
+ "canDragDuplicate": true
632
+ });
633
+ }
634
+ };
635
+
636
+ Blockly.Blocks['data_filterlistindex'] = {
637
+ init: function() {
638
+ this.jsonInit({
639
+ "message0": 'index',
640
+ "args0": [],
641
+ "category": Blockly.Categories.dataLists,
642
+ "extensions": ["colours_data_lists", "output_string"],
643
+ "canDragDuplicate": true
644
+ });
645
+ }
646
+ };
647
+
648
+ Blockly.Blocks['data_filterlist'] = {
649
+ init: function() {
650
+ this.jsonInit({
651
+ "message0": 'filter %1 by %2 %3 %4',
652
+ "args0": [
653
+ {
654
+ "type": "field_variable",
655
+ "name": "LIST",
656
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
657
+ },
658
+ {
659
+ "type": "input_value",
660
+ "name": "INDEX"
661
+ },
662
+ {
663
+ "type": "input_value",
664
+ "name": "ITEM"
665
+ },
666
+ {
667
+ "type": "input_value",
668
+ "name": "BOOL",
669
+ "check": "Boolean"
670
+ }
671
+ ],
672
+ "category": Blockly.Categories.dataLists,
673
+ "extensions": ["colours_data_lists", "shape_statement"]
674
+ });
675
+ }
676
+ };
677
+
678
+ Blockly.Blocks['data_arraylist'] = {
679
+ init: function() {
680
+ this.jsonInit({
681
+ "message0": 'set %2 to array %1',
682
+ "args0": [
683
+ {
684
+ "type": "input_value",
685
+ "name": "VALUE"
686
+ },
687
+ {
688
+ "type": "field_variable",
689
+ "name": "LIST",
690
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
691
+ }
692
+ ],
693
+ "category": Blockly.Categories.dataLists,
694
+ "extensions": ["colours_data_lists", "shape_statement"]
695
+ });
696
+ }
697
+ };
698
+
699
+ Blockly.Blocks['data_listforeachnum'] = {
700
+ init: function() {
701
+ this.jsonInit({
702
+ "message0": 'for each index: %2 in %1',
703
+ "message1": "%1",
704
+ "message2": "%1",
705
+ "lastDummyAlign2": "RIGHT",
706
+ "args0": [
707
+ {
708
+ "type": "field_variable",
709
+ "name": "LIST",
710
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
711
+ },
712
+ {
713
+ "type": "field_variable",
714
+ "name": "VARIABLE"
715
+ }
716
+ ],
717
+ "args1": [
718
+ {
719
+ "type": "input_statement",
720
+ "check": 'normal',
721
+ "name": "SUBSTACK"
722
+ }
723
+ ],
724
+ "args2": [
725
+ {
726
+ "type": "field_image",
727
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
728
+ "width": 24,
729
+ "height": 24,
730
+ "alt": "*",
731
+ "flip_rtl": true
732
+ }
733
+ ],
734
+ "category": Blockly.Categories.dataLists,
735
+ "extensions": ["colours_data_lists", "shape_statement"]
736
+ });
737
+ }
738
+ };
739
+
740
+ Blockly.Blocks['data_listforeachitem'] = {
741
+ init: function() {
742
+ this.jsonInit({
743
+ "message0": 'for each value: %2 in %1',
744
+ "message1": "%1",
745
+ "message2": "%1",
746
+ "lastDummyAlign2": "RIGHT",
747
+ "args0": [
748
+ {
749
+ "type": "field_variable",
750
+ "name": "LIST",
751
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
752
+ },
753
+ {
754
+ "type": "field_variable",
755
+ "name": "VARIABLE"
756
+ }
757
+ ],
758
+ "args1": [
759
+ {
760
+ "type": "input_statement",
761
+ "check": 'normal',
762
+ "name": "SUBSTACK"
763
+ }
764
+ ],
765
+ "args2": [
766
+ {
767
+ "type": "field_image",
768
+ "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
769
+ "width": 24,
770
+ "height": 24,
771
+ "alt": "*",
772
+ "flip_rtl": true
773
+ }
774
+ ],
775
+ "category": Blockly.Categories.dataLists,
776
+ "extensions": ["colours_data_lists", "shape_statement"]
777
+ });
778
+ }
779
+ };
780
+
781
+ /**
782
+ * Mixin to add a context menu for any variable getter blocks defined by a extension block.
783
+ * It adds one item for each variable defined on the workspace.
784
+ * @mixin
785
+ * @augments Blockly.Block
786
+ * @package
787
+ * @readonly
788
+ */
789
+ Blockly.Constants.Data.EXTENSION_VARIABLE_GETTER_MENU = {
790
+ /**
791
+ * Add context menu option to change the selected variable.
792
+ * @param {!Array} options List of menu options to add to.
793
+ * @this Blockly.Block
794
+ */
795
+ customContextMenu: function(options) {
796
+ var varField = this.inputList[0].fieldRow[0];
797
+ if (this.isCollapsed()) {
798
+ return;
799
+ }
800
+ var currentVarName = varField.text_;
801
+ if (!this.isInFlyout) {
802
+ var variablesList = this.workspace.getVariablesOfType(varField.variable_.type);
803
+ variablesList.sort(function(a, b) {
804
+ return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
805
+ });
806
+ for (var i = 0; i < variablesList.length; i++) {
807
+ var varName = variablesList[i].name;
808
+ if (varName == currentVarName) continue;
809
+
810
+ var option = {enabled: true};
811
+ option.text = varName;
812
+
813
+ option.callback =
814
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
815
+ variablesList[i].getId(), varField.name);
816
+ options.push(option);
817
+ }
818
+ } else {
819
+ var renameOption = {
820
+ text: Blockly.Msg.RENAME_VARIABLE,
821
+ enabled: true,
822
+ callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
823
+ varField.name)
824
+ };
825
+ var deleteOption = {
826
+ text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
827
+ enabled: true,
828
+ callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
829
+ varField.name)
830
+ };
831
+ options.push(renameOption);
832
+ options.push(deleteOption);
833
+ }
834
+ }
835
+ };
836
+
837
+ Blockly.Extensions.registerMixin('contextMenu_getVariableBlockAnyType',
838
+ Blockly.Constants.Data.EXTENSION_VARIABLE_GETTER_MENU);
839
+
840
+ /**
841
+ * Mixin to add a context menu for a data_variable block. It adds one item for
842
+ * each variable defined on the workspace.
843
+ * @mixin
844
+ * @augments Blockly.Block
845
+ * @package
846
+ * @readonly
847
+ */
848
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN = {
849
+ /**
850
+ * Add context menu option to change the selected variable.
851
+ * @param {!Array} options List of menu options to add to.
852
+ * @this Blockly.Block
853
+ */
854
+ customContextMenu: function(options) {
855
+ var fieldName = 'VARIABLE';
856
+ if (this.isCollapsed()) {
857
+ return;
858
+ }
859
+ var currentVarName = this.getField(fieldName).text_;
860
+ if (!this.isInFlyout) {
861
+ var variablesList = this.workspace.getVariablesOfType('');
862
+ variablesList.sort(function(a, b) {
863
+ return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
864
+ });
865
+ for (var i = 0; i < variablesList.length; i++) {
866
+ var varName = variablesList[i].name;
867
+ if (varName == currentVarName) continue;
868
+
869
+ var option = {enabled: true};
870
+ option.text = varName;
871
+
872
+ option.callback =
873
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
874
+ variablesList[i].getId(), fieldName);
875
+ options.push(option);
876
+ }
877
+ } else {
878
+ var renameOption = {
879
+ text: Blockly.Msg.RENAME_VARIABLE,
880
+ enabled: true,
881
+ callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
882
+ fieldName)
883
+ };
884
+ var deleteOption = {
885
+ text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
886
+ enabled: true,
887
+ callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
888
+ fieldName)
889
+ };
890
+ options.push(renameOption);
891
+ options.push(deleteOption);
892
+ }
893
+ }
894
+ };
895
+
896
+ Blockly.Extensions.registerMixin('contextMenu_getVariableBlock',
897
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN);
898
+
899
+ /**
900
+ * Mixin to add a context menu for a data_listcontents block. It adds one item for
901
+ * each list defined on the workspace.
902
+ * @mixin
903
+ * @augments Blockly.Block
904
+ * @package
905
+ * @readonly
906
+ */
907
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN = {
908
+ /**
909
+ * Add context menu option to change the selected list.
910
+ * @param {!Array} options List of menu options to add to.
911
+ * @this Blockly.Block
912
+ */
913
+ customContextMenu: function(options) {
914
+ var fieldName = 'LIST';
915
+ if (this.isCollapsed()) {
916
+ return;
917
+ }
918
+ var currentVarName = this.getField(fieldName).text_;
919
+ if (!this.isInFlyout) {
920
+ var variablesList = this.workspace.getVariablesOfType('list');
921
+ variablesList.sort(function(a, b) {
922
+ return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
923
+ });
924
+ for (var i = 0; i < variablesList.length; i++) {
925
+ var varName = variablesList[i].name;
926
+ if (varName == currentVarName) continue;
927
+
928
+ var option = {enabled: true};
929
+ option.text = varName;
930
+
931
+ option.callback =
932
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
933
+ variablesList[i].getId(), fieldName);
934
+ options.push(option);
935
+ }
936
+ } else {
937
+ var renameOption = {
938
+ text: Blockly.Msg.RENAME_LIST,
939
+ enabled: true,
940
+ callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
941
+ fieldName)
942
+ };
943
+ var deleteOption = {
944
+ text: Blockly.Msg.DELETE_LIST.replace('%1', currentVarName),
945
+ enabled: true,
946
+ callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
947
+ fieldName)
948
+ };
949
+ options.push(renameOption);
950
+ options.push(deleteOption);
951
+ }
952
+ }
953
+ };
954
+ Blockly.Extensions.registerMixin('contextMenu_getListBlock',
955
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN);
956
+
957
+ /**
958
+ * Callback factory for dropdown menu options associated with a variable getter
959
+ * block. Each variable on the workspace gets its own item in the dropdown
960
+ * menu, and clicking on that item changes the text of the field on the source
961
+ * block.
962
+ * @param {!Blockly.Block} block The block to update.
963
+ * @param {string} id The id of the variable to set on this block.
964
+ * @param {string} fieldName The name of the field to update on the block.
965
+ * @return {!function()} A function that updates the block with the new name.
966
+ */
967
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY = function(block,
968
+ id, fieldName) {
969
+ return function() {
970
+ var variableField = block.getField(fieldName);
971
+ if (!variableField) {
972
+ console.log("Tried to get a variable field on the wrong type of block.");
973
+ }
974
+ variableField.setValue(id);
975
+ };
976
+ };
977
+
978
+ /**
979
+ * Callback for rename variable dropdown menu option associated with a
980
+ * variable getter block.
981
+ * @param {!Blockly.Block} block The block with the variable to rename.
982
+ * @param {string} fieldName The name of the field to inspect on the block.
983
+ * @return {!function()} A function that renames the variable.
984
+ */
985
+ Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY = function(block,
986
+ fieldName) {
987
+ return function() {
988
+ var workspace = block.workspace;
989
+ var variable = block.getField(fieldName).getVariable();
990
+ Blockly.Variables.renameVariable(workspace, variable);
991
+ };
992
+ };
993
+
994
+ /**
995
+ * Callback for delete variable dropdown menu option associated with a
996
+ * variable getter block.
997
+ * @param {!Blockly.Block} block The block with the variable to delete.
998
+ * @param {string} fieldName The name of the field to inspect on the block.
999
+ * @return {!function()} A function that deletes the variable.
1000
+ */
1001
+ Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY = function(block,
1002
+ fieldName) {
1003
+ return function() {
1004
+ var workspace = block.workspace;
1005
+ var variable = block.getField(fieldName).getVariable();
1006
+ workspace.deleteVariableById(variable.getId());
1007
+ };
1008
+ };
blocks_vertical/default_toolbox.js ADDED
@@ -0,0 +1,583 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.defaultToolbox');
24
+
25
+ goog.require('Blockly.Blocks');
26
+
27
+ /**
28
+ * @fileoverview Provide a default toolbox XML.
29
+ */
30
+
31
+ Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: none">' +
32
+ '<category name="%{BKY_CATEGORY_MOTION}" id="motion" colour="#4C97FF" secondaryColour="#3373CC">' +
33
+ '<block type="motion_movesteps" id="motion_movesteps">' +
34
+ '<value name="STEPS">' +
35
+ '<shadow type="math_number">' +
36
+ '<field name="NUM">10</field>' +
37
+ '</shadow>' +
38
+ '</value>' +
39
+ '</block>' +
40
+ '<block type="motion_movesteps" id="motion_movesteps">' +
41
+ '<value name="STEPS">' +
42
+ '<shadow type="math_number">' +
43
+ '<field name="NUM">10</field>' +
44
+ '</shadow>' +
45
+ '</value>' +
46
+ '</block>' +
47
+ '<block type="motion_turnright" id="motion_turnright">' +
48
+ '<value name="DEGREES">' +
49
+ '<shadow type="math_number">' +
50
+ '<field name="NUM">15</field>' +
51
+ '</shadow>' +
52
+ '</value>' +
53
+ '</block>' +
54
+ '<block type="motion_turnleft" id="motion_turnleft">' +
55
+ '<value name="DEGREES">' +
56
+ '<shadow type="math_number">' +
57
+ '<field name="NUM">15</field>' +
58
+ '</shadow>' +
59
+ '</value>' +
60
+ '</block>' +
61
+ '<block type="motion_pointindirection" id="motion_pointindirection">' +
62
+ '<value name="DIRECTION">' +
63
+ '<shadow type="math_angle">' +
64
+ '<field name="NUM">90</field>' +
65
+ '</shadow>' +
66
+ '</value>' +
67
+ '</block>' +
68
+ '<block type="motion_pointtowards" id="motion_pointtowards">' +
69
+ '<value name="TOWARDS">' +
70
+ '<shadow type="motion_pointtowards_menu">' +
71
+ '</shadow>' +
72
+ '</value>' +
73
+ '</block>' +
74
+ '<block type="motion_gotoxy" id="motion_gotoxy">' +
75
+ '<value name="X">' +
76
+ '<shadow id="movex" type="math_number">' +
77
+ '<field name="NUM">0</field>' +
78
+ '</shadow>' +
79
+ '</value>' +
80
+ '<value name="Y">' +
81
+ '<shadow id="movey" type="math_number">' +
82
+ '<field name="NUM">0</field>' +
83
+ '</shadow>' +
84
+ '</value>' +
85
+ '</block>' +
86
+ '<block type="motion_goto" id="motion_goto">' +
87
+ '<value name="TO">' +
88
+ '<shadow type="motion_goto_menu">' +
89
+ '</shadow>' +
90
+ '</value>' +
91
+ '</block>' +
92
+ '<block type="motion_glidesecstoxy" id="motion_glidesecstoxy">' +
93
+ '<value name="SECS">' +
94
+ '<shadow type="math_number">' +
95
+ '<field name="NUM">1</field>' +
96
+ '</shadow>' +
97
+ '</value>' +
98
+ '<value name="X">' +
99
+ '<shadow id="glidex" type="math_number">' +
100
+ '<field name="NUM">0</field>' +
101
+ '</shadow>' +
102
+ '</value>' +
103
+ '<value name="Y">' +
104
+ '<shadow id="glidey" type="math_number">' +
105
+ '<field name="NUM">0</field>' +
106
+ '</shadow>' +
107
+ '</value>' +
108
+ '</block>' +
109
+ '<block type="motion_glideto" id="motion_glideto">' +
110
+ '<value name="SECS">' +
111
+ '<shadow type="math_number">' +
112
+ '<field name="NUM">1</field>' +
113
+ '</shadow>' +
114
+ '</value>' +
115
+ '<value name="TO">' +
116
+ '<shadow type="motion_glideto_menu">' +
117
+ '</shadow>' +
118
+ '</value>' +
119
+ '</block>' +
120
+ '<block type="motion_changexby" id="motion_changexby">' +
121
+ '<value name="DX">' +
122
+ '<shadow type="math_number">' +
123
+ '<field name="NUM">10</field>' +
124
+ '</shadow>' +
125
+ '</value>' +
126
+ '</block>' +
127
+ '<block type="motion_setx" id="motion_setx">' +
128
+ '<value name="X">' +
129
+ '<shadow id="setx" type="math_number">' +
130
+ '<field name="NUM">0</field>' +
131
+ '</shadow>' +
132
+ '</value>' +
133
+ '</block>' +
134
+ '<block type="motion_changeyby" id="motion_changeyby">' +
135
+ '<value name="DY">' +
136
+ '<shadow type="math_number">' +
137
+ '<field name="NUM">10</field>' +
138
+ '</shadow>' +
139
+ '</value>' +
140
+ '</block>' +
141
+ '<block type="motion_sety" id="motion_sety">' +
142
+ '<value name="Y">' +
143
+ '<shadow id="sety" type="math_number">' +
144
+ '<field name="NUM">0</field>' +
145
+ '</shadow>' +
146
+ '</value>' +
147
+ '</block>' +
148
+ '<block type="motion_ifonedgebounce" id="motion_ifonedgebounce"></block>' +
149
+ '<block type="motion_setrotationstyle" id="motion_setrotationstyle"></block>' +
150
+ '<block type="motion_xposition" id="motion_xposition"></block>' +
151
+ '<block type="motion_yposition" id="motion_yposition"></block>' +
152
+ '<block type="motion_direction" id="motion_direction"></block>' +
153
+ '</category>' +
154
+ '<category name="%{BKY_CATEGORY_LOOKS}" id="looks" colour="#9966FF" secondaryColour="#774DCB">' +
155
+ '<block type="looks_show" id="looks_show"></block>' +
156
+ '<block type="looks_hide" id="looks_hide"></block>' +
157
+ '<block type="looks_switchcostumeto" id="looks_switchcostumeto">' +
158
+ '<value name="COSTUME">' +
159
+ '<shadow type="looks_costume"></shadow>' +
160
+ '</value>' +
161
+ '</block>' +
162
+ '<block type="looks_nextcostume" id="looks_nextcostume"></block>' +
163
+ '<block type="looks_nextbackdrop" id="looks_nextbackdrop"></block>' +
164
+ '<block type="looks_switchbackdropto" id="looks_switchbackdropto">' +
165
+ '<value name="BACKDROP">' +
166
+ '<shadow type="looks_backdrops"></shadow>' +
167
+ '</value>' +
168
+ '</block>' +
169
+ '<block type="looks_switchbackdroptoandwait" id="looks_switchbackdroptoandwait">' +
170
+ '<value name="BACKDROP">' +
171
+ '<shadow type="looks_backdrops"></shadow>' +
172
+ '</value>' +
173
+ '</block>' +
174
+ '<block type="looks_changeeffectby" id="looks_changeeffectby">' +
175
+ '<value name="CHANGE">' +
176
+ '<shadow type="math_number">' +
177
+ '<field name="NUM">10</field>' +
178
+ '</shadow>' +
179
+ '</value>' +
180
+ '</block>' +
181
+ '<block type="looks_seteffectto" id="looks_seteffectto">' +
182
+ '<value name="VALUE">' +
183
+ '<shadow type="math_number">' +
184
+ '<field name="NUM">10</field>' +
185
+ '</shadow>' +
186
+ '</value>' +
187
+ '</block>' +
188
+ '<block type="looks_cleargraphiceffects" id="looks_cleargraphiceffects"></block>' +
189
+ '<block type="looks_changesizeby" id="looks_changesizeby">' +
190
+ '<value name="CHANGE">' +
191
+ '<shadow type="math_number">' +
192
+ '<field name="NUM">10</field>' +
193
+ '</shadow>' +
194
+ '</value>' +
195
+ '</block>' +
196
+ '<block type="looks_setsizeto" id="looks_setsizeto">' +
197
+ '<value name="SIZE">' +
198
+ '<shadow type="math_number">' +
199
+ '<field name="NUM">100</field>' +
200
+ '</shadow>' +
201
+ '</value>' +
202
+ '</block>' +
203
+ '<block type="looks_gotofrontback" id="looks_gotofrontback"></block>' +
204
+ '<block type="looks_goTargetLayer" id="looks_goTargetLayer"></block>' +
205
+ '<block type="looks_goforwardbackwardlayers" id="looks_goforwardbackwardlayers">' +
206
+ '<value name="NUM">' +
207
+ '<shadow type="math_integer">' +
208
+ '<field name="NUM">1</field>' +
209
+ '</shadow>' +
210
+ '</value>' +
211
+ '</block>' +
212
+ '<block type="looks_costumenumbername" id="looks_costumenumbername"></block>' +
213
+ '<block type="looks_backdropnumbername" id="looks_backdropnumbername"></block>' +
214
+ '<block type="looks_size" id="looks_size"></block>' +
215
+ '</category>' +
216
+ '<category name="%{BKY_CATEGORY_SOUND}" id="sound" colour="#D65CD6" secondaryColour="#BD42BD">' +
217
+ '<block type="sound_play" id="sound_play">' +
218
+ '<value name="SOUND_MENU">' +
219
+ '<shadow type="sound_sounds_menu"></shadow>' +
220
+ '</value>' +
221
+ '</block>' +
222
+ '<block type="sound_playuntildone" id="sound_playuntildone">' +
223
+ '<value name="SOUND_MENU">' +
224
+ '<shadow type="sound_sounds_menu"></shadow>' +
225
+ '</value>' +
226
+ '</block>' +
227
+ '<block type="sound_stopallsounds" id="sound_stopallsounds"></block>' +
228
+ '<block type="sound_changeeffectby" id="sound_changeeffectby">' +
229
+ '<value name="VALUE">' +
230
+ '<shadow type="math_number">' +
231
+ '<field name="NUM">10</field>' +
232
+ '</shadow>' +
233
+ '</value>' +
234
+ '</block>' +
235
+ '<block type="sound_seteffectto" id="sound_seteffectto">' +
236
+ '<value name="VALUE">' +
237
+ '<shadow type="math_number">' +
238
+ '<field name="NUM">100</field>' +
239
+ '</shadow>' +
240
+ '</value>' +
241
+ '</block>' +
242
+ '<block type="sound_cleareffects" id="sound_cleareffects"></block>' +
243
+ '<block type="sound_changevolumeby" id="sound_changevolumeby">' +
244
+ '<value name="VOLUME">' +
245
+ '<shadow type="math_number">' +
246
+ '<field name="NUM">-10</field>' +
247
+ '</shadow>' +
248
+ '</value>' +
249
+ '</block>' +
250
+ '<block type="sound_setvolumeto" id="sound_setvolumeto">' +
251
+ '<value name="VOLUME">' +
252
+ '<shadow type="math_number">' +
253
+ '<field name="NUM">100</field>' +
254
+ '</shadow>' +
255
+ '</value>' +
256
+ '</block>' +
257
+ '<block type="sound_volume" id="sound_volume"></block>' +
258
+ '</category>' +
259
+ '<category name="%{BKY_CATEGORY_EVENTS}" id="events" colour="#FFD500" secondaryColour="#CC9900">' +
260
+ '<block type="event_whenflagclicked" id="event_whenflagclicked"></block>' +
261
+ '<block type="event_whenkeypressed" id="event_whenkeypressed">' +
262
+ '</block>' +
263
+ '<block type="event_whenanything" id="event_whenanything">' +
264
+ '</block>' +
265
+ '<block type="event_whenthisspriteclicked" id="event_whenthisspriteclicked"></block>' +
266
+ '<block type="event_whenbackdropswitchesto" id="event_whenbackdropswitchesto">' +
267
+ '</block>' +
268
+ '<block type="event_whengreaterthan" id="event_whengreaterthan">' +
269
+ '<value name="VALUE">' +
270
+ '<shadow type="math_number">' +
271
+ '<field name="NUM">10</field>' +
272
+ '</shadow>' +
273
+ '</value>' +
274
+ '</block>' +
275
+ '<block type="event_whenbroadcastreceived" id="event_whenbroadcastreceived">' +
276
+ '</block>' +
277
+ '<block type="event_broadcast" id="event_broadcast">' +
278
+ '<value name="BROADCAST_INPUT">' +
279
+ '<shadow type="event_broadcast_menu"></shadow>' +
280
+ '</value>' +
281
+ '</block>' +
282
+ '<block type="event_broadcastandwait" id="event_broadcastandwait">' +
283
+ '<value name="BROADCAST_INPUT">' +
284
+ '<shadow type="event_broadcast_menu"></shadow>' +
285
+ '</value>' +
286
+ '</block>' +
287
+ '</category>' +
288
+ '<category name="%{BKY_CATEGORY_CONTROL}" id="control" colour="#FFAB19" secondaryColour="#CF8B17">' +
289
+ '<block type="control_wait" id="control_wait">' +
290
+ '<value name="DURATION">' +
291
+ '<shadow type="math_positive_number">' +
292
+ '<field name="NUM">1</field>' +
293
+ '</shadow>' +
294
+ '</value>' +
295
+ '</block>' +
296
+ '<block type="control_repeat" id="control_repeat">' +
297
+ '<value name="TIMES">' +
298
+ '<shadow type="math_whole_number">' +
299
+ '<field name="NUM">10</field>' +
300
+ '</shadow>' +
301
+ '</value>' +
302
+ '</block>' +
303
+ '<block type="control_forever" id="control_forever"></block>' +
304
+ '<block type="control_if" id="control_if"></block>' +
305
+ '<block type="control_if_else" id="control_if_else"></block>' +
306
+ '<block type="control_wait_until" id="control_wait_until"></block>' +
307
+ '<block type="control_repeat_until" id="control_repeat_until"></block>' +
308
+ '<block type="control_stop" id="control_stop"></block>' +
309
+ '<block type="control_start_as_clone" id="control_start_as_clone"></block>' +
310
+ '<block type="control_create_clone_of" id="control_create_clone_of">' +
311
+ '<value name="CLONE_OPTION">' +
312
+ '<shadow type="control_create_clone_of_menu"></shadow>' +
313
+ '</value>' +
314
+ '</block>' +
315
+ '<block type="control_delete_this_clone" id="control_delete_this_clone"></block>' +
316
+ '<block type="control_for_each" id="control_for_each"></block>' +
317
+ '</category>' +
318
+ '<category name="%{BKY_CATEGORY_SENSING}" id="sensing" colour="#4CBFE6" secondaryColour="#2E8EB8">' +
319
+ '<block type="sensing_touchingobject" id="sensing_touchingobject">' +
320
+ '<value name="TOUCHINGOBJECTMENU">' +
321
+ '<shadow type="sensing_touchingobjectmenu"></shadow>' +
322
+ '</value>' +
323
+ '</block>' +
324
+ '<block type="sensing_touchingcolor" id="sensing_touchingcolor">' +
325
+ '<value name="COLOR">' +
326
+ '<shadow type="colour_picker"></shadow>' +
327
+ '</value>' +
328
+ '</block>' +
329
+ '<block type="sensing_coloristouchingcolor" id="sensing_coloristouchingcolor">' +
330
+ '<value name="COLOR">' +
331
+ '<shadow type="colour_picker"></shadow>' +
332
+ '</value>' +
333
+ '<value name="COLOR2">' +
334
+ '<shadow type="colour_picker"></shadow>' +
335
+ '</value>' +
336
+ '</block>' +
337
+ '<block type="sensing_distanceto" id="sensing_distanceto">' +
338
+ '<value name="DISTANCETOMENU">' +
339
+ '<shadow type="sensing_distancetomenu"></shadow>' +
340
+ '</value>' +
341
+ '</block>' +
342
+ '<block type="sensing_keypressed" id="sensing_keypressed">' +
343
+ '<value name="KEY_OPTION">' +
344
+ '<shadow type="sensing_keyoptions"></shadow>' +
345
+ '</value>' +
346
+ '</block>' +
347
+ '<block type="sensing_mousedown" id="sensing_mousedown"></block>' +
348
+ '<block type="sensing_mousex" id="sensing_mousex"></block>' +
349
+ '<block type="sensing_mousey" id="sensing_mousey"></block>' +
350
+ '<block type="sensing_setdragmode" id="sensing_setdragmode"></block>' +
351
+ '<block type="sensing_loudness" id="sensing_loudness"></block>' +
352
+ '<block type="sensing_timer" id="sensing_timer"></block>' +
353
+ '<block type="sensing_resettimer" id="sensing_resettimer"></block>' +
354
+ '<block type="sensing_of" id="sensing_of">' +
355
+ '<value name="OBJECT">' +
356
+ '<shadow type="sensing_of_object_menu"></shadow>' +
357
+ '</value>' +
358
+ '</block>' +
359
+ '<block type="sensing_current" id="sensing_current"></block>' +
360
+ '<block type="sensing_dayssince2000" id="sensing_dayssince2000"></block>' +
361
+ '</category>' +
362
+ '<category name="%{BKY_CATEGORY_OPERATORS}" id="operators" colour="#40BF4A" secondaryColour="#389438">' +
363
+ '<block type="operator_add" id="operator_add">' +
364
+ '<value name="NUM1">' +
365
+ '<shadow type="math_number">' +
366
+ '<field name="NUM"></field>' +
367
+ '</shadow>' +
368
+ '</value>' +
369
+ '<value name="NUM2">' +
370
+ '<shadow type="math_number">' +
371
+ '<field name="NUM"></field>' +
372
+ '</shadow>' +
373
+ '</value>' +
374
+ '</block>' +
375
+ '<block type="operator_subtract" id="operator_subtract">' +
376
+ '<value name="NUM1">' +
377
+ '<shadow type="math_number">' +
378
+ '<field name="NUM"></field>' +
379
+ '</shadow>' +
380
+ '</value>' +
381
+ '<value name="NUM2">' +
382
+ '<shadow type="math_number">' +
383
+ '<field name="NUM"></field>' +
384
+ '</shadow>' +
385
+ '</value>' +
386
+ '</block>' +
387
+ '<block type="operator_multiply" id="operator_multiply">' +
388
+ '<value name="NUM1">' +
389
+ '<shadow type="math_number">' +
390
+ '<field name="NUM"></field>' +
391
+ '</shadow>' +
392
+ '</value>' +
393
+ '<value name="NUM2">' +
394
+ '<shadow type="math_number">' +
395
+ '<field name="NUM"></field>' +
396
+ '</shadow>' +
397
+ '</value>' +
398
+ '</block>' +
399
+ '<block type="operator_divide" id="operator_divide">' +
400
+ '<value name="NUM1">' +
401
+ '<shadow type="math_number">' +
402
+ '<field name="NUM"></field>' +
403
+ '</shadow>' +
404
+ '</value>' +
405
+ '<value name="NUM2">' +
406
+ '<shadow type="math_number">' +
407
+ '<field name="NUM"></field>' +
408
+ '</shadow>' +
409
+ '</value>' +
410
+ '</block>' +
411
+ '<block type="operator_random" id="operator_random">' +
412
+ '<value name="FROM">' +
413
+ '<shadow type="math_number">' +
414
+ '<field name="NUM">1</field>' +
415
+ '</shadow>' +
416
+ '</value>' +
417
+ '<value name="TO">' +
418
+ '<shadow type="math_number">' +
419
+ '<field name="NUM">10</field>' +
420
+ '</shadow>' +
421
+ '</value>' +
422
+ '</block>' +
423
+ '<block type="operator_lt" id="operator_lt">' +
424
+ '<value name="OPERAND1">' +
425
+ '<shadow type="text">' +
426
+ '<field name="TEXT"></field>' +
427
+ '</shadow>' +
428
+ '</value>' +
429
+ '<value name="OPERAND2">' +
430
+ '<shadow type="text">' +
431
+ '<field name="TEXT"></field>' +
432
+ '</shadow>' +
433
+ '</value>' +
434
+ '</block>' +
435
+ '<block type="operator_equals" id="operator_equals">' +
436
+ '<value name="OPERAND1">' +
437
+ '<shadow type="text">' +
438
+ '<field name="TEXT"></field>' +
439
+ '</shadow>' +
440
+ '</value>' +
441
+ '<value name="OPERAND2">' +
442
+ '<shadow type="text">' +
443
+ '<field name="TEXT"></field>' +
444
+ '</shadow>' +
445
+ '</value>' +
446
+ '</block>' +
447
+ '<block type="operator_gt" id="operator_gt">' +
448
+ '<value name="OPERAND1">' +
449
+ '<shadow type="text">' +
450
+ '<field name="TEXT"></field>' +
451
+ '</shadow>' +
452
+ '</value>' +
453
+ '<value name="OPERAND2">' +
454
+ '<shadow type="text">' +
455
+ '<field name="TEXT"></field>' +
456
+ '</shadow>' +
457
+ '</value>' +
458
+ '</block>' +
459
+ '<block type="operator_and" id="operator_and"></block>' +
460
+ '<block type="operator_or" id="operator_or"></block>' +
461
+ '<block type="operator_not" id="operator_not"></block>' +
462
+ '<block type="operator_join" id="operator_join">' +
463
+ '<value name="STRING1">' +
464
+ '<shadow type="text">' +
465
+ '<field name="TEXT">hello</field>' +
466
+ '</shadow>' +
467
+ '</value>' +
468
+ '<value name="STRING2">' +
469
+ '<shadow type="text">' +
470
+ '<field name="TEXT">world</field>' +
471
+ '</shadow>' +
472
+ '</value>' +
473
+ '</block>' +
474
+ '<block type="operator_letter_of" id="operator_letter_of">' +
475
+ '<value name="LETTER">' +
476
+ '<shadow type="math_whole_number">' +
477
+ '<field name="NUM">1</field>' +
478
+ '</shadow>' +
479
+ '</value>' +
480
+ '<value name="STRING">' +
481
+ '<shadow type="text">' +
482
+ '<field name="TEXT">world</field>' +
483
+ '</shadow>' +
484
+ '</value>' +
485
+ '</block>' +
486
+ '<block type="operator_length" id="operator_length">' +
487
+ '<value name="STRING">' +
488
+ '<shadow type="text">' +
489
+ '<field name="TEXT">world</field>' +
490
+ '</shadow>' +
491
+ '</value>' +
492
+ '</block>' +
493
+ '<block type="operator_contains" id="operator_contains">' +
494
+ '<value name="STRING1">' +
495
+ '<shadow type="text">' +
496
+ '<field name="TEXT">hello</field>' +
497
+ '</shadow>' +
498
+ '</value>' +
499
+ '<value name="STRING2">' +
500
+ '<shadow type="text">' +
501
+ '<field name="TEXT">world</field>' +
502
+ '</shadow>' +
503
+ '</value>' +
504
+ '</block>' +
505
+ '<block type="operator_mod" id="operator_mod">' +
506
+ '<value name="NUM1">' +
507
+ '<shadow type="math_number">' +
508
+ '<field name="NUM"></field>' +
509
+ '</shadow>' +
510
+ '</value>' +
511
+ '<value name="NUM2">' +
512
+ '<shadow type="math_number">' +
513
+ '<field name="NUM"></field>' +
514
+ '</shadow>' +
515
+ '</value>' +
516
+ '</block>' +
517
+ '<block type="operator_round" id="operator_round">' +
518
+ '<value name="NUM">' +
519
+ '<shadow type="math_number">' +
520
+ '<field name="NUM"></field>' +
521
+ '</shadow>' +
522
+ '</value>' +
523
+ '</block>' +
524
+ '<block type="operator_mathop" id="operator_mathop">' +
525
+ '<value name="NUM">' +
526
+ '<shadow type="math_number">' +
527
+ '<field name="NUM"></field>' +
528
+ '</shadow>' +
529
+ '</value>' +
530
+ '</block>' +
531
+ '</category>' +
532
+ '<category name="%{BKY_CATEGORY_VARIABLES}" id="variable" colour="#FF8C1A" secondaryColour="#DB6E00" custom="VARIABLE">' +
533
+ '</category>' +
534
+ '<category name="%{BKY_CATEGORY_LISTS}" id="list" colour="#FF661A" secondaryColour="#FF5500" custom="LIST">' +
535
+ '</category>' +
536
+ '<category name="%{BKY_CATEGORY_MYBLOCKS}" id="more" colour="#FF6680" secondaryColour="#FF4D6A" custom="PROCEDURE">' +
537
+ '</category>' +
538
+ '<category name="Extensions" id="extensions" colour="#FF6680" secondaryColour="#FF4D6A" ' +
539
+ 'iconURI="../media/extensions/wedo2-block-icon.svg" showStatusButton="true" ' +
540
+ 'options="extensionControls">' +
541
+ '<block type="extension_pen_down" id="extension_pen_down"></block>' +
542
+ '<block type="extension_music_drum" id="extension_music_drum">' +
543
+ '<value name="NUMBER">' +
544
+ '<shadow type="math_number">' +
545
+ '<field name="NUM">1</field>' +
546
+ '</shadow>' +
547
+ '</value>' +
548
+ '</block>' +
549
+ '<block type="extension_wedo_motor" id="extension_wedo_motor"></block>' +
550
+ '<block type="extension_wedo_hat" id="extension_wedo_hat"></block>' +
551
+ '<block type="extension_wedo_boolean" id="extension_wedo_boolean"></block>' +
552
+ '<block type="control_fieldbutton" id="control_fieldbutton"></block>' +
553
+ '<block type="control_fieldcheckboxoriginal" id="control_fieldcheckboxoriginal"></block>' +
554
+ '<block type="motion_mutatorCheckboxTest" id="motion_mutatorCheckboxTest"></block>' +
555
+ '<block type="operators_expandablejoininputs" id="extension_wedo_boolean"></block>' +
556
+ '<block type="extension_wedo_tilt_reporter" id="extension_wedo_reporter">' +
557
+ '<value name="TILT">' +
558
+ '<shadow type="extension_wedo_tilt_menu"></shadow>' +
559
+ '</value>' +
560
+ '</block>' +
561
+ '<block type="extension_music_reporter" id="extension_music_reporter"></block>' +
562
+ '<block type="extension_microbit_display" id="extension_microbit_display">' +
563
+ '<value name="MATRIX">' +
564
+ '<shadow type="matrix">' +
565
+ '<field name="MATRIX">0101010101100010101000100</field>' +
566
+ '</shadow>' +
567
+ '</value>' +
568
+ '</block>' +
569
+ '<block type="extension_music_play_note" id="extension_music_play_note">' +
570
+ '<value name="NOTE">' +
571
+ '<shadow type="note">' +
572
+ '<field name="NOTE">60</field>' +
573
+ '</shadow>' +
574
+ '</value>' +
575
+ '<value name="BEATS">' +
576
+ '<shadow type="math_number">' +
577
+ '<field name="NUM">0.25</field>' +
578
+ '</shadow>' +
579
+ '</value>' +
580
+ '</block>' +
581
+ '<block type="field_textdropdown_test" id="extension_wedo_boolean"></block>' +
582
+ '</category>' +
583
+ '</xml>';
blocks_vertical/event.js ADDED
@@ -0,0 +1,489 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.event');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+ Blockly.Blocks['event_whentouchingobject'] = {
31
+ /**
32
+ * Block for when a sprite is touching an object.
33
+ * @this Blockly.Block
34
+ */
35
+ init: function () {
36
+ this.jsonInit({
37
+ "message0": Blockly.Msg.EVENT_WHENTOUCHINGOBJECT,
38
+ "args0": [
39
+ {
40
+ "type": "input_value",
41
+ "name": "TOUCHINGOBJECTMENU"
42
+ }
43
+ ],
44
+ "category": Blockly.Categories.event,
45
+ "extensions": ["colours_event", "shape_hat"]
46
+ });
47
+ }
48
+ };
49
+
50
+ Blockly.Blocks['event_touchingobjectmenu'] = {
51
+ /**
52
+ * "Touching [Object]" Block Menu.
53
+ * @this Blockly.Block
54
+ */
55
+ init: function () {
56
+ this.jsonInit({
57
+ "message0": "%1",
58
+ "args0": [
59
+ {
60
+ "type": "field_dropdown",
61
+ "name": "TOUCHINGOBJECTMENU",
62
+ "options": [
63
+ [Blockly.Msg.SENSING_TOUCHINGOBJECT_POINTER, '_mouse_'],
64
+ [Blockly.Msg.SENSING_TOUCHINGOBJECT_EDGE, '_edge_']
65
+ ]
66
+ }
67
+ ],
68
+ "extensions": ["colours_event", "output_string"]
69
+ });
70
+ }
71
+ };
72
+
73
+ Blockly.Blocks['event_whenflagclicked'] = {
74
+ /**
75
+ * Block for when flag clicked.
76
+ * @this Blockly.Block
77
+ */
78
+ init: function () {
79
+ this.jsonInit({
80
+ "id": "event_whenflagclicked",
81
+ "message0": Blockly.Msg.EVENT_WHENFLAGCLICKED,
82
+ "args0": [
83
+ {
84
+ "type": "field_image",
85
+ "src": Blockly.mainWorkspace.options.pathToMedia + "blue-flag.svg",
86
+ "width": 24,
87
+ "height": 24,
88
+ "alt": "flag"
89
+ }
90
+ ],
91
+ "category": Blockly.Categories.event,
92
+ "extensions": ["colours_event", "shape_hat"]
93
+ });
94
+ }
95
+ };
96
+
97
+ Blockly.Blocks['event_whenstopclicked'] = {
98
+ /**
99
+ * pm: Block for when stop button clicked.
100
+ * @this Blockly.Block
101
+ */
102
+ init: function () {
103
+ this.jsonInit({
104
+ "id": "event_whenstopclicked",
105
+ "message0": "when %1 clicked",
106
+ "args0": [
107
+ {
108
+ "type": "field_image",
109
+ "src": Blockly.mainWorkspace.options.pathToMedia + "/icons/control_stop.svg",
110
+ "width": 24,
111
+ "height": 24,
112
+ "alt": "stop"
113
+ }
114
+ ],
115
+ "category": Blockly.Categories.event,
116
+ "extensions": ["colours_event", "shape_hat"]
117
+ });
118
+ }
119
+ };
120
+
121
+ Blockly.Blocks['event_whenthisspriteclicked'] = {
122
+ /**
123
+ * Block for when this sprite clicked.
124
+ * @this Blockly.Block
125
+ */
126
+ init: function () {
127
+ this.jsonInit({
128
+ "message0": Blockly.Msg.EVENT_WHENTHISSPRITECLICKED,
129
+ "category": Blockly.Categories.event,
130
+ "extensions": ["colours_event", "shape_hat"]
131
+ });
132
+ }
133
+
134
+ };
135
+
136
+ Blockly.Blocks['event_whenstageclicked'] = {
137
+ /**
138
+ * Block for when the stage is clicked.
139
+ * @this Blockly.Block
140
+ */
141
+ init: function () {
142
+ this.jsonInit({
143
+ "message0": Blockly.Msg.EVENT_WHENSTAGECLICKED,
144
+ "category": Blockly.Categories.event,
145
+ "extensions": ["colours_event", "shape_hat"]
146
+ });
147
+ }
148
+ };
149
+
150
+ Blockly.Blocks['event_whenbroadcastreceived'] = {
151
+ /**
152
+ * Block for when broadcast received.
153
+ * @this Blockly.Block
154
+ */
155
+ init: function () {
156
+ this.jsonInit({
157
+ "id": "event_whenbroadcastreceived",
158
+ "message0": Blockly.Msg.EVENT_WHENBROADCASTRECEIVED,
159
+ "args0": [
160
+ {
161
+ "type": "field_variable",
162
+ "name": "BROADCAST_OPTION",
163
+ "variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
164
+ "variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
165
+ }
166
+ ],
167
+ "category": Blockly.Categories.event,
168
+ "extensions": ["colours_event", "shape_hat"]
169
+ });
170
+ }
171
+ };
172
+
173
+ Blockly.Blocks['event_whenbackdropswitchesto'] = {
174
+ /**
175
+ * Block for when the current backdrop switched to a selected backdrop.
176
+ * @this Blockly.Block
177
+ */
178
+ init: function () {
179
+ this.jsonInit({
180
+ "message0": Blockly.Msg.EVENT_WHENBACKDROPSWITCHESTO,
181
+ "args0": [
182
+ {
183
+ "type": "field_dropdown",
184
+ "name": "BACKDROP",
185
+ "options": [
186
+ ['backdrop1', 'BACKDROP1']
187
+ ]
188
+ }
189
+ ],
190
+ "category": Blockly.Categories.event,
191
+ "extensions": ["colours_event", "shape_hat"]
192
+ });
193
+ }
194
+ };
195
+
196
+ Blockly.Blocks['event_whengreaterthan'] = {
197
+ /**
198
+ * Block for when loudness/timer/video motion is greater than the value.
199
+ * @this Blockly.Block
200
+ */
201
+ init: function () {
202
+ this.jsonInit({
203
+ "message0": Blockly.Msg.EVENT_WHENGREATERTHAN,
204
+ "args0": [
205
+ {
206
+ "type": "field_dropdown",
207
+ "name": "WHENGREATERTHANMENU",
208
+ "options": [
209
+ [Blockly.Msg.EVENT_WHENGREATERTHAN_LOUDNESS, 'LOUDNESS'],
210
+ [Blockly.Msg.EVENT_WHENGREATERTHAN_TIMER, 'TIMER']
211
+ ]
212
+ },
213
+ {
214
+ "type": "input_value",
215
+ "name": "VALUE"
216
+ }
217
+ ],
218
+ "category": Blockly.Categories.event,
219
+ "extensions": ["colours_event", "shape_hat"]
220
+ });
221
+ }
222
+ };
223
+
224
+ Blockly.Blocks['event_broadcast_menu'] = {
225
+ /**
226
+ * Broadcast drop-down menu.
227
+ * @this Blockly.Block
228
+ */
229
+ init: function () {
230
+ this.jsonInit({
231
+ "message0": "%1",
232
+ "args0": [
233
+ {
234
+ "type": "field_variable",
235
+ "name": "BROADCAST_OPTION",
236
+ "variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
237
+ "variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
238
+ }
239
+ ],
240
+ "colour": Blockly.Colours.event.secondary,
241
+ "colourSecondary": Blockly.Colours.event.secondary,
242
+ "colourTertiary": Blockly.Colours.event.tertiary,
243
+ "extensions": ["output_string"]
244
+ });
245
+ }
246
+ };
247
+
248
+ Blockly.Blocks['event_broadcast'] = {
249
+ /**
250
+ * Block to send a broadcast.
251
+ * @this Blockly.Block
252
+ */
253
+ init: function () {
254
+ this.jsonInit({
255
+ "id": "event_broadcast",
256
+ "message0": Blockly.Msg.EVENT_BROADCAST,
257
+ "args0": [
258
+ {
259
+ "type": "input_value",
260
+ "name": "BROADCAST_INPUT"
261
+ }
262
+ ],
263
+ "category": Blockly.Categories.event,
264
+ "extensions": ["colours_event", "shape_statement"]
265
+ });
266
+ }
267
+ };
268
+
269
+ Blockly.Blocks['event_broadcastandwait'] = {
270
+ /**
271
+ * Block to send a broadcast.
272
+ * @this Blockly.Block
273
+ */
274
+ init: function () {
275
+ this.jsonInit({
276
+ "message0": Blockly.Msg.EVENT_BROADCASTANDWAIT,
277
+ "args0": [
278
+ {
279
+ "type": "input_value",
280
+ "name": "BROADCAST_INPUT"
281
+ }
282
+ ],
283
+ "category": Blockly.Categories.event,
284
+ "extensions": ["colours_event", "shape_statement"]
285
+ });
286
+ }
287
+ };
288
+
289
+ Blockly.Blocks['event_whenkeypressed'] = {
290
+ /**
291
+ * Block to send a broadcast.
292
+ * @this Blockly.Block
293
+ */
294
+ init: function () {
295
+ this.jsonInit({
296
+ "id": "event_whenkeypressed",
297
+ "message0": Blockly.Msg.EVENT_WHENKEYPRESSED,
298
+ "args0": [
299
+ {
300
+ "type": "field_dropdown",
301
+ "name": "KEY_OPTION",
302
+ "options": [
303
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'],
304
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'],
305
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'],
306
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'],
307
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'],
308
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'],
309
+ ['a', 'a'],
310
+ ['b', 'b'],
311
+ ['c', 'c'],
312
+ ['d', 'd'],
313
+ ['e', 'e'],
314
+ ['f', 'f'],
315
+ ['g', 'g'],
316
+ ['h', 'h'],
317
+ ['i', 'i'],
318
+ ['j', 'j'],
319
+ ['k', 'k'],
320
+ ['l', 'l'],
321
+ ['m', 'm'],
322
+ ['n', 'n'],
323
+ ['o', 'o'],
324
+ ['p', 'p'],
325
+ ['q', 'q'],
326
+ ['r', 'r'],
327
+ ['s', 's'],
328
+ ['t', 't'],
329
+ ['u', 'u'],
330
+ ['v', 'v'],
331
+ ['w', 'w'],
332
+ ['x', 'x'],
333
+ ['y', 'y'],
334
+ ['z', 'z'],
335
+ ['0', '0'],
336
+ ['1', '1'],
337
+ ['2', '2'],
338
+ ['3', '3'],
339
+ ['4', '4'],
340
+ ['5', '5'],
341
+ ['6', '6'],
342
+ ['7', '7'],
343
+ ['8', '8'],
344
+ ['9', '9']
345
+ ]
346
+ }
347
+ ],
348
+ "category": Blockly.Categories.event,
349
+ "extensions": ["colours_event", "shape_hat"]
350
+ });
351
+ }
352
+ };
353
+
354
+ Blockly.Blocks['event_whenkeyhit'] = {
355
+ /**
356
+ * Block to send a broadcast.
357
+ * @this Blockly.Block
358
+ */
359
+ init: function () {
360
+ this.jsonInit({
361
+ "id": "event_whenkeyhit",
362
+ "message0": "when %1 key hit",
363
+ "args0": [
364
+ {
365
+ "type": "field_dropdown",
366
+ "name": "KEY_OPTION",
367
+ "options": [
368
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'],
369
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'],
370
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'],
371
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'],
372
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'],
373
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'],
374
+ ['a', 'a'],
375
+ ['b', 'b'],
376
+ ['c', 'c'],
377
+ ['d', 'd'],
378
+ ['e', 'e'],
379
+ ['f', 'f'],
380
+ ['g', 'g'],
381
+ ['h', 'h'],
382
+ ['i', 'i'],
383
+ ['j', 'j'],
384
+ ['k', 'k'],
385
+ ['l', 'l'],
386
+ ['m', 'm'],
387
+ ['n', 'n'],
388
+ ['o', 'o'],
389
+ ['p', 'p'],
390
+ ['q', 'q'],
391
+ ['r', 'r'],
392
+ ['s', 's'],
393
+ ['t', 't'],
394
+ ['u', 'u'],
395
+ ['v', 'v'],
396
+ ['w', 'w'],
397
+ ['x', 'x'],
398
+ ['y', 'y'],
399
+ ['z', 'z'],
400
+ ['0', '0'],
401
+ ['1', '1'],
402
+ ['2', '2'],
403
+ ['3', '3'],
404
+ ['4', '4'],
405
+ ['5', '5'],
406
+ ['6', '6'],
407
+ ['7', '7'],
408
+ ['8', '8'],
409
+ ['9', '9']
410
+ ]
411
+ }
412
+ ],
413
+ "category": Blockly.Categories.event,
414
+ "extensions": ["colours_event", "shape_hat"]
415
+ });
416
+ }
417
+ };
418
+
419
+ Blockly.Blocks['event_whenmousescrolled'] = {
420
+ /**
421
+ * pm: Block to send a broadcast when the mouse is scrolled in a direction.
422
+ * @this Blockly.Block
423
+ */
424
+ init: function () {
425
+ this.jsonInit({
426
+ "id": "event_whenmousescrolled",
427
+ "message0": "when mouse is scrolled %1",
428
+ "args0": [
429
+ {
430
+ "type": "field_dropdown",
431
+ "name": "KEY_OPTION",
432
+ "options": [
433
+ ['up', 'up'],
434
+ ['down', 'down']
435
+ ]
436
+ }
437
+ ],
438
+ "category": Blockly.Categories.event,
439
+ "extensions": ["colours_event", "shape_hat"]
440
+ });
441
+ }
442
+ };
443
+
444
+ Blockly.Blocks["event_always"] = {
445
+ init: function() {
446
+ this.jsonInit({
447
+ "inputsInline": true,
448
+ "message0": "always",
449
+ "args0": [],
450
+ "category": Blockly.Categories.event,
451
+ "extensions": ["colours_event", "shape_hat"]
452
+ });
453
+ }
454
+ };
455
+
456
+ Blockly.Blocks["event_whenanything"] = {
457
+ init: function() {
458
+ this.jsonInit({
459
+ "inputsInline": true,
460
+ "message0": "when %1",
461
+ "args0": [
462
+ {
463
+ "type": "input_value",
464
+ "name": "ANYTHING",
465
+ "check": "Boolean"
466
+ }
467
+ ],
468
+ "category": Blockly.Categories.event,
469
+ "extensions": ["colours_event", "shape_hat"]
470
+ });
471
+ }
472
+ };
473
+
474
+ Blockly.Blocks["event_whenjavascript"] = {
475
+ init: function () {
476
+ this.jsonInit({
477
+ "inputsInline": true,
478
+ "message0": "when javascript %1 === true",
479
+ "args0": [
480
+ {
481
+ "type": "input_value",
482
+ "name": "JS"
483
+ }
484
+ ],
485
+ "category": Blockly.Categories.event,
486
+ "extensions": ["colours_event", "shape_hat"]
487
+ });
488
+ }
489
+ };
blocks_vertical/extensions.js ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.extensions');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+ Blockly.Blocks['extension_pen_down'] = {
31
+ /**
32
+ * @this Blockly.Block
33
+ */
34
+ init: function() {
35
+ this.jsonInit({
36
+ "message0": "%1 %2 pen down",
37
+ "args0": [
38
+ {
39
+ "type": "field_image",
40
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/pen-block-icon.svg",
41
+ "width": 40,
42
+ "height": 40
43
+ },
44
+ {
45
+ "type": "field_vertical_separator"
46
+ }
47
+ ],
48
+ "category": Blockly.Categories.more,
49
+ "extensions": ["colours_more", "shape_statement", "scratch_extension"]
50
+ });
51
+ }
52
+ };
53
+
54
+ Blockly.Blocks['extension_music_drum'] = {
55
+ /**
56
+ * @this Blockly.Block
57
+ */
58
+ init: function() {
59
+ this.jsonInit({
60
+ "message0": "%1 %2 play drum %3",
61
+ "args0": [
62
+ {
63
+ "type": "field_image",
64
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
65
+ "width": 40,
66
+ "height": 40
67
+ },
68
+ {
69
+ "type": "field_vertical_separator"
70
+ },
71
+ {
72
+ "type": "input_value",
73
+ "name": "NUMBER"
74
+ }
75
+ ],
76
+ "category": Blockly.Categories.more,
77
+ "extensions": ["colours_more", "shape_statement", "scratch_extension"]
78
+ });
79
+ }
80
+ };
81
+
82
+ Blockly.Blocks['extension_wedo_motor'] = {
83
+ /**
84
+ * @this Blockly.Block
85
+ */
86
+ init: function() {
87
+ this.jsonInit({
88
+ "message0": "%1 %2 turn a motor %3",
89
+ "args0": [
90
+ {
91
+ "type": "field_image",
92
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
93
+ "width": 40,
94
+ "height": 40
95
+ },
96
+ {
97
+ "type": "field_vertical_separator"
98
+ },
99
+ {
100
+ "type": "field_image",
101
+ "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
102
+ "width": 24,
103
+ "height": 24
104
+ }
105
+ ],
106
+ "category": Blockly.Categories.more,
107
+ "extensions": ["colours_more", "shape_statement", "scratch_extension"]
108
+ });
109
+ }
110
+ };
111
+
112
+ Blockly.Blocks['extension_wedo_hat'] = {
113
+ /**
114
+ * @this Blockly.Block
115
+ */
116
+ init: function() {
117
+ this.jsonInit({
118
+ "message0": "%1 %2 when I am wearing a hat",
119
+ "args0": [
120
+ {
121
+ "type": "field_image",
122
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
123
+ "width": 40,
124
+ "height": 40
125
+ },
126
+ {
127
+ "type": "field_vertical_separator"
128
+ }
129
+ ],
130
+ "category": Blockly.Categories.more,
131
+ "extensions": ["colours_more", "shape_hat", "scratch_extension"]
132
+ });
133
+ }
134
+ };
135
+
136
+ Blockly.Blocks['extension_wedo_boolean'] = {
137
+ /**
138
+ * @this Blockly.Block
139
+ */
140
+ init: function() {
141
+ this.jsonInit({
142
+ "message0": "%1 %2 O RLY?",
143
+ "args0": [
144
+ {
145
+ "type": "field_image",
146
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
147
+ "width": 40,
148
+ "height": 40
149
+ },
150
+ {
151
+ "type": "field_vertical_separator"
152
+ }
153
+ ],
154
+ "category": Blockly.Categories.more,
155
+ "extensions": ["colours_more", "output_boolean", "scratch_extension"]
156
+ });
157
+ }
158
+ };
159
+
160
+ Blockly.Blocks['extension_wedo_tilt_reporter'] = {
161
+ /**
162
+ * @this Blockly.Block
163
+ */
164
+ init: function() {
165
+ this.jsonInit({
166
+ "message0": "%1 %2 tilt angle %3",
167
+ "args0": [
168
+ {
169
+ "type": "field_image",
170
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
171
+ "width": 40,
172
+ "height": 40
173
+ },
174
+ {
175
+ "type": "field_vertical_separator"
176
+ },
177
+ {
178
+ "type": "input_value",
179
+ "name": "TILT"
180
+ }
181
+ ],
182
+ "category": Blockly.Categories.more,
183
+ "extensions": ["colours_more", "output_number", "scratch_extension"]
184
+ });
185
+ }
186
+ };
187
+
188
+ Blockly.Blocks['extension_wedo_tilt_menu'] = {
189
+ /**
190
+ * @this Blockly.Block
191
+ */
192
+ init: function() {
193
+ this.jsonInit({
194
+ "message0": "%1",
195
+ "args0": [
196
+ {
197
+ "type": "field_dropdown",
198
+ "name": "TILT",
199
+ "options": [
200
+ ['Any', 'Any'],
201
+ ['Whirl', 'Whirl'],
202
+ ['South', 'South'],
203
+ ['Back in time', 'Back in time']
204
+ ]
205
+ }
206
+ ],
207
+ "extensions": ["colours_more", "output_string"]
208
+ });
209
+ }
210
+ };
211
+
212
+ Blockly.Blocks['extension_music_reporter'] = {
213
+ /**
214
+ * @this Blockly.Block
215
+ */
216
+ init: function() {
217
+ this.jsonInit({
218
+ "message0": "%1 %2 hey now, you're an all-star",
219
+ "args0": [
220
+ {
221
+ "type": "field_image",
222
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
223
+ "width": 40,
224
+ "height": 40
225
+ },
226
+ {
227
+ "type": "field_vertical_separator"
228
+ }
229
+ ],
230
+ "category": Blockly.Categories.more,
231
+ "extensions": ["colours_more", "output_number", "scratch_extension"]
232
+ });
233
+ }
234
+ };
235
+
236
+ Blockly.Blocks['extension_microbit_display'] = {
237
+ /**
238
+ * @this Blockly.Block
239
+ */
240
+ init: function() {
241
+ this.jsonInit({
242
+ "message0": "%1 %2 display %3",
243
+ "args0": [
244
+ {
245
+ "type": "field_image",
246
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/microbit-block-icon.svg",
247
+ "width": 40,
248
+ "height": 40
249
+ },
250
+ {
251
+ "type": "field_vertical_separator"
252
+ },
253
+ {
254
+ "type": "input_value",
255
+ "name": "MATRIX"
256
+ },
257
+ ],
258
+ "category": Blockly.Categories.pen,
259
+ "extensions": ["colours_pen", "shape_statement", "scratch_extension"]
260
+ });
261
+ }
262
+ };
263
+
264
+ Blockly.Blocks['extension_music_play_note'] = {
265
+ /**
266
+ * @this Blockly.Block
267
+ */
268
+ init: function() {
269
+ this.jsonInit({
270
+ "message0": "%1 %2 play note %3 for %4 beats",
271
+ "args0": [
272
+ {
273
+ "type": "field_image",
274
+ "src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
275
+ "width": 40,
276
+ "height": 40
277
+ },
278
+ {
279
+ "type": "field_vertical_separator"
280
+ },
281
+ {
282
+ "type": "input_value",
283
+ "name": "NOTE"
284
+ },
285
+ {
286
+ "type": "input_value",
287
+ "name": "BEATS"
288
+ }
289
+ ],
290
+ "category": Blockly.Categories.pen,
291
+ "extensions": ["colours_pen", "shape_statement", "scratch_extension"]
292
+ });
293
+ }
294
+ };
blocks_vertical/live_tests.js ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ goog.provide('Blockly.Blocks.liveTests');
4
+
5
+ goog.require('Blockly.Blocks');
6
+ goog.require('Blockly.Colours');
7
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
8
+
9
+ Blockly.Blocks['sensing_set_of'] = {
10
+ /**
11
+ * Block to report properties of sprites.
12
+ * @this Blockly.Block
13
+ */
14
+ init: function() {
15
+ this.jsonInit({
16
+ "message0": 'set %1 of %2 to %3',
17
+ "args0": [
18
+ {
19
+ "type": "field_dropdown",
20
+ "name": "PROPERTY",
21
+ "options": [
22
+ [Blockly.Msg.SENSING_OF_XPOSITION, 'x position'],
23
+ [Blockly.Msg.SENSING_OF_YPOSITION, 'y position'],
24
+ [Blockly.Msg.SENSING_OF_DIRECTION, 'direction'],
25
+ [Blockly.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'],
26
+ [Blockly.Msg.SENSING_OF_COSTUMENAME, 'costume name'],
27
+ [Blockly.Msg.SENSING_OF_SIZE, 'size'],
28
+ [Blockly.Msg.SENSING_OF_VOLUME, 'volume'],
29
+ [Blockly.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
30
+ [Blockly.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name']
31
+ ]
32
+ },
33
+ {
34
+ "type": "input_value",
35
+ "name": "OBJECT"
36
+ },
37
+ {
38
+ "type": "input_value",
39
+ "name": "VALUE"
40
+ }
41
+ ],
42
+ "category": Blockly.Categories.sensing,
43
+ "extensions": ["colours_sensing", "shape_statement"]
44
+ });
45
+ }
46
+ };
47
+
48
+ Blockly.Blocks['looks_setVertTransform'] = {
49
+ /**
50
+ * Block to report properties of sprites.
51
+ * @this Blockly.Block
52
+ */
53
+ init: function() {
54
+ this.jsonInit({
55
+ "message0": 'skew sprite vertically %1 %',
56
+ "args0": [
57
+ {
58
+ "type": "input_value",
59
+ "name": "PERCENT"
60
+ }
61
+ ],
62
+ "category": Blockly.Categories.looks,
63
+ "extensions": ["colours_looks", "shape_statement"]
64
+ });
65
+ }
66
+ };
67
+
68
+ Blockly.Blocks['looks_setHorizTransform'] = {
69
+ /**
70
+ * Block to report properties of sprites.
71
+ * @this Blockly.Block
72
+ */
73
+ init: function() {
74
+ this.jsonInit({
75
+ "message0": 'skew sprite horizontally %1 %',
76
+ "args0": [
77
+ {
78
+ "type": "input_value",
79
+ "name": "PERCENT"
80
+ }
81
+ ],
82
+ "category": Blockly.Categories.looks,
83
+ "extensions": ["colours_looks", "shape_statement"]
84
+ });
85
+ }
86
+ };
87
+
88
+ Blockly.Blocks['field_textdropdown_test'] = {
89
+ init: function() {
90
+ this.jsonInit({
91
+ "message0": "%1",
92
+ "args0": [
93
+ {
94
+ "type": "field_textdropdown",
95
+ "name": "TEXT",
96
+ "options": [
97
+ ['item1', 'item1'],
98
+ ['item2', 'item2'],
99
+ ['item3', 'item3']
100
+ ]
101
+ }
102
+ ],
103
+ "output": "String",
104
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
105
+ "colour": Blockly.Colours.textField,
106
+ "colourSecondary": Blockly.Colours.textField,
107
+ "colourTertiary": Blockly.Colours.textField
108
+ })
109
+ }
110
+ }
111
+
112
+ Blockly.Blocks['motion_mutatorCheckboxTest_checkboxMutatorMenu'] = {
113
+ init: function () {
114
+ this.setInputsInline(false);
115
+ this.setColour("#c1c1c1");
116
+ }
117
+ };
118
+ Blockly.Blocks['motion_mutatorCheckboxTest'] = {
119
+ /**
120
+ * @this Blockly.Block
121
+ */
122
+ init: function () {
123
+ this.jsonInit({
124
+ "message0": 'checkbox mutator',
125
+ "args0": [],
126
+ "category": Blockly.Categories.control,
127
+ "extensions": ["colours_control", "shape_statement"]
128
+ });
129
+ this.setMutator(new Blockly.Mutator([]));
130
+
131
+ this.BORDER_FIELDS = ["ABC", "DEF"];
132
+ this.FIELD_NAMES = ["first", "second"];
133
+
134
+ this.inputs_ = [false, false];
135
+ },
136
+
137
+ mutationToDom: function () {
138
+ // console.log('mutationToDom', this.inputs_);
139
+ if (!this.inputs_) {
140
+ return null;
141
+ }
142
+ const container = document.createElement("mutation");
143
+ for (let i = 0; i < this.inputs_.length; i++) {
144
+ if (this.inputs_[i]) {
145
+ container.setAttribute(this.BORDER_FIELDS[i], this.inputs_[i]);
146
+ }
147
+ }
148
+ return container;
149
+ },
150
+
151
+ domToMutation: function (xmlElement) {
152
+ for (let i = 0; i < this.inputs_.length; i++) {
153
+ this.inputs_[i] = xmlElement.getAttribute(this.BORDER_FIELDS[i].toLowerCase()) == "true";
154
+ }
155
+ // console.log('domToMutation', this.inputs_);
156
+ this.updateShape_();
157
+ },
158
+
159
+ decompose: function (workspace) {
160
+ // console.log('decompose');
161
+ const containerBlock = workspace.newBlock('motion_mutatorCheckboxTest_checkboxMutatorMenu');
162
+ for (let i = 0; i < this.inputs_.length; i++) {
163
+ // BaseBlockly.Msg[this.BORDER_FIELDS[i]] = this.FIELD_NAMES[i];
164
+ containerBlock.appendDummyInput()
165
+ // .setAlign(Blockly.ALIGN_RIGHT)
166
+ .appendField(this.FIELD_NAMES[i])
167
+ .appendField(new Blockly.FieldCheckboxOriginal(this.inputs_[i] ? "TRUE" : "FALSE"), this.BORDER_FIELDS[i].toUpperCase());
168
+ }
169
+ containerBlock.initSvg();
170
+ containerBlock.moveBy(4, 22);
171
+ return containerBlock;
172
+ },
173
+
174
+ compose: function (containerBlock) {
175
+ // console.log('compose');
176
+ // Set states
177
+ for (let i = 0; i < this.inputs_.length; i++) {
178
+ const field = this.BORDER_FIELDS[i].toUpperCase();
179
+ const value = containerBlock.getFieldValue(field);
180
+ // console.log(value);
181
+ this.inputs_[i] = value == "TRUE";
182
+ }
183
+ this.updateShape_();
184
+ },
185
+
186
+ updateShape_: function () {
187
+ // console.log('updateShape_');
188
+ for (let i = 0; i < this.inputs_.length; i++) {
189
+ if ((!this.inputs_[i]) && (this.getInput(this.BORDER_FIELDS[i].toUpperCase()))) {
190
+ this.removeInput(this.BORDER_FIELDS[i].toUpperCase());
191
+ }
192
+ }
193
+ for (let i = 0; i < this.inputs_.length; i++) {
194
+ if ((this.inputs_[i]) && (!(this.getInput(this.BORDER_FIELDS[i].toUpperCase())))) {
195
+ // BaseBlockly.Msg[this.BORDER_FIELDS[i]] = this.FIELD_NAMES[i];
196
+ this.appendValueInput(this.BORDER_FIELDS[i].toUpperCase())
197
+ // .setAlign(Blockly.ALIGN_RIGHT)
198
+ // todo: insert string/number input?
199
+ .appendField(this.FIELD_NAMES[i]);
200
+ }
201
+ }
202
+ }
203
+ };
204
+
205
+ Blockly.Blocks['control_fieldbutton'] = {
206
+ /**
207
+ * @this Blockly.Block
208
+ */
209
+ init: function () {
210
+ this.jsonInit({
211
+ "message0": 'button %1',
212
+ "args0": [
213
+ {
214
+ "type": "field_button",
215
+ "name": "BUTTON",
216
+ "label": "alert",
217
+ "opcode": "alert"
218
+ }
219
+ ],
220
+ "category": Blockly.Categories.control,
221
+ "extensions": ["colours_control", "shape_statement"]
222
+ });
223
+ },
224
+
225
+ onFieldButtonClicked_: function (opcode) {
226
+ if (opcode === "alert") {
227
+ alert('wow');
228
+ } else if (opcode === "flaberghasted") {
229
+ alert(':rivflabbergasted:')
230
+ }
231
+ }
232
+ };
233
+
234
+ Blockly.Blocks['control_fieldcheckboxoriginal'] = {
235
+ /**
236
+ * @this Blockly.Block
237
+ */
238
+ init: function () {
239
+ this.jsonInit({
240
+ "message0": 'mm checkbox %1 gagag %2',
241
+ "args0": [
242
+ {
243
+ "type": "field_checkbox_original",
244
+ "name": "BUTTON"
245
+ },
246
+ {
247
+ "type": "field_checkbox_original",
248
+ "name": "BUTT2ON"
249
+ }
250
+ ],
251
+ "category": Blockly.Categories.control,
252
+ "extensions": ["colours_control", "shape_statement"]
253
+ });
254
+ }
255
+ };
256
+
257
+ Blockly.Blocks['control_testcolorfieldoriginal'] = {
258
+ /**
259
+ * @this Blockly.Block
260
+ */
261
+ init: function () {
262
+ this.jsonInit({
263
+ "message0": 'color %1',
264
+ "args0": [
265
+ {
266
+ "type": "field_colour",
267
+ "colour": "#ff0000",
268
+ "name": "COLOR"
269
+ }
270
+ ],
271
+ "category": Blockly.Categories.control,
272
+ "extensions": ["colours_control", "shape_statement"]
273
+ });
274
+ }
275
+ };
276
+
277
+ Blockly.Blocks['control_blockduplicatesondrag'] = {
278
+ /**
279
+ * @this Blockly.Block
280
+ */
281
+ init: function () {
282
+ this.jsonInit({
283
+ "message0": 'duplicate',
284
+ "category": Blockly.Categories.control,
285
+ "canDragDuplicate": true,
286
+ "extensions": ["colours_control", "shape_statement"]
287
+ });
288
+ }
289
+ };
290
+
291
+ Blockly.Blocks['control_dualblock'] = {
292
+ /**
293
+ * @this Blockly.Block
294
+ */
295
+ init: function () {
296
+ this.jsonInit({
297
+ "message0": 'dual block',
298
+ "category": Blockly.Categories.control,
299
+ "extensions": ["colours_control", "shape_statement", "output_string"]
300
+ });
301
+ }
302
+ };
303
+
304
+ Blockly.Blocks['operators_expandablejoininputs'] = {
305
+ /**
306
+ * @this Blockly.Block
307
+ */
308
+ init: function () {
309
+ this.jsonInit({
310
+ "message0": 'join %1 %2',
311
+ "args0": [
312
+ {
313
+ "type": "field_expandable_remove",
314
+ "name": "REMOVE"
315
+ },
316
+ {
317
+ "type": "field_expandable_add",
318
+ "name": "ADD"
319
+ }
320
+ ],
321
+ "category": Blockly.Categories.operators,
322
+ "extensions": ["colours_operators", "output_string"]
323
+ });
324
+
325
+ this.inputs_ = 0;
326
+ // this.lastMutation_ = null;
327
+ },
328
+
329
+ mutationToDom: function () {
330
+ // on save
331
+ // console.log('mutationToDom');
332
+ const container = document.createElement("mutation");
333
+ let number = Number(this.inputs_);
334
+ if (isNaN(number)) number = 0;
335
+ container.setAttribute("INPUTCOUNT", String(number));
336
+ // console.log(this.inputs_);
337
+ return container;
338
+ },
339
+
340
+ domToMutation: function (xmlElement) {
341
+ // on load
342
+ // console.log('domToMutation');
343
+ // console.log(xmlElement.getAttribute("INPUTCOUNT"));
344
+ const inputCount = Number(xmlElement.getAttribute("INPUTCOUNT"));
345
+ // console.log(inputCount);
346
+ this.inputs_ = isNaN(inputCount) ? 0 : inputCount;
347
+ // console.log(this.inputs_);
348
+ for (let i = 0; i < this.inputs_; i++) {
349
+ this.appendValueInput(`INPUT${i + 1}`);
350
+ }
351
+ },
352
+
353
+ saveExtraState: function() {
354
+ let number = Number(this.inputs_);
355
+ if (isNaN(number)) number = 0;
356
+ return {inputs: number}
357
+ },
358
+
359
+ loadExtraState: function(state) {
360
+ this.inputs_ = isNaN(state.inputs) ? 0 : state.inputs;
361
+ for (let i = 0; i < this.inputs_; i++) {
362
+ this.appendValueInput(`INPUT${i + 1}`);
363
+ }
364
+ },
365
+
366
+ // updateShape_: function () {
367
+ // this.lastMutation_ = this.mutationToDom();
368
+ // console.log('updateShape_');
369
+ // console.log(this.inputs_);
370
+ // for (let i = 0; i < this.inputs_; i++) {
371
+ // this.appendValueInput(`INPUT${i + 1}`);
372
+ // }
373
+ // this.updateIfNeeded_();
374
+ // },
375
+ // updateIfNeeded_: function () {
376
+ // this.initSvg();
377
+ // if (this.rendered) {
378
+ // this.render();
379
+ // }
380
+ // // manually update because idk why
381
+ // Blockly.Events.setGroup(true);
382
+ // var oldMutation = Blockly.Xml.domToText(this.lastMutation_);
383
+ // var newMutation = Blockly.Xml.domToText(this.mutationToDom());
384
+ // Blockly.Events.fire(new Blockly.Events.BlockChange(this,
385
+ // 'mutation', null, oldMutation, newMutation));
386
+ // Blockly.Events.setGroup(false);
387
+ // },
388
+
389
+ onExpandableButtonClicked_: function (isAdding) {
390
+ // Create an event group to keep field value and mutator in sync
391
+ // Return null at the end because setValue is called here already.
392
+ Blockly.Events.setGroup(true);
393
+ var oldMutation = Blockly.Xml.domToText(this.mutationToDom());
394
+ if (!isAdding) {
395
+ const number = this.inputs_;
396
+ this.removeInput(`INPUT${number}`);
397
+ this.inputs_--;
398
+ if (this.inputs_ < 0) {
399
+ this.inputs_ = 0;
400
+ }
401
+ // console.log(this.inputs_);
402
+ // this.updateIfNeeded_();
403
+ } else {
404
+ this.inputs_++;
405
+ const number = this.inputs_;
406
+ this.appendValueInput(`INPUT${number}`);
407
+ // console.log(this.inputs_);
408
+ // this.updateIfNeeded_();
409
+ }
410
+ this.initSvg();
411
+ if (this.rendered) {
412
+ this.render();
413
+ }
414
+ var newMutation = Blockly.Xml.domToText(this.mutationToDom());
415
+ Blockly.Events.fire(new Blockly.Events.BlockChange(this,
416
+ 'mutation', null, oldMutation, newMutation));
417
+ Blockly.Events.setGroup(false);
418
+ }
419
+ };
blocks_vertical/looks.js ADDED
@@ -0,0 +1,1158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.looks');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+
31
+ Blockly.Blocks['looks_sayforsecs'] = {
32
+ /**
33
+ * Block to say for some time.
34
+ * @this Blockly.Block
35
+ */
36
+ init: function() {
37
+ this.jsonInit({
38
+ "message0": Blockly.Msg.LOOKS_SAYFORSECS,
39
+ "args0": [
40
+ {
41
+ "type": "input_value",
42
+ "name": "MESSAGE"
43
+ },
44
+ {
45
+ "type": "input_value",
46
+ "name": "SECS"
47
+ }
48
+ ],
49
+ "category": Blockly.Categories.looks,
50
+ "extensions": ["colours_looks", "shape_statement"]
51
+ });
52
+ }
53
+ };
54
+
55
+ Blockly.Blocks['looks_say'] = {
56
+ /**
57
+ * Block to say.
58
+ * @this Blockly.Block
59
+ */
60
+ init: function() {
61
+ this.jsonInit({
62
+ "message0": Blockly.Msg.LOOKS_SAY,
63
+ "args0": [
64
+ {
65
+ "type": "input_value",
66
+ "name": "MESSAGE"
67
+ }
68
+ ],
69
+ "category": Blockly.Categories.looks,
70
+ "extensions": ["colours_looks", "shape_statement"]
71
+ });
72
+ }
73
+ };
74
+
75
+ Blockly.Blocks['looks_thinkforsecs'] = {
76
+ /**
77
+ * Block to think for some time.
78
+ * @this Blockly.Block
79
+ */
80
+ init: function() {
81
+ this.jsonInit({
82
+ "message0": Blockly.Msg.LOOKS_THINKFORSECS,
83
+ "args0": [
84
+ {
85
+ "type": "input_value",
86
+ "name": "MESSAGE"
87
+ },
88
+ {
89
+ "type": "input_value",
90
+ "name": "SECS"
91
+ }
92
+ ],
93
+ "category": Blockly.Categories.looks,
94
+ "extensions": ["colours_looks", "shape_statement"]
95
+ });
96
+ }
97
+ };
98
+
99
+ Blockly.Blocks['looks_think'] = {
100
+ /**
101
+ * Block to think.
102
+ * @this Blockly.Block
103
+ */
104
+ init: function() {
105
+ this.jsonInit({
106
+ "message0": Blockly.Msg.LOOKS_THINK,
107
+ "args0": [
108
+ {
109
+ "type": "input_value",
110
+ "name": "MESSAGE"
111
+ }
112
+ ],
113
+ "category": Blockly.Categories.looks,
114
+ "extensions": ["colours_looks", "shape_statement"]
115
+ });
116
+ }
117
+ };
118
+
119
+ Blockly.Blocks["looks_setFont"] = {
120
+ init: function() {
121
+ this.jsonInit({
122
+ "inputsInline":true,
123
+ "args0":[
124
+ {
125
+ "type":"input_value",
126
+ "name":"font"
127
+ },
128
+ {
129
+ "type":"input_value",
130
+ "name":"size"
131
+ }
132
+ ],
133
+ "message0":"set font to %1 with font size %2",
134
+ "category": Blockly.Categories.looks,
135
+ "extensions": ["colours_looks", "shape_statement"]
136
+ });
137
+ }
138
+ };
139
+
140
+ Blockly.Blocks["looks_setColor"] = {
141
+ init: function() {
142
+ this.jsonInit({
143
+ "inputsInline":true,
144
+ "args0":[
145
+ {
146
+ "type":"field_dropdown",
147
+ "name":"prop",
148
+ "options":[
149
+ ["border","BUBBLE_STROKE"],
150
+ ["fill","BUBBLE_FILL"],
151
+ ["text","TEXT_FILL"]
152
+ ]
153
+ },
154
+ {
155
+ "type":"input_value",
156
+ "name":"color"
157
+ }
158
+ ],
159
+ "message0":"set %1 color to %2",
160
+ "category": Blockly.Categories.looks,
161
+ "extensions": ["colours_looks", "shape_statement"]
162
+ });
163
+ }
164
+ };
165
+
166
+ Blockly.Blocks["looks_setShape"] = {
167
+ init: function() {
168
+ this.jsonInit({
169
+ "inputsInline":true,
170
+ "args0":[
171
+ {
172
+ "type":"field_dropdown",
173
+ "name":"prop",
174
+ "options":[
175
+ ["minimum width","MIN_WIDTH"],
176
+ ["maximum width","MAX_LINE_WIDTH"],
177
+ ["border line width","STROKE_WIDTH"],
178
+ ["padding size","PADDING"],
179
+ ["corner radius","CORNER_RADIUS"],
180
+ ["tail height","TAIL_HEIGHT"],
181
+ ["font pading percent","FONT_HEIGHT_RATIO"],
182
+ ["text length limit","texlim"]
183
+ ]
184
+ },
185
+ {
186
+ "type":"input_value",
187
+ "name":"color"
188
+ }
189
+ ],
190
+ "message0":"set text bubble %1 to %2",
191
+ "category": Blockly.Categories.looks,
192
+ "extensions": ["colours_looks", "shape_statement"]
193
+ });
194
+ }
195
+ };
196
+
197
+ Blockly.Blocks['looks_show'] = {
198
+ /**
199
+ * Show block.
200
+ * @this Blockly.Block
201
+ */
202
+ init: function() {
203
+ this.jsonInit({
204
+ "message0": Blockly.Msg.LOOKS_SHOW,
205
+ "category": Blockly.Categories.looks,
206
+ "extensions": ["colours_looks", "shape_statement"]
207
+ });
208
+ }
209
+ };
210
+
211
+ Blockly.Blocks['looks_hide'] = {
212
+ /**
213
+ * Hide block.
214
+ * @this Blockly.Block
215
+ */
216
+ init: function() {
217
+ this.jsonInit({
218
+ "message0": Blockly.Msg.LOOKS_HIDE,
219
+ "category": Blockly.Categories.looks,
220
+ "extensions": ["colours_looks", "shape_statement"]
221
+ });
222
+ }
223
+ };
224
+
225
+
226
+ Blockly.Blocks['looks_changeVisibilityOfSprite_menu'] = {
227
+ /**
228
+ * pm: changeVisibilityOfSprite drop-down menu.
229
+ * @this Blockly.Block
230
+ */
231
+ init: function () {
232
+ this.jsonInit({
233
+ "message0": "%1",
234
+ "args0": [
235
+ {
236
+ "type": "field_dropdown",
237
+ "name": "VISIBLE_OPTION",
238
+ "options": [
239
+ ["myself", '_myself_']
240
+ ]
241
+ }
242
+ ],
243
+ "extensions": ["colours_looks", "output_string"]
244
+ });
245
+ }
246
+ };
247
+
248
+ Blockly.Blocks['looks_changeVisibilityOfSprite'] = {
249
+ /**
250
+ * pm: changeVisibilityOfSprite block.
251
+ * @this Blockly.Block
252
+ */
253
+ init: function () {
254
+ this.jsonInit({
255
+ "message0": "%1 %2",
256
+ "inputsInline": true,
257
+ "args0": [
258
+ {
259
+ "type": "field_dropdown",
260
+ "name": "VISIBLE_TYPE",
261
+ "options": [
262
+ ["show", "show"],
263
+ ["hide", "hide"]
264
+ ]
265
+ },
266
+ {
267
+ "type": "input_value",
268
+ "name": "VISIBLE_OPTION"
269
+ }
270
+ ],
271
+ "category": Blockly.Categories.looks,
272
+ "extensions": ["colours_looks", "shape_statement"]
273
+ });
274
+ }
275
+ };
276
+
277
+ Blockly.Blocks['looks_changeVisibilityOfSpriteShow'] = {
278
+ /**
279
+ * pm: changeVisibilityOfSprite block.
280
+ * @this Blockly.Block
281
+ */
282
+ init: function () {
283
+ this.jsonInit({
284
+ "message0": "show %1",
285
+ "inputsInline": true,
286
+ "args0": [
287
+ {
288
+ "type": "input_value",
289
+ "name": "VISIBLE_OPTION"
290
+ }
291
+ ],
292
+ "category": Blockly.Categories.looks,
293
+ "extensions": ["colours_looks", "shape_statement"]
294
+ });
295
+ }
296
+ };
297
+
298
+ Blockly.Blocks['looks_changeVisibilityOfSpriteHide'] = {
299
+ /**
300
+ * pm: changeVisibilityOfSprite block.
301
+ * @this Blockly.Block
302
+ */
303
+ init: function () {
304
+ this.jsonInit({
305
+ "message0": "hide %1",
306
+ "inputsInline": true,
307
+ "args0": [
308
+ {
309
+ "type": "input_value",
310
+ "name": "VISIBLE_OPTION"
311
+ }
312
+ ],
313
+ "category": Blockly.Categories.looks,
314
+ "extensions": ["colours_looks", "shape_statement"]
315
+ });
316
+ }
317
+ };
318
+
319
+ Blockly.Blocks['looks_hideallsprites'] = {
320
+ /**
321
+ * Hide-all-sprites block. Does not actually do anything. This is an
322
+ * obsolete block that is implemented for compatibility with Scratch 2.0
323
+ * projects.
324
+ * @this Blockly.Block
325
+ */
326
+ init: function() {
327
+ this.jsonInit({
328
+ "message0": Blockly.Msg.LOOKS_HIDEALLSPRITES,
329
+ "category": Blockly.Categories.looks,
330
+ "extensions": ["colours_looks", "shape_statement"]
331
+ });
332
+ }
333
+ };
334
+
335
+ Blockly.Blocks["looks_setTintColor"] = {
336
+ init: function() {
337
+ this.jsonInit({
338
+ "inputsInline": true,
339
+ "args0":[
340
+ {
341
+ "type":"input_value",
342
+ "name":"color"
343
+ }
344
+ ],
345
+ "message0":"set tint color to %1",
346
+ "category": Blockly.Categories.looks,
347
+ "extensions": ["colours_looks", "shape_statement"]
348
+ });
349
+ }
350
+ };
351
+ Blockly.Blocks['looks_tintColor'] = {
352
+ /**
353
+ * pm: Block to report the tint color effect in hex code
354
+ * @this Blockly.Block
355
+ */
356
+ init: function () {
357
+ this.jsonInit({
358
+ "message0": "tint color",
359
+ "category": Blockly.Categories.looks,
360
+ "checkboxInFlyout": true,
361
+ "extensions": ["colours_looks", "output_string"]
362
+ });
363
+ }
364
+ };
365
+
366
+ Blockly.Blocks['looks_changeeffectby'] = {
367
+ /**
368
+ * Block to change graphic effect.
369
+ * @this Blockly.Block
370
+ */
371
+ init: function() {
372
+ this.jsonInit({
373
+ "message0": Blockly.Msg.LOOKS_CHANGEEFFECTBY,
374
+ "args0": [
375
+ {
376
+ "type": "field_dropdown",
377
+ "name": "EFFECT",
378
+ "options": [
379
+ [Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'],
380
+ [Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'],
381
+ [Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'],
382
+ [Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'],
383
+ [Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'],
384
+ [Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'],
385
+ [Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST'],
386
+ ["saturation", 'SATURATION'],
387
+ ["red", 'RED'],
388
+ ["green", 'GREEN'],
389
+ ["blue", 'BLUE'],
390
+ ["opaque", 'OPAQUE']
391
+ ]
392
+ },
393
+ {
394
+ "type": "input_value",
395
+ "name": "CHANGE"
396
+ }
397
+ ],
398
+ "category": Blockly.Categories.looks,
399
+ "extensions": ["colours_looks", "shape_statement"]
400
+ });
401
+ }
402
+ };
403
+
404
+ Blockly.Blocks['looks_seteffectto'] = {
405
+ /**
406
+ * Block to set graphic effect.
407
+ * @this Blockly.Block
408
+ */
409
+ init: function() {
410
+ this.jsonInit({
411
+ "message0": Blockly.Msg.LOOKS_SETEFFECTTO,
412
+ "args0": [
413
+ {
414
+ "type": "field_dropdown",
415
+ "name": "EFFECT",
416
+ "options": [
417
+ [Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'],
418
+ [Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'],
419
+ [Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'],
420
+ [Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'],
421
+ [Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'],
422
+ [Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'],
423
+ [Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST'],
424
+ ["saturation", 'SATURATION'],
425
+ ["red", 'RED'],
426
+ ["green", 'GREEN'],
427
+ ["blue", 'BLUE'],
428
+ ["opaque", 'OPAQUE']
429
+ ]
430
+ },
431
+ {
432
+ "type": "input_value",
433
+ "name": "VALUE"
434
+ }
435
+ ],
436
+ "category": Blockly.Categories.looks,
437
+ "extensions": ["colours_looks", "shape_statement"]
438
+ });
439
+ }
440
+ };
441
+
442
+ Blockly.Blocks['looks_cleargraphiceffects'] = {
443
+ /**
444
+ * Block to clear graphic effects.
445
+ * @this Blockly.Block
446
+ */
447
+ init: function() {
448
+ this.jsonInit({
449
+ "message0": Blockly.Msg.LOOKS_CLEARGRAPHICEFFECTS,
450
+ "category": Blockly.Categories.looks,
451
+ "extensions": ["colours_looks", "shape_statement"]
452
+ });
453
+ }
454
+ };
455
+
456
+ Blockly.Blocks['looks_changesizeby'] = {
457
+ /**
458
+ * Block to change size
459
+ * @this Blockly.Block
460
+ */
461
+ init: function() {
462
+ this.jsonInit({
463
+ "message0": Blockly.Msg.LOOKS_CHANGESIZEBY,
464
+ "args0": [
465
+ {
466
+ "type": "input_value",
467
+ "name": "CHANGE"
468
+ }
469
+ ],
470
+ "category": Blockly.Categories.looks,
471
+ "extensions": ["colours_looks", "shape_statement"]
472
+ });
473
+ }
474
+ };
475
+
476
+ Blockly.Blocks['looks_setsizeto'] = {
477
+ /**
478
+ * Block to set size
479
+ * @this Blockly.Block
480
+ */
481
+ init: function() {
482
+ this.jsonInit({
483
+ "message0": Blockly.Msg.LOOKS_SETSIZETO,
484
+ "args0": [
485
+ {
486
+ "type": "input_value",
487
+ "name": "SIZE"
488
+ }
489
+ ],
490
+ "category": Blockly.Categories.looks,
491
+ "extensions": ["colours_looks", "shape_statement"]
492
+ });
493
+ }
494
+ };
495
+
496
+ Blockly.Blocks['looks_size'] = {
497
+ /**
498
+ * Block to report size
499
+ * @this Blockly.Block
500
+ */
501
+ init: function() {
502
+ this.jsonInit({
503
+ "message0": Blockly.Msg.LOOKS_SIZE,
504
+ "category": Blockly.Categories.looks,
505
+ "checkboxInFlyout": true,
506
+ "extensions": ["colours_looks", "output_number"]
507
+ });
508
+ }
509
+ };
510
+
511
+ Blockly.Blocks['looks_changestretchby'] = {
512
+ /**
513
+ * Block to change stretch. Does not actually do anything. This is an
514
+ * obsolete block that is implemented for compatibility with Scratch 1.4
515
+ * projects as well as 2.0 projects that still have the block.
516
+ * The "stretch" blocks were introduced in very early versions of Scratch,
517
+ * but their functionality was removed shortly later. They still appeared
518
+ * correctly up until (and including) Scratch 1.4 - as "change stretch by"
519
+ * and "set stretch to" - but were removed altogether in Scratch 2.0, and
520
+ * displayed as red "undefined" blocks. Some Scratch projects still contain
521
+ * these blocks, however, and they don't open in 3.0 unless the blocks
522
+ * actually exist (though they still don't funcitonally do anything).
523
+ * @this Blockly.Block
524
+ */
525
+ init: function() {
526
+ this.jsonInit({
527
+ "message0": Blockly.Msg.LOOKS_CHANGESTRETCHBY,
528
+ "args0": [
529
+ {
530
+ "type": "input_value",
531
+ "name": "CHANGE"
532
+ }
533
+ ],
534
+ "category": Blockly.Categories.looks,
535
+ "extensions": ["colours_looks", "shape_statement"]
536
+ });
537
+ }
538
+ };
539
+
540
+ Blockly.Blocks['looks_setstretchto'] = {
541
+ /**
542
+ * Block to set stretch. Does not actually do anything. This is an obsolete
543
+ * block that is implemented for compatibility with Scratch 1.4 projects
544
+ * (see looks_changestretchby).
545
+ * @this Blockly.Block
546
+ */
547
+ init: function() {
548
+ this.jsonInit({
549
+ "message0": Blockly.Msg.LOOKS_SETSTRETCHTO,
550
+ "args0": [
551
+ {
552
+ "type": "input_value",
553
+ "name": "STRETCH"
554
+ }
555
+ ],
556
+ "category": Blockly.Categories.looks,
557
+ "extensions": ["colours_looks", "shape_statement"]
558
+ });
559
+ }
560
+ };
561
+
562
+ Blockly.Blocks['looks_costume'] = {
563
+ /**
564
+ * Costumes drop-down menu.
565
+ * @this Blockly.Block
566
+ */
567
+ init: function() {
568
+ this.jsonInit({
569
+ "message0": "%1",
570
+ "args0": [
571
+ {
572
+ "type": "field_dropdown",
573
+ "name": "COSTUME",
574
+ "options": [
575
+ ['costume1', 'COSTUME1'],
576
+ ['costume2', 'COSTUME2']
577
+ ]
578
+ }
579
+ ],
580
+ "colour": Blockly.Colours.looks.secondary,
581
+ "colourSecondary": Blockly.Colours.looks.secondary,
582
+ "colourTertiary": Blockly.Colours.looks.tertiary,
583
+ "extensions": ["output_string"]
584
+ });
585
+ }
586
+ };
587
+
588
+ Blockly.Blocks['looks_switchcostumeto'] = {
589
+ /**
590
+ * Block to switch the sprite's costume to the selected one.
591
+ * @this Blockly.Block
592
+ */
593
+ init: function() {
594
+ this.jsonInit({
595
+ "message0": Blockly.Msg.LOOKS_SWITCHCOSTUMETO,
596
+ "args0": [
597
+ {
598
+ "type": "input_value",
599
+ "name": "COSTUME"
600
+ }
601
+ ],
602
+ "category": Blockly.Categories.looks,
603
+ "extensions": ["colours_looks", "shape_statement"]
604
+ });
605
+ }
606
+ };
607
+
608
+ Blockly.Blocks['looks_nextcostume'] = {
609
+ /**
610
+ * Block to switch the sprite's costume to the next one.
611
+ * @this Blockly.Block
612
+ */
613
+ init: function() {
614
+ this.jsonInit({
615
+ "message0": Blockly.Msg.LOOKS_NEXTCOSTUME,
616
+ "category": Blockly.Categories.looks,
617
+ "extensions": ["colours_looks", "shape_statement"]
618
+ });
619
+ }
620
+ };
621
+
622
+ Blockly.Blocks['looks_previouscostume'] = {
623
+ /**
624
+ * pm: Block to switch the sprite's costume to the previous one.
625
+ * @this Blockly.Block
626
+ */
627
+ init: function() {
628
+ this.jsonInit({
629
+ "message0": "previous costume",
630
+ "category": Blockly.Categories.looks,
631
+ "extensions": ["colours_looks", "shape_statement"]
632
+ });
633
+ }
634
+ };
635
+
636
+ Blockly.Blocks['looks_switchbackdropto'] = {
637
+ /**
638
+ * Block to switch the backdrop to the selected one.
639
+ * @this Blockly.Block
640
+ */
641
+ init: function() {
642
+ this.jsonInit({
643
+ "message0": Blockly.Msg.LOOKS_SWITCHBACKDROPTO,
644
+ "args0": [
645
+ {
646
+ "type": "input_value",
647
+ "name": "BACKDROP"
648
+ }
649
+ ],
650
+ "category": Blockly.Categories.looks,
651
+ "extensions": ["colours_looks", "shape_statement"]
652
+ });
653
+ }
654
+ };
655
+
656
+ Blockly.Blocks['looks_backdrops'] = {
657
+ /**
658
+ * Backdrop list
659
+ * @this Blockly.Block
660
+ */
661
+ init: function() {
662
+ this.jsonInit({
663
+ "id": "looks_backdrops",
664
+ "message0": "%1",
665
+ "args0": [
666
+ {
667
+ "type": "field_dropdown",
668
+ "name": "BACKDROP",
669
+ "options": [
670
+ ['backdrop1', 'BACKDROP1']
671
+ ]
672
+ }
673
+ ],
674
+ "colour": Blockly.Colours.looks.secondary,
675
+ "colourSecondary": Blockly.Colours.looks.secondary,
676
+ "colourTertiary": Blockly.Colours.looks.tertiary,
677
+ "extensions": ["output_string"]
678
+ });
679
+ }
680
+ };
681
+
682
+ Blockly.Blocks['looks_gotofrontback'] = {
683
+ /**
684
+ * "Go to front/back" Block.
685
+ * @this Blockly.Block
686
+ */
687
+ init: function() {
688
+ this.jsonInit({
689
+ "message0": Blockly.Msg.LOOKS_GOTOFRONTBACK,
690
+ "args0": [
691
+ {
692
+ "type": "field_dropdown",
693
+ "name": "FRONT_BACK",
694
+ "options": [
695
+ [Blockly.Msg.LOOKS_GOTOFRONTBACK_FRONT, 'front'],
696
+ [Blockly.Msg.LOOKS_GOTOFRONTBACK_BACK, 'back']
697
+ ]
698
+ }
699
+ ],
700
+ "category": Blockly.Categories.looks,
701
+ "extensions": ["colours_looks", "shape_statement"]
702
+ });
703
+ }
704
+ };
705
+
706
+ Blockly.Blocks['looks_goforwardbackwardlayers'] = {
707
+ /**
708
+ * "Go forward/backward [Number] Layers" Block.
709
+ * @this Blockly.Block
710
+ */
711
+ init: function() {
712
+ this.jsonInit({
713
+ "message0": Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS,
714
+ "args0": [
715
+ {
716
+ "type": "field_dropdown",
717
+ "name": "FORWARD_BACKWARD",
718
+ "options": [
719
+ [Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS_FORWARD, 'forward'],
720
+ [Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS_BACKWARD, 'backward']
721
+ ]
722
+ },
723
+ {
724
+ "type": "input_value",
725
+ "name": "NUM"
726
+ }
727
+ ],
728
+ "category": Blockly.Categories.looks,
729
+ "extensions": ["colours_looks", "shape_statement"]
730
+ });
731
+ }
732
+ };
733
+
734
+ Blockly.Blocks['looks_goTargetLayer'] = {
735
+ /**
736
+ * "Go infront/behind [sprite]" Block.
737
+ * @this Blockly.Block
738
+ */
739
+ init: function() {
740
+ this.jsonInit({
741
+ "message0": "go %1 %2",
742
+ "args0": [
743
+ {
744
+ "type": "field_dropdown",
745
+ "name": "FORWARD_BACKWARD",
746
+ "options": [
747
+ ['infront', 'infront'],
748
+ ['behind', 'behind']
749
+ ]
750
+ },
751
+ {
752
+ "type": "input_value",
753
+ "name": "VISIBLE_OPTION"
754
+ }
755
+ ],
756
+ "category": Blockly.Categories.looks,
757
+ "extensions": ["colours_looks", "shape_statement"]
758
+ });
759
+ }
760
+ };
761
+
762
+ Blockly.Blocks["looks_layersSetLayer"] = {
763
+ init: function() {
764
+ this.jsonInit({
765
+ "inputsInline": true,
766
+ "category": "looks",
767
+ "message0": "go to layer %1",
768
+ "args0": [
769
+ {
770
+ "type": "input_value",
771
+ "name": "NUM"
772
+ }
773
+ ],
774
+ "extensions": [
775
+ "shape_statement",
776
+ "colours_looks"
777
+ ]
778
+ });
779
+ }
780
+ };
781
+
782
+ Blockly.Blocks["looks_layersGetLayer"] = {
783
+ init: function() {
784
+ this.jsonInit({
785
+ "inputsInline": true,
786
+ "category": "looks",
787
+ "message0": "layer",
788
+ "checkboxInFlyout": true,
789
+ "extensions": [
790
+ "output_number",
791
+ "colours_looks"
792
+ ]
793
+ });
794
+ }
795
+ };
796
+
797
+ Blockly.Blocks['looks_backdropnumbername'] = {
798
+ /**
799
+ * Block to report backdrop's number or name
800
+ * @this Blockly.Block
801
+ */
802
+ init: function() {
803
+ this.jsonInit({
804
+ "message0": Blockly.Msg.LOOKS_BACKDROPNUMBERNAME,
805
+ "args0": [
806
+ {
807
+ "type": "field_dropdown",
808
+ "name": "NUMBER_NAME",
809
+ "options": [
810
+ [Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'],
811
+ [Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name']
812
+ ]
813
+ }
814
+ ],
815
+ "category": Blockly.Categories.looks,
816
+ "checkboxInFlyout": true,
817
+ "extensions": ["colours_looks", "output_number"]
818
+ });
819
+ }
820
+ };
821
+
822
+ Blockly.Blocks['looks_costumenumbername'] = {
823
+ /**
824
+ * Block to report costume's number or name
825
+ * @this Blockly.Block
826
+ */
827
+ init: function() {
828
+ this.jsonInit({
829
+ "message0": Blockly.Msg.LOOKS_COSTUMENUMBERNAME,
830
+ "args0": [
831
+ {
832
+ "type": "field_dropdown",
833
+ "name": "NUMBER_NAME",
834
+ "options": [
835
+ [Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'],
836
+ [Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name']
837
+ ]
838
+ }
839
+ ],
840
+ "category": Blockly.Categories.looks,
841
+ "checkboxInFlyout": true,
842
+ "extensions": ["colours_looks", "output_number"]
843
+ });
844
+ }
845
+ };
846
+
847
+ Blockly.Blocks['looks_switchbackdroptoandwait'] = {
848
+ /**
849
+ * Block to switch the backdrop to the selected one and wait.
850
+ * @this Blockly.Block
851
+ */
852
+ init: function() {
853
+ this.jsonInit({
854
+ "message0": Blockly.Msg.LOOKS_SWITCHBACKDROPTOANDWAIT,
855
+ "args0": [
856
+ {
857
+ "type": "input_value",
858
+ "name": "BACKDROP"
859
+ }
860
+ ],
861
+ "category": Blockly.Categories.looks,
862
+ "extensions": ["colours_looks", "shape_statement"]
863
+ });
864
+ }
865
+ };
866
+
867
+ Blockly.Blocks['looks_nextbackdrop'] = {
868
+ /**
869
+ * Block to switch the backdrop to the next one.
870
+ * @this Blockly.Block
871
+ */
872
+ init: function() {
873
+ this.jsonInit({
874
+ "message0": Blockly.Msg.LOOKS_NEXTBACKDROP_BLOCK,
875
+ "category": Blockly.Categories.looks,
876
+ "extensions": ["colours_looks", "shape_statement"]
877
+ });
878
+ }
879
+ };
880
+
881
+ Blockly.Blocks['looks_previousbackdrop'] = {
882
+ /**
883
+ * pm: Block to switch the backdrop to the previous one.
884
+ * @this Blockly.Block
885
+ */
886
+ init: function() {
887
+ this.jsonInit({
888
+ "message0": "previous backdrop",
889
+ "category": Blockly.Categories.looks,
890
+ "extensions": ["colours_looks", "shape_statement"]
891
+ });
892
+ }
893
+ };
894
+
895
+ Blockly.Blocks["looks_setStretch"] = {
896
+ init: function() {
897
+ this.jsonInit({
898
+ "inputsInline": true,
899
+ "category": "looks",
900
+ "args0": [
901
+ {
902
+ "type": "input_value",
903
+ "name": "X"
904
+ },
905
+ {
906
+ "type": "input_value",
907
+ "name": "Y"
908
+ }
909
+ ],
910
+ "message0": "set stretch to x: %1 y: %2",
911
+ "extensions": [
912
+ "shape_statement",
913
+ "colours_looks"
914
+ ]
915
+ });
916
+ }
917
+ };
918
+
919
+ Blockly.Blocks["looks_changeStretch"] = {
920
+ init: function() {
921
+ this.jsonInit({
922
+ "inputsInline": true,
923
+ "category": "looks",
924
+ "args0": [
925
+ {
926
+ "type": "input_value",
927
+ "name": "X"
928
+ },
929
+ {
930
+ "type": "input_value",
931
+ "name": "Y"
932
+ }
933
+ ],
934
+ "message0": "change stretch by x: %1 y: %2",
935
+ "extensions": [
936
+ "shape_statement",
937
+ "colours_looks"
938
+ ]
939
+ });
940
+ }
941
+ };
942
+
943
+ Blockly.Blocks["looks_stretchGetX"] = {
944
+ init: function() {
945
+ this.jsonInit({
946
+ "inputsInline": true,
947
+ "checkboxInFlyout": true,
948
+ "category": "looks",
949
+ "message0": "x stretch",
950
+ "extensions": [
951
+ "output_string",
952
+ "colours_looks"
953
+ ]
954
+ });
955
+ }
956
+ };
957
+
958
+ Blockly.Blocks["looks_stretchGetY"] = {
959
+ init: function() {
960
+ this.jsonInit({
961
+ "inputsInline": true,
962
+ "checkboxInFlyout": true,
963
+ "category": "looks",
964
+ "message0": "y stretch",
965
+ "extensions": [
966
+ "output_string",
967
+ "colours_looks"
968
+ ]
969
+ });
970
+ }
971
+ };
972
+
973
+ Blockly.Blocks["looks_getSpriteVisible"] = {
974
+ init: function() {
975
+ this.jsonInit({
976
+ "inputsInline": true,
977
+ "category": "looks",
978
+ "message0": "visible?",
979
+ "checkboxInFlyout": true,
980
+ "extensions": [
981
+ "output_boolean",
982
+ "colours_looks"
983
+ ]
984
+ });
985
+ }
986
+ };
987
+
988
+ Blockly.Blocks['looks_getOtherSpriteVisible_menu'] = {
989
+ /**
990
+ * pm: Sprite-visible drop-down menu.
991
+ * @this Blockly.Block
992
+ */
993
+ init: function () {
994
+ this.jsonInit({
995
+ "message0": "%1",
996
+ "args0": [
997
+ {
998
+ "type": "field_dropdown",
999
+ "name": "VISIBLE_OPTION",
1000
+ "options": [
1001
+ ["myself", '_myself_']
1002
+ ]
1003
+ }
1004
+ ],
1005
+ "extensions": ["colours_looks", "output_string"]
1006
+ });
1007
+ }
1008
+ };
1009
+
1010
+ Blockly.Blocks["looks_getOtherSpriteVisible"] = {
1011
+ init: function() {
1012
+ this.jsonInit({
1013
+ "inputsInline": true,
1014
+ "category": "looks",
1015
+ "message0": "is %1 visible?",
1016
+ "args0": [
1017
+ {
1018
+ "type": "input_value",
1019
+ "name": "VISIBLE_OPTION"
1020
+ }
1021
+ ],
1022
+ "extensions": [
1023
+ "output_boolean",
1024
+ "colours_looks"
1025
+ ]
1026
+ });
1027
+ }
1028
+ };
1029
+
1030
+ Blockly.Blocks["looks_getEffectValue"] = {
1031
+ init: function() {
1032
+ this.jsonInit({
1033
+ "inputsInline": true,
1034
+ "category": "looks",
1035
+ "message0": "%1 effect",
1036
+ "checkboxInFlyout": true,
1037
+ "args0": [
1038
+ {
1039
+ "type": "field_dropdown",
1040
+ "name": "EFFECT",
1041
+ "options": [
1042
+ [Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'],
1043
+ [Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'],
1044
+ [Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'],
1045
+ [Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'],
1046
+ [Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'],
1047
+ [Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'],
1048
+ [Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST'],
1049
+ ["saturation", 'SATURATION'],
1050
+ ["red", 'RED'],
1051
+ ["green", 'GREEN'],
1052
+ ["blue", 'BLUE'],
1053
+ ["opaque", 'OPAQUE']
1054
+ ]
1055
+ }
1056
+ ],
1057
+ "extensions": [
1058
+ "output_number",
1059
+ "colours_looks"
1060
+ ]
1061
+ });
1062
+ }
1063
+ };
1064
+
1065
+ Blockly.Blocks["looks_sayHeight"] = {
1066
+ init: function() {
1067
+ this.jsonInit({
1068
+ "inputsInline": true,
1069
+ "category": "looks",
1070
+ "message0": "bubble height",
1071
+ "checkboxInFlyout": true,
1072
+ "extensions": [
1073
+ "output_string",
1074
+ "colours_looks"
1075
+ ]
1076
+ });
1077
+ }
1078
+ };
1079
+
1080
+ Blockly.Blocks["looks_sayWidth"] = {
1081
+ init: function() {
1082
+ this.jsonInit({
1083
+ "inputsInline": true,
1084
+ "category": "looks",
1085
+ "message0": "bubble width",
1086
+ "checkboxInFlyout": true,
1087
+ "extensions": [
1088
+ "output_string",
1089
+ "colours_looks"
1090
+ ]
1091
+ });
1092
+ }
1093
+ };
1094
+
1095
+ Blockly.Blocks['looks_stoptalking'] = {
1096
+ /**
1097
+ * pm: Block to stop talking/thinking.
1098
+ * @this Blockly.Block
1099
+ */
1100
+ init: function () {
1101
+ this.jsonInit({
1102
+ "message0": "stop speaking",
1103
+ "category": Blockly.Categories.looks,
1104
+ "extensions": ["colours_looks", "shape_statement"]
1105
+ });
1106
+ }
1107
+ };
1108
+
1109
+ Blockly.Blocks['looks_getinputofcostume'] = {
1110
+ /**
1111
+ * pm: Block to report an attribute on a costume
1112
+ * @this Blockly.Block
1113
+ */
1114
+ init: function() {
1115
+ this.jsonInit({
1116
+ "message0": "%1 of %2",
1117
+ "args0": [
1118
+ {
1119
+ "type": "input_value",
1120
+ "name": "INPUT"
1121
+ },
1122
+ {
1123
+ "type": "input_value",
1124
+ "name": "COSTUME"
1125
+ },
1126
+ ],
1127
+ "category": Blockly.Categories.looks,
1128
+ "inputsInline": true,
1129
+ "extensions": ["colours_looks", "output_number"]
1130
+ });
1131
+ }
1132
+ };
1133
+
1134
+ Blockly.Blocks['looks_getinput_menu'] = {
1135
+ /**
1136
+ * pm: List of options for the first input of looks_getinputofcostume.
1137
+ * @this Blockly.Block
1138
+ */
1139
+ init: function () {
1140
+ this.jsonInit({
1141
+ "message0": "%1",
1142
+ "args0": [
1143
+ {
1144
+ "type": "field_dropdown",
1145
+ "name": "INPUT",
1146
+ "options": [
1147
+ ['width', 'width'],
1148
+ ['height', 'height'],
1149
+ ['rotation center x', 'rotation center x'],
1150
+ ['rotation center y', 'rotation center y'],
1151
+ ['drawing mode', 'drawing mode']
1152
+ ]
1153
+ }
1154
+ ],
1155
+ "extensions": ["colours_looks", "output_string"]
1156
+ });
1157
+ }
1158
+ };
blocks_vertical/motion.js ADDED
@@ -0,0 +1,887 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.motion');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+
31
+ Blockly.Blocks['motion_movesteps'] = {
32
+ /**
33
+ * Block to move steps.
34
+ * @this Blockly.Block
35
+ */
36
+ init: function() {
37
+ this.jsonInit({
38
+ "message0": Blockly.Msg.MOTION_MOVESTEPS,
39
+ "args0": [
40
+ {
41
+ "type": "input_value",
42
+ "name": "STEPS"
43
+ }
44
+ ],
45
+ "category": Blockly.Categories.motion,
46
+ "extensions": ["colours_motion", "shape_statement"]
47
+ });
48
+ }
49
+ };
50
+
51
+ Blockly.Blocks['motion_movebacksteps'] = {
52
+ /**
53
+ * pm: Block to move back steps.
54
+ * @this Blockly.Block
55
+ */
56
+ init: function() {
57
+ this.jsonInit({
58
+ "message0": "move back %1 steps",
59
+ "args0": [
60
+ {
61
+ "type": "input_value",
62
+ "name": "STEPS"
63
+ }
64
+ ],
65
+ "category": Blockly.Categories.motion,
66
+ "extensions": ["colours_motion", "shape_statement"]
67
+ });
68
+ }
69
+ };
70
+
71
+ Blockly.Blocks['motion_moveupdownsteps'] = {
72
+ /**
73
+ * pm: Block to move up or down steps.
74
+ * @this Blockly.Block
75
+ */
76
+ init: function() {
77
+ this.jsonInit({
78
+ "message0": "move %1 %2 steps",
79
+ "args0": [
80
+ {
81
+ "type": "field_dropdown",
82
+ "name": "DIRECTION",
83
+ "options": [
84
+ ['up', 'up'],
85
+ ['down', 'down']
86
+ ]
87
+ },
88
+ {
89
+ "type": "input_value",
90
+ "name": "STEPS"
91
+ }
92
+ ],
93
+ "category": Blockly.Categories.motion,
94
+ "extensions": ["colours_motion", "shape_statement"]
95
+ });
96
+ }
97
+ };
98
+
99
+ Blockly.Blocks['motion_turnright'] = {
100
+ /**
101
+ * Block to turn right.
102
+ * @this Blockly.Block
103
+ */
104
+ init: function() {
105
+ this.jsonInit({
106
+ "message0": Blockly.Msg.MOTION_TURNRIGHT,
107
+ "args0": [
108
+ {
109
+ "type": "field_image",
110
+ "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
111
+ "width": 24,
112
+ "height": 24
113
+ },
114
+ {
115
+ "type": "input_value",
116
+ "name": "DEGREES"
117
+ }
118
+ ],
119
+ "category": Blockly.Categories.motion,
120
+ "extensions": ["colours_motion", "shape_statement"]
121
+ });
122
+ }
123
+ };
124
+
125
+ Blockly.Blocks['motion_turnleft'] = {
126
+ /**
127
+ * Block to turn left.
128
+ * @this Blockly.Block
129
+ */
130
+ init: function() {
131
+ this.jsonInit({
132
+ "message0": Blockly.Msg.MOTION_TURNLEFT,
133
+ "args0": [
134
+ {
135
+ "type": "field_image",
136
+ "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg",
137
+ "width": 24,
138
+ "height": 24
139
+ },
140
+ {
141
+ "type": "input_value",
142
+ "name": "DEGREES"
143
+ }
144
+ ],
145
+ "category": Blockly.Categories.motion,
146
+ "extensions": ["colours_motion", "shape_statement"]
147
+ });
148
+ }
149
+ };
150
+
151
+ Blockly.Blocks['motion_turnrightaroundxy'] = {
152
+ /**
153
+ * pm: Block to turn right around a certain point.
154
+ * @this Blockly.Block
155
+ */
156
+ init: function () {
157
+ this.jsonInit({
158
+ "message0": "turn %1 %2 degrees around x: %3 y: %4",
159
+ "args0": [
160
+ {
161
+ "type": "field_image",
162
+ "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
163
+ "width": 24,
164
+ "height": 24
165
+ },
166
+ {
167
+ "type": "input_value",
168
+ "name": "DEGREES"
169
+ },
170
+ {
171
+ "type": "input_value",
172
+ "name": "X"
173
+ },
174
+ {
175
+ "type": "input_value",
176
+ "name": "Y"
177
+ }
178
+ ],
179
+ "category": Blockly.Categories.motion,
180
+ "extensions": ["colours_motion", "shape_statement"]
181
+ });
182
+ }
183
+ };
184
+
185
+ Blockly.Blocks['motion_turnleftaroundxy'] = {
186
+ /**
187
+ * pm: Block to turn left around a certain point.
188
+ * @this Blockly.Block
189
+ */
190
+ init: function () {
191
+ this.jsonInit({
192
+ "message0": "turn %1 %2 degrees around x: %3 y: %4",
193
+ "args0": [
194
+ {
195
+ "type": "field_image",
196
+ "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg",
197
+ "width": 24,
198
+ "height": 24
199
+ },
200
+ {
201
+ "type": "input_value",
202
+ "name": "DEGREES"
203
+ },
204
+ {
205
+ "type": "input_value",
206
+ "name": "X"
207
+ },
208
+ {
209
+ "type": "input_value",
210
+ "name": "Y"
211
+ }
212
+ ],
213
+ "category": Blockly.Categories.motion,
214
+ "extensions": ["colours_motion", "shape_statement"]
215
+ });
216
+ }
217
+ };
218
+
219
+ Blockly.Blocks['motion_pointindirection'] = {
220
+ /**
221
+ * Block to point in direction.
222
+ * @this Blockly.Block
223
+ */
224
+ init: function() {
225
+ this.jsonInit({
226
+ "message0": Blockly.Msg.MOTION_POINTINDIRECTION,
227
+ "args0": [
228
+ {
229
+ "type": "input_value",
230
+ "name": "DIRECTION"
231
+ }
232
+ ],
233
+ "category": Blockly.Categories.motion,
234
+ "extensions": ["colours_motion", "shape_statement"]
235
+ });
236
+ }
237
+ };
238
+
239
+ Blockly.Blocks['motion_pointtowards_menu'] = {
240
+ /**
241
+ * Point towards drop-down menu.
242
+ * @this Blockly.Block
243
+ */
244
+ init: function() {
245
+ this.jsonInit({
246
+ "message0": "%1",
247
+ "args0": [
248
+ {
249
+ "type": "field_dropdown",
250
+ "name": "TOWARDS",
251
+ "options": [
252
+ [Blockly.Msg.MOTION_POINTTOWARDS_POINTER, '_mouse_'],
253
+ [Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, '_random_']
254
+ ]
255
+ }
256
+ ],
257
+ "colour": Blockly.Colours.motion.secondary,
258
+ "colourSecondary": Blockly.Colours.motion.secondary,
259
+ "colourTertiary": Blockly.Colours.motion.tertiary,
260
+ "extensions": ["output_string"]
261
+ });
262
+ }
263
+ };
264
+
265
+ Blockly.Blocks['motion_turnaround'] = {
266
+ /**
267
+ * pm: Block to point in the opposite direction.
268
+ * @this Blockly.Block
269
+ */
270
+ init: function() {
271
+ this.jsonInit({
272
+ "message0": "turn around",
273
+ "category": Blockly.Categories.motion,
274
+ "extensions": ["colours_motion", "shape_statement"]
275
+ });
276
+ }
277
+ };
278
+
279
+ Blockly.Blocks['motion_pointinrandomdirection'] = {
280
+ /**
281
+ * pm: Block to point in a random direction.
282
+ * @this Blockly.Block
283
+ */
284
+ init: function () {
285
+ this.jsonInit({
286
+ "message0": "point in random direction",
287
+ "category": Blockly.Categories.motion,
288
+ "extensions": ["colours_motion", "shape_statement"]
289
+ });
290
+ }
291
+ };
292
+
293
+ Blockly.Blocks['motion_pointtowardsxy'] = {
294
+ /**
295
+ * pm: Block to point towards an x and y position.
296
+ * @this Blockly.Block
297
+ */
298
+ init: function () {
299
+ this.jsonInit({
300
+ "message0": "point towards x: %1 y: %2",
301
+ "args0": [
302
+ {
303
+ "type": "input_value",
304
+ "name": "X"
305
+ },
306
+ {
307
+ "type": "input_value",
308
+ "name": "Y"
309
+ }
310
+ ],
311
+ "category": Blockly.Categories.motion,
312
+ "extensions": ["colours_motion", "shape_statement"]
313
+ });
314
+ }
315
+ };
316
+
317
+ Blockly.Blocks['motion_pointtowards'] = {
318
+ /**
319
+ * Block to point in direction.
320
+ * @this Blockly.Block
321
+ */
322
+ init: function() {
323
+ this.jsonInit({
324
+ "message0": Blockly.Msg.MOTION_POINTTOWARDS,
325
+ "args0": [
326
+ {
327
+ "type": "input_value",
328
+ "name": "TOWARDS"
329
+ }
330
+ ],
331
+ "category": Blockly.Categories.motion,
332
+ "extensions": ["colours_motion", "shape_statement"]
333
+ });
334
+ }
335
+ };
336
+
337
+ Blockly.Blocks['motion_goto_menu'] = {
338
+ /**
339
+ * Go to drop-down menu.
340
+ * @this Blockly.Block
341
+ */
342
+ init: function() {
343
+ this.jsonInit({
344
+ "message0": "%1",
345
+ "args0": [
346
+ {
347
+ "type": "field_dropdown",
348
+ "name": "TO",
349
+ "options": [
350
+ [Blockly.Msg.MOTION_GOTO_POINTER, '_mouse_'],
351
+ [Blockly.Msg.MOTION_GOTO_RANDOM, '_random_']
352
+ ]
353
+ }
354
+ ],
355
+ "colour": Blockly.Colours.motion.secondary,
356
+ "colourSecondary": Blockly.Colours.motion.secondary,
357
+ "colourTertiary": Blockly.Colours.motion.tertiary,
358
+ "extensions": ["output_string"]
359
+ });
360
+ }
361
+ };
362
+
363
+ Blockly.Blocks['motion_gotoxy'] = {
364
+ /**
365
+ * Block to go to X, Y.
366
+ * @this Blockly.Block
367
+ */
368
+ init: function() {
369
+ this.jsonInit({
370
+ "message0": Blockly.Msg.MOTION_GOTOXY,
371
+ "args0": [
372
+ {
373
+ "type": "input_value",
374
+ "name": "X"
375
+ },
376
+ {
377
+ "type": "input_value",
378
+ "name": "Y"
379
+ }
380
+ ],
381
+ "category": Blockly.Categories.motion,
382
+ "extensions": ["colours_motion", "shape_statement"]
383
+ });
384
+ }
385
+ };
386
+
387
+ Blockly.Blocks['motion_goto'] = {
388
+ /**
389
+ * Block to go to a menu item.
390
+ * @this Blockly.Block
391
+ */
392
+ init: function() {
393
+ this.jsonInit({
394
+ "message0": Blockly.Msg.MOTION_GOTO,
395
+ "args0": [
396
+ {
397
+ "type": "input_value",
398
+ "name": "TO"
399
+ }
400
+ ],
401
+ "category": Blockly.Categories.motion,
402
+ "extensions": ["colours_motion", "shape_statement"]
403
+ });
404
+ }
405
+ };
406
+
407
+ Blockly.Blocks['motion_glidesecstoxy'] = {
408
+ /**
409
+ * Block to glide for a specified time.
410
+ * @this Blockly.Block
411
+ */
412
+ init: function() {
413
+ this.jsonInit({
414
+ "message0": Blockly.Msg.MOTION_GLIDESECSTOXY,
415
+ "args0": [
416
+ {
417
+ "type": "input_value",
418
+ "name": "SECS"
419
+ },
420
+ {
421
+ "type": "input_value",
422
+ "name": "X"
423
+ },
424
+ {
425
+ "type": "input_value",
426
+ "name": "Y"
427
+ }
428
+ ],
429
+ "category": Blockly.Categories.motion,
430
+ "extensions": ["colours_motion", "shape_statement"]
431
+ });
432
+ }
433
+ };
434
+
435
+ Blockly.Blocks['motion_glidedirectionstepsinseconds'] = {
436
+ /**
437
+ * pm: Block to glide for a specified time in a specified direction.
438
+ * @this Blockly.Block
439
+ */
440
+ init: function() {
441
+ this.jsonInit({
442
+ "message0": "glide %1 steps %2 in %3 secs",
443
+ "args0": [
444
+ {
445
+ "type": "input_value",
446
+ "name": "STEPS"
447
+ },
448
+ {
449
+ "type": "field_dropdown",
450
+ "name": "DIRECTION",
451
+ "options": [
452
+ ['forwards', 'forwards'],
453
+ ['backwards', 'backwards'],
454
+ ['up', 'up'],
455
+ ['down', 'down']
456
+ ]
457
+ },
458
+ {
459
+ "type": "input_value",
460
+ "name": "SECS"
461
+ },
462
+ ],
463
+ "category": Blockly.Categories.motion,
464
+ "extensions": ["colours_motion", "shape_statement"]
465
+ });
466
+ }
467
+ };
468
+
469
+ Blockly.Blocks['motion_glideto_menu'] = {
470
+ /**
471
+ * Glide to drop-down menu
472
+ * @this Blockly.Block
473
+ */
474
+ init: function() {
475
+ this.jsonInit({
476
+ "message0": "%1",
477
+ "args0": [
478
+ {
479
+ "type": "field_dropdown",
480
+ "name": "TO",
481
+ "options": [
482
+ [Blockly.Msg.MOTION_GLIDETO_POINTER, '_mouse_'],
483
+ [Blockly.Msg.MOTION_GLIDETO_RANDOM, '_random_']
484
+ ]
485
+ }
486
+ ],
487
+ "colour": Blockly.Colours.motion.secondary,
488
+ "colourSecondary": Blockly.Colours.motion.secondary,
489
+ "colourTertiary": Blockly.Colours.motion.tertiary,
490
+ "extensions": ["output_string"]
491
+ });
492
+ }
493
+ };
494
+
495
+ Blockly.Blocks['motion_glideto'] = {
496
+ /**
497
+ * Block to glide to a menu item
498
+ * @this Blockly.Block
499
+ */
500
+ init: function() {
501
+ this.jsonInit({
502
+ "message0": Blockly.Msg.MOTION_GLIDETO,
503
+ "args0": [
504
+ {
505
+ "type": "input_value",
506
+ "name": "SECS"
507
+ },
508
+ {
509
+ "type": "input_value",
510
+ "name": "TO"
511
+ }
512
+ ],
513
+ "category": Blockly.Categories.motion,
514
+ "extensions": ["colours_motion", "shape_statement"]
515
+ });
516
+ }
517
+ };
518
+
519
+ Blockly.Blocks['motion_changebyxy'] = {
520
+ /**
521
+ * pm: Block to change X and Y at the same time.
522
+ * @this Blockly.Block
523
+ */
524
+ init: function() {
525
+ this.jsonInit({
526
+ "message0": "change by x: %1 y: %2",
527
+ "args0": [
528
+ {
529
+ "type": "input_value",
530
+ "name": "DX"
531
+ },
532
+ {
533
+ "type": "input_value",
534
+ "name": "DY"
535
+ }
536
+ ],
537
+ "category": Blockly.Categories.motion,
538
+ "extensions": ["colours_motion", "shape_statement"]
539
+ });
540
+ }
541
+ };
542
+
543
+ Blockly.Blocks['motion_changexby'] = {
544
+ /**
545
+ * Block to change X.
546
+ * @this Blockly.Block
547
+ */
548
+ init: function() {
549
+ this.jsonInit({
550
+ "message0": Blockly.Msg.MOTION_CHANGEXBY,
551
+ "args0": [
552
+ {
553
+ "type": "input_value",
554
+ "name": "DX"
555
+ }
556
+ ],
557
+ "category": Blockly.Categories.motion,
558
+ "extensions": ["colours_motion", "shape_statement"]
559
+ });
560
+ }
561
+ };
562
+
563
+ Blockly.Blocks['motion_setx'] = {
564
+ /**
565
+ * Block to set X.
566
+ * @this Blockly.Block
567
+ */
568
+ init: function() {
569
+ this.jsonInit({
570
+ "message0": Blockly.Msg.MOTION_SETX,
571
+ "args0": [
572
+ {
573
+ "type": "input_value",
574
+ "name": "X"
575
+ }
576
+ ],
577
+ "category": Blockly.Categories.motion,
578
+ "extensions": ["colours_motion", "shape_statement"]
579
+ });
580
+ }
581
+ };
582
+
583
+ Blockly.Blocks['motion_changeyby'] = {
584
+ /**
585
+ * Block to change Y.
586
+ * @this Blockly.Block
587
+ */
588
+ init: function() {
589
+ this.jsonInit({
590
+ "message0": Blockly.Msg.MOTION_CHANGEYBY,
591
+ "args0": [
592
+ {
593
+ "type": "input_value",
594
+ "name": "DY"
595
+ }
596
+ ],
597
+ "category": Blockly.Categories.motion,
598
+ "extensions": ["colours_motion", "shape_statement"]
599
+ });
600
+ }
601
+ };
602
+
603
+ Blockly.Blocks['motion_sety'] = {
604
+ /**
605
+ * Block to set Y.
606
+ * @this Blockly.Block
607
+ */
608
+ init: function() {
609
+ this.jsonInit({
610
+ "message0": Blockly.Msg.MOTION_SETY,
611
+ "args0": [
612
+ {
613
+ "type": "input_value",
614
+ "name": "Y"
615
+ }
616
+ ],
617
+ "category": Blockly.Categories.motion,
618
+ "extensions": ["colours_motion", "shape_statement"]
619
+ });
620
+ }
621
+ };
622
+
623
+ Blockly.Blocks['motion_ifonedgebounce'] = {
624
+ /**
625
+ * Block to bounce on edge.
626
+ * @this Blockly.Block
627
+ */
628
+ init: function() {
629
+ this.jsonInit({
630
+ "message0": Blockly.Msg.MOTION_IFONEDGEBOUNCE,
631
+ "category": Blockly.Categories.motion,
632
+ "extensions": ["colours_motion", "shape_statement"]
633
+ });
634
+ }
635
+ };
636
+
637
+ Blockly.Blocks['motion_ifonspritebounce'] = {
638
+ /**
639
+ * pm: Block to bounce on a sprite.
640
+ * @this Blockly.Block
641
+ */
642
+ init: function () {
643
+ this.jsonInit({
644
+ "message0": "if touching %1, bounce",
645
+ "args0": [
646
+ {
647
+ "type": "input_value",
648
+ "name": "SPRITE"
649
+ }
650
+ ],
651
+ "category": Blockly.Categories.motion,
652
+ "extensions": ["colours_motion", "shape_statement"]
653
+ });
654
+ }
655
+ };
656
+
657
+ Blockly.Blocks['motion_ifonxybounce'] = {
658
+ /**
659
+ * pm: Block to bounce on x and y.
660
+ * @this Blockly.Block
661
+ */
662
+ init: function () {
663
+ this.jsonInit({
664
+ "message0": "if touching x: %1 y: %2, bounce",
665
+ "args0": [
666
+ {
667
+ "type": "input_value",
668
+ "name": "X"
669
+ },
670
+ {
671
+ "type": "input_value",
672
+ "name": "Y"
673
+ }
674
+ ],
675
+ "category": Blockly.Categories.motion,
676
+ "extensions": ["colours_motion", "shape_statement"]
677
+ });
678
+ }
679
+ };
680
+
681
+ Blockly.Blocks['motion_setrotationstyle'] = {
682
+ /**
683
+ * Block to set rotation style.
684
+ * @this Blockly.Block
685
+ */
686
+ init: function() {
687
+ this.jsonInit({
688
+ "message0": Blockly.Msg.MOTION_SETROTATIONSTYLE,
689
+ "args0": [
690
+ {
691
+ "type": "field_dropdown",
692
+ "name": "STYLE",
693
+ "options": [
694
+ [Blockly.Msg.MOTION_SETROTATIONSTYLE_LEFTRIGHT, 'left-right'],
695
+ ['up-down', 'up-down'],
696
+ ['look at', 'look at'],
697
+ [Blockly.Msg.MOTION_SETROTATIONSTYLE_DONTROTATE, 'don\'t rotate'],
698
+ [Blockly.Msg.MOTION_SETROTATIONSTYLE_ALLAROUND, 'all around']
699
+ ]
700
+ }
701
+ ],
702
+ "category": Blockly.Categories.motion,
703
+ "extensions": ["colours_motion", "shape_statement"]
704
+ });
705
+ }
706
+ };
707
+
708
+ Blockly.Blocks['motion_xposition'] = {
709
+ /**
710
+ * Block to report X.
711
+ * @this Blockly.Block
712
+ */
713
+ init: function() {
714
+ this.jsonInit({
715
+ "message0": Blockly.Msg.MOTION_XPOSITION,
716
+ "category": Blockly.Categories.motion,
717
+ "checkboxInFlyout": true,
718
+ "extensions": ["colours_motion", "output_number"]
719
+ });
720
+ }
721
+ };
722
+
723
+ Blockly.Blocks['motion_yposition'] = {
724
+ /**
725
+ * Block to report Y.
726
+ * @this Blockly.Block
727
+ */
728
+ init: function() {
729
+ this.jsonInit({
730
+ "message0": Blockly.Msg.MOTION_YPOSITION,
731
+ "category": Blockly.Categories.motion,
732
+ "checkboxInFlyout": true,
733
+ "extensions": ["colours_motion", "output_number"]
734
+ });
735
+ }
736
+ };
737
+
738
+ Blockly.Blocks['motion_direction'] = {
739
+ /**
740
+ * Block to report direction.
741
+ * @this Blockly.Block
742
+ */
743
+ init: function() {
744
+ this.jsonInit({
745
+ "message0": Blockly.Msg.MOTION_DIRECTION,
746
+ "category": Blockly.Categories.motion,
747
+ "checkboxInFlyout": true,
748
+ "extensions": ["colours_motion", "output_number"]
749
+ });
750
+ }
751
+ };
752
+
753
+ Blockly.Blocks['motion_scroll_right'] = {
754
+ /**
755
+ * Block to scroll the stage right. Does not actually do anything. This is
756
+ * an obsolete block that is implemented for compatibility with Scratch 2.0
757
+ * projects.
758
+ * @this Blockly.Block
759
+ */
760
+ init: function() {
761
+ this.jsonInit({
762
+ "message0": Blockly.Msg.MOTION_SCROLLRIGHT,
763
+ "args0": [
764
+ {
765
+ "type": "input_value",
766
+ "name": "DISTANCE"
767
+ }
768
+ ],
769
+ "category": Blockly.Categories.motion,
770
+ "extensions": ["colours_motion", "shape_statement"]
771
+ });
772
+ }
773
+ };
774
+
775
+ Blockly.Blocks['motion_scroll_up'] = {
776
+ /**
777
+ * Block to scroll the stage up. Does not actually do anything. This is an
778
+ * obsolete block that is implemented for compatibility with Scratch 2.0
779
+ * projects.
780
+ * @this Blockly.Block
781
+ */
782
+ init: function() {
783
+ this.jsonInit({
784
+ "message0": Blockly.Msg.MOTION_SCROLLUP,
785
+ "args0": [
786
+ {
787
+ "type": "input_value",
788
+ "name": "DISTANCE"
789
+ }
790
+ ],
791
+ "category": Blockly.Categories.motion,
792
+ "extensions": ["colours_motion", "shape_statement"]
793
+ });
794
+ }
795
+ };
796
+
797
+ Blockly.Blocks['motion_move_sprite_to_scene_side'] = {
798
+ /**
799
+ * pm: Block to move the sprite to the stage's side.
800
+ * @this Blockly.Block
801
+ */
802
+ init: function () {
803
+ this.jsonInit({
804
+ "message0": "move to stage %1",
805
+ "args0": [
806
+ {
807
+ "type": "field_dropdown",
808
+ "name": "ALIGNMENT",
809
+ "options": [
810
+ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'],
811
+ ['bottom', 'bottom'],
812
+ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'],
813
+ [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'],
814
+ [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'],
815
+ ['top', 'top'],
816
+ [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right'],
817
+ ['left', 'left'],
818
+ ['right', 'right'],
819
+ ]
820
+ }
821
+ ],
822
+ "category": Blockly.Categories.motion,
823
+ "extensions": ["colours_motion", "shape_statement"]
824
+ });
825
+ }
826
+ };
827
+
828
+ Blockly.Blocks['motion_align_scene'] = {
829
+ /**
830
+ * Block to change the stage's scrolling alignment. Does not actually do
831
+ * anything. This is an obsolete block that is implemented for compatibility
832
+ * with Scratch 2.0 projects.
833
+ * @this Blockly.Block
834
+ */
835
+ init: function() {
836
+ this.jsonInit({
837
+ "message0": Blockly.Msg.MOTION_ALIGNSCENE,
838
+ "args0": [
839
+ {
840
+ "type": "field_dropdown",
841
+ "name": "ALIGNMENT",
842
+ "options": [
843
+ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'],
844
+ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'],
845
+ [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'],
846
+ [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'],
847
+ [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right']
848
+ ]
849
+ }
850
+ ],
851
+ "category": Blockly.Categories.motion,
852
+ "extensions": ["colours_motion", "shape_statement"]
853
+ });
854
+ }
855
+ };
856
+
857
+ Blockly.Blocks['motion_xscroll'] = {
858
+ /**
859
+ * Block to report the stage's scroll position's X value. Does not actually
860
+ * do anything. This is an obsolete block that is implemented for
861
+ * compatibility with Scratch 2.0 projects.
862
+ * @this Blockly.Block
863
+ */
864
+ init: function() {
865
+ this.jsonInit({
866
+ "message0": Blockly.Msg.MOTION_XSCROLL,
867
+ "category": Blockly.Categories.motion,
868
+ "extensions": ["colours_motion", "output_number"]
869
+ });
870
+ }
871
+ };
872
+
873
+ Blockly.Blocks['motion_yscroll'] = {
874
+ /**
875
+ * Block to report the stage's scroll position's Y value. Does not actually
876
+ * do anything. This is an obsolete block that is implemented for
877
+ * compatibility with Scratch 2.0 projects.
878
+ * @this Blockly.Block
879
+ */
880
+ init: function() {
881
+ this.jsonInit({
882
+ "message0": Blockly.Msg.MOTION_YSCROLL,
883
+ "category": Blockly.Categories.motion,
884
+ "extensions": ["colours_motion", "output_number"]
885
+ });
886
+ }
887
+ };
blocks_vertical/operators.js ADDED
@@ -0,0 +1,1288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.operators');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+
31
+ Blockly.Blocks['operator_add'] = {
32
+ /**
33
+ * Block for adding two numbers.
34
+ * @this Blockly.Block
35
+ */
36
+ init: function() {
37
+ this.jsonInit({
38
+ "message0": Blockly.Msg.OPERATORS_ADD,
39
+ "args0": [
40
+ {
41
+ "type": "input_value",
42
+ "name": "NUM1"
43
+ },
44
+ {
45
+ "type": "input_value",
46
+ "name": "NUM2"
47
+ }
48
+ ],
49
+ "category": Blockly.Categories.operators,
50
+ "extensions": ["colours_operators", "output_number"]
51
+ });
52
+ }
53
+ };
54
+
55
+ Blockly.Blocks['operator_subtract'] = {
56
+ /**
57
+ * Block for subtracting two numbers.
58
+ * @this Blockly.Block
59
+ */
60
+ init: function() {
61
+ this.jsonInit({
62
+ "message0": Blockly.Msg.OPERATORS_SUBTRACT,
63
+ "args0": [
64
+ {
65
+ "type": "input_value",
66
+ "name": "NUM1"
67
+ },
68
+ {
69
+ "type": "input_value",
70
+ "name": "NUM2"
71
+ }
72
+ ],
73
+ "category": Blockly.Categories.operators,
74
+ "extensions": ["colours_operators", "output_number"]
75
+ });
76
+ }
77
+ };
78
+
79
+ Blockly.Blocks['operator_multiply'] = {
80
+ /**
81
+ * Block for multiplying two numbers.
82
+ * @this Blockly.Block
83
+ */
84
+ init: function() {
85
+ this.jsonInit({
86
+ "message0": Blockly.Msg.OPERATORS_MULTIPLY,
87
+ "args0": [
88
+ {
89
+ "type": "input_value",
90
+ "name": "NUM1"
91
+ },
92
+ {
93
+ "type": "input_value",
94
+ "name": "NUM2"
95
+ }
96
+ ],
97
+ "category": Blockly.Categories.operators,
98
+ "extensions": ["colours_operators", "output_number"]
99
+ });
100
+ }
101
+ };
102
+
103
+ Blockly.Blocks['operator_divide'] = {
104
+ /**
105
+ * Block for dividing two numbers.
106
+ * @this Blockly.Block
107
+ */
108
+ init: function() {
109
+ this.jsonInit({
110
+ "message0": Blockly.Msg.OPERATORS_DIVIDE,
111
+ "args0": [
112
+ {
113
+ "type": "input_value",
114
+ "name": "NUM1"
115
+ },
116
+ {
117
+ "type": "input_value",
118
+ "name": "NUM2"
119
+ }
120
+ ],
121
+ "category": Blockly.Categories.operators,
122
+ "extensions": ["colours_operators", "output_number"]
123
+ });
124
+ }
125
+ };
126
+
127
+ Blockly.Blocks['operator_random'] = {
128
+ /**
129
+ * Block for picking a random number.
130
+ * @this Blockly.Block
131
+ */
132
+ init: function() {
133
+ this.jsonInit({
134
+ "message0": Blockly.Msg.OPERATORS_RANDOM,
135
+ "args0": [
136
+ {
137
+ "type": "input_value",
138
+ "name": "FROM"
139
+ },
140
+ {
141
+ "type": "input_value",
142
+ "name": "TO"
143
+ }
144
+ ],
145
+ "category": Blockly.Categories.operators,
146
+ "extensions": ["colours_operators", "output_number"]
147
+ });
148
+ }
149
+ };
150
+
151
+ Blockly.Blocks['operator_lt'] = {
152
+ /**
153
+ * Block for less than comparator.
154
+ * @this Blockly.Block
155
+ */
156
+ init: function() {
157
+ this.jsonInit({
158
+ "message0": Blockly.Msg.OPERATORS_LT,
159
+ "args0": [
160
+ {
161
+ "type": "input_value",
162
+ "name": "OPERAND1"
163
+ },
164
+ {
165
+ "type": "input_value",
166
+ "name": "OPERAND2"
167
+ }
168
+ ],
169
+ "category": Blockly.Categories.operators,
170
+ "extensions": ["colours_operators", "output_boolean"]
171
+ });
172
+ }
173
+ };
174
+
175
+ Blockly.Blocks['operator_equals'] = {
176
+ /**
177
+ * Block for equals comparator.
178
+ * @this Blockly.Block
179
+ */
180
+ init: function() {
181
+ this.jsonInit({
182
+ "message0": Blockly.Msg.OPERATORS_EQUALS,
183
+ "args0": [
184
+ {
185
+ "type": "input_value",
186
+ "name": "OPERAND1"
187
+ },
188
+ {
189
+ "type": "input_value",
190
+ "name": "OPERAND2"
191
+ }
192
+ ],
193
+ "category": Blockly.Categories.operators,
194
+ "extensions": ["colours_operators", "output_boolean"]
195
+ });
196
+ }
197
+ };
198
+
199
+ Blockly.Blocks['operator_gt'] = {
200
+ /**
201
+ * Block for greater than comparator.
202
+ * @this Blockly.Block
203
+ */
204
+ init: function() {
205
+ this.jsonInit({
206
+ "message0": Blockly.Msg.OPERATORS_GT,
207
+ "args0": [
208
+ {
209
+ "type": "input_value",
210
+ "name": "OPERAND1"
211
+ },
212
+ {
213
+ "type": "input_value",
214
+ "name": "OPERAND2"
215
+ }
216
+ ],
217
+ "category": Blockly.Categories.operators,
218
+ "extensions": ["colours_operators", "output_boolean"]
219
+ });
220
+ }
221
+ };
222
+
223
+ Blockly.Blocks['operator_gtorequal'] = {
224
+ /**
225
+ * pm: Block for greater than or equal comparator.
226
+ * @this Blockly.Block
227
+ */
228
+ init: function() {
229
+ this.jsonInit({
230
+ "message0": "%1 ≥ %2",
231
+ "args0": [
232
+ {
233
+ "type": "input_value",
234
+ "name": "OPERAND1"
235
+ },
236
+ {
237
+ "type": "input_value",
238
+ "name": "OPERAND2"
239
+ }
240
+ ],
241
+ "category": Blockly.Categories.operators,
242
+ "extensions": ["colours_operators", "output_boolean"]
243
+ });
244
+ }
245
+ };
246
+
247
+ Blockly.Blocks['operator_ltorequal'] = {
248
+ /**
249
+ * pm: Block for less than or equal comparator.
250
+ * @this Blockly.Block
251
+ */
252
+ init: function() {
253
+ this.jsonInit({
254
+ "message0": "%1 ≤ %2",
255
+ "args0": [
256
+ {
257
+ "type": "input_value",
258
+ "name": "OPERAND1"
259
+ },
260
+ {
261
+ "type": "input_value",
262
+ "name": "OPERAND2"
263
+ }
264
+ ],
265
+ "category": Blockly.Categories.operators,
266
+ "extensions": ["colours_operators", "output_boolean"]
267
+ });
268
+ }
269
+ };
270
+
271
+ Blockly.Blocks['operator_notequal'] = {
272
+ /**
273
+ * pm: Block for not equal comparator.
274
+ * @this Blockly.Block
275
+ */
276
+ init: function() {
277
+ this.jsonInit({
278
+ "message0": "%1 ≠ %2",
279
+ "args0": [
280
+ {
281
+ "type": "input_value",
282
+ "name": "OPERAND1"
283
+ },
284
+ {
285
+ "type": "input_value",
286
+ "name": "OPERAND2"
287
+ }
288
+ ],
289
+ "category": Blockly.Categories.operators,
290
+ "extensions": ["colours_operators", "output_boolean"]
291
+ });
292
+ }
293
+ };
294
+
295
+ Blockly.Blocks['operator_and'] = {
296
+ /**
297
+ * Block for "and" boolean comparator.
298
+ * @this Blockly.Block
299
+ */
300
+ init: function() {
301
+ this.jsonInit({
302
+ "message0": Blockly.Msg.OPERATORS_AND,
303
+ "args0": [
304
+ {
305
+ "type": "input_value",
306
+ "name": "OPERAND1",
307
+ "check": "Boolean"
308
+ },
309
+ {
310
+ "type": "input_value",
311
+ "name": "OPERAND2",
312
+ "check": "Boolean"
313
+ }
314
+ ],
315
+ "category": Blockly.Categories.operators,
316
+ "extensions": ["colours_operators", "output_boolean"]
317
+ });
318
+ }
319
+ };
320
+
321
+ Blockly.Blocks['operator_nand'] = {
322
+ /**
323
+ * pm: Block for "nand" boolean comparator.
324
+ * @this Blockly.Block
325
+ */
326
+ init: function() {
327
+ this.jsonInit({
328
+ "message0": "%1 nand %2",
329
+ "args0": [
330
+ {
331
+ "type": "input_value",
332
+ "name": "OPERAND1",
333
+ "check": "Boolean"
334
+ },
335
+ {
336
+ "type": "input_value",
337
+ "name": "OPERAND2",
338
+ "check": "Boolean"
339
+ }
340
+ ],
341
+ "category": Blockly.Categories.operators,
342
+ "extensions": ["colours_operators", "output_boolean"]
343
+ });
344
+ }
345
+ };
346
+ Blockly.Blocks['operator_nor'] = {
347
+ /**
348
+ * pm: Block for "nor" boolean comparator.
349
+ * @this Blockly.Block
350
+ */
351
+ init: function () {
352
+ this.jsonInit({
353
+ "message0": "%1 nor %2",
354
+ "args0": [
355
+ {
356
+ "type": "input_value",
357
+ "name": "OPERAND1",
358
+ "check": "Boolean"
359
+ },
360
+ {
361
+ "type": "input_value",
362
+ "name": "OPERAND2",
363
+ "check": "Boolean"
364
+ }
365
+ ],
366
+ "category": Blockly.Categories.operators,
367
+ "extensions": ["colours_operators", "output_boolean"]
368
+ });
369
+ }
370
+ };
371
+ Blockly.Blocks['operator_xor'] = {
372
+ /**
373
+ * pm: Block for "xor" boolean comparator.
374
+ * @this Blockly.Block
375
+ */
376
+ init: function () {
377
+ this.jsonInit({
378
+ "message0": "%1 xor %2",
379
+ "args0": [
380
+ {
381
+ "type": "input_value",
382
+ "name": "OPERAND1",
383
+ "check": "Boolean"
384
+ },
385
+ {
386
+ "type": "input_value",
387
+ "name": "OPERAND2",
388
+ "check": "Boolean"
389
+ }
390
+ ],
391
+ "category": Blockly.Categories.operators,
392
+ "extensions": ["colours_operators", "output_boolean"]
393
+ });
394
+ }
395
+ };
396
+ Blockly.Blocks['operator_xnor'] = {
397
+ /**
398
+ * pm: Block for "nor" boolean comparator.
399
+ * @this Blockly.Block
400
+ */
401
+ init: function () {
402
+ this.jsonInit({
403
+ "message0": "%1 xnor %2",
404
+ "args0": [
405
+ {
406
+ "type": "input_value",
407
+ "name": "OPERAND1",
408
+ "check": "Boolean"
409
+ },
410
+ {
411
+ "type": "input_value",
412
+ "name": "OPERAND2",
413
+ "check": "Boolean"
414
+ }
415
+ ],
416
+ "category": Blockly.Categories.operators,
417
+ "extensions": ["colours_operators", "output_boolean"]
418
+ });
419
+ }
420
+ };
421
+
422
+ Blockly.Blocks['operator_or'] = {
423
+ /**
424
+ * Block for "or" boolean comparator.
425
+ * @this Blockly.Block
426
+ */
427
+ init: function() {
428
+ this.jsonInit({
429
+ "message0": Blockly.Msg.OPERATORS_OR,
430
+ "args0": [
431
+ {
432
+ "type": "input_value",
433
+ "name": "OPERAND1",
434
+ "check": "Boolean"
435
+ },
436
+ {
437
+ "type": "input_value",
438
+ "name": "OPERAND2",
439
+ "check": "Boolean"
440
+ }
441
+ ],
442
+ "category": Blockly.Categories.operators,
443
+ "extensions": ["colours_operators", "output_boolean"]
444
+ });
445
+ }
446
+ };
447
+
448
+ Blockly.Blocks['operator_not'] = {
449
+ /**
450
+ * Block for "not" unary boolean operator.
451
+ * @this Blockly.Block
452
+ */
453
+ init: function() {
454
+ this.jsonInit({
455
+ "message0": Blockly.Msg.OPERATORS_NOT,
456
+ "args0": [
457
+ {
458
+ "type": "input_value",
459
+ "name": "OPERAND",
460
+ "check": "Boolean"
461
+ }
462
+ ],
463
+ "category": Blockly.Categories.operators,
464
+ "extensions": ["colours_operators", "output_boolean"]
465
+ });
466
+ }
467
+ };
468
+
469
+ Blockly.Blocks['operator_join'] = {
470
+ /**
471
+ * Block for string join operator.
472
+ * @this Blockly.Block
473
+ */
474
+ init: function() {
475
+ this.jsonInit({
476
+ "message0": Blockly.Msg.OPERATORS_JOIN,
477
+ "args0": [
478
+ {
479
+ "type": "input_value",
480
+ "name": "STRING1"
481
+ },
482
+ {
483
+ "type": "input_value",
484
+ "name": "STRING2"
485
+ }
486
+ ],
487
+ "category": Blockly.Categories.operators,
488
+ "extensions": ["colours_operators", "output_string"]
489
+ });
490
+ }
491
+ };
492
+
493
+ Blockly.Blocks['operator_join3'] = {
494
+ /**
495
+ * pm: Block for joining 3 strings together.
496
+ * @this Blockly.Block
497
+ */
498
+ init: function() {
499
+ this.jsonInit({
500
+ "message0": Blockly.Msg.OPERATORS_JOIN3,
501
+ "args0": [
502
+ {
503
+ "type": "input_value",
504
+ "name": "STRING1"
505
+ },
506
+ {
507
+ "type": "input_value",
508
+ "name": "STRING2"
509
+ },
510
+ {
511
+ "type": "input_value",
512
+ "name": "STRING3"
513
+ }
514
+ ],
515
+ "category": Blockly.Categories.operators,
516
+ "extensions": ["colours_operators", "output_string"]
517
+ });
518
+ }
519
+ };
520
+
521
+ Blockly.Blocks['operator_letter_of'] = {
522
+ /**
523
+ * Block for "letter _ of _" operator.
524
+ * @this Blockly.Block
525
+ */
526
+ init: function() {
527
+ this.jsonInit({
528
+ "message0": Blockly.Msg.OPERATORS_LETTEROF,
529
+ "args0": [
530
+ {
531
+ "type": "input_value",
532
+ "name": "LETTER"
533
+ },
534
+ {
535
+ "type": "input_value",
536
+ "name": "STRING"
537
+ }
538
+ ],
539
+ "category": Blockly.Categories.operators,
540
+ "extensions": ["colours_operators", "output_string"]
541
+ });
542
+ }
543
+ };
544
+
545
+ Blockly.Blocks['operator_length'] = {
546
+ /**
547
+ * Block for string length operator.
548
+ * @this Blockly.Block
549
+ */
550
+ init: function() {
551
+ this.jsonInit({
552
+ "message0": Blockly.Msg.OPERATORS_LENGTH,
553
+ "args0": [
554
+ {
555
+ "type": "input_value",
556
+ "name": "STRING"
557
+ }
558
+ ],
559
+ "category": Blockly.Categories.operators,
560
+ "extensions": ["colours_operators", "output_string"]
561
+ });
562
+ }
563
+ };
564
+
565
+ Blockly.Blocks['operator_contains'] = {
566
+ /**
567
+ * Block for _ contains _ operator
568
+ * @this Blockly.Block
569
+ */
570
+ init: function() {
571
+ this.jsonInit({
572
+ "message0": Blockly.Msg.OPERATORS_CONTAINS,
573
+ "args0": [
574
+ {
575
+ "type": "input_value",
576
+ "name": "STRING1"
577
+ },
578
+ {
579
+ "type": "input_value",
580
+ "name": "STRING2"
581
+ }
582
+ ],
583
+ "category": Blockly.Categories.operators,
584
+ "extensions": ["colours_operators", "output_boolean"]
585
+ });
586
+ }
587
+ };
588
+
589
+ Blockly.Blocks['operator_mod'] = {
590
+ /**
591
+ * Block for mod two numbers.
592
+ * @this Blockly.Block
593
+ */
594
+ init: function() {
595
+ this.jsonInit({
596
+ "message0": Blockly.Msg.OPERATORS_MOD,
597
+ "args0": [
598
+ {
599
+ "type": "input_value",
600
+ "name": "NUM1"
601
+ },
602
+ {
603
+ "type": "input_value",
604
+ "name": "NUM2"
605
+ }
606
+ ],
607
+ "category": Blockly.Categories.operators,
608
+ "extensions": ["colours_operators", "output_number"]
609
+ });
610
+ }
611
+ };
612
+
613
+ Blockly.Blocks['operator_round'] = {
614
+ /**
615
+ * Block for rounding a numbers.
616
+ * @this Blockly.Block
617
+ */
618
+ init: function() {
619
+ this.jsonInit({
620
+ "message0": Blockly.Msg.OPERATORS_ROUND,
621
+ "args0": [
622
+ {
623
+ "type": "input_value",
624
+ "name": "NUM"
625
+ }
626
+ ],
627
+ "category": Blockly.Categories.operators,
628
+ "extensions": ["colours_operators", "output_number"]
629
+ });
630
+ }
631
+ };
632
+
633
+ Blockly.Blocks['operator_mathop'] = {
634
+ /**
635
+ * Block for "advanced" math ops on a number.
636
+ * @this Blockly.Block
637
+ */
638
+ init: function() {
639
+ this.jsonInit({
640
+ "message0": Blockly.Msg.OPERATORS_MATHOP,
641
+ "args0": [
642
+ {
643
+ "type": "field_dropdown",
644
+ "name": "OPERATOR",
645
+ "options": [
646
+ [Blockly.Msg.OPERATORS_MATHOP_ABS, 'abs'],
647
+ [Blockly.Msg.OPERATORS_MATHOP_FLOOR, 'floor'],
648
+ [Blockly.Msg.OPERATORS_MATHOP_CEILING, 'ceiling'],
649
+ ['sign', 'sign'],
650
+ [Blockly.Msg.OPERATORS_MATHOP_SQRT, 'sqrt'],
651
+ [Blockly.Msg.OPERATORS_MATHOP_SIN, 'sin'],
652
+ [Blockly.Msg.OPERATORS_MATHOP_COS, 'cos'],
653
+ [Blockly.Msg.OPERATORS_MATHOP_TAN, 'tan'],
654
+ [Blockly.Msg.OPERATORS_MATHOP_ASIN, 'asin'],
655
+ [Blockly.Msg.OPERATORS_MATHOP_ACOS, 'acos'],
656
+ [Blockly.Msg.OPERATORS_MATHOP_ATAN, 'atan'],
657
+ [Blockly.Msg.OPERATORS_MATHOP_LN, 'ln'],
658
+ [Blockly.Msg.OPERATORS_MATHOP_LOG, 'log'],
659
+ ['log2', 'log2'],
660
+ [Blockly.Msg.OPERATORS_MATHOP_EEXP, 'e ^'],
661
+ [Blockly.Msg.OPERATORS_MATHOP_10EXP, '10 ^']
662
+ ]
663
+ },
664
+ {
665
+ "type": "input_value",
666
+ "name": "NUM"
667
+ }
668
+ ],
669
+ "category": Blockly.Categories.operators,
670
+ "extensions": ["colours_operators", "output_number"]
671
+ });
672
+ }
673
+ };
674
+ Blockly.Blocks['operator_advlog'] = {
675
+ /**
676
+ * Block for better use of logarithm
677
+ * @this Blockly.Block
678
+ */
679
+ init: function() {
680
+ this.jsonInit({
681
+ "message0": Blockly.Msg.OPERATORS_ADVLOG,
682
+ "args0": [
683
+ {
684
+ "type": "input_value",
685
+ "name": "NUM1",
686
+ },
687
+ {
688
+ "type": "input_value",
689
+ "name": "NUM2"
690
+ }
691
+ ],
692
+ "category": Blockly.Categories.operators,
693
+ "extensions": ["colours_operators", "output_number"]
694
+ });
695
+ }
696
+ };
697
+
698
+ Blockly.Blocks["operator_regexmatch"] = {
699
+ init: function() {
700
+ this.jsonInit({
701
+ "inputsInline": true,
702
+ "message0": "match %1 with regex %2 %3",
703
+ "args0": [
704
+ {
705
+ "type": "input_value",
706
+ "name": "text"
707
+ },
708
+ {
709
+ "type": "input_value",
710
+ "name": "reg"
711
+ },
712
+ {
713
+ "type": "input_value",
714
+ "name": "regrule"
715
+ }
716
+ ],
717
+ "category": Blockly.Categories.operators,
718
+ "extensions": ["colours_operators", "output_string"]
719
+ });
720
+ }
721
+ };
722
+
723
+ Blockly.Blocks["operator_replaceAll"] = {
724
+ init: function() {
725
+ this.jsonInit({
726
+ "inputsInline": true,
727
+ "message0": "in %1 replace all %2 with %3",
728
+ "args0": [
729
+ {
730
+ "type": "input_value",
731
+ "name": "text"
732
+ },
733
+ {
734
+ "type": "input_value",
735
+ "name": "term"
736
+ },
737
+ {
738
+ "type": "input_value",
739
+ "name": "res"
740
+ }
741
+ ],
742
+ "category": Blockly.Categories.operators,
743
+ "extensions": ["colours_operators", "output_string"]
744
+ });
745
+ }
746
+ };
747
+
748
+ Blockly.Blocks["operator_replaceFirst"] = {
749
+ init: function() {
750
+ this.jsonInit({
751
+ "inputsInline": true,
752
+ "message0": "in %1 replace first %2 with %3",
753
+ "args0": [
754
+ {
755
+ "type": "input_value",
756
+ "name": "text"
757
+ },
758
+ {
759
+ "type": "input_value",
760
+ "name": "term"
761
+ },
762
+ {
763
+ "type": "input_value",
764
+ "name": "res"
765
+ }
766
+ ],
767
+ "category": Blockly.Categories.operators,
768
+ "extensions": ["colours_operators", "output_string"]
769
+ });
770
+ }
771
+ };
772
+
773
+ Blockly.Blocks["operator_getLettersFromIndexToIndexInText"] = {
774
+ init: function() {
775
+ this.jsonInit({
776
+ "inputsInline": true,
777
+ "message0": "letters from %1 up to before %2 in %3",
778
+ "args0": [
779
+ {
780
+ "type": "input_value",
781
+ "name": "INDEX1"
782
+ },
783
+ {
784
+ "type": "input_value",
785
+ "name": "INDEX2"
786
+ },
787
+ {
788
+ "type": "input_value",
789
+ "name": "TEXT"
790
+ }
791
+ ],
792
+ "category": Blockly.Categories.operators,
793
+ "extensions": ["colours_operators", "output_string"]
794
+ });
795
+ }
796
+ };
797
+
798
+
799
+ Blockly.Blocks["operator_getLettersFromIndexToIndexInTextFixed"] = {
800
+ /**
801
+ * pm: Duplicate of operator_getLettersFromIndexToIndexInText to prevent breaking old projects.
802
+ * @this Blockly.Block
803
+ */
804
+ init: function() {
805
+ this.jsonInit({
806
+ "inputsInline": true,
807
+ "message0": Blockly.Msg.OPERATORS_LETTERSFROMTOIN,
808
+ "args0": [
809
+ {
810
+ "type": "input_value",
811
+ "name": "INDEX1"
812
+ },
813
+ {
814
+ "type": "input_value",
815
+ "name": "INDEX2"
816
+ },
817
+ {
818
+ "type": "input_value",
819
+ "name": "TEXT"
820
+ }
821
+ ],
822
+ "category": Blockly.Categories.operators,
823
+ "extensions": ["colours_operators", "output_string"]
824
+ });
825
+ }
826
+ };
827
+
828
+ Blockly.Blocks["operator_readLineInMultilineText"] = {
829
+ init: function() {
830
+ this.jsonInit({
831
+ "inputsInline": true,
832
+ "message0": "read line %1 in %2",
833
+ "args0": [
834
+ {
835
+ "type": "input_value",
836
+ "name": "LINE"
837
+ },
838
+ {
839
+ "type": "input_value",
840
+ "name": "TEXT"
841
+ }
842
+ ],
843
+ "category": Blockly.Categories.operators,
844
+ "extensions": ["colours_operators", "output_string"]
845
+ });
846
+ }
847
+ };
848
+
849
+ Blockly.Blocks["operator_newLine"] = {
850
+ init: function() {
851
+ this.jsonInit({
852
+ "inputsInline": true,
853
+ "message0": "new line",
854
+ "args0": [],
855
+ "category": Blockly.Categories.operators,
856
+ "extensions": ["colours_operators", "output_string"]
857
+ });
858
+ }
859
+ };
860
+
861
+ Blockly.Blocks["operator_tabCharacter"] = {
862
+ init: function() {
863
+ this.jsonInit({
864
+ "inputsInline": true,
865
+ "message0": "tab character",
866
+ "args0": [],
867
+ "category": Blockly.Categories.operators,
868
+ "extensions": ["colours_operators", "output_string"]
869
+ });
870
+ }
871
+ };
872
+
873
+ Blockly.Blocks["operator_stringify"] = {
874
+ init: function() {
875
+ this.jsonInit({
876
+ "inputsInline": true,
877
+ "message0": "%1",
878
+ "args0": [
879
+ {
880
+ "type": "input_value",
881
+ "name": "ONE"
882
+ }
883
+ ],
884
+ "category": Blockly.Categories.operators,
885
+ "extensions": ["colours_operators", "output_string"]
886
+ });
887
+ }
888
+ };
889
+
890
+ Blockly.Blocks["operator_boolify"] = {
891
+ init: function () {
892
+ this.jsonInit({
893
+ "inputsInline": true,
894
+ "message0": "%1",
895
+ "args0": [
896
+ {
897
+ "type": "input_value",
898
+ "name": "ONE"
899
+ }
900
+ ],
901
+ "category": Blockly.Categories.operators,
902
+ "extensions": ["colours_operators", "output_boolean"]
903
+ });
904
+ }
905
+ };
906
+
907
+ Blockly.Blocks["operator_character_to_code"] = {
908
+ init: function () {
909
+ this.jsonInit({
910
+ "inputsInline": true,
911
+ "message0": "character %1 to id",
912
+ "args0": [
913
+ {
914
+ "type": "input_value",
915
+ "name": "ONE"
916
+ }
917
+ ],
918
+ "category": Blockly.Categories.operators,
919
+ "extensions": ["colours_operators", "output_number"]
920
+ });
921
+ }
922
+ };
923
+
924
+ Blockly.Blocks["operator_code_to_character"] = {
925
+ init: function () {
926
+ this.jsonInit({
927
+ "inputsInline": true,
928
+ "message0": "id %1 to character",
929
+ "args0": [
930
+ {
931
+ "type": "input_value",
932
+ "name": "ONE"
933
+ }
934
+ ],
935
+ "category": Blockly.Categories.operators,
936
+ "extensions": ["colours_operators", "output_string"]
937
+ });
938
+ }
939
+ };
940
+
941
+ Blockly.Blocks["operator_lerpFunc"] = {
942
+ init: function() {
943
+ this.jsonInit({
944
+ "inputsInline": true,
945
+ "message0": "interpolate %1 to %2 by %3",
946
+ "args0": [
947
+ {
948
+ "type": "input_value",
949
+ "name": "ONE"
950
+ },
951
+ {
952
+ "type": "input_value",
953
+ "name": "TWO"
954
+ },
955
+ {
956
+ "type": "input_value",
957
+ "name": "AMOUNT"
958
+ }
959
+ ],
960
+ "category": Blockly.Categories.operators,
961
+ "extensions": ["colours_operators", "output_string"]
962
+ });
963
+ }
964
+ };
965
+
966
+ Blockly.Blocks["operator_advMath"] = {
967
+ init: function() {
968
+ this.jsonInit({
969
+ "inputsInline": true,
970
+ "message0": "%1 %2 %3",
971
+ "args0": [
972
+ {
973
+ "type": "input_value",
974
+ "name": "ONE"
975
+ },
976
+ {
977
+ "type": "field_dropdown",
978
+ "name": "OPTION",
979
+ "options": [
980
+ ["^", "^"],
981
+ ["root", "root"],
982
+ ["log", "log"]
983
+ ]
984
+ },
985
+ {
986
+ "type": "input_value",
987
+ "name": "TWO"
988
+ }
989
+ ],
990
+ "category": Blockly.Categories.operators,
991
+ "extensions": ["colours_operators", "output_string"]
992
+ });
993
+ }
994
+ };
995
+
996
+ Blockly.Blocks["operator_advMathExpanded"] = {
997
+ /**
998
+ * pm: Duplicate of operator_advMath to prevent breaking old projects.
999
+ * Updated to split power and root + log, while also allowing extra params for them
1000
+ * @this Blockly.Block
1001
+ */
1002
+ init: function() {
1003
+ this.jsonInit({
1004
+ "inputsInline": true,
1005
+ "message0": "%1 * %2 %3 %4",
1006
+ "args0": [
1007
+ {
1008
+ "type": "input_value",
1009
+ "name": "ONE"
1010
+ },
1011
+ {
1012
+ "type": "input_value",
1013
+ "name": "TWO"
1014
+ },
1015
+ {
1016
+ "type": "field_dropdown",
1017
+ "name": "OPTION",
1018
+ "options": [
1019
+ ["root", "root"],
1020
+ ["log", "log"]
1021
+ ]
1022
+ },
1023
+ {
1024
+ "type": "input_value",
1025
+ "name": "THREE"
1026
+ }
1027
+ ],
1028
+ "category": Blockly.Categories.operators,
1029
+ "extensions": ["colours_operators", "output_number"]
1030
+ });
1031
+ }
1032
+ };
1033
+ Blockly.Blocks['operator_power'] = {
1034
+ /**
1035
+ * pm: Block for getting a ^ b.
1036
+ * @this Blockly.Block
1037
+ */
1038
+ init: function() {
1039
+ this.jsonInit({
1040
+ "message0": "%1 ^ %2",
1041
+ "args0": [
1042
+ {
1043
+ "type": "input_value",
1044
+ "name": "NUM1"
1045
+ },
1046
+ {
1047
+ "type": "input_value",
1048
+ "name": "NUM2"
1049
+ }
1050
+ ],
1051
+ "category": Blockly.Categories.operators,
1052
+ "extensions": ["colours_operators", "output_number"]
1053
+ });
1054
+ }
1055
+ };
1056
+
1057
+ Blockly.Blocks["operator_constrainnumber"] = {
1058
+ init: function() {
1059
+ this.jsonInit({
1060
+ "inputsInline": true,
1061
+ "message0": "constrain %1 min %2 max %3",
1062
+ "args0": [
1063
+ {
1064
+ "type": "input_value",
1065
+ "name": "inp"
1066
+ },
1067
+ {
1068
+ "type": "input_value",
1069
+ "name": "min"
1070
+ },
1071
+ {
1072
+ "type": "input_value",
1073
+ "name": "max"
1074
+ }
1075
+ ],
1076
+ "category": Blockly.Categories.operators,
1077
+ "extensions": ["colours_operators", "output_string"]
1078
+ });
1079
+ }
1080
+ };
1081
+
1082
+ Blockly.Blocks["operator_trueBoolean"] = {
1083
+ init: function() {
1084
+ this.jsonInit({
1085
+ "inputsInline": true,
1086
+ "message0": "true",
1087
+ "args0": [],
1088
+ "category": Blockly.Categories.operators,
1089
+ "extensions": ["colours_operators", "output_boolean"]
1090
+ });
1091
+ }
1092
+ };
1093
+
1094
+ Blockly.Blocks["operator_falseBoolean"] = {
1095
+ init: function() {
1096
+ this.jsonInit({
1097
+ "inputsInline": true,
1098
+ "message0": "false",
1099
+ "args0": [],
1100
+ "category": Blockly.Categories.operators,
1101
+ "extensions": ["colours_operators", "output_boolean"]
1102
+ });
1103
+ }
1104
+ };
1105
+
1106
+ Blockly.Blocks["operator_randomBoolean"] = {
1107
+ init: function() {
1108
+ this.jsonInit({
1109
+ "inputsInline": true,
1110
+ "message0": "random",
1111
+ "args0": [],
1112
+ "category": Blockly.Categories.operators,
1113
+ "extensions": ["colours_operators", "output_boolean"]
1114
+ });
1115
+ }
1116
+ };
1117
+
1118
+ Blockly.Blocks["operator_indexOfTextInText"] = {
1119
+ init: function() {
1120
+ this.jsonInit({
1121
+ "inputsInline": true,
1122
+ "message0": "index of %1 in %2",
1123
+ "args0": [
1124
+ {
1125
+ "type": "input_value",
1126
+ "name": "TEXT1"
1127
+ },
1128
+ {
1129
+ "type": "input_value",
1130
+ "name": "TEXT2"
1131
+ }
1132
+ ],
1133
+ "category": Blockly.Categories.operator,
1134
+ "extensions": ["colours_operators", "output_number"]
1135
+ });
1136
+ }
1137
+ };
1138
+
1139
+ Blockly.Blocks["operator_lastIndexOfTextInText"] = {
1140
+ init: function() {
1141
+ this.jsonInit({
1142
+ "inputsInline": true,
1143
+ "message0": "last index of %1 in %2",
1144
+ "args0": [
1145
+ {
1146
+ "type": "input_value",
1147
+ "name": "TEXT1"
1148
+ },
1149
+ {
1150
+ "type": "input_value",
1151
+ "name": "TEXT2"
1152
+ }
1153
+ ],
1154
+ "category": Blockly.Categories.operator,
1155
+ "extensions": ["colours_operators", "output_number"]
1156
+ });
1157
+ }
1158
+ };
1159
+
1160
+ Blockly.Blocks["operator_countAppearTimes"] = {
1161
+ init: function() {
1162
+ this.jsonInit({
1163
+ "inputsInline": true,
1164
+ "message0": "amount of times %1 appears in %2",
1165
+ "args0": [
1166
+ {
1167
+ "type": "input_value",
1168
+ "name": "TEXT1"
1169
+ },
1170
+ {
1171
+ "type": "input_value",
1172
+ "name": "TEXT2"
1173
+ }
1174
+ ],
1175
+ "category": Blockly.Categories.operator,
1176
+ "extensions": ["colours_operators", "output_number"]
1177
+ });
1178
+ }
1179
+ };
1180
+
1181
+ Blockly.Blocks["operator_textIncludesLetterFrom"] = {
1182
+ init: function () {
1183
+ this.jsonInit({
1184
+ "inputsInline": true,
1185
+ "message0": "%1 includes a letter from %2?",
1186
+ "args0": [
1187
+ {
1188
+ "type": "input_value",
1189
+ "name": "TEXT1"
1190
+ },
1191
+ {
1192
+ "type": "input_value",
1193
+ "name": "TEXT2"
1194
+ }
1195
+ ],
1196
+ "category": Blockly.Categories.operator,
1197
+ "extensions": ["colours_operators", "output_boolean"]
1198
+ });
1199
+ }
1200
+ };
1201
+
1202
+ Blockly.Blocks["operator_textStartsOrEndsWith"] = {
1203
+ init: function() {
1204
+ this.jsonInit({
1205
+ "inputsInline": true,
1206
+ "message0": "%1 %2 with %3?",
1207
+ "args0": [
1208
+ {
1209
+ "type": "input_value",
1210
+ "name": "TEXT1"
1211
+ },
1212
+ {
1213
+ "type": "field_dropdown",
1214
+ "name": "OPTION",
1215
+ "options": [
1216
+ ["starts", "starts"],
1217
+ ["ends", "ends"]
1218
+ ]
1219
+ },
1220
+ {
1221
+ "type": "input_value",
1222
+ "name": "TEXT2"
1223
+ }
1224
+ ],
1225
+ "category": Blockly.Categories.operator,
1226
+ "extensions": ["colours_operators", "output_boolean"]
1227
+ });
1228
+ }
1229
+ };
1230
+
1231
+ Blockly.Blocks["operator_toUpperLowerCase"] = {
1232
+ init: function() {
1233
+ this.jsonInit({
1234
+ "inputsInline": true,
1235
+ "message0": "%1 to %2",
1236
+ "args0": [
1237
+ {
1238
+ "type": "input_value",
1239
+ "name": "TEXT"
1240
+ },
1241
+ {
1242
+ "type": "field_dropdown",
1243
+ "name": "OPTION",
1244
+ "options": [
1245
+ ["uppercase", "upper"],
1246
+ ["lowercase", "lower"]
1247
+ ]
1248
+ }
1249
+ ],
1250
+ "category": Blockly.Categories.operators,
1251
+ "extensions": ["colours_operators", "output_string"]
1252
+ });
1253
+ }
1254
+ };
1255
+
1256
+ Blockly.Blocks["operator_javascript_output"] = {
1257
+ init: function () {
1258
+ this.jsonInit({
1259
+ "inputsInline": true,
1260
+ "message0": "javascript %1",
1261
+ "args0": [
1262
+ {
1263
+ "type": "input_value",
1264
+ "name": "JS"
1265
+ }
1266
+ ],
1267
+ "category": Blockly.Categories.operators,
1268
+ "extensions": ["colours_operators", "output_string"]
1269
+ });
1270
+ }
1271
+ };
1272
+
1273
+ Blockly.Blocks["operator_javascript_boolean"] = {
1274
+ init: function () {
1275
+ this.jsonInit({
1276
+ "inputsInline": true,
1277
+ "message0": "javascript %1",
1278
+ "args0": [
1279
+ {
1280
+ "type": "input_value",
1281
+ "name": "JS"
1282
+ }
1283
+ ],
1284
+ "category": Blockly.Categories.operators,
1285
+ "extensions": ["colours_operators", "output_boolean"]
1286
+ });
1287
+ }
1288
+ };
blocks_vertical/procedures.js ADDED
@@ -0,0 +1,1305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Procedure blocks for Scratch.
23
+ */
24
+ 'use strict';
25
+
26
+ goog.provide('Blockly.ScratchBlocks.ProcedureUtils');
27
+
28
+ goog.require('Blockly.Blocks');
29
+ goog.require('Blockly.Colours');
30
+ goog.require('Blockly.constants');
31
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
32
+
33
+ // Serialization and deserialization.
34
+
35
+ /**
36
+ * Create XML to represent the (non-editable) name and arguments of a procedure
37
+ * call block.
38
+ * @return {!Element} XML storage element.
39
+ * @this Blockly.Block
40
+ */
41
+ Blockly.ScratchBlocks.ProcedureUtils.callerMutationToDom = function() {
42
+ var container = document.createElement('mutation');
43
+ container.setAttribute('proccode', this.procCode_.replaceAll('<', '&lt;'));
44
+ container.setAttribute('argumentids', JSON.stringify(this.argumentIds_));
45
+ container.setAttribute('warp', JSON.stringify(this.warp_));
46
+ container.setAttribute('returns', JSON.stringify(this.output_));
47
+ container.setAttribute('edited', JSON.stringify(this.edited));
48
+ container.setAttribute('optype', JSON.stringify(this.outputType));
49
+ container.setAttribute('color', JSON.stringify(this.color));
50
+ container.innerText = this.image;
51
+ return container;
52
+ };
53
+
54
+ /**
55
+ * Parse XML to restore the (non-editable) name and arguments of a procedure
56
+ * call block.
57
+ * @param {!Element} xmlElement XML storage element.
58
+ * @this Blockly.Block
59
+ */
60
+ Blockly.ScratchBlocks.ProcedureUtils.callerDomToMutation = function(xmlElement) {
61
+ this.procCode_ = xmlElement.getAttribute('proccode').replaceAll('&lt;', '<');
62
+ this.generateShadows_ =
63
+ JSON.parse(xmlElement.getAttribute('generateshadows'));
64
+ this.argumentIds_ = JSON.parse(xmlElement.getAttribute('argumentids'));
65
+ this.warp_ = JSON.parse(xmlElement.getAttribute('warp'));
66
+ this.output_ = JSON.parse(xmlElement.getAttribute('returns'));
67
+ this.edited = JSON.parse(xmlElement.getAttribute('edited'));
68
+ this.outputType = JSON.parse(xmlElement.getAttribute('optype'));
69
+ this.color = JSON.parse(xmlElement.getAttribute('color'));
70
+ // compat bc dum poopoo code
71
+ if (!this.color) this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
72
+ if (this.color && this.color.primary) {
73
+ this.color = [this.color.primary, this.color.secondary, this.color.tertiary]
74
+ }
75
+ // @todo figure out why the fuck we are even getting 8 digit hex colors in the first place
76
+ this.color = this.color.map(c => c.slice(0, 7))
77
+ this.image = xmlElement.innerText;
78
+ this.updateDisplay_();
79
+ };
80
+
81
+ /**
82
+ * Create XML to represent the (non-editable) name and arguments of a
83
+ * procedures_prototype block or a procedures_declaration block.
84
+ * @param {boolean=} opt_generateShadows Whether to include the generateshadows
85
+ * flag in the generated XML. False if not provided.
86
+ * @return {!Element} XML storage element.
87
+ * @this Blockly.Block
88
+ */
89
+ Blockly.ScratchBlocks.ProcedureUtils.definitionMutationToDom = function(
90
+ opt_generateShadows) {
91
+ var container = document.createElement('mutation');
92
+
93
+ if (opt_generateShadows) {
94
+ container.setAttribute('generateshadows', true);
95
+ }
96
+ container.setAttribute('proccode', this.procCode_.replaceAll('<', '&lt;'));
97
+ container.setAttribute('argumentids', JSON.stringify(this.argumentIds_));
98
+ container.setAttribute('argumentnames', JSON.stringify(this.displayNames_));
99
+ container.setAttribute('argumentdefaults', JSON.stringify(this.argumentDefaults_));
100
+ container.setAttribute('warp', JSON.stringify(this.warp_));
101
+ container.setAttribute('returns', JSON.stringify(this.output_));
102
+ container.setAttribute('edited', JSON.stringify(this.edited));
103
+ container.setAttribute('optype', JSON.stringify(this.outputType));
104
+ container.setAttribute('color', JSON.stringify(this.color));
105
+ container.innerText = this.image;
106
+ return container;
107
+ };
108
+
109
+ /**
110
+ * Parse XML to restore the (non-editable) name and arguments of a
111
+ * procedures_prototype block or a procedures_declaration block.
112
+ * @param {!Element} xmlElement XML storage element.
113
+ * @this Blockly.Block
114
+ */
115
+ Blockly.ScratchBlocks.ProcedureUtils.definitionDomToMutation = function(xmlElement) {
116
+ this.procCode_ = xmlElement.getAttribute('proccode').replaceAll('&lt;', '<');
117
+ this.warp_ = JSON.parse(xmlElement.getAttribute('warp'));
118
+
119
+ var prevArgIds = this.argumentIds_;
120
+ var prevDisplayNames = this.displayNames_;
121
+
122
+ this.argumentIds_ = JSON.parse(xmlElement.getAttribute('argumentids'));
123
+ this.displayNames_ = JSON.parse(xmlElement.getAttribute('argumentnames'));
124
+ this.argumentDefaults_ = JSON.parse(xmlElement.getAttribute('argumentdefaults'));
125
+ this.output_ = JSON.parse(xmlElement.getAttribute('returns'));
126
+ this.outputType = JSON.parse(xmlElement.getAttribute('optype'));
127
+ this.edited = JSON.parse(xmlElement.getAttribute('edited'));
128
+ this.image = xmlElement.innerText;
129
+ this.color = JSON.parse(xmlElement.getAttribute('color'));
130
+ // compat bc dum poopoo code
131
+ if (!this.color) this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
132
+ if (this.color && this.color.primary) {
133
+ this.color = [this.color.primary, this.color.secondary, this.color.tertiary]
134
+ }
135
+ // @todo figure out why the fuck we are even getting 8 digit hex colors in the first place
136
+ this.color = this.color.map(c => c.slice(0, 7))
137
+ this.image = xmlElement.innerText;
138
+ this.updateDisplay_();
139
+ if (this.updateArgumentReporterNames_) {
140
+ this.updateArgumentReporterNames_(prevArgIds, prevDisplayNames);
141
+ }
142
+ };
143
+
144
+ // End of serialization and deserialization.
145
+
146
+ // Shared by all three procedure blocks (procedures_declaration,
147
+ // procedures_call, and procedures_prototype).
148
+ /**
149
+ * Returns the name of the procedure this block calls, or the empty string if
150
+ * it has not yet been set.
151
+ * @return {string} Procedure name.
152
+ * @this Blockly.Block
153
+ */
154
+ Blockly.ScratchBlocks.ProcedureUtils.getProcCode = function() {
155
+ return this.procCode_;
156
+ };
157
+
158
+ /**
159
+ * Update the block's structure and appearance to match the internally stored
160
+ * mutation.
161
+ * @private
162
+ * @this Blockly.Block
163
+ */
164
+ Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_ = function() {
165
+ var wasRendered = this.rendered;
166
+ // @todo add statement check?
167
+ var ConectionType = (this.outputType || (this.output_ ? 'string' : 'statement')).toLowerCase()
168
+ this.rendered = false;
169
+
170
+ var connectionMap = this.disconnectOldBlocks_();
171
+ this.removeAllInputs_();
172
+
173
+ this.createAllInputs_(connectionMap);
174
+ this.deleteShadows_(connectionMap);
175
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE);
176
+ // only change the color if we have a color to change to
177
+ this.setColour(...this.color)
178
+ if (
179
+ this.outputConnection &&
180
+ this.outputConnection.targetConnection &&
181
+ this.outputConnection.targetConnection.sourceBlock_.type === 'procedures_definition_return') {
182
+ this.outputConnection.targetConnection.sourceBlock_.setColour(...this.color)
183
+ }
184
+ if (
185
+ this.previousConnection &&
186
+ this.previousConnection.targetConnection &&
187
+ this.previousConnection.targetConnection.sourceBlock_.type === 'procedures_definition') {
188
+ this.previousConnection.targetConnection.sourceBlock_.setColour(...this.color)
189
+ }
190
+ if (this.output_) {
191
+ this.setPreviousStatement(false)
192
+ this.setNextStatement(false)
193
+ switch (ConectionType) {
194
+ case 'string':
195
+ case 'number':
196
+ default:
197
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); break;
198
+ case 'boolean':
199
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL); break;
200
+ }
201
+ this.setOutput(this.output_, this.isDisplayOnly ? 'procedure' : null);
202
+ } else {
203
+ this.setOutput(false)
204
+ switch (ConectionType) {
205
+ case 'statement':
206
+ this.setPreviousStatement(!this.output_, this.isDisplayOnly ? 'procedure' : 'normal')
207
+ this.setNextStatement(!this.output_, this.isDisplayOnly ? 'procedure' : 'normal')
208
+ break
209
+ case 'end':
210
+ this.setPreviousStatement(!this.output_, this.isDisplayOnly ? 'procedure' : 'normal')
211
+ this.setNextStatement(false, 'procedure')
212
+ break
213
+ }
214
+ }
215
+
216
+ this.rendered = wasRendered;
217
+ if (wasRendered && !this.isInsertionMarker()) {
218
+ this.initSvg();
219
+ this.render();
220
+ }
221
+ };
222
+
223
+ /**
224
+ * Disconnect old blocks from all value inputs on this block, but hold onto them
225
+ * in case they can be reattached later. Also save the shadow DOM if it exists.
226
+ * The result is a map from argument ID to information that was associated with
227
+ * that argument at the beginning of the mutation.
228
+ * @return {!Object.<string, {shadow: Element, block: Blockly.Block}>} An object
229
+ * mapping argument IDs to blocks and shadow DOMs.
230
+ * @private
231
+ * @this Blockly.Block
232
+ */
233
+ Blockly.ScratchBlocks.ProcedureUtils.disconnectOldBlocks_ = function() {
234
+ // Remove old stuff
235
+ var connectionMap = {};
236
+ for (var i = 0, input; input = this.inputList[i]; i++) {
237
+ if (input.connection) {
238
+ var target = input.connection.targetBlock();
239
+ var saveInfo = {
240
+ shadow: input.connection.getShadowDom(),
241
+ block: target
242
+ };
243
+ connectionMap[input.name] = saveInfo;
244
+
245
+ // Remove the shadow DOM, then disconnect the block. Otherwise a shadow
246
+ // block will respawn instantly, and we'd have to remove it when we remove
247
+ // the input.
248
+ input.connection.setShadowDom(null);
249
+ if (target) {
250
+ input.connection.disconnect();
251
+ }
252
+ }
253
+ }
254
+ return connectionMap;
255
+ };
256
+
257
+ /**
258
+ * Remove all inputs on the block, including dummy inputs.
259
+ * Assumes no input has shadow DOM set.
260
+ * @private
261
+ * @this Blockly.Block
262
+ */
263
+ Blockly.ScratchBlocks.ProcedureUtils.removeAllInputs_ = function() {
264
+ // Delete inputs directly instead of with block.removeInput to avoid splicing
265
+ // out of the input list at every index.
266
+ for (var i = 0, input; input = this.inputList[i]; i++) {
267
+ input.dispose();
268
+ }
269
+ this.inputList = [];
270
+ };
271
+
272
+ Blockly.ScratchBlocks.ProcedureUtils.createIcon_ = function() {
273
+ if (!this.image) return
274
+ if (this.image.startsWith('data:') || this.image.startsWith('http')) {
275
+ const iconField = new Blockly.FieldImage(this.image, 40, 40);
276
+ const separatorField = new Blockly.FieldVerticalSeparator();
277
+ this.appendDummyInput()
278
+ .appendField(iconField)
279
+ .appendField(separatorField);
280
+ }
281
+ };
282
+
283
+ /**
284
+ * Create all inputs specified by the new procCode, and populate them with
285
+ * shadow blocks or reconnected old blocks as appropriate.
286
+ * @param {!Object.<string, {shadow: Element, block: Blockly.Block}>}
287
+ * connectionMap An object mapping argument IDs to blocks and shadow DOMs.
288
+ * @private
289
+ * @this Blockly.Block
290
+ */
291
+ Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_ = function(connectionMap) {
292
+ this.createIcon_()
293
+ // Split the proc into components, by %n, %b, and %s (ignoring escaped).
294
+ var procComponents = this.procCode_.split(/(?=[^\\]%[nsbc])/);
295
+ procComponents = procComponents.map(function(c) {
296
+ return c.trim(); // Strip whitespace.
297
+ });
298
+ // Create arguments and labels as appropriate.
299
+ var argumentCount = 0;
300
+ for (var i = 0, component; component = procComponents[i]; i++) {
301
+ var labelText;
302
+ var argumentType = component.substring(1, 2);
303
+ var id = this.argumentIds_[argumentCount];
304
+ // user error shouldnt literally nuke the app, ignore invalid markers instead of erroring on them
305
+ if (component.substring(0, 1) == '%' && (['n', 's', 'b', 'c'].includes(argumentType)) && id) {
306
+ /*
307
+ if (!(argumentType == 'n' || argumentType == 'b' || argumentType == 's')) {
308
+ throw new Error(
309
+ 'Found an custom procedure with an invalid type: ' + argumentType);
310
+ }
311
+ */
312
+ labelText = component.substring(2).trim();
313
+
314
+ if (argumentType == "c") {
315
+ var input = this.appendStatementInput(id)
316
+ } else {
317
+ var input = this.appendValueInput(id);
318
+ }
319
+ if (argumentType == 'b') {
320
+ input.setCheck('Boolean');
321
+ }
322
+ this.populateArgument_(argumentType, argumentCount, connectionMap, id,
323
+ input);
324
+ argumentCount++;
325
+ } else {
326
+ labelText = component.trim();
327
+ }
328
+ this.addProcedureLabel_(labelText.replace(/\\%/, '%'));
329
+ }
330
+ };
331
+
332
+ /**
333
+ * Delete all shadow blocks in the given map.
334
+ * @param {!Object.<string, Blockly.Block>} connectionMap An object mapping
335
+ * argument IDs to the blocks that were connected to those IDs at the
336
+ * beginning of the mutation.
337
+ * @private
338
+ * @this Blockly.Block
339
+ */
340
+ Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_ = function(connectionMap) {
341
+ // Get rid of all of the old shadow blocks if they aren't connected.
342
+ if (connectionMap) {
343
+ for (var id in connectionMap) {
344
+ var saveInfo = connectionMap[id];
345
+ if (saveInfo) {
346
+ var block = saveInfo['block'];
347
+ if (block && block.isShadow()) {
348
+ block.dispose();
349
+ connectionMap[id] = null;
350
+ // At this point we know which shadow DOMs are about to be orphaned in
351
+ // the VM. What do we do with that information?
352
+ }
353
+ }
354
+ }
355
+ }
356
+ };
357
+ // End of shared code.
358
+
359
+ /**
360
+ * Add a label field with the given text to a procedures_call or
361
+ * procedures_prototype block.
362
+ * @param {string} text The label text.
363
+ * @private
364
+ */
365
+ Blockly.ScratchBlocks.ProcedureUtils.addLabelField_ = function(text) {
366
+ this.appendDummyInput().appendField(text);
367
+ };
368
+
369
+ /**
370
+ * Add a label editor with the given text to a procedures_declaration
371
+ * block. Editing the text in the label editor updates the text of the
372
+ * corresponding label fields on function calls.
373
+ * @param {string} text The label text.
374
+ * @private
375
+ */
376
+ Blockly.ScratchBlocks.ProcedureUtils.addLabelEditor_ = function(text) {
377
+ if (text) {
378
+ this.appendDummyInput(Blockly.utils.genUid()).
379
+ appendField(new Blockly.FieldTextInputRemovable(text));
380
+ }
381
+ };
382
+
383
+ /**
384
+ * Build a DOM node representing a shadow block of the given type.
385
+ * @param {string} type One of 's' (string) or 'n' (number).
386
+ * @return {!Element} The DOM node representing the new shadow block.
387
+ * @private
388
+ * @this Blockly.Block
389
+ */
390
+ Blockly.ScratchBlocks.ProcedureUtils.buildShadowDom_ = function(type) {
391
+ var shadowDom = goog.dom.createDom('shadow');
392
+ if (type == 'n') {
393
+ var shadowType = 'math_number';
394
+ var fieldName = 'NUM';
395
+ var fieldValue = '1';
396
+ } else {
397
+ var shadowType = 'text';
398
+ var fieldName = 'TEXT';
399
+ var fieldValue = '';
400
+ }
401
+ shadowDom.setAttribute('type', shadowType);
402
+ var fieldDom = goog.dom.createDom('field', null, fieldValue);
403
+ fieldDom.setAttribute('name', fieldName);
404
+ shadowDom.appendChild(fieldDom);
405
+ return shadowDom;
406
+ };
407
+
408
+ /**
409
+ * Create a new shadow block and attach it to the given input.
410
+ * @param {!Blockly.Input} input The value input to attach a block to.
411
+ * @param {string} argumentType One of 'b' (boolean), 's' (string) or
412
+ * 'n' (number).
413
+ * @private
414
+ * @this Blockly.Block
415
+ */
416
+ Blockly.ScratchBlocks.ProcedureUtils.attachShadow_ = function(input,
417
+ argumentType) {
418
+ if (argumentType == 'n' || argumentType == 's') {
419
+ var blockType = argumentType == 'n' ? 'math_number' : 'text';
420
+ Blockly.Events.disable();
421
+ try {
422
+ var newBlock = this.workspace.newBlock(blockType);
423
+ if (argumentType == 'n') {
424
+ newBlock.setFieldValue('1', 'NUM');
425
+ } else {
426
+ newBlock.setFieldValue('', 'TEXT');
427
+ }
428
+ newBlock.setShadow(true);
429
+ if (!this.isInsertionMarker()) {
430
+ newBlock.initSvg();
431
+ newBlock.render(false);
432
+ }
433
+ } finally {
434
+ Blockly.Events.enable();
435
+ }
436
+ if (Blockly.Events.isEnabled()) {
437
+ Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
438
+ }
439
+ newBlock.outputConnection.connect(input.connection);
440
+ }
441
+ };
442
+
443
+ /**
444
+ * Create a new argument reporter block.
445
+ * @param {string} argumentType One of 'b' (boolean), 's' (string) or
446
+ * 'n' (number).
447
+ * @param {string} displayName The name of the argument as provided by the
448
+ * user, which becomes the text of the label on the argument reporter block.
449
+ * @return {!Blockly.BlockSvg} The newly created argument reporter block.
450
+ * @private
451
+ * @this Blockly.Block
452
+ */
453
+ Blockly.ScratchBlocks.ProcedureUtils.createArgumentReporter_ = function(
454
+ argumentType, displayName) {
455
+ switch (argumentType) {
456
+ case 'n':
457
+ case 's':
458
+ var blockType = 'argument_reporter_string_number';
459
+ break;
460
+ case 'b':
461
+ var blockType = 'argument_reporter_boolean';
462
+ break;
463
+ case 'c':
464
+ var blockType = 'argument_reporter_command';
465
+ break;
466
+ }
467
+ Blockly.Events.disable();
468
+ try {
469
+ var newBlock = this.workspace.newBlock(blockType);
470
+ newBlock.setShadow(true);
471
+ newBlock.setFieldValue(displayName, 'VALUE');
472
+ newBlock.color = this.color
473
+ newBlock.setColour(...this.color)
474
+ if (!this.isInsertionMarker()) {
475
+ newBlock.initSvg();
476
+ newBlock.render(false);
477
+ }
478
+ } finally {
479
+ Blockly.Events.enable();
480
+ }
481
+ if (Blockly.Events.isEnabled()) {
482
+ Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
483
+ }
484
+ return newBlock;
485
+ };
486
+
487
+ /**
488
+ * Populate the argument by attaching the correct child block or shadow to the
489
+ * given input.
490
+ * @param {string} type One of 'b' (boolean), 's' (string) or 'n' (number).
491
+ * @param {number} index The index of this argument into the argument id array.
492
+ * @param {!Object.<string, {shadow: Element, block: Blockly.Block}>}
493
+ * connectionMap An object mapping argument IDs to blocks and shadow DOMs.
494
+ * @param {string} id The ID of the input to populate.
495
+ * @param {!Blockly.Input} input The newly created input to populate.
496
+ * @private
497
+ * @this Blockly.Block
498
+ */
499
+ Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnCaller_ = function(type,
500
+ index, connectionMap, id, input) {
501
+ var oldBlock = null;
502
+ var oldShadow = null;
503
+ if (connectionMap && (id in connectionMap)) {
504
+ var saveInfo = connectionMap[id];
505
+ oldBlock = saveInfo['block'];
506
+ oldShadow = saveInfo['shadow'];
507
+ }
508
+
509
+ if (connectionMap && oldBlock) {
510
+ // Reattach the old block and shadow DOM.
511
+ connectionMap[input.name] = null;
512
+ if (type == "c") {
513
+ oldBlock.previousConnection.connect(input.connection);
514
+ } else {
515
+ oldBlock.outputConnection.connect(input.connection);
516
+ }
517
+ if (type != 'b' && type != 'c' && this.generateShadows_) {
518
+ var shadowDom = oldShadow || this.buildShadowDom_(type);
519
+ console.log("setting shadow dom: " + shadowDom);
520
+ input.connection.setShadowDom(shadowDom);
521
+ }
522
+ } else if (this.generateShadows_) {
523
+ this.attachShadow_(input, type);
524
+ }
525
+ };
526
+
527
+ /**
528
+ * Populate the argument by attaching the correct argument reporter to the given
529
+ * input.
530
+ * @param {string} type One of 'b' (boolean), 's' (string) or 'n' (number).
531
+ * @param {number} index The index of this argument into the argument ID and
532
+ * argument display name arrays.
533
+ * @param {!Object.<string, {shadow: Element, block: Blockly.Block}>}
534
+ * connectionMap An object mapping argument IDs to blocks and shadow DOMs.
535
+ * @param {string} id The ID of the input to populate.
536
+ * @param {!Blockly.Input} input The newly created input to populate.
537
+ * @private
538
+ * @this Blockly.Block
539
+ */
540
+ Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnPrototype_ = function(
541
+ type, index, connectionMap, id, input) {
542
+ var oldBlock = null;
543
+ if (connectionMap && (id in connectionMap)) {
544
+ var saveInfo = connectionMap[id];
545
+ oldBlock = saveInfo['block'];
546
+ }
547
+
548
+ var oldTypeMatches =
549
+ Blockly.ScratchBlocks.ProcedureUtils.checkOldTypeMatches_(oldBlock, type);
550
+ var displayName = this.displayNames_[index];
551
+
552
+ // Decide which block to attach.
553
+ if (connectionMap && oldBlock && oldTypeMatches) {
554
+ // Update the text if needed. The old argument reporter is the same type,
555
+ // and on the same input, but the argument's display name may have changed.
556
+ var argumentReporter = oldBlock;
557
+ argumentReporter.setFieldValue(displayName, 'VALUE');
558
+ connectionMap[input.name] = null;
559
+ } else {
560
+ var argumentReporter = this.createArgumentReporter_(type, displayName);
561
+ }
562
+
563
+ // Attach the block.
564
+ if (type == "c") {
565
+ input.connection.connect(argumentReporter.previousConnection);
566
+ } else {
567
+ input.connection.connect(argumentReporter.outputConnection);
568
+ }
569
+ };
570
+
571
+ /**
572
+ * Populate the argument by attaching the correct argument editor to the given
573
+ * input.
574
+ * @param {string} type One of 'b' (boolean), 's' (string) or 'n' (number).
575
+ * @param {number} index The index of this argument into the argument id and
576
+ * argument display name arrays.
577
+ * @param {!Object.<string, {shadow: Element, block: Blockly.Block}>}
578
+ * connectionMap An object mapping argument IDs to blocks and shadow DOMs.
579
+ * @param {string} id The ID of the input to populate.
580
+ * @param {!Blockly.Input} input The newly created input to populate.
581
+ * @private
582
+ * @this Blockly.Block
583
+ */
584
+ Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnDeclaration_ = function(
585
+ type, index, connectionMap, id, input) {
586
+
587
+ var oldBlock = null;
588
+ if (connectionMap && (id in connectionMap)) {
589
+ var saveInfo = connectionMap[id];
590
+ oldBlock = saveInfo['block'];
591
+ }
592
+
593
+ // TODO: This always returns false, because it checks for argument reporter
594
+ // blocks instead of argument editor blocks. Create a new version for argument
595
+ // editors.
596
+ var oldTypeMatches =
597
+ Blockly.ScratchBlocks.ProcedureUtils.checkOldTypeMatches_(oldBlock, type);
598
+ var displayName = this.displayNames_[index];
599
+
600
+ // Decide which block to attach.
601
+ if (oldBlock && oldTypeMatches) {
602
+ var argumentEditor = oldBlock;
603
+ oldBlock.setFieldValue(displayName, 'TEXT');
604
+ connectionMap[input.name] = null;
605
+ } else {
606
+ var argumentEditor = this.createArgumentEditor_(type, displayName);
607
+ }
608
+
609
+ // Attach the block.
610
+ if (type == "c") {
611
+ input.connection.connect(argumentEditor.previousConnection);
612
+ } else {
613
+ input.connection.connect(argumentEditor.outputConnection);
614
+ }
615
+ };
616
+
617
+ /**
618
+ * Check whether the type of the old block corresponds to the given argument
619
+ * type.
620
+ * @param {Blockly.BlockSvg} oldBlock The old block to check.
621
+ * @param {string} type The argument type. One of 'n', 'n', or 's'.
622
+ * @return {boolean} True if the type matches, false otherwise.
623
+ */
624
+ Blockly.ScratchBlocks.ProcedureUtils.checkOldTypeMatches_ = function(oldBlock,
625
+ type) {
626
+ if (!oldBlock) {
627
+ return false;
628
+ }
629
+ if ((type == 'n' || type == 's') &&
630
+ oldBlock.type == 'argument_reporter_string_number') {
631
+ return true;
632
+ }
633
+ if (type == 'b' && oldBlock.type == 'argument_reporter_boolean') {
634
+ return true;
635
+ }
636
+ //dunno if this is needed but oh well
637
+ if (type == 'c' && oldBlock.type == 'argument_reporter_command') {
638
+ return true;
639
+ }
640
+ return false;
641
+ };
642
+
643
+ /**
644
+ * Create an argument editor.
645
+ * An argument editor is a shadow block with a single text field, which is used
646
+ * to set the display name of the argument.
647
+ * @param {string} argumentType One of 'b' (boolean), 's' (string) or
648
+ * 'n' (number).
649
+ * @param {string} displayName The display name of this argument, which is the
650
+ * text of the field on the shadow block.
651
+ * @return {!Blockly.BlockSvg} The newly created argument editor block.
652
+ * @private
653
+ * @this Blockly.Block
654
+ */
655
+ Blockly.ScratchBlocks.ProcedureUtils.createArgumentEditor_ = function(
656
+ argumentType, displayName) {
657
+ Blockly.Events.disable();
658
+ try {
659
+ switch (argumentType) {
660
+ case 'n':
661
+ case 's':
662
+ var newBlock = this.workspace.newBlock('argument_editor_string_number');
663
+ break;
664
+ case 'b':
665
+ var newBlock = this.workspace.newBlock('argument_editor_boolean');
666
+ break;
667
+ case 'c':
668
+ var newBlock = this.workspace.newBlock('argument_editor_command')
669
+ }
670
+ newBlock.setFieldValue(displayName, 'TEXT');
671
+ newBlock.setShadow(true);
672
+ if (!this.isInsertionMarker()) {
673
+ newBlock.initSvg();
674
+ newBlock.render(false);
675
+ }
676
+ } finally {
677
+ Blockly.Events.enable();
678
+ }
679
+ if (Blockly.Events.isEnabled()) {
680
+ Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
681
+ }
682
+ return newBlock;
683
+ };
684
+
685
+ /**
686
+ * Update the serializable information on the block based on the existing inputs
687
+ * and their text.
688
+ */
689
+ Blockly.ScratchBlocks.ProcedureUtils.updateDeclarationProcCode_ = function() {
690
+ this.procCode_ = '';
691
+ this.displayNames_ = [];
692
+ this.argumentIds_ = [];
693
+ for (var i = 0; i < this.inputList.length; i++) {
694
+ if (i != 0) {
695
+ this.procCode_ += ' ';
696
+ }
697
+ var input = this.inputList[i];
698
+ if (input.type == Blockly.DUMMY_INPUT) {
699
+ this.procCode_ += input.fieldRow[0].getValue();
700
+ } else if (input.type == Blockly.INPUT_VALUE || input.type == Blockly.NEXT_STATEMENT) {
701
+ // Inspect the argument editor.
702
+ var target = input.connection.targetBlock();
703
+ this.displayNames_.push(target.getFieldValue('TEXT'));
704
+ this.argumentIds_.push(input.name);
705
+ switch (target.type) {
706
+ case 'argument_editor_string_number':
707
+ this.procCode_ += '%s';
708
+ break;
709
+ case 'argument_editor_boolean':
710
+ this.procCode_ += '%b';
711
+ break;
712
+ case 'argument_editor_command':
713
+ this.procCode_ += "%c";
714
+ break;
715
+ }
716
+ } else {
717
+ throw new Error(
718
+ 'Unexpected input type on a procedure mutator root: ' + input.type);
719
+ }
720
+ }
721
+ };
722
+
723
+ /**
724
+ * Focus on the last argument editor or label editor on the block.
725
+ * @private
726
+ */
727
+ Blockly.ScratchBlocks.ProcedureUtils.focusLastEditor_ = function() {
728
+ if (this.inputList.length > 0) {
729
+ var newInput = this.inputList[this.inputList.length - 1];
730
+ if (newInput.type == Blockly.DUMMY_INPUT) {
731
+ newInput.fieldRow[0].showEditor_();
732
+ } else if (newInput.type == Blockly.INPUT_VALUE) {
733
+ // Inspect the argument editor.
734
+ var target = newInput.connection.targetBlock();
735
+ target.getField('TEXT').showEditor_();
736
+ }
737
+ }
738
+ };
739
+
740
+ /**
741
+ * Externally-visible function to add a label to the procedure declaration.
742
+ * @public
743
+ */
744
+ Blockly.ScratchBlocks.ProcedureUtils.addLabelExternal = function() {
745
+ Blockly.WidgetDiv.hide(true);
746
+ this.procCode_ = this.procCode_ + ' label text';
747
+ this.updateDisplay_();
748
+ this.focusLastEditor_();
749
+ };
750
+
751
+ /**
752
+ * Externally-visible function to add a boolean argument to the procedure
753
+ * declaration.
754
+ * @public
755
+ */
756
+ Blockly.ScratchBlocks.ProcedureUtils.addBooleanExternal = function() {
757
+ Blockly.WidgetDiv.hide(true);
758
+ this.procCode_ = this.procCode_ + ' %b';
759
+ this.displayNames_.push('boolean');
760
+ this.argumentIds_.push(Blockly.utils.genUid());
761
+ this.argumentDefaults_.push('false');
762
+ this.updateDisplay_();
763
+ this.focusLastEditor_();
764
+ };
765
+
766
+ Blockly.ScratchBlocks.ProcedureUtils.addCommandExternal = function () {
767
+ Blockly.WidgetDiv.hide(true);
768
+ this.procCode_ = this.procCode_ + " %c";
769
+ this.displayNames_.push("branch");
770
+ this.argumentIds_.push("SUBSTACK" + Blockly.utils.genUid());
771
+ this.argumentDefaults_.push("");
772
+ this.updateDisplay_();
773
+ this.focusLastEditor_();
774
+ };
775
+
776
+ /**
777
+ * Externally-visible function to add a string/number argument to the procedure
778
+ * declaration.
779
+ * @public
780
+ */
781
+ Blockly.ScratchBlocks.ProcedureUtils.addStringNumberExternal = function() {
782
+ Blockly.WidgetDiv.hide(true);
783
+ this.procCode_ = this.procCode_ + ' %s';
784
+ this.displayNames_.push('number or text');
785
+ this.argumentIds_.push(Blockly.utils.genUid());
786
+ this.argumentDefaults_.push('');
787
+ this.updateDisplay_();
788
+ this.focusLastEditor_();
789
+ };
790
+
791
+ /**
792
+ * Externally-visible function to get the warp on procedure declaration.
793
+ * @return {boolean} The value of the warp_ property.
794
+ * @public
795
+ */
796
+ Blockly.ScratchBlocks.ProcedureUtils.getWarp = function() {
797
+ return this.warp_;
798
+ };
799
+
800
+ Blockly.ScratchBlocks.ProcedureUtils.getReturns = function() {
801
+ return this.output_;
802
+ };
803
+
804
+ Blockly.ScratchBlocks.ProcedureUtils.getEdited = function() {
805
+ return this.edited;
806
+ }
807
+
808
+ Blockly.ScratchBlocks.ProcedureUtils.setEdited = function(edited) {
809
+ this.edited = edited;
810
+ }
811
+
812
+ Blockly.ScratchBlocks.ProcedureUtils.setReturns = function(returns) {
813
+ this.output_ = returns;
814
+ this.updateDisplay_();
815
+ };
816
+
817
+ Blockly.ScratchBlocks.ProcedureUtils.setType = function(type) {
818
+ this.outputType = type.toLowerCase()
819
+ this.updateDisplay_();
820
+ }
821
+
822
+ Blockly.ScratchBlocks.ProcedureUtils.setImage = function(image) {
823
+ this.image = image
824
+ this.updateDisplay_();
825
+ }
826
+
827
+ Blockly.ScratchBlocks.ProcedureUtils.unsetImage = function() {
828
+ this.image = ''
829
+ this.updateDisplay_();
830
+ }
831
+
832
+ Blockly.ScratchBlocks.ProcedureUtils.setColor = function(primary, secondary, tertiary) {
833
+ this.color = [primary, secondary, tertiary]
834
+ this.updateDisplay_();
835
+ }
836
+
837
+ Blockly.ScratchBlocks.ProcedureUtils.removeColor = function() {
838
+ this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
839
+ this.updateDisplay_();
840
+ }
841
+
842
+ /**
843
+ * Externally-visible function to set the warp on procedure declaration.
844
+ * @param {boolean} warp The value of the warp_ property.
845
+ * @public
846
+ */
847
+ Blockly.ScratchBlocks.ProcedureUtils.setWarp = function(warp) {
848
+ this.warp_ = warp;
849
+ };
850
+
851
+ /**
852
+ * Callback to remove a field, only for the declaration block.
853
+ * @param {Blockly.Field} field The field being removed.
854
+ * @public
855
+ */
856
+ Blockly.ScratchBlocks.ProcedureUtils.removeFieldCallback = function(field) {
857
+ // Do not delete if there is only one input
858
+ if (this.inputList.length === 1) {
859
+ return;
860
+ }
861
+ var inputNameToRemove = null;
862
+ for (var n = 0; n < this.inputList.length; n++) {
863
+ var input = this.inputList[n];
864
+ if (input.connection) {
865
+ var target = input.connection.targetBlock();
866
+ if (target.getField(field.name) == field) {
867
+ inputNameToRemove = input.name;
868
+ }
869
+ } else {
870
+ for (var j = 0; j < input.fieldRow.length; j++) {
871
+ if (input.fieldRow[j] == field) {
872
+ inputNameToRemove = input.name;
873
+ }
874
+ }
875
+ }
876
+ }
877
+ if (inputNameToRemove) {
878
+ Blockly.WidgetDiv.hide(true);
879
+ this.removeInput(inputNameToRemove);
880
+ this.onChangeFn();
881
+ this.updateDisplay_();
882
+ }
883
+ };
884
+
885
+ /**
886
+ * Callback to pass removeField up to the declaration block from arguments.
887
+ * @param {Blockly.Field} field The field being removed.
888
+ * @public
889
+ */
890
+ Blockly.ScratchBlocks.ProcedureUtils.removeArgumentCallback_ = function(field) {
891
+ if (this.parentBlock_ && this.parentBlock_.removeFieldCallback) {
892
+ this.parentBlock_.removeFieldCallback(field);
893
+ }
894
+ };
895
+
896
+ /**
897
+ * Update argument reporter field values after an edit to the prototype mutation
898
+ * using previous argument ids and names.
899
+ * Because the argument reporters only store names and not which argument ids they
900
+ * are linked to, it would not be safe to update all argument reporters on the workspace
901
+ * since they may be argument reporters with the same name from a different procedure.
902
+ * Until there is a more explicit way of identifying argument reporter blocks using ids,
903
+ * be conservative and only update argument reporters that are used in the
904
+ * stack below the prototype, ie the definition.
905
+ * @param {!Array<string>} prevArgIds The previous ordering of argument ids.
906
+ * @param {!Array<string>} prevDisplayNames The previous argument names.
907
+ * @this Blockly.Block
908
+ */
909
+ Blockly.ScratchBlocks.ProcedureUtils.updateArgumentReporterNames_ = function(prevArgIds, prevDisplayNames) {
910
+ var nameChanges = [];
911
+ var argReporters = [];
912
+ var definitionBlock = this.getParent();
913
+ if (!definitionBlock) return;
914
+
915
+ // Create a list of argument reporters that are descendants of the definition stack (see above comment)
916
+ var allBlocks = definitionBlock.getDescendants(false);
917
+ for (var i = 0; i < allBlocks.length; i++) {
918
+ var block = allBlocks[i];
919
+ if ((block.type === 'argument_reporter_string_number' ||
920
+ block.type === 'argument_reporter_boolean' ||
921
+ block.type === 'argument_reporter_command') &&
922
+ !block.isShadow()) { // Exclude arg reporters in the prototype block, which are shadows.
923
+ argReporters.push(block);
924
+ }
925
+ }
926
+
927
+ // Create a list of "name changes", including the new name and blocks matching the old name
928
+ // Only search over the current set of argument ids, ignore args that have been removed
929
+ for (var i = 0, id; id = this.argumentIds_[i]; i++) {
930
+ // Find the previous index of this argument id. Could be -1 if it is newly added.
931
+ var prevIndex = prevArgIds.indexOf(id);
932
+ if (prevIndex == -1) continue; // Newly added argument, no corresponding previous argument to update.
933
+ var prevName = prevDisplayNames[prevIndex];
934
+ if (prevName != this.displayNames_[i]) {
935
+ nameChanges.push({
936
+ newName: this.displayNames_[i],
937
+ blocks: argReporters.filter(function(block) {
938
+ return block.getFieldValue('VALUE') == prevName;
939
+ })
940
+ });
941
+ }
942
+ }
943
+
944
+ // Finally update the blocks for each name change.
945
+ // Do this after creating the lists to avoid cycles of renaming.
946
+ for (var j = 0, nameChange; nameChange = nameChanges[j]; j++) {
947
+ for (var k = 0, block; block = nameChange.blocks[k]; k++) {
948
+ block.setFieldValue(nameChange.newName, 'VALUE');
949
+ }
950
+ }
951
+ };
952
+
953
+ Blockly.ScratchBlocks.ProcedureUtils.argumentReporterMutationToDom = function() {
954
+ var dom = document.createElement('mutation');
955
+ dom.setAttribute('color', JSON.stringify(this.color))
956
+ return dom
957
+ };
958
+
959
+ Blockly.ScratchBlocks.ProcedureUtils.argumentReporterDomToMutation = function(dom) {
960
+ try {
961
+ this.color = JSON.parse(dom.getAttribute('color'))
962
+ this.updateDisplay_()
963
+ } catch (err) {
964
+ console.warn('unknown old argument reporter')
965
+ }
966
+ };
967
+
968
+ Blockly.ScratchBlocks.ProcedureUtils.argumentReporterUpdateDisplay = function(dom) {
969
+ this.setColour(...this.color)
970
+ };
971
+
972
+ Blockly.Blocks['procedures_definition'] = {
973
+ /**
974
+ * Block for defining a procedure with no return value.
975
+ * @this Blockly.Block
976
+ */
977
+ init: function() {
978
+ this.jsonInit({
979
+ "message0": Blockly.Msg.PROCEDURES_DEFINITION,
980
+ "args0": [
981
+ {
982
+ "type": "input_statement",
983
+ "name": "custom_block",
984
+ "check": 'procedure'
985
+ }
986
+ ],
987
+ "extensions": ["colours_more", "shape_hat", "procedure_def_contextmenu"]
988
+ });
989
+ }
990
+ };
991
+
992
+ Blockly.Blocks['procedures_definition_return'] = {
993
+ /**
994
+ * Block for defining a procedure with no return value.
995
+ * @this Blockly.Block
996
+ */
997
+ init: function() {
998
+ this.jsonInit({
999
+ "message0": Blockly.Msg.PROCEDURES_DEFINITION,
1000
+ "args0": [
1001
+ {
1002
+ "type": "input_value",
1003
+ "name": "custom_block",
1004
+ "check": 'procedure'
1005
+ }
1006
+ ],
1007
+ "extensions": ["colours_more", "shape_hat", "procedure_def_contextmenu"]
1008
+ });
1009
+ }
1010
+ };
1011
+
1012
+ Blockly.Blocks['procedures_call'] = {
1013
+ /**
1014
+ * Block for calling a procedure with no return value.
1015
+ * @this Blockly.Block
1016
+ */
1017
+ init: function() {
1018
+ this.jsonInit({
1019
+ "extensions": ["colours_more", "shape_statement", "procedure_call_contextmenu"]
1020
+ });
1021
+ this.procCode_ = '';
1022
+ this.argumentIds_ = [];
1023
+ this.warp_ = false;
1024
+ this.output_ = false;
1025
+ this.isDisplayOnly = false
1026
+ this.edited = false
1027
+ this.outputType = 'statement'
1028
+ this.image = ''
1029
+ this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
1030
+ },
1031
+ // Shared.
1032
+ getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
1033
+ removeAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.removeAllInputs_,
1034
+ disconnectOldBlocks_: Blockly.ScratchBlocks.ProcedureUtils.disconnectOldBlocks_,
1035
+ deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_,
1036
+ createIcon_: Blockly.ScratchBlocks.ProcedureUtils.createIcon_,
1037
+ createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_,
1038
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_,
1039
+
1040
+ // Exist on all three blocks, but have different implementations.
1041
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.callerMutationToDom,
1042
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.callerDomToMutation,
1043
+ populateArgument_: Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnCaller_,
1044
+ addProcedureLabel_: Blockly.ScratchBlocks.ProcedureUtils.addLabelField_,
1045
+
1046
+ // Only exists on the external caller.
1047
+ attachShadow_: Blockly.ScratchBlocks.ProcedureUtils.attachShadow_,
1048
+ buildShadowDom_: Blockly.ScratchBlocks.ProcedureUtils.buildShadowDom_
1049
+ };
1050
+
1051
+ Blockly.Blocks['procedures_prototype'] = {
1052
+ /**
1053
+ * Block for calling a procedure with no return value, for rendering inside
1054
+ * define block.
1055
+ * @this Blockly.Block
1056
+ */
1057
+ init: function() {
1058
+ this.jsonInit({
1059
+ "extensions": ["colours_more", 'shape_procedure']
1060
+ });
1061
+
1062
+ /* Data known about the procedure. */
1063
+ this.procCode_ = '';
1064
+ this.displayNames_ = [];
1065
+ this.argumentIds_ = [];
1066
+ this.argumentDefaults_ = [];
1067
+ this.warp_ = false;
1068
+ this.output_ = false;
1069
+ this.isDisplayOnly = true
1070
+ this.edited = false
1071
+ this.outputType = 'statement'
1072
+ this.image = ''
1073
+ this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
1074
+ },
1075
+ // Shared.
1076
+ getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
1077
+ removeAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.removeAllInputs_,
1078
+ disconnectOldBlocks_: Blockly.ScratchBlocks.ProcedureUtils.disconnectOldBlocks_,
1079
+ deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_,
1080
+ createIcon_: Blockly.ScratchBlocks.ProcedureUtils.createIcon_,
1081
+ createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_,
1082
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_,
1083
+
1084
+ // Exist on all three blocks, but have different implementations.
1085
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.definitionMutationToDom,
1086
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.definitionDomToMutation,
1087
+ populateArgument_: Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnPrototype_,
1088
+ addProcedureLabel_: Blockly.ScratchBlocks.ProcedureUtils.addLabelField_,
1089
+
1090
+ // Only exists on procedures_prototype.
1091
+ createArgumentReporter_: Blockly.ScratchBlocks.ProcedureUtils.createArgumentReporter_,
1092
+ updateArgumentReporterNames_: Blockly.ScratchBlocks.ProcedureUtils.updateArgumentReporterNames_
1093
+ };
1094
+
1095
+ Blockly.Blocks['procedures_declaration'] = {
1096
+ /**
1097
+ * The root block in the procedure declaration editor.
1098
+ * @this Blockly.Block
1099
+ */
1100
+ init: function() {
1101
+ this.jsonInit({
1102
+ "extensions": ["colours_more", 'shape_procedure']
1103
+ });
1104
+ /* Data known about the procedure. */
1105
+ this.procCode_ = '';
1106
+ this.displayNames_ = [];
1107
+ this.argumentIds_ = [];
1108
+ this.argumentDefaults_ = [];
1109
+ this.warp_ = false;
1110
+ this.output_ = false;
1111
+ this.isDisplayOnly = true
1112
+ this.edited = false
1113
+ this.outputType = 'statement'
1114
+ this.image = ''
1115
+ this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
1116
+ },
1117
+ // Shared.
1118
+ getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
1119
+ removeAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.removeAllInputs_,
1120
+ disconnectOldBlocks_: Blockly.ScratchBlocks.ProcedureUtils.disconnectOldBlocks_,
1121
+ deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_,
1122
+ createIcon_: Blockly.ScratchBlocks.ProcedureUtils.createIcon_,
1123
+ createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_,
1124
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_,
1125
+
1126
+ // Exist on all three blocks, but have different implementations.
1127
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.definitionMutationToDom,
1128
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.definitionDomToMutation,
1129
+ populateArgument_: Blockly.ScratchBlocks.ProcedureUtils.populateArgumentOnDeclaration_,
1130
+ addProcedureLabel_: Blockly.ScratchBlocks.ProcedureUtils.addLabelEditor_,
1131
+
1132
+ // Exist on declaration and arguments editors, with different implementations.
1133
+ removeFieldCallback: Blockly.ScratchBlocks.ProcedureUtils.removeFieldCallback,
1134
+
1135
+ // Only exist on procedures_declaration.
1136
+ createArgumentEditor_: Blockly.ScratchBlocks.ProcedureUtils.createArgumentEditor_,
1137
+ focusLastEditor_: Blockly.ScratchBlocks.ProcedureUtils.focusLastEditor_,
1138
+ getWarp: Blockly.ScratchBlocks.ProcedureUtils.getWarp,
1139
+ setWarp: Blockly.ScratchBlocks.ProcedureUtils.setWarp,
1140
+ getReturns: Blockly.ScratchBlocks.ProcedureUtils.getReturns,
1141
+ setReturns: Blockly.ScratchBlocks.ProcedureUtils.setReturns,
1142
+ getEdited: Blockly.ScratchBlocks.ProcedureUtils.getEdited,
1143
+ setEdited: Blockly.ScratchBlocks.ProcedureUtils.setEdited,
1144
+ setType: Blockly.ScratchBlocks.ProcedureUtils.setType,
1145
+ setImage: Blockly.ScratchBlocks.ProcedureUtils.setImage,
1146
+ unsetImage: Blockly.ScratchBlocks.ProcedureUtils.unsetImage,
1147
+ setColor: Blockly.ScratchBlocks.ProcedureUtils.setColor,
1148
+ removeColor: Blockly.ScratchBlocks.ProcedureUtils.removeColor,
1149
+ addLabelExternal: Blockly.ScratchBlocks.ProcedureUtils.addLabelExternal,
1150
+ addBooleanExternal: Blockly.ScratchBlocks.ProcedureUtils.addBooleanExternal,
1151
+ addCommandExternal: Blockly.ScratchBlocks.ProcedureUtils.addCommandExternal,
1152
+ addStringNumberExternal: Blockly.ScratchBlocks.ProcedureUtils.addStringNumberExternal,
1153
+ onChangeFn: Blockly.ScratchBlocks.ProcedureUtils.updateDeclarationProcCode_
1154
+ };
1155
+
1156
+ Blockly.Blocks['argument_reporter_boolean'] = {
1157
+ init: function() {
1158
+ this.jsonInit({
1159
+ "message0": " %1",
1160
+ "args0": [
1161
+ {
1162
+ "type": "field_label_serializable",
1163
+ "name": "VALUE",
1164
+ "text": ""
1165
+ }
1166
+ ],
1167
+ "extensions": ["colours_more", "output_boolean"]
1168
+ });
1169
+ },
1170
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterUpdateDisplay,
1171
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterMutationToDom,
1172
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterDomToMutation
1173
+ };
1174
+
1175
+ Blockly.Blocks['argument_reporter_string_number'] = {
1176
+ init: function() {
1177
+ this.jsonInit({
1178
+ "message0": " %1",
1179
+ "args0": [
1180
+ {
1181
+ "type": "field_label_serializable",
1182
+ "name": "VALUE",
1183
+ "text": ""
1184
+ }
1185
+ ],
1186
+ "extensions": ["colours_more", "output_number", "output_string"]
1187
+ });
1188
+ },
1189
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterUpdateDisplay,
1190
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterMutationToDom,
1191
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterDomToMutation
1192
+ };
1193
+
1194
+ Blockly.Blocks['argument_reporter_command'] = {
1195
+ init: function () {
1196
+ this.jsonInit({ "message0": " %1",
1197
+ "args0": [
1198
+ {
1199
+ "type": "field_label_serializable",
1200
+ "name": "VALUE",
1201
+ "text": ""
1202
+ }
1203
+ ],
1204
+ "canDragDuplicate": true,
1205
+ "extensions": ["colours_more", "shape_statement"],
1206
+ });
1207
+ },
1208
+ updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterUpdateDisplay,
1209
+ mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterMutationToDom,
1210
+ domToMutation: Blockly.ScratchBlocks.ProcedureUtils.argumentReporterDomToMutation
1211
+ };
1212
+
1213
+ Blockly.Blocks['argument_editor_boolean'] = {
1214
+ init: function() {
1215
+ this.jsonInit({ "message0": " %1",
1216
+ "args0": [
1217
+ {
1218
+ "type": "field_input_removable",
1219
+ "name": "TEXT",
1220
+ "text": "foo"
1221
+ }
1222
+ ],
1223
+ "colour": Blockly.Colours.textField,
1224
+ "colourSecondary": Blockly.Colours.textField,
1225
+ "colourTertiary": Blockly.Colours.textField,
1226
+ "extensions": ["output_boolean"]
1227
+ });
1228
+ },
1229
+ // Exist on declaration and arguments editors, with different implementations.
1230
+ removeFieldCallback: Blockly.ScratchBlocks.ProcedureUtils.removeArgumentCallback_
1231
+ };
1232
+
1233
+ Blockly.Blocks['argument_editor_string_number'] = {
1234
+ init: function() {
1235
+ this.jsonInit({ "message0": " %1",
1236
+ "args0": [
1237
+ {
1238
+ "type": "field_input_removable",
1239
+ "name": "TEXT",
1240
+ "text": "foo"
1241
+ }
1242
+ ],
1243
+ "colour": Blockly.Colours.textField,
1244
+ "colourSecondary": Blockly.Colours.textField,
1245
+ "colourTertiary": Blockly.Colours.textField,
1246
+ "extensions": ["output_number", "output_string"]
1247
+ });
1248
+ },
1249
+ // Exist on declaration and arguments editors, with different implementations.
1250
+ removeFieldCallback: Blockly.ScratchBlocks.ProcedureUtils.removeArgumentCallback_
1251
+ };
1252
+
1253
+ Blockly.Blocks['argument_editor_command'] = {
1254
+ init: function () {
1255
+ this.jsonInit({ "message0": " %1",
1256
+ "args0": [
1257
+ {
1258
+ "type": "field_input_removable",
1259
+ "name": "TEXT",
1260
+ "text": "foo"
1261
+ }
1262
+ ],
1263
+ "colour": Blockly.Colours.textField,
1264
+ "colourSecondary": Blockly.Colours.textField,
1265
+ "colourTertiary": Blockly.Colours.textField,
1266
+ "extensions": ["colours_more", "shape_statement"],
1267
+ });
1268
+ },
1269
+ // Exist on declaration and arguments editors, with different implementations.
1270
+ removeFieldCallback: Blockly.ScratchBlocks.ProcedureUtils.removeArgumentCallback_,
1271
+ };
1272
+
1273
+ Blockly.Blocks['procedures_set'] = {
1274
+ init: function() {
1275
+ this.jsonInit({
1276
+ "message0": 'set %1 to %2',
1277
+ "args0": [
1278
+ {
1279
+ "type": "input_value",
1280
+ "name": "PARAM"
1281
+ },
1282
+ {
1283
+ "type": "input_value",
1284
+ "name": "VALUE"
1285
+ }
1286
+ ],
1287
+ "extensions": ["colours_more", "shape_statement"]
1288
+ });
1289
+ }
1290
+ };
1291
+
1292
+ Blockly.Blocks['procedures_return'] = {
1293
+ init: function() {
1294
+ this.jsonInit({
1295
+ "message0": 'return %1',
1296
+ "args0": [
1297
+ {
1298
+ "type": "input_value",
1299
+ "name": "return"
1300
+ }
1301
+ ],
1302
+ "extensions": ["colours_more", "shape_end"]
1303
+ });
1304
+ }
1305
+ };
blocks_vertical/sensing.js ADDED
@@ -0,0 +1,1158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.sensing');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+
31
+ Blockly.Blocks['sensing_touchingobject'] = {
32
+ /**
33
+ * Block to Report if its touching a Object.
34
+ * @this Blockly.Block
35
+ */
36
+ init: function() {
37
+ this.jsonInit({
38
+ "message0": Blockly.Msg.SENSING_TOUCHINGOBJECT,
39
+ "args0": [
40
+ {
41
+ "type": "input_value",
42
+ "name": "TOUCHINGOBJECTMENU"
43
+ }
44
+ ],
45
+ "category": Blockly.Categories.sensing,
46
+ "extensions": ["colours_sensing", "output_boolean"]
47
+ });
48
+ }
49
+ };
50
+
51
+ Blockly.Blocks['sensing_objecttouchingclonesprite'] = {
52
+ /**
53
+ * pm: Block to Report if an Object is touching a clone of another sprite.
54
+ * @this Blockly.Block
55
+ */
56
+ init: function () {
57
+ this.jsonInit({
58
+ "message0": "%1 touching clone of %2?",
59
+ "args0": [
60
+ {
61
+ "type": "input_value",
62
+ "name": "FULLTOUCHINGOBJECTMENU"
63
+ },
64
+ {
65
+ "type": "input_value",
66
+ "name": "SPRITETOUCHINGOBJECTMENU"
67
+ }
68
+ ],
69
+ "category": Blockly.Categories.sensing,
70
+ "extensions": ["colours_sensing", "output_boolean"]
71
+ });
72
+ }
73
+ };
74
+
75
+ Blockly.Blocks['sensing_objecttouchingobject'] = {
76
+ /**
77
+ * pm" Block to Report if an Object is touching another Object.
78
+ * @this Blockly.Block
79
+ */
80
+ init: function () {
81
+ this.jsonInit({
82
+ "message0": "%1 touching %2?",
83
+ "args0": [
84
+ {
85
+ "type": "input_value",
86
+ "name": "FULLTOUCHINGOBJECTMENU"
87
+ },
88
+ {
89
+ "type": "input_value",
90
+ "name": "SPRITETOUCHINGOBJECTMENU"
91
+ }
92
+ ],
93
+ "category": Blockly.Categories.sensing,
94
+ "extensions": ["colours_sensing", "output_boolean"]
95
+ });
96
+ }
97
+ };
98
+
99
+ Blockly.Blocks['sensing_touchingobjectmenu'] = {
100
+ /**
101
+ * "Touching [Object]" Block Menu.
102
+ * @this Blockly.Block
103
+ */
104
+ init: function() {
105
+ this.jsonInit({
106
+ "message0": "%1",
107
+ "args0": [
108
+ {
109
+ "type": "field_dropdown",
110
+ "name": "TOUCHINGOBJECTMENU",
111
+ "options": [
112
+ [Blockly.Msg.SENSING_TOUCHINGOBJECT_POINTER, '_mouse_'],
113
+ [Blockly.Msg.SENSING_TOUCHINGOBJECT_EDGE, '_edge_']
114
+ ]
115
+ }
116
+ ],
117
+ "extensions": ["colours_sensing", "output_string"]
118
+ });
119
+ }
120
+ };
121
+
122
+ Blockly.Blocks['sensing_fulltouchingobjectmenu'] = {
123
+ /**
124
+ * pm: "Touching [Object]" Block Menu with more options.
125
+ * @this Blockly.Block
126
+ */
127
+ init: function() {
128
+ this.jsonInit({
129
+ "message0": "%1",
130
+ "args0": [
131
+ {
132
+ "type": "field_dropdown",
133
+ "name": "FULLTOUCHINGOBJECTMENU",
134
+ "options": [
135
+ ["mouse-pointer", '_mouse_'],
136
+ ["edge", '_edge_'],
137
+ ["this sprite", '_myself_']
138
+ ]
139
+ }
140
+ ],
141
+ "extensions": ["colours_sensing", "output_string"]
142
+ });
143
+ }
144
+ };
145
+
146
+ Blockly.Blocks['sensing_touchingobjectmenusprites'] = {
147
+ /**
148
+ * pm: "Touching [Object]" Block Menu with sprite options.
149
+ * @this Blockly.Block
150
+ */
151
+ init: function () {
152
+ this.jsonInit({
153
+ "message0": "%1",
154
+ "args0": [
155
+ {
156
+ "type": "field_dropdown",
157
+ "name": "SPRITETOUCHINGOBJECTMENU",
158
+ "options": [
159
+ ["this sprite", '_myself_']
160
+ ]
161
+ }
162
+ ],
163
+ "extensions": ["colours_sensing", "output_string"]
164
+ });
165
+ }
166
+ };
167
+
168
+ Blockly.Blocks['sensing_touchingcolor'] = {
169
+ /**
170
+ * Block to Report if its touching a certain Color.
171
+ * @this Blockly.Block
172
+ */
173
+ init: function() {
174
+ this.jsonInit({
175
+ "message0": Blockly.Msg.SENSING_TOUCHINGCOLOR,
176
+ "args0": [
177
+ {
178
+ "type": "input_value",
179
+ "name": "COLOR"
180
+ }
181
+ ],
182
+ "category": Blockly.Categories.sensing,
183
+ "extensions": ["colours_sensing", "output_boolean"]
184
+ });
185
+ }
186
+ };
187
+
188
+ Blockly.Blocks['sensing_coloristouchingcolor'] = {
189
+ /**
190
+ * Block to Report if a color is touching a certain Color.
191
+ * @this Blockly.Block
192
+ */
193
+ init: function() {
194
+ this.jsonInit({
195
+ "message0": Blockly.Msg.SENSING_COLORISTOUCHINGCOLOR,
196
+ "args0": [
197
+ {
198
+ "type": "input_value",
199
+ "name": "COLOR"
200
+ },
201
+ {
202
+ "type": "input_value",
203
+ "name": "COLOR2"
204
+ }
205
+ ],
206
+ "category": Blockly.Categories.sensing,
207
+ "extensions": ["colours_sensing", "output_boolean"]
208
+ });
209
+ }
210
+ };
211
+
212
+ Blockly.Blocks['sensing_distanceto'] = {
213
+ /**
214
+ * Block to Report distance to another Object.
215
+ * @this Blockly.Block
216
+ */
217
+ init: function() {
218
+ this.jsonInit({
219
+ "message0": Blockly.Msg.SENSING_DISTANCETO,
220
+ "args0": [
221
+ {
222
+ "type": "input_value",
223
+ "name": "DISTANCETOMENU"
224
+ }
225
+ ],
226
+ "category": Blockly.Categories.sensing,
227
+ "extensions": ["colours_sensing", "output_number"]
228
+ });
229
+ }
230
+ };
231
+
232
+ Blockly.Blocks['sensing_distancetomenu'] = {
233
+ /**
234
+ * "Distance to [Object]" Block Menu.
235
+ * @this Blockly.Block
236
+ */
237
+ init: function() {
238
+ this.jsonInit({
239
+ "message0": "%1",
240
+ "args0": [
241
+ {
242
+ "type": "field_dropdown",
243
+ "name": "DISTANCETOMENU",
244
+ "options": [
245
+ [Blockly.Msg.SENSING_DISTANCETO_POINTER, '_mouse_']
246
+ ]
247
+ }
248
+ ],
249
+ "extensions": ["colours_sensing", "output_string"]
250
+ });
251
+ }
252
+ };
253
+
254
+ Blockly.Blocks['sensing_askandwait'] = {
255
+ /**
256
+ * Block to ask a question and wait
257
+ * @this Blockly.Block
258
+ */
259
+ init: function() {
260
+ this.jsonInit({
261
+ "message0": Blockly.Msg.SENSING_ASKANDWAIT,
262
+ "args0": [
263
+ {
264
+ "type": "input_value",
265
+ "name": "QUESTION"
266
+ }
267
+ ],
268
+ "category": Blockly.Categories.sensing,
269
+ "extensions": ["colours_sensing", "shape_statement"]
270
+ });
271
+ }
272
+ };
273
+
274
+ Blockly.Blocks['sensing_answer'] = {
275
+ /**
276
+ * Block to report answer
277
+ * @this Blockly.Block
278
+ */
279
+ init: function() {
280
+ this.jsonInit({
281
+ "message0": Blockly.Msg.SENSING_ANSWER,
282
+ "category": Blockly.Categories.sensing,
283
+ "checkboxInFlyout": true,
284
+ "extensions": ["colours_sensing", "output_number"]
285
+ });
286
+ }
287
+ };
288
+
289
+ Blockly.Blocks['sensing_keypressed'] = {
290
+ /**
291
+ * Block to Report if a key is pressed.
292
+ * @this Blockly.Block
293
+ */
294
+ init: function() {
295
+ this.jsonInit({
296
+ "message0": Blockly.Msg.SENSING_KEYPRESSED,
297
+ "args0": [
298
+ {
299
+ "type": "input_value",
300
+ "name": "KEY_OPTION"
301
+ }
302
+ ],
303
+ "category": Blockly.Categories.sensing,
304
+ "extensions": ["colours_sensing", "output_boolean"]
305
+ });
306
+ }
307
+ };
308
+
309
+ Blockly.Blocks['sensing_keyhit'] = {
310
+ /**
311
+ * pm: Block to Report if a key is hit on the same tick.
312
+ * @this Blockly.Block
313
+ */
314
+ init: function () {
315
+ this.jsonInit({
316
+ "message0": "key %1 hit?",
317
+ "args0": [
318
+ {
319
+ "type": "input_value",
320
+ "name": "KEY_OPTION"
321
+ }
322
+ ],
323
+ "category": Blockly.Categories.sensing,
324
+ "extensions": ["colours_sensing", "output_boolean"]
325
+ });
326
+ }
327
+ };
328
+
329
+ Blockly.Blocks['sensing_mousescrolling'] = {
330
+ /**
331
+ * pm: Block to report if the mouse is scrolling in a direction.
332
+ * @this Blockly.Block
333
+ */
334
+ init: function () {
335
+ this.jsonInit({
336
+ "message0": "is mouse scrolling %1?",
337
+ "args0": [
338
+ {
339
+ "type": "input_value",
340
+ "name": "SCROLL_OPTION"
341
+ }
342
+ ],
343
+ "category": Blockly.Categories.sensing,
344
+ "extensions": ["colours_sensing", "output_boolean"]
345
+ });
346
+ }
347
+ };
348
+
349
+ Blockly.Blocks['sensing_scrolldirections'] = {
350
+ /**
351
+ * pm: Options for scroll direction
352
+ * @this Blockly.Block
353
+ */
354
+ init: function () {
355
+ this.jsonInit({
356
+ "message0": "%1",
357
+ "args0": [
358
+ {
359
+ "type": "field_dropdown",
360
+ "name": "SCROLL_OPTION",
361
+ "options": [
362
+ ['up', 'up'],
363
+ ['down', 'down']
364
+ ]
365
+ }
366
+ ],
367
+ "extensions": ["colours_sensing", "output_string"]
368
+ });
369
+ }
370
+ };
371
+
372
+ Blockly.Blocks['sensing_keyoptions'] = {
373
+ /**
374
+ * Options for Keys
375
+ * @this Blockly.Block
376
+ */
377
+ init: function() {
378
+ this.jsonInit({
379
+ "message0": "%1",
380
+ "args0": [
381
+ {
382
+ "type": "field_dropdown",
383
+ "name": "KEY_OPTION",
384
+ "options": [
385
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'],
386
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'],
387
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'],
388
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'],
389
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'],
390
+ [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'],
391
+ ['a', 'a'],
392
+ ['b', 'b'],
393
+ ['c', 'c'],
394
+ ['d', 'd'],
395
+ ['e', 'e'],
396
+ ['f', 'f'],
397
+ ['g', 'g'],
398
+ ['h', 'h'],
399
+ ['i', 'i'],
400
+ ['j', 'j'],
401
+ ['k', 'k'],
402
+ ['l', 'l'],
403
+ ['m', 'm'],
404
+ ['n', 'n'],
405
+ ['o', 'o'],
406
+ ['p', 'p'],
407
+ ['q', 'q'],
408
+ ['r', 'r'],
409
+ ['s', 's'],
410
+ ['t', 't'],
411
+ ['u', 'u'],
412
+ ['v', 'v'],
413
+ ['w', 'w'],
414
+ ['x', 'x'],
415
+ ['y', 'y'],
416
+ ['z', 'z'],
417
+ ['0', '0'],
418
+ ['1', '1'],
419
+ ['2', '2'],
420
+ ['3', '3'],
421
+ ['4', '4'],
422
+ ['5', '5'],
423
+ ['6', '6'],
424
+ ['7', '7'],
425
+ ['8', '8'],
426
+ ['9', '9']
427
+ ]
428
+ }
429
+ ],
430
+ "extensions": ["colours_sensing", "output_string"]
431
+ });
432
+ }
433
+ };
434
+
435
+ Blockly.Blocks['sensing_fingeroptions'] = {
436
+ /**
437
+ * pm: Options for Fingers
438
+ * @this Blockly.Block
439
+ */
440
+ init: function () {
441
+ this.jsonInit({
442
+ "message0": "%1",
443
+ "args0": [
444
+ {
445
+ "type": "field_dropdown",
446
+ "name": "FINGER_OPTION",
447
+ "options": [
448
+ ['1', '1'],
449
+ ['2', '2'],
450
+ ['3', '3'],
451
+ ['4', '4'],
452
+ ['5', '5']
453
+ ]
454
+ }
455
+ ],
456
+ "extensions": ["colours_sensing", "output_string"]
457
+ });
458
+ }
459
+ };
460
+
461
+ Blockly.Blocks['sensing_mousedown'] = {
462
+ /**
463
+ * Block to Report if the mouse is down.
464
+ * @this Blockly.Block
465
+ */
466
+ init: function() {
467
+ this.jsonInit({
468
+ "message0": Blockly.Msg.SENSING_MOUSEDOWN,
469
+ "category": Blockly.Categories.sensing,
470
+ "checkboxInFlyout": true,
471
+ "extensions": ["colours_sensing", "output_boolean"]
472
+ });
473
+ }
474
+ };
475
+
476
+ Blockly.Blocks['sensing_mouseclicked'] = {
477
+ /**
478
+ * pm: Block to Report if the mouse is clicked on the same tick.
479
+ * @this Blockly.Block
480
+ */
481
+ init: function() {
482
+ this.jsonInit({
483
+ "message0": "mouse clicked?",
484
+ "category": Blockly.Categories.sensing,
485
+ "checkboxInFlyout": true,
486
+ "extensions": ["colours_sensing", "output_boolean"]
487
+ });
488
+ }
489
+ };
490
+
491
+ Blockly.Blocks['sensing_fingerdown'] = {
492
+ /**
493
+ * pm: Block to Report if the specified finger is down.
494
+ * @this Blockly.Block
495
+ */
496
+ init: function() {
497
+ this.jsonInit({
498
+ "message0": "finger %1 down?",
499
+ "args0": [
500
+ {
501
+ "type": "input_value",
502
+ "name": "FINGER_OPTION"
503
+ }
504
+ ],
505
+ "category": Blockly.Categories.sensing,
506
+ "extensions": ["colours_sensing", "output_boolean"]
507
+ });
508
+ }
509
+ };
510
+
511
+ Blockly.Blocks['sensing_fingertapped'] = {
512
+ /**
513
+ * pm: Block to Report if the specified finger has tapped on this frame.
514
+ * @this Blockly.Block
515
+ */
516
+ init: function() {
517
+ this.jsonInit({
518
+ "message0": "finger %1 tapped?",
519
+ "args0": [
520
+ {
521
+ "type": "input_value",
522
+ "name": "FINGER_OPTION"
523
+ }
524
+ ],
525
+ "category": Blockly.Categories.sensing,
526
+ "extensions": ["colours_sensing", "output_boolean"]
527
+ });
528
+ }
529
+ };
530
+
531
+ Blockly.Blocks['sensing_mousex'] = {
532
+ /**
533
+ * Block to report mouse's x position
534
+ * @this Blockly.Block
535
+ */
536
+ init: function() {
537
+ this.jsonInit({
538
+ "message0": Blockly.Msg.SENSING_MOUSEX,
539
+ "category": Blockly.Categories.sensing,
540
+ "checkboxInFlyout": true,
541
+ "extensions": ["colours_sensing", "output_number"]
542
+ });
543
+ }
544
+ };
545
+
546
+ Blockly.Blocks['sensing_mousey'] = {
547
+ /**
548
+ * Block to report mouse's y position
549
+ * @this Blockly.Block
550
+ */
551
+ init: function() {
552
+ this.jsonInit({
553
+ "message0": Blockly.Msg.SENSING_MOUSEY,
554
+ "category": Blockly.Categories.sensing,
555
+ "checkboxInFlyout": true,
556
+ "extensions": ["colours_sensing", "output_number"]
557
+ });
558
+ }
559
+ };
560
+
561
+ Blockly.Blocks['sensing_fingerx'] = {
562
+ /**
563
+ * pm: Block to report finger #<options>'s x position
564
+ * @this Blockly.Block
565
+ */
566
+ init: function() {
567
+ this.jsonInit({
568
+ "message0": "finger %1 x",
569
+ "args0": [
570
+ {
571
+ "type": "input_value",
572
+ "name": "FINGER_OPTION"
573
+ }
574
+ ],
575
+ "category": Blockly.Categories.sensing,
576
+ "extensions": ["colours_sensing", "output_number"]
577
+ });
578
+ }
579
+ };
580
+
581
+ Blockly.Blocks['sensing_fingery'] = {
582
+ /**
583
+ * pm: Block to report finger #<options>'s y position
584
+ * @this Blockly.Block
585
+ */
586
+ init: function() {
587
+ this.jsonInit({
588
+ "message0": "finger %1 y",
589
+ "args0": [
590
+ {
591
+ "type": "input_value",
592
+ "name": "FINGER_OPTION"
593
+ }
594
+ ],
595
+ "category": Blockly.Categories.sensing,
596
+ "extensions": ["colours_sensing", "output_number"]
597
+ });
598
+ }
599
+ };
600
+
601
+ Blockly.Blocks['sensing_setclipboard'] = {
602
+ /**
603
+ * pm: Block to add an item to the Clipboard
604
+ * @this Blockly.Block
605
+ */
606
+ init: function () {
607
+ this.jsonInit({
608
+ "message0": Blockly.Msg.SENSING_ADDTOCLIPBOARD,
609
+ "args0": [
610
+ {
611
+ "type": "input_value",
612
+ "name": "ITEM"
613
+ }
614
+ ],
615
+ "category": Blockly.Categories.sensing,
616
+ "extensions": ["colours_sensing", "shape_statement"]
617
+ });
618
+ }
619
+ };
620
+
621
+ Blockly.Blocks['sensing_getclipboard'] = {
622
+ /**
623
+ * pm: Block to report the current item in the Clipboard
624
+ * @this Blockly.Block
625
+ */
626
+ init: function() {
627
+ this.jsonInit({
628
+ "message0": Blockly.Msg.SENSING_CLIPBOARDITEM,
629
+ "category": Blockly.Categories.sensing,
630
+ "checkboxInFlyout": true,
631
+ "extensions": ["colours_sensing", "output_string"]
632
+ });
633
+ }
634
+ };
635
+
636
+ Blockly.Blocks['sensing_setdragmode'] = {
637
+ /**
638
+ * Block to set drag mode.
639
+ * @this Blockly.Block
640
+ */
641
+ init: function() {
642
+ this.jsonInit({
643
+ "message0": Blockly.Msg.SENSING_SETDRAGMODE,
644
+ "args0": [
645
+ {
646
+ "type": "field_dropdown",
647
+ "name": "DRAG_MODE",
648
+ "options": [
649
+ [Blockly.Msg.SENSING_SETDRAGMODE_DRAGGABLE, 'draggable'],
650
+ [Blockly.Msg.SENSING_SETDRAGMODE_NOTDRAGGABLE, 'not draggable']
651
+ ]
652
+ }
653
+ ],
654
+ "category": Blockly.Categories.sensing,
655
+ "extensions": ["colours_sensing", "shape_statement"]
656
+ });
657
+ }
658
+ };
659
+
660
+ Blockly.Blocks['sensing_getdragmode'] = {
661
+ /**
662
+ * pm: Block to report drag mode.
663
+ * @this Blockly.Block
664
+ */
665
+ init: function() {
666
+ this.jsonInit({
667
+ "message0": "draggable?",
668
+ "category": Blockly.Categories.sensing,
669
+ "checkboxInFlyout": true,
670
+ "extensions": ["colours_sensing", "output_boolean"]
671
+ });
672
+ }
673
+ };
674
+
675
+ Blockly.Blocks['sensing_loudness'] = {
676
+ /**
677
+ * Block to report loudness
678
+ * @this Blockly.Block
679
+ */
680
+ init: function() {
681
+ this.jsonInit({
682
+ "message0": Blockly.Msg.SENSING_LOUDNESS,
683
+ "category": Blockly.Categories.sensing,
684
+ "checkboxInFlyout": true,
685
+ "extensions": ["colours_sensing", "output_number"]
686
+ });
687
+ }
688
+ };
689
+
690
+ Blockly.Blocks['sensing_loud'] = {
691
+ /**
692
+ * Block to report if the loudness is "loud" (greater than 10). This is an
693
+ * obsolete block that is implemented for compatibility with Scratch 2.0 and
694
+ * 1.4 projects.
695
+ * @this Blockly.Block
696
+ */
697
+ init: function() {
698
+ this.jsonInit({
699
+ "message0": Blockly.Msg.SENSING_LOUD,
700
+ "category": Blockly.Categories.sensing,
701
+ "checkboxInFlyout": true,
702
+ "extensions": ["colours_sensing", "output_boolean"]
703
+ });
704
+ }
705
+ };
706
+
707
+ Blockly.Blocks['sensing_timer'] = {
708
+ /**
709
+ * Block to report timer
710
+ * @this Blockly.Block
711
+ */
712
+ init: function() {
713
+ this.jsonInit({
714
+ "message0": Blockly.Msg.SENSING_TIMER,
715
+ "category": Blockly.Categories.sensing,
716
+ "checkboxInFlyout": true,
717
+ "extensions": ["colours_sensing", "output_number"]
718
+ });
719
+ }
720
+ };
721
+
722
+ Blockly.Blocks['sensing_resettimer'] = {
723
+ /**
724
+ * Block to reset timer
725
+ * @this Blockly.Block
726
+ */
727
+ init: function() {
728
+ this.jsonInit({
729
+ "message0": Blockly.Msg.SENSING_RESETTIMER,
730
+ "category": Blockly.Categories.sensing,
731
+ "extensions": ["colours_sensing", "shape_statement"]
732
+ });
733
+ }
734
+ };
735
+
736
+ Blockly.Blocks['sensing_of_object_menu'] = {
737
+ /**
738
+ * "* of _" object menu.
739
+ * @this Blockly.Block
740
+ */
741
+ init: function() {
742
+ this.jsonInit({
743
+ "message0": "%1",
744
+ "args0": [
745
+ {
746
+ "type": "field_dropdown",
747
+ "name": "OBJECT",
748
+ "options": [
749
+ ['Sprite1', 'Sprite1'],
750
+ ['Stage', '_stage_']
751
+ ]
752
+ }
753
+ ],
754
+ "category": Blockly.Categories.sensing,
755
+ "extensions": ["colours_sensing", "output_string"]
756
+ });
757
+ }
758
+ };
759
+
760
+
761
+ Blockly.Blocks['sensing_of'] = {
762
+ /**
763
+ * Block to report properties of sprites.
764
+ * @this Blockly.Block
765
+ */
766
+ init: function() {
767
+ this.jsonInit({
768
+ "message0": Blockly.Msg.SENSING_OF,
769
+ "args0": [
770
+ {
771
+ "type": "field_dropdown",
772
+ "name": "PROPERTY",
773
+ "options": [
774
+ [Blockly.Msg.SENSING_OF_XPOSITION, 'x position'],
775
+ [Blockly.Msg.SENSING_OF_YPOSITION, 'y position'],
776
+ [Blockly.Msg.SENSING_OF_DIRECTION, 'direction'],
777
+ [Blockly.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'],
778
+ [Blockly.Msg.SENSING_OF_COSTUMENAME, 'costume name'],
779
+ [Blockly.Msg.SENSING_OF_SIZE, 'size'],
780
+ [Blockly.Msg.SENSING_OF_VOLUME, 'volume'],
781
+ [Blockly.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
782
+ [Blockly.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name']
783
+ ]
784
+ },
785
+ {
786
+ "type": "input_value",
787
+ "name": "OBJECT"
788
+ }
789
+ ],
790
+ "output": true,
791
+ "category": Blockly.Categories.sensing,
792
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND,
793
+ "extensions": ["colours_sensing"]
794
+ });
795
+ }
796
+ };
797
+
798
+ Blockly.Blocks['sensing_current'] = {
799
+ /**
800
+ * Block to Report the current option.
801
+ * @this Blockly.Block
802
+ */
803
+ init: function() {
804
+ this.jsonInit({
805
+ "message0": Blockly.Msg.SENSING_CURRENT,
806
+ "args0": [
807
+ {
808
+ "type": "field_dropdown",
809
+ "name": "CURRENTMENU",
810
+ "options": [
811
+ [Blockly.Msg.SENSING_CURRENT_YEAR, 'YEAR'],
812
+ [Blockly.Msg.SENSING_CURRENT_MONTH, 'MONTH'],
813
+ [Blockly.Msg.SENSING_CURRENT_DATE, 'DATE'],
814
+ [Blockly.Msg.SENSING_CURRENT_DAYOFWEEK, 'DAYOFWEEK'],
815
+ [Blockly.Msg.SENSING_CURRENT_HOUR, 'HOUR'],
816
+ [Blockly.Msg.SENSING_CURRENT_MINUTE, 'MINUTE'],
817
+ [Blockly.Msg.SENSING_CURRENT_SECOND, 'SECOND'],
818
+ ['js timestamp', 'TIMESTAMP']
819
+ ]
820
+ }
821
+ ],
822
+ "category": Blockly.Categories.sensing,
823
+ "checkboxInFlyout": true,
824
+ "extensions": ["colours_sensing", "output_number"]
825
+ });
826
+ }
827
+ };
828
+
829
+ Blockly.Blocks['sensing_dayssince2000'] = {
830
+ /**
831
+ * Block to report days since 2000
832
+ * @this Blockly.Block
833
+ */
834
+ init: function() {
835
+ this.jsonInit({
836
+ "message0": Blockly.Msg.SENSING_DAYSSINCE2000,
837
+ "category": Blockly.Categories.sensing,
838
+ "checkboxInFlyout": true,
839
+ "extensions": ["colours_sensing", "output_number"]
840
+ });
841
+ }
842
+ };
843
+
844
+ Blockly.Blocks['sensing_username'] = {
845
+ /**
846
+ * Block to report user's username
847
+ * @this Blockly.Block
848
+ */
849
+ init: function() {
850
+ this.jsonInit({
851
+ "message0": Blockly.Msg.SENSING_USERNAME,
852
+ "category": Blockly.Categories.sensing,
853
+ "checkboxInFlyout": true,
854
+ "extensions": ["colours_sensing", "output_number"]
855
+ });
856
+ }
857
+ };
858
+
859
+ Blockly.Blocks['sensing_loggedin'] = {
860
+ /**
861
+ * pm: Block to report if a user is logged in.
862
+ * @this Blockly.Block
863
+ */
864
+ init: function () {
865
+ this.jsonInit({
866
+ "message0": 'logged in?',
867
+ "category": Blockly.Categories.sensing,
868
+ "checkboxInFlyout": true,
869
+ "extensions": ["colours_sensing", "output_boolean"]
870
+ });
871
+ }
872
+ };
873
+
874
+ Blockly.Blocks['sensing_userid'] = {
875
+ /**
876
+ * Block to report user's ID. Does not actually do anything. This is an
877
+ * obsolete block that is implemented for compatibility with Scratch 2.0
878
+ * projects.
879
+ * @this Blockly.Block
880
+ */
881
+ init: function() {
882
+ this.jsonInit({
883
+ "message0": Blockly.Msg.SENSING_USERID,
884
+ "category": Blockly.Categories.sensing,
885
+ "extensions": ["colours_sensing", "output_number"]
886
+ });
887
+ }
888
+ };
889
+
890
+ Blockly.Blocks["sensing_regextest"] = {
891
+ init: function() {
892
+ this.jsonInit({
893
+ "inputsInline": true,
894
+ "message0": "test regex %2 %3 with text %1",
895
+ "args0": [
896
+ {
897
+ "type": "input_value",
898
+ "name": "text"
899
+ },
900
+ {
901
+ "type": "input_value",
902
+ "name": "reg"
903
+ },
904
+ {
905
+ "type": "input_value",
906
+ "name": "regrule"
907
+ }
908
+ ],
909
+ "category": Blockly.Categories.sensing,
910
+ "extensions": ["colours_sensing", "output_boolean"]
911
+ });
912
+ }
913
+ };
914
+
915
+ Blockly.Blocks["sensing_thing_is_number"] = {
916
+ init: function() {
917
+ this.jsonInit({
918
+ "inputsInline": true,
919
+ "message0": "%1 is number?",
920
+ "args0": [
921
+ {
922
+ "type": "input_value",
923
+ "name": "TEXT1"
924
+ }
925
+ ],
926
+ "category": Blockly.Categories.sensing,
927
+ "extensions": ["colours_sensing", "output_boolean"]
928
+ });
929
+ }
930
+ };
931
+
932
+ Blockly.Blocks["sensing_thing_has_text"] = {
933
+ init: function () {
934
+ this.jsonInit({
935
+ "inputsInline": true,
936
+ "message0": "%1 has text?",
937
+ "args0": [
938
+ {
939
+ "type": "input_value",
940
+ "name": "TEXT1"
941
+ }
942
+ ],
943
+ "category": Blockly.Categories.sensing,
944
+ "extensions": ["colours_sensing", "output_boolean"]
945
+ });
946
+ }
947
+ };
948
+
949
+ Blockly.Blocks["sensing_thing_has_number"] = {
950
+ init: function() {
951
+ this.jsonInit({
952
+ "inputsInline": true,
953
+ "message0": "%1 has number?",
954
+ "args0": [
955
+ {
956
+ "type": "input_value",
957
+ "name": "TEXT1"
958
+ }
959
+ ],
960
+ "category": Blockly.Categories.sensing,
961
+ "extensions": ["colours_sensing", "output_boolean"]
962
+ });
963
+ }
964
+ };
965
+
966
+ Blockly.Blocks["sensing_mobile"] = {
967
+ init: function() {
968
+ this.jsonInit({
969
+ "inputsInline": true,
970
+ "message0": "mobile?",
971
+ "args0": [],
972
+ "category": Blockly.Categories.sensing,
973
+ "extensions": ["colours_sensing", "output_boolean"]
974
+ });
975
+ }
976
+ };
977
+
978
+ Blockly.Blocks["sensing_thing_is_text"] = {
979
+ init: function() {
980
+ this.jsonInit({
981
+ "inputsInline": true,
982
+ "message0": "%1 is text?",
983
+ "args0": [
984
+ {
985
+ "type": "input_value",
986
+ "name": "TEXT1"
987
+ }
988
+ ],
989
+ "category": Blockly.Categories.sensing,
990
+ "extensions": ["colours_sensing", "output_boolean"]
991
+ });
992
+ }
993
+ };
994
+
995
+
996
+
997
+ Blockly.Blocks["sensing_getspritewithattrib"] = {
998
+ init: function() {
999
+ this.jsonInit({
1000
+ "inputsInline": true,
1001
+ "message0": "get sprite with %1 set to %2",
1002
+ "args0": [
1003
+ {
1004
+ "type": "input_value",
1005
+ "name": "var"
1006
+ },
1007
+ {
1008
+ "type": "input_value",
1009
+ "name": "val"
1010
+ }
1011
+ ],
1012
+ "category": Blockly.Categories.sensing,
1013
+ "extensions": ["colours_sensing", "output_string"]
1014
+ });
1015
+ }
1016
+ };
1017
+
1018
+ Blockly.Blocks['sensing_distanceTo'] = {
1019
+ init: function() {
1020
+ this.jsonInit({
1021
+ "message0": 'distance from %1 %2 to %3 %4',
1022
+ "args0": [
1023
+ {
1024
+ "type": "input_value",
1025
+ "name": "x1"
1026
+ },
1027
+ {
1028
+ "type": "input_value",
1029
+ "name": "y1"
1030
+ },
1031
+ {
1032
+ "type": "input_value",
1033
+ "name": "x2"
1034
+ },
1035
+ {
1036
+ "type": "input_value",
1037
+ "name": "y2"
1038
+ }
1039
+ ],
1040
+ "category": Blockly.Categories.sensing,
1041
+ "extensions": ["colours_sensing", "output_number"]
1042
+ });
1043
+ }
1044
+ };
1045
+
1046
+ Blockly.Blocks['sensing_directionTo'] = {
1047
+ init: function() {
1048
+ this.jsonInit({
1049
+ "message0": 'direction to %1 %2 from %3 %4',
1050
+ "args0": [
1051
+ {
1052
+ "type": "input_value",
1053
+ "name": "x2"
1054
+ },
1055
+ {
1056
+ "type": "input_value",
1057
+ "name": "y2"
1058
+ },
1059
+ {
1060
+ "type": "input_value",
1061
+ "name": "x1"
1062
+ },
1063
+ {
1064
+ "type": "input_value",
1065
+ "name": "y1"
1066
+ }
1067
+ ],
1068
+ "category": Blockly.Categories.sensing,
1069
+ "extensions": ["colours_sensing", "output_number"]
1070
+ });
1071
+ }
1072
+ };
1073
+
1074
+ Blockly.Blocks['sensing_isUpperCase'] = {
1075
+ init: function() {
1076
+ this.jsonInit({
1077
+ "message0": 'is character %1 uppercase?',
1078
+ "args0": [
1079
+ {
1080
+ "type": "input_value",
1081
+ "name": "text"
1082
+ }
1083
+ ],
1084
+ "category": Blockly.Categories.sensing,
1085
+ "extensions": ["colours_sensing", "output_boolean"]
1086
+ });
1087
+ }
1088
+ };
1089
+
1090
+ Blockly.Blocks['sensing_getoperatingsystem'] = {
1091
+ /**
1092
+ * pm: Block to report the users Operating System
1093
+ * @this Blockly.Block
1094
+ */
1095
+ init: function () {
1096
+ this.jsonInit({
1097
+ "message0": "operating system",
1098
+ "category": Blockly.Categories.sensing,
1099
+ "extensions": ["colours_sensing", "output_string"]
1100
+ });
1101
+ }
1102
+ };
1103
+
1104
+ Blockly.Blocks['sensing_getbrowser'] = {
1105
+ /**
1106
+ * pm: Block to report the users Operating System
1107
+ * @this Blockly.Block
1108
+ */
1109
+ init: function () {
1110
+ this.jsonInit({
1111
+ "message0": "browser",
1112
+ "category": Blockly.Categories.sensing,
1113
+ "extensions": ["colours_sensing", "output_string"]
1114
+ });
1115
+ }
1116
+ };
1117
+
1118
+ Blockly.Blocks['sensing_geturl'] = {
1119
+ /**
1120
+ * pm: Block to report the users Operating System
1121
+ * @this Blockly.Block
1122
+ */
1123
+ init: function () {
1124
+ this.jsonInit({
1125
+ "message0": "url",
1126
+ "category": Blockly.Categories.sensing,
1127
+ "extensions": ["colours_sensing", "output_string"]
1128
+ });
1129
+ }
1130
+ };
1131
+
1132
+ Blockly.Blocks['sensing_getxyoftouchingsprite'] = {
1133
+ /**
1134
+ * Block to set drag mode.
1135
+ * @this Blockly.Block
1136
+ */
1137
+ init: function() {
1138
+ this.jsonInit({
1139
+ "message0": "%1 of touching %2 point",
1140
+ "args0": [
1141
+ {
1142
+ "type": "field_dropdown",
1143
+ "name": "XY",
1144
+ "options": [
1145
+ ['x', 'x'],
1146
+ ['y', 'y']
1147
+ ]
1148
+ },
1149
+ {
1150
+ "type": "input_value",
1151
+ "name": "SPRITE"
1152
+ }
1153
+ ],
1154
+ "category": Blockly.Categories.sensing,
1155
+ "extensions": ["colours_sensing", "output_number"]
1156
+ });
1157
+ }
1158
+ };
blocks_vertical/sound.js ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.sound');
24
+
25
+ goog.require('Blockly.Blocks');
26
+ goog.require('Blockly.Colours');
27
+ goog.require('Blockly.constants');
28
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
29
+
30
+ Blockly.Blocks['sound_sounds_menu'] = {
31
+ /**
32
+ * Sound effects drop-down menu.
33
+ * @this Blockly.Block
34
+ */
35
+ init: function() {
36
+ this.jsonInit({
37
+ "message0": "%1",
38
+ "args0": [
39
+ {
40
+ "type": "field_dropdown",
41
+ "name": "SOUND_MENU",
42
+ "options": [
43
+ ['1', '0'],
44
+ ['2', '1'],
45
+ ['3', '2'],
46
+ ['4', '3'],
47
+ ['5', '4'],
48
+ ['6', '5'],
49
+ ['7', '6'],
50
+ ['8', '7'],
51
+ ['9', '8'],
52
+ ['10', '9'],
53
+ ['call a function', function() {
54
+ window.alert('function called!');}
55
+ ]
56
+ ]
57
+ }
58
+ ],
59
+ "colour": Blockly.Colours.sounds.secondary,
60
+ "colourSecondary": Blockly.Colours.sounds.secondary,
61
+ "colourTertiary": Blockly.Colours.sounds.tertiary,
62
+ "extensions": ["output_string"]
63
+ });
64
+ }
65
+ };
66
+
67
+ Blockly.Blocks['sound_play'] = {
68
+ /**
69
+ * Block to play sound.
70
+ * @this Blockly.Block
71
+ */
72
+ init: function() {
73
+ this.jsonInit({
74
+ "message0": Blockly.Msg.SOUND_PLAY,
75
+ "args0": [
76
+ {
77
+ "type": "input_value",
78
+ "name": "SOUND_MENU"
79
+ }
80
+ ],
81
+ "category": Blockly.Categories.sound,
82
+ "extensions": ["colours_sounds", "shape_statement"]
83
+ });
84
+ }
85
+ };
86
+
87
+ Blockly.Blocks['sound_playuntildone'] = {
88
+ /**
89
+ * Block to play sound until done.
90
+ * @this Blockly.Block
91
+ */
92
+ init: function() {
93
+ this.jsonInit({
94
+ "message0": Blockly.Msg.SOUND_PLAYUNTILDONE,
95
+ "args0": [
96
+ {
97
+ "type": "input_value",
98
+ "name": "SOUND_MENU"
99
+ }
100
+ ],
101
+ "category": Blockly.Categories.sound,
102
+ "extensions": ["colours_sounds", "shape_statement"]
103
+ });
104
+ }
105
+ };
106
+
107
+ Blockly.Blocks['sound_stop'] = {
108
+ /**
109
+ * pm: Block to stop a sound.
110
+ * @this Blockly.Block
111
+ */
112
+ init: function() {
113
+ this.jsonInit({
114
+ "message0": "stop sound %1",
115
+ "args0": [
116
+ {
117
+ "type": "input_value",
118
+ "name": "SOUND_MENU"
119
+ }
120
+ ],
121
+ "category": Blockly.Categories.sound,
122
+ "extensions": ["colours_sounds", "shape_statement"]
123
+ });
124
+ }
125
+ };
126
+
127
+ Blockly.Blocks['sound_pause'] = {
128
+ /**
129
+ * pm: Block to pause a sound.
130
+ * @this Blockly.Block
131
+ */
132
+ init: function () {
133
+ this.jsonInit({
134
+ "message0": "pause sound %1",
135
+ "args0": [
136
+ {
137
+ "type": "input_value",
138
+ "name": "SOUND_MENU"
139
+ }
140
+ ],
141
+ "category": Blockly.Categories.sound,
142
+ "extensions": ["colours_sounds", "shape_statement"]
143
+ });
144
+ }
145
+ };
146
+
147
+ Blockly.Blocks['sound_set_stop_fadeout_to'] = {
148
+ /**
149
+ * pm: Block to set the fadeout time on a sound.
150
+ * The fadeout time is used when the sound is stopped in any way.
151
+ * @this Blockly.Block
152
+ */
153
+ init: function () {
154
+ this.jsonInit({
155
+ "message0": "set fade out to %1 seconds on %2",
156
+ "args0": [
157
+ {
158
+ "type": "input_value",
159
+ "name": "VALUE"
160
+ },
161
+ {
162
+ "type": "input_value",
163
+ "name": "SOUND_MENU"
164
+ }
165
+ ],
166
+ "category": Blockly.Categories.sound,
167
+ "extensions": ["colours_sounds", "shape_statement"]
168
+ });
169
+ }
170
+ };
171
+
172
+ Blockly.Blocks['sound_play_at_seconds'] = {
173
+ /**
174
+ * pm: Block to start a sound at a specific time position.
175
+ * @this Blockly.Block
176
+ */
177
+ init: function () {
178
+ this.jsonInit({
179
+ "message0": "start sound %1 at %2 seconds",
180
+ "args0": [
181
+ {
182
+ "type": "input_value",
183
+ "name": "SOUND_MENU"
184
+ },
185
+ {
186
+ "type": "input_value",
187
+ "name": "VALUE"
188
+ }
189
+ ],
190
+ "category": Blockly.Categories.sound,
191
+ "extensions": ["colours_sounds", "shape_statement"]
192
+ });
193
+ }
194
+ };
195
+
196
+ Blockly.Blocks['sound_play_at_seconds_until_done'] = {
197
+ /**
198
+ * pm: Block to start a sound at a specific time position.
199
+ * This block will wait until the sound is actually finished
200
+ * before continuing the stack.
201
+ * @this Blockly.Block
202
+ */
203
+ init: function () {
204
+ this.jsonInit({
205
+ "message0": "play sound %1 starting at %2 seconds until done",
206
+ "args0": [
207
+ {
208
+ "type": "input_value",
209
+ "name": "SOUND_MENU"
210
+ },
211
+ {
212
+ "type": "input_value",
213
+ "name": "VALUE"
214
+ }
215
+ ],
216
+ "category": Blockly.Categories.sound,
217
+ "extensions": ["colours_sounds", "shape_statement"]
218
+ });
219
+ }
220
+ };
221
+
222
+ Blockly.Blocks['sound_stopallsounds'] = {
223
+ /**
224
+ * Block to stop all sounds
225
+ * @this Blockly.Block
226
+ */
227
+ init: function() {
228
+ this.jsonInit({
229
+ "message0": Blockly.Msg.SOUND_STOPALLSOUNDS,
230
+ "category": Blockly.Categories.sound,
231
+ "extensions": ["colours_sounds", "shape_statement"]
232
+ });
233
+ }
234
+ };
235
+
236
+ Blockly.Blocks['sound_pauseallsounds'] = {
237
+ /**
238
+ * pm: Block to pause all sounds
239
+ * @this Blockly.Block
240
+ */
241
+ init: function() {
242
+ this.jsonInit({
243
+ "message0": "pause all sounds",
244
+ "category": Blockly.Categories.sound,
245
+ "extensions": ["colours_sounds", "shape_statement"]
246
+ });
247
+ }
248
+ };
249
+
250
+ Blockly.Blocks['sound_playallsounds'] = {
251
+ /**
252
+ * pm: Block to play all sounds
253
+ * @this Blockly.Block
254
+ */
255
+ init: function() {
256
+ this.jsonInit({
257
+ "message0": "play all sounds",
258
+ "category": Blockly.Categories.sound,
259
+ "extensions": ["colours_sounds", "shape_statement"]
260
+ });
261
+ }
262
+ };
263
+
264
+ Blockly.Blocks['sound_seteffectto'] = {
265
+ /**
266
+ * Block to set the audio effect
267
+ * @this Blockly.Block
268
+ */
269
+ init: function() {
270
+ this.jsonInit({
271
+ "message0": Blockly.Msg.SOUND_SETEFFECTO,
272
+ "args0": [
273
+ {
274
+ "type": "field_dropdown",
275
+ "name": "EFFECT",
276
+ "options": [
277
+ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'],
278
+ [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN']
279
+ ]
280
+ },
281
+ {
282
+ "type": "input_value",
283
+ "name": "VALUE"
284
+ }
285
+ ],
286
+ "category": Blockly.Categories.sound,
287
+ "extensions": ["colours_sounds", "shape_statement"]
288
+ });
289
+ }
290
+ };
291
+
292
+
293
+ Blockly.Blocks['sound_changeeffectby'] = {
294
+ /**
295
+ * Block to change the audio effect
296
+ * @this Blockly.Block
297
+ */
298
+ init: function() {
299
+ this.jsonInit({
300
+ "message0": Blockly.Msg.SOUND_CHANGEEFFECTBY,
301
+ "args0": [
302
+ {
303
+ "type": "field_dropdown",
304
+ "name": "EFFECT",
305
+ "options": [
306
+ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'],
307
+ [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN']
308
+ ]
309
+ },
310
+ {
311
+ "type": "input_value",
312
+ "name": "VALUE"
313
+ }
314
+ ],
315
+ "category": Blockly.Categories.sound,
316
+ "extensions": ["colours_sounds", "shape_statement"]
317
+ });
318
+ }
319
+ };
320
+
321
+ Blockly.Blocks['sound_cleareffects'] = {
322
+ /**
323
+ * Block to clear audio effects
324
+ * @this Blockly.Block
325
+ */
326
+ init: function() {
327
+ this.jsonInit({
328
+ "message0": Blockly.Msg.SOUND_CLEAREFFECTS,
329
+ "category": Blockly.Categories.sound,
330
+ "extensions": ["colours_sounds", "shape_statement"]
331
+ });
332
+ }
333
+ };
334
+
335
+ Blockly.Blocks['sound_getEffectValue'] = {
336
+ /**
337
+ * pm: Block to report sound effect values
338
+ * @this Blockly.Block
339
+ */
340
+ init: function() {
341
+ this.jsonInit({
342
+ "inputsInline": true,
343
+ "message0": "%1 effect",
344
+ "checkboxInFlyout": true,
345
+ "category": Blockly.Categories.sound,
346
+ "args0": [
347
+ {
348
+ "type": "field_dropdown",
349
+ "name": "EFFECT",
350
+ "options": [
351
+ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'],
352
+ [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN']
353
+ ]
354
+ }
355
+ ],
356
+ "extensions": ["colours_sounds", "output_number"]
357
+ });
358
+ }
359
+ };
360
+
361
+ Blockly.Blocks['sound_changevolumeby'] = {
362
+ /**
363
+ * Block to change the sprite's volume by a certain value
364
+ * @this Blockly.Block
365
+ */
366
+ init: function() {
367
+ this.jsonInit({
368
+ "message0": Blockly.Msg.SOUND_CHANGEVOLUMEBY,
369
+ "args0": [
370
+ {
371
+ "type": "input_value",
372
+ "name": "VOLUME"
373
+ }
374
+ ],
375
+ "category": Blockly.Categories.sound,
376
+ "extensions": ["colours_sounds", "shape_statement"]
377
+ });
378
+ }
379
+ };
380
+
381
+ Blockly.Blocks['sound_setvolumeto'] = {
382
+ /**
383
+ * Block to set the sprite's volume to a certain percent
384
+ * @this Blockly.Block
385
+ */
386
+ init: function() {
387
+ this.jsonInit({
388
+ "message0": Blockly.Msg.SOUND_SETVOLUMETO,
389
+ "args0": [
390
+ {
391
+ "type": "input_value",
392
+ "name": "VOLUME"
393
+ }
394
+ ],
395
+ "category": Blockly.Categories.sound,
396
+ "extensions": ["colours_sounds", "shape_statement"]
397
+ });
398
+ }
399
+ };
400
+
401
+ Blockly.Blocks['sound_volume'] = {
402
+ /**
403
+ * Block to report volume
404
+ * @this Blockly.Block
405
+ */
406
+ init: function() {
407
+ this.jsonInit({
408
+ "message0": Blockly.Msg.SOUND_VOLUME,
409
+ "category": Blockly.Categories.sound,
410
+ "checkboxInFlyout": true,
411
+ "extensions": ["colours_sounds", "output_number"]
412
+ });
413
+ }
414
+ };
415
+
416
+ Blockly.Blocks["sound_isSoundPlaying"] = {
417
+ init: function() {
418
+ this.jsonInit({
419
+ "inputsInline": true,
420
+ "category": Blockly.Categories.sound,
421
+ "message0": "is %1 playing?",
422
+ "args0": [
423
+ {
424
+ "type": "input_value",
425
+ "name": "SOUND_MENU"
426
+ }
427
+ ],
428
+ "extensions": [
429
+ "output_boolean",
430
+ "colours_sounds"
431
+ ]
432
+ });
433
+ }
434
+ };
435
+
436
+ Blockly.Blocks['sound_getLength'] = {
437
+ /**
438
+ * pm: Block to report the length of a sound.
439
+ * @this Blockly.Block
440
+ */
441
+ init: function() {
442
+ this.jsonInit({
443
+ "message0": "length of %1",
444
+ "args0": [
445
+ {
446
+ "type": "input_value",
447
+ "name": "SOUND_MENU"
448
+ }
449
+ ],
450
+ "category": Blockly.Categories.sound,
451
+ "extensions": ["colours_sounds", "output_number"]
452
+ });
453
+ }
454
+ };
455
+
456
+ Blockly.Blocks['sound_getTimePosition'] = {
457
+ /**
458
+ * pm: Block to report the current time position of a sound.
459
+ * @this Blockly.Block
460
+ */
461
+ init: function () {
462
+ this.jsonInit({
463
+ "message0": "current time position of %1",
464
+ "args0": [
465
+ {
466
+ "type": "input_value",
467
+ "name": "SOUND_MENU"
468
+ }
469
+ ],
470
+ "category": Blockly.Categories.sound,
471
+ "extensions": ["colours_sounds", "output_number"]
472
+ });
473
+ }
474
+ };
475
+
476
+ Blockly.Blocks['sound_getSoundVolume'] = {
477
+ /**
478
+ * pm: Block to report the volume of a sound at the current position.
479
+ * @this Blockly.Block
480
+ */
481
+ init: function () {
482
+ this.jsonInit({
483
+ "message0": "current volume of %1",
484
+ "args0": [
485
+ {
486
+ "type": "input_value",
487
+ "name": "SOUND_MENU"
488
+ }
489
+ ],
490
+ "category": Blockly.Categories.sound,
491
+ "extensions": ["colours_sounds", "output_number"]
492
+ });
493
+ }
494
+ };
blocks_vertical/vertical_extensions.js ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2017 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Extensions for vertical blocks in scratch-blocks.
23
+ * The following extensions can be used to describe a block in Scratch terms.
24
+ * For instance, a block in the operators colour scheme with a number output
25
+ * would have the "colours_operators" and "output_number" extensions.
26
+ * @author [email protected] (Rachel Fenichel)
27
+ */
28
+ 'use strict';
29
+
30
+ goog.provide('Blockly.ScratchBlocks.VerticalExtensions');
31
+
32
+ goog.require('Blockly.Colours');
33
+ goog.require('Blockly.constants');
34
+
35
+
36
+ /**
37
+ * Helper function that generates an extension based on a category name.
38
+ * The generated function will set primary, secondary, and tertiary colours
39
+ * based on the category name.
40
+ * @param {String} category The name of the category to set colours for.
41
+ * @return {function} An extension function that sets colours based on the given
42
+ * category.
43
+ */
44
+ Blockly.ScratchBlocks.VerticalExtensions.colourHelper = function(category) {
45
+ var colours = Blockly.Colours[category];
46
+ if (!(colours && colours.primary && colours.secondary && colours.tertiary)) {
47
+ throw new Error('Could not find colours for category "' + category + '"');
48
+ }
49
+ /**
50
+ * Set the primary, secondary, and tertiary colours on this block for the
51
+ * given category.
52
+ * @this {Blockly.Block}
53
+ */
54
+ return function() {
55
+ this.setColourFromRawValues_(colours.primary, colours.secondary,
56
+ colours.tertiary);
57
+ };
58
+ };
59
+
60
+ /**
61
+ * Extension to set the colours of a text field, which are all the same.
62
+ */
63
+ Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD = function() {
64
+ this.setColourFromRawValues_(Blockly.Colours.textField,
65
+ Blockly.Colours.textField, Blockly.Colours.textField);
66
+ };
67
+
68
+ /**
69
+ * Extension to make a block fit into a stack of statements, regardless of its
70
+ * inputs. That means the block should have a previous connection and a next
71
+ * connection and have inline inputs.
72
+ * @this {Blockly.Block}
73
+ * @readonly
74
+ */
75
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_PROCEDURE = function() {
76
+ this.setInputsInline(true);
77
+ this.setPreviousStatement(true, 'procedure');
78
+ this.setNextStatement(true, 'procedure');
79
+ };
80
+
81
+ /**
82
+ * Extension to make a block fit into a stack of statements, regardless of its
83
+ * inputs. That means the block should have a previous connection and a next
84
+ * connection and have inline inputs.
85
+ * @this {Blockly.Block}
86
+ * @readonly
87
+ */
88
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_CASE = function() {
89
+ this.setInputsInline(true);
90
+ this.setPreviousStatement(true, 'switchCase');
91
+ this.setNextStatement(true, 'switchCase');
92
+ };
93
+
94
+ /**
95
+ * Extension to make a block fit into a stack of statements, regardless of its
96
+ * inputs. That means the block should have a previous connection and a next
97
+ * connection and have inline inputs.
98
+ * @this {Blockly.Block}
99
+ * @readonly
100
+ */
101
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT = function() {
102
+ this.setInputsInline(true);
103
+ this.setPreviousStatement(true, 'normal');
104
+ this.setNextStatement(true, 'normal');
105
+ };
106
+
107
+ /**
108
+ * Extension to make a block be shaped as a hat block, regardless of its
109
+ * inputs. That means the block should have a next connection and have inline
110
+ * inputs, but have no previous connection.
111
+ * @this {Blockly.Block}
112
+ * @readonly
113
+ */
114
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT = function() {
115
+ this.setInputsInline(true);
116
+ this.setNextStatement(true, 'normal');
117
+ };
118
+
119
+ /**
120
+ * Extension to make a block be shaped as an end block, regardless of its
121
+ * inputs. That means the block should have a previous connection and have
122
+ * inline inputs, but have no next connection.
123
+ * @this {Blockly.Block}
124
+ * @readonly
125
+ */
126
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END = function() {
127
+ this.setInputsInline(true);
128
+ this.setPreviousStatement(true, 'normal');
129
+ };
130
+
131
+ /**
132
+ * Extension to make represent a number reporter in Scratch-Blocks.
133
+ * That means the block has inline inputs, a round output shape, and a 'Number'
134
+ * output type.
135
+ * @this {Blockly.Block}
136
+ * @readonly
137
+ */
138
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER = function() {
139
+ this.setInputsInline(true);
140
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
141
+ this.setOutput(true, 'Number');
142
+ };
143
+
144
+ /**
145
+ * Extension to make represent a string reporter in Scratch-Blocks.
146
+ * That means the block has inline inputs, a round output shape, and a 'String'
147
+ * output type.
148
+ * @this {Blockly.Block}
149
+ * @readonly
150
+ */
151
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING = function() {
152
+ this.setInputsInline(true);
153
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
154
+ this.setOutput(true, 'String');
155
+ };
156
+
157
+ /**
158
+ * Extension to make represent a boolean reporter in Scratch-Blocks.
159
+ * That means the block has inline inputs, a round output shape, and a 'Boolean'
160
+ * output type.
161
+ * @this {Blockly.Block}
162
+ * @readonly
163
+ */
164
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN = function() {
165
+ this.setInputsInline(true);
166
+ this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
167
+ this.setOutput(true, 'Boolean');
168
+ };
169
+
170
+ /**
171
+ * Mixin to add a context menu for a procedure definition block.
172
+ * It adds the "edit" option and removes the "duplicate" option.
173
+ * @mixin
174
+ * @augments Blockly.Block
175
+ * @package
176
+ * @readonly
177
+ */
178
+ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = {
179
+ /**
180
+ * Add the "edit" option and removes the "duplicate" option from the context
181
+ * menu.
182
+ * @param {!Array.<!Object>} menuOptions List of menu options to edit.
183
+ * @this Blockly.Block
184
+ */
185
+ customContextMenu: function(menuOptions) {
186
+ // Add the edit option at the end.
187
+ menuOptions.push(Blockly.Procedures.makeEditOption(this));
188
+
189
+ // Find the delete option and update its callback to be specific to
190
+ // functions.
191
+ for (var i = 0, option; option = menuOptions[i]; i++) {
192
+ if (option.text == Blockly.Msg.DELETE_BLOCK) {
193
+ var input = this.getInput('custom_block');
194
+ // this is the root block, not the shadow block.
195
+ if (input && input.connection && input.connection.targetBlock()) {
196
+ var procCode = input.connection.targetBlock().getProcCode();
197
+ } else {
198
+ return;
199
+ }
200
+ var rootBlock = this;
201
+ option.callback = function() {
202
+ var didDelete = Blockly.Procedures.deleteProcedureDefCallback(
203
+ procCode, rootBlock);
204
+ if (!didDelete) {
205
+ alert(Blockly.Msg.PROCEDURE_USED);
206
+ }
207
+ };
208
+ }
209
+ }
210
+ // Find and remove the duplicate option
211
+ for (var i = 0, option; option = menuOptions[i]; i++) {
212
+ if (option.text == Blockly.Msg.DUPLICATE) {
213
+ menuOptions.splice(i, 1);
214
+ break;
215
+ }
216
+ }
217
+ }
218
+ };
219
+
220
+ /**
221
+ * Mixin to add a context menu for a procedure call block.
222
+ * It adds the "edit" option and the "define" option.
223
+ * @mixin
224
+ * @augments Blockly.Block
225
+ * @package
226
+ * @readonly
227
+ */
228
+ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = {
229
+ /**
230
+ * Add the "edit" option to the context menu.
231
+ * @todo Add "go to definition" option once implemented.
232
+ * @param {!Array.<!Object>} menuOptions List of menu options to edit.
233
+ * @this Blockly.Block
234
+ */
235
+ customContextMenu: function(menuOptions) {
236
+ menuOptions.push(Blockly.Procedures.makeEditOption(this));
237
+ }
238
+ };
239
+
240
+
241
+ Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() {
242
+ this.isScratchExtension = true;
243
+ };
244
+
245
+ /**
246
+ * Register all extensions for scratch-blocks.
247
+ * @package
248
+ */
249
+ Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() {
250
+ var categoryNames =
251
+ ['control', 'data', 'data_lists', 'sounds', 'motion', 'looks', 'event',
252
+ 'sensing', 'pen', 'operators', 'more'];
253
+ // Register functions for all category colours.
254
+ for (var i = 0; i < categoryNames.length; i++) {
255
+ var name = categoryNames[i];
256
+ Blockly.Extensions.register('colours_' + name,
257
+ Blockly.ScratchBlocks.VerticalExtensions.colourHelper(name));
258
+ }
259
+
260
+ // Text fields transcend categories.
261
+ Blockly.Extensions.register('colours_textfield',
262
+ Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD);
263
+
264
+ // Register extensions for common block shapes.
265
+ Blockly.Extensions.register('shape_procedure',
266
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_PROCEDURE);
267
+ Blockly.Extensions.register('shape_case',
268
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_CASE);
269
+ Blockly.Extensions.register('shape_statement',
270
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT);
271
+ Blockly.Extensions.register('shape_hat',
272
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT);
273
+ Blockly.Extensions.register('shape_end',
274
+ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END);
275
+
276
+ // Output shapes and types are related.
277
+ Blockly.Extensions.register('output_number',
278
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER);
279
+ Blockly.Extensions.register('output_string',
280
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING);
281
+ Blockly.Extensions.register('output_boolean',
282
+ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN);
283
+
284
+ // Custom procedures have interesting context menus.
285
+ Blockly.Extensions.registerMixin('procedure_def_contextmenu',
286
+ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU);
287
+ Blockly.Extensions.registerMixin('procedure_call_contextmenu',
288
+ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU);
289
+
290
+ // Extension blocks have slightly different block rendering.
291
+ Blockly.Extensions.register('scratch_extension',
292
+ Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION);
293
+ };
294
+
295
+ Blockly.ScratchBlocks.VerticalExtensions.registerAll();
build.py ADDED
@@ -0,0 +1,608 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python2.7
2
+ # Compresses the core Blockly files into a single JavaScript file.
3
+ #
4
+ # Copyright 2012 Google Inc.
5
+ # https://developers.google.com/blockly/
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ # This script generates two versions of Blockly's core files:
20
+ # blockly_compressed.js
21
+ # blockly_uncompressed.js
22
+ # The compressed file is a concatenation of all of Blockly's core files which
23
+ # have been run through Google's Closure Compiler. This is done using the
24
+ # online API (which takes a few seconds and requires an Internet connection).
25
+ # The uncompressed file is a script that loads in each of Blockly's core files
26
+ # one by one. This takes much longer for a browser to load, but is useful
27
+ # when debugging code since line numbers are meaningful and variables haven't
28
+ # been renamed. The uncompressed file also allows for a faster developement
29
+ # cycle since there is no need to rebuild or recompile, just reload.
30
+ #
31
+ # This script also generates:
32
+ # blocks_compressed.js: The compressed common blocks.
33
+ # blocks_vertical_compressed.js: The compressed Scratch vertical blocks.
34
+ # msg/js/<LANG>.js for every language <LANG> defined in msg/js/<LANG>.json.
35
+
36
+ import sys
37
+ if sys.version_info[0] != 2:
38
+ raise Exception("Blockly build only compatible with Python 2.x.\n"
39
+ "You are using: " + sys.version)
40
+
41
+ import errno, glob, httplib, json, os, re, subprocess, threading, urllib
42
+
43
+ REMOTE_COMPILER = "remote"
44
+
45
+ CLOSURE_DIR = os.path.pardir
46
+ CLOSURE_ROOT = os.path.pardir
47
+ CLOSURE_LIBRARY = "closure-library"
48
+ CLOSURE_COMPILER = REMOTE_COMPILER
49
+
50
+ CLOSURE_DIR_NPM = "node_modules"
51
+ CLOSURE_ROOT_NPM = os.path.join("node_modules")
52
+ CLOSURE_LIBRARY_NPM = "google-closure-library"
53
+ CLOSURE_COMPILER_NPM = ("google-closure-compiler.cmd" if os.name == "nt" else "google-closure-compiler")
54
+
55
+ def import_path(fullpath):
56
+ """Import a file with full path specification.
57
+ Allows one to import from any directory, something __import__ does not do.
58
+
59
+ Args:
60
+ fullpath: Path and filename of import.
61
+
62
+ Returns:
63
+ An imported module.
64
+ """
65
+ path, filename = os.path.split(fullpath)
66
+ filename, ext = os.path.splitext(filename)
67
+ sys.path.append(path)
68
+ module = __import__(filename)
69
+ reload(module) # Might be out of date.
70
+ del sys.path[-1]
71
+ return module
72
+
73
+ def read(filename):
74
+ f = open(filename)
75
+ content = "".join(f.readlines())
76
+ f.close()
77
+ return content
78
+
79
+ HEADER = ("// Do not edit this file; automatically generated by build.py.\n"
80
+ "'use strict';\n")
81
+
82
+
83
+ class Gen_uncompressed(threading.Thread):
84
+ """Generate a JavaScript file that loads Blockly's raw files.
85
+ Runs in a separate thread.
86
+ """
87
+ def __init__(self, search_paths, vertical, closure_env):
88
+ threading.Thread.__init__(self)
89
+ self.search_paths = search_paths
90
+ self.vertical = vertical
91
+ self.closure_env = closure_env
92
+
93
+ def run(self):
94
+ target_filename = 'blockly_uncompressed_vertical.js'
95
+ f = open(target_filename, 'w')
96
+ f.write(HEADER)
97
+ f.write(self.format_js("""
98
+ var isNodeJS = !!(typeof module !== 'undefined' && module.exports &&
99
+ typeof window === 'undefined');
100
+
101
+ if (isNodeJS) {
102
+ var window = {};
103
+ require('{closure_library}');
104
+ }
105
+
106
+ window.BLOCKLY_DIR = (function() {
107
+ if (!isNodeJS) {
108
+ // Find name of current directory.
109
+ var scripts = document.getElementsByTagName('script');
110
+ var re = new RegExp('(.+)[\/]blockly_uncompressed_vertical\.js$');
111
+ for (var i = 0, script; script = scripts[i]; i++) {
112
+ var match = re.exec(script.src);
113
+ if (match) {
114
+ return match[1];
115
+ }
116
+ }
117
+ alert('Could not detect Blockly\\'s directory name.');
118
+ }
119
+ return '';
120
+ })();
121
+
122
+ window.BLOCKLY_BOOT = function() {
123
+ var dir = '';
124
+ if (isNodeJS) {
125
+ require('{closure_library}');
126
+ dir = 'blockly';
127
+ } else {
128
+ // Execute after Closure has loaded.
129
+ if (!window.goog) {
130
+ alert('Error: Closure not found. Read this:\\n' +
131
+ 'developers.google.com/blockly/guides/modify/web/closure');
132
+ }
133
+ if (window.BLOCKLY_DIR.search(/node_modules/)) {
134
+ dir = '..';
135
+ } else {
136
+ dir = window.BLOCKLY_DIR.match(/[^\\/]+$/)[0];
137
+ }
138
+ }
139
+ """))
140
+ add_dependency = []
141
+ base_path = calcdeps.FindClosureBasePath(self.search_paths)
142
+ for dep in calcdeps.BuildDependenciesFromFiles(self.search_paths):
143
+ add_dependency.append(calcdeps.GetDepsLine(dep, base_path))
144
+ add_dependency.sort() # Deterministic build.
145
+ add_dependency = '\n'.join(add_dependency)
146
+ # Find the Blockly directory name and replace it with a JS variable.
147
+ # This allows blockly_uncompressed.js to be compiled on one computer and be
148
+ # used on another, even if the directory name differs.
149
+ m = re.search('[\\/]([^\\/]+)[\\/]core[\\/]blockly.js', add_dependency)
150
+ add_dependency = re.sub('([\\/])' + re.escape(m.group(1)) +
151
+ '([\\/]core[\\/])', '\\1" + dir + "\\2', add_dependency)
152
+ f.write(add_dependency + '\n')
153
+
154
+ provides = []
155
+ for dep in calcdeps.BuildDependenciesFromFiles(self.search_paths):
156
+ # starts with '../' or 'node_modules/'
157
+ if not dep.filename.startswith(self.closure_env["closure_root"] + os.sep):
158
+ provides.extend(dep.provides)
159
+ provides.sort() # Deterministic build.
160
+ f.write('\n')
161
+ f.write('// Load Blockly.\n')
162
+ for provide in provides:
163
+ f.write("goog.require('%s');\n" % provide)
164
+
165
+ f.write(self.format_js("""
166
+ delete this.BLOCKLY_DIR;
167
+ delete this.BLOCKLY_BOOT;
168
+ };
169
+
170
+ if (isNodeJS) {
171
+ window.BLOCKLY_BOOT();
172
+ module.exports = Blockly;
173
+ } else {
174
+ // Delete any existing Closure (e.g. Soy's nogoog_shim).
175
+ document.write('<script>var goog = undefined;</script>');
176
+ // Load fresh Closure Library.
177
+ document.write('<script src="' + window.BLOCKLY_DIR +
178
+ '/{closure_dir}/{closure_library}/closure/goog/base.js"></script>');
179
+ document.write('<script>window.BLOCKLY_BOOT();</script>');
180
+ }
181
+ """))
182
+ f.close()
183
+ print("SUCCESS: " + target_filename)
184
+
185
+ def format_js(self, code):
186
+ """Format JS in a way that python's format method can work with to not
187
+ consider brace-wrapped sections to be format replacements while still
188
+ replacing known keys.
189
+ """
190
+
191
+ key_whitelist = self.closure_env.keys()
192
+
193
+ keys_pipe_separated = reduce(lambda accum, key: accum + "|" + key, key_whitelist)
194
+ begin_brace = re.compile(r"\{(?!%s)" % (keys_pipe_separated,))
195
+
196
+ end_brace = re.compile(r"\}")
197
+ def end_replacement(match):
198
+ try:
199
+ maybe_key = match.string[match.string[:match.start()].rindex("{") + 1:match.start()]
200
+ except ValueError:
201
+ return "}}"
202
+
203
+ if maybe_key and maybe_key in key_whitelist:
204
+ return "}"
205
+ else:
206
+ return "}}"
207
+
208
+ return begin_brace.sub("{{", end_brace.sub(end_replacement, code)).format(**self.closure_env)
209
+
210
+ class Gen_compressed(threading.Thread):
211
+ """Generate a JavaScript file that contains all of Blockly's core and all
212
+ required parts of Closure, compiled together.
213
+ Uses the Closure Compiler's online API.
214
+ Runs in a separate thread.
215
+ """
216
+ def __init__(self, search_paths_vertical, closure_env):
217
+ threading.Thread.__init__(self)
218
+ self.search_paths_vertical = search_paths_vertical
219
+ self.closure_env = closure_env
220
+
221
+ def run(self):
222
+ self.gen_core(True)
223
+ self.gen_core(False)
224
+ self.gen_blocks("vertical")
225
+ self.gen_blocks("common")
226
+
227
+ def gen_core(self, vertical):
228
+ target_filename = 'blockly_compressed_vertical.js'
229
+ search_paths = self.search_paths_vertical
230
+ # Define the parameters for the POST request.
231
+ params = [
232
+ ("compilation_level", "SIMPLE"),
233
+
234
+ # remote will filter this out
235
+ ("language_in", "ECMASCRIPT_2017"),
236
+ ("language_out", "ECMASCRIPT5"),
237
+ ("rewrite_polyfills", "false"),
238
+ ("define", "goog.DEBUG=false"),
239
+
240
+ # local will filter this out
241
+ ("use_closure_library", "true"),
242
+ ]
243
+
244
+ # Read in all the source files.
245
+ filenames = calcdeps.CalculateDependencies(search_paths,
246
+ [os.path.join("core", "blockly.js")])
247
+ filenames.sort() # Deterministic build.
248
+ for filename in filenames:
249
+ # Append filenames as false arguments the step before compiling will
250
+ # either transform them into arguments for local or remote compilation
251
+ params.append(("js_file", filename))
252
+
253
+ self.do_compile(params, target_filename, filenames, "")
254
+
255
+ def gen_blocks(self, block_type):
256
+ if block_type == "vertical":
257
+ target_filename = "blocks_compressed_vertical.js"
258
+ filenames = glob.glob(os.path.join("blocks_vertical", "*.js"))
259
+ elif block_type == "common":
260
+ target_filename = "blocks_compressed.js"
261
+ filenames = glob.glob(os.path.join("blocks_common", "*.js"))
262
+
263
+ # glob.glob ordering is platform-dependent and not necessary deterministic
264
+ filenames.sort() # Deterministic build.
265
+
266
+ # Define the parameters for the POST request.
267
+ params = [
268
+ ("compilation_level", "SIMPLE"),
269
+ ]
270
+
271
+ # Read in all the source files.
272
+ # Add Blockly.Blocks to be compatible with the compiler.
273
+ params.append(("js_file", os.path.join("build", "gen_blocks.js")))
274
+ # Add Blockly.Colours for use of centralized colour bank
275
+ filenames.append(os.path.join("core", "colours.js"))
276
+ filenames.append(os.path.join("core", "constants.js"))
277
+
278
+ for filename in filenames:
279
+ # Append filenames as false arguments the step before compiling will
280
+ # either transform them into arguments for local or remote compilation
281
+ params.append(("js_file", filename))
282
+
283
+ # Remove Blockly.Blocks to be compatible with Blockly.
284
+ remove = "var Blockly={Blocks:{}};"
285
+ self.do_compile(params, target_filename, filenames, remove)
286
+
287
+ def do_compile(self, params, target_filename, filenames, remove):
288
+ if self.closure_env["closure_compiler"] == REMOTE_COMPILER:
289
+ do_compile = self.do_compile_remote
290
+ else:
291
+ do_compile = self.do_compile_local
292
+ json_data = do_compile(params, target_filename)
293
+
294
+ if self.report_errors(target_filename, filenames, json_data):
295
+ self.write_output(target_filename, remove, json_data)
296
+ self.report_stats(target_filename, json_data)
297
+
298
+ def do_compile_local(self, params, target_filename):
299
+ filter_keys = ["use_closure_library"]
300
+
301
+ # Drop arg if arg is js_file else add dashes
302
+ dash_params = []
303
+ for (arg, value) in params:
304
+ dash_params.append((value,) if arg == "js_file" else ("--" + arg, value))
305
+
306
+ # Flatten dash_params into dash_args if their keys are not in filter_keys
307
+ dash_args = []
308
+ for pair in dash_params:
309
+ if pair[0][2:] not in filter_keys:
310
+ dash_args.extend(pair)
311
+
312
+ # Build the final args array by prepending CLOSURE_COMPILER_NPM to
313
+ # dash_args and dropping any falsy members
314
+ args = []
315
+ for group in [[CLOSURE_COMPILER_NPM], dash_args]:
316
+ args.extend(filter(lambda item: item, group))
317
+
318
+ proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
319
+ (stdout, stderr) = proc.communicate()
320
+
321
+ # Build the JSON response.
322
+ filesizes = [os.path.getsize(value) for (arg, value) in params if arg == "js_file"]
323
+ return dict(
324
+ compiledCode=stdout,
325
+ statistics=dict(
326
+ originalSize=reduce(lambda v, size: v + size, filesizes, 0),
327
+ compressedSize=len(stdout),
328
+ )
329
+ )
330
+
331
+ def do_compile_remote(self, params, target_filename):
332
+ filter_keys = [
333
+ "language_in",
334
+ "language_out",
335
+ "rewrite_polyfills",
336
+ "define",
337
+ ]
338
+
339
+ params.extend([
340
+ ("output_format", "json"),
341
+ ("output_info", "compiled_code"),
342
+ ("output_info", "warnings"),
343
+ ("output_info", "errors"),
344
+ ("output_info", "statistics"),
345
+ ])
346
+
347
+ # Send the request to Google.
348
+ remoteParams = []
349
+ for (arg, value) in params:
350
+ if not arg in filter_keys:
351
+ if arg == "js_file":
352
+ if not value.startswith(self.closure_env["closure_root"] + os.sep):
353
+ remoteParams.append(("js_code", read(value)))
354
+ # Change the normal compilation_level value SIMPLE to the remove
355
+ # service's SIMPLE_OPTIMIZATIONS
356
+ elif arg == "compilation_level" and value == "SIMPLE":
357
+ remoteParams.append((arg, "SIMPLE_OPTIMIZATIONS"))
358
+ else:
359
+ remoteParams.append((arg, value))
360
+
361
+ headers = {"Content-type": "application/x-www-form-urlencoded"}
362
+ conn = httplib.HTTPSConnection("closure-compiler.appspot.com")
363
+ conn.request("POST", "/compile", urllib.urlencode(remoteParams), headers)
364
+ response = conn.getresponse()
365
+ json_str = response.read()
366
+ conn.close()
367
+
368
+ # Parse the JSON response.
369
+ return json.loads(json_str)
370
+
371
+ def report_errors(self, target_filename, filenames, json_data):
372
+ def file_lookup(name):
373
+ if not name.startswith("Input_"):
374
+ return "???"
375
+ n = int(name[6:]) - 1
376
+ return filenames[n]
377
+
378
+ if json_data.has_key("serverErrors"):
379
+ errors = json_data["serverErrors"]
380
+ for error in errors:
381
+ print("SERVER ERROR: %s" % target_filename)
382
+ print(error["error"])
383
+ elif json_data.has_key("errors"):
384
+ errors = json_data["errors"]
385
+ for error in errors:
386
+ print("FATAL ERROR")
387
+ print(error["error"])
388
+ if error["file"]:
389
+ print("%s at line %d:" % (
390
+ file_lookup(error["file"]), error["lineno"]))
391
+ print(error["line"])
392
+ print((" " * error["charno"]) + "^")
393
+ sys.exit(1)
394
+ else:
395
+ if json_data.has_key("warnings"):
396
+ warnings = json_data["warnings"]
397
+ for warning in warnings:
398
+ print("WARNING")
399
+ print(warning["warning"])
400
+ if warning["file"]:
401
+ print("%s at line %d:" % (
402
+ file_lookup(warning["file"]), warning["lineno"]))
403
+ print(warning["line"])
404
+ print((" " * warning["charno"]) + "^")
405
+ print()
406
+
407
+ return True
408
+
409
+ return False
410
+
411
+ def write_output(self, target_filename, remove, json_data):
412
+ if not json_data.has_key("compiledCode"):
413
+ print("FATAL ERROR: Compiler did not return compiledCode.")
414
+ sys.exit(1)
415
+
416
+ code = HEADER + "\n" + json_data["compiledCode"]
417
+ code = code.replace(remove, "")
418
+
419
+ # Trim down Google's (and only Google's) Apache licences.
420
+ # The Closure Compiler preserves these.
421
+ LICENSE = re.compile("""/\\*
422
+
423
+ [\w ]+
424
+
425
+ Copyright \\d+ Google Inc.
426
+ https://developers.google.com/blockly/
427
+
428
+ Licensed under the Apache License, Version 2.0 \(the "License"\);
429
+ you may not use this file except in compliance with the License.
430
+ You may obtain a copy of the License at
431
+
432
+ http://www.apache.org/licenses/LICENSE-2.0
433
+
434
+ Unless required by applicable law or agreed to in writing, software
435
+ distributed under the License is distributed on an "AS IS" BASIS,
436
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
437
+ See the License for the specific language governing permissions and
438
+ limitations under the License.
439
+ \\*/""")
440
+ code = re.sub(LICENSE, "", code)
441
+
442
+ stats = json_data["statistics"]
443
+ original_b = stats["originalSize"]
444
+ compressed_b = stats["compressedSize"]
445
+ if original_b > 0 and compressed_b > 0:
446
+ f = open(target_filename, "w")
447
+ f.write(code)
448
+ f.close()
449
+
450
+ def report_stats(self, target_filename, json_data):
451
+ stats = json_data["statistics"]
452
+ original_b = stats["originalSize"]
453
+ compressed_b = stats["compressedSize"]
454
+ if original_b > 0 and compressed_b > 0:
455
+ original_kb = int(original_b / 1024 + 0.5)
456
+ compressed_kb = int(compressed_b / 1024 + 0.5)
457
+ ratio = int(float(compressed_b) / float(original_b) * 100 + 0.5)
458
+ print("SUCCESS: " + target_filename)
459
+ print("Size changed from %d KB to %d KB (%d%%)." % (
460
+ original_kb, compressed_kb, ratio))
461
+ else:
462
+ print("UNKNOWN ERROR")
463
+
464
+
465
+ class Gen_langfiles(threading.Thread):
466
+ """Generate JavaScript file for each natural language supported.
467
+
468
+ Runs in a separate thread.
469
+ """
470
+
471
+ def __init__(self):
472
+ threading.Thread.__init__(self)
473
+
474
+ def _rebuild(self, srcs, dests):
475
+ # Determine whether any of the files in srcs is newer than any in dests.
476
+ try:
477
+ return (max(os.path.getmtime(src) for src in srcs) >
478
+ min(os.path.getmtime(dest) for dest in dests))
479
+ except OSError as e:
480
+ # Was a file not found?
481
+ if e.errno == errno.ENOENT:
482
+ # If it was a source file, we can't proceed.
483
+ if e.filename in srcs:
484
+ print("Source file missing: " + e.filename)
485
+ sys.exit(1)
486
+ else:
487
+ # If a destination file was missing, rebuild.
488
+ return True
489
+ else:
490
+ print("Error checking file creation times: " + e)
491
+
492
+ def run(self):
493
+ # The files msg/json/{en,qqq,synonyms}.json depend on msg/messages.js.
494
+ if self._rebuild([os.path.join("msg", "messages.js")],
495
+ [os.path.join("msg", "json", f) for f in
496
+ ["en.json", "qqq.json", "synonyms.json"]]):
497
+ try:
498
+ subprocess.check_call([
499
+ "python",
500
+ os.path.join("i18n", "js_to_json.py"),
501
+ "--input_file", "msg/messages.js",
502
+ "--output_dir", "msg/json/",
503
+ "--quiet"])
504
+ except (subprocess.CalledProcessError, OSError) as e:
505
+ # Documentation for subprocess.check_call says that CalledProcessError
506
+ # will be raised on failure, but I found that OSError is also possible.
507
+ print("Error running i18n/js_to_json.py: ", e)
508
+ sys.exit(1)
509
+
510
+ # Checking whether it is necessary to rebuild the js files would be a lot of
511
+ # work since we would have to compare each <lang>.json file with each
512
+ # <lang>.js file. Rebuilding is easy and cheap, so just go ahead and do it.
513
+ try:
514
+ # Use create_messages.py to create .js files from .json files.
515
+ cmd = [
516
+ "python",
517
+ os.path.join("i18n", "create_messages.py"),
518
+ "--source_lang_file", os.path.join("msg", "json", "en.json"),
519
+ "--source_synonym_file", os.path.join("msg", "json", "synonyms.json"),
520
+ "--source_constants_file", os.path.join("msg", "json", "constants.json"),
521
+ "--key_file", os.path.join("msg", "json", "keys.json"),
522
+ "--output_dir", os.path.join("msg", "js"),
523
+ "--quiet"]
524
+ json_files = glob.glob(os.path.join("msg", "json", "*.json"))
525
+ json_files = [file for file in json_files if not
526
+ (file.endswith(("keys.json", "synonyms.json", "qqq.json", "constants.json")))]
527
+ cmd.extend(json_files)
528
+ subprocess.check_call(cmd)
529
+ except (subprocess.CalledProcessError, OSError) as e:
530
+ print("Error running i18n/create_messages.py: ", e)
531
+ sys.exit(1)
532
+
533
+ # Output list of .js files created.
534
+ for f in json_files:
535
+ # This assumes the path to the current directory does not contain "json".
536
+ f = f.replace("json", "js")
537
+ if os.path.isfile(f):
538
+ print("SUCCESS: " + f)
539
+ else:
540
+ print("FAILED to create " + f)
541
+
542
+ if __name__ == "__main__":
543
+ try:
544
+ closure_dir = CLOSURE_DIR_NPM
545
+ closure_root = CLOSURE_ROOT_NPM
546
+ closure_library = CLOSURE_LIBRARY_NPM
547
+ closure_compiler = CLOSURE_COMPILER_NPM
548
+
549
+ # Load calcdeps from the local library
550
+ calcdeps = import_path(os.path.join(
551
+ closure_root, closure_library, "closure", "bin", "calcdeps.py"))
552
+
553
+ # Sanity check the local compiler
554
+ test_args = [closure_compiler, os.path.join("build", "test_input.js")]
555
+ test_proc = subprocess.Popen(test_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
556
+ (stdout, _) = test_proc.communicate()
557
+ assert stdout == read(os.path.join("build", "test_expect.js"))
558
+
559
+ print("Using local compiler: %s ...\n" % CLOSURE_COMPILER_NPM)
560
+ except (ImportError, AssertionError):
561
+ print("Using remote compiler: closure-compiler.appspot.com ...\n")
562
+
563
+ try:
564
+ closure_dir = CLOSURE_DIR
565
+ closure_root = CLOSURE_ROOT
566
+ closure_library = CLOSURE_LIBRARY
567
+ closure_compiler = CLOSURE_COMPILER
568
+
569
+ calcdeps = import_path(os.path.join(
570
+ closure_root, closure_library, "closure", "bin", "calcdeps.py"))
571
+ except ImportError:
572
+ if os.path.isdir(os.path.join(os.path.pardir, "closure-library-read-only")):
573
+ # Dir got renamed when Closure moved from Google Code to GitHub in 2014.
574
+ print("Error: Closure directory needs to be renamed from"
575
+ "'closure-library-read-only' to 'closure-library'.\n"
576
+ "Please rename this directory.")
577
+ elif os.path.isdir(os.path.join(os.path.pardir, "google-closure-library")):
578
+ print("Error: Closure directory needs to be renamed from"
579
+ "'google-closure-library' to 'closure-library'.\n"
580
+ "Please rename this directory.")
581
+ else:
582
+ print("""Error: Closure not found. Read this:
583
+ developers.google.com/blockly/guides/modify/web/closure""")
584
+ sys.exit(1)
585
+
586
+ search_paths = calcdeps.ExpandDirectories(
587
+ ["core", os.path.join(closure_root, closure_library)])
588
+
589
+ search_paths_vertical = search_paths
590
+
591
+ closure_env = {
592
+ "closure_dir": closure_dir,
593
+ "closure_root": closure_root,
594
+ "closure_library": closure_library,
595
+ "closure_compiler": closure_compiler,
596
+ }
597
+
598
+ # Run all tasks in parallel threads.
599
+ # Uncompressed is limited by processor speed.
600
+ # Compressed is limited by network and server speed.
601
+ # Vertical:
602
+ Gen_uncompressed(search_paths_vertical, True, closure_env).start()
603
+
604
+ # Compressed forms of vertical
605
+ Gen_compressed(search_paths_vertical, closure_env).start()
606
+
607
+ # This is run locally in a separate thread.
608
+ # Gen_langfiles().start()
build/gen_blocks.js ADDED
@@ -0,0 +1 @@
 
 
1
+ goog.provide('Blockly.Blocks');
build/test_expect.js ADDED
@@ -0,0 +1 @@
 
 
1
+ var Blockly={Blocks:{}};
build/test_input.js ADDED
@@ -0,0 +1 @@
 
 
1
+ goog.provide('Blockly.Blocks');
cleanup.sh ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Script for cleaning up blockly-specific files when merging blockly into scratch-blocks
4
+ # Removes files and directories that scratch-blocks doesn't want.
5
+ # Rachel Fenichel ([email protected])
6
+
7
+ # Note: 'ours' is scratch-blocks, 'theirs' is blockly.
8
+
9
+ # Formatting helpers.
10
+ indent() { sed 's/^/ /'; }
11
+ indent_more() { sed 's/^/\t/'; }
12
+ empty_lines() { printf '\n\n'; }
13
+
14
+
15
+ empty_lines
16
+ echo Cleaning up a merge from Blockly to Scratch-Blocks...
17
+
18
+ # Get rid of Blockly's internationalization/messages. This is not usually worth
19
+ # scrolling up to look at.
20
+ empty_lines
21
+ echo Cleaning up Blockly message files...
22
+ # Turn on more powerful globbing
23
+ shopt -s extglob
24
+
25
+ # Having trouble with directories. Let's just go there.
26
+ cd msg/json
27
+ git rm -f !(en.json|synonyms.json) | indent_more
28
+ cd ../..
29
+
30
+ # Having trouble with directories. Let's just go there.
31
+ cd msg/js
32
+ git rm -f !(en.js) | indent_more
33
+ cd ../..
34
+
35
+ # Turn powerful globbing off again
36
+ shopt -u extglob
37
+
38
+ # Whole directories that we want to get rid of.
39
+ empty_lines
40
+ echo Removing blockly-specific directories...
41
+ dirslist="accessible demos tests/generators appengine blocks local_build"
42
+ for directory in $dirslist
43
+ do
44
+ echo 'Cleaning up' $directory | indent
45
+ git rm -rf $directory | indent_more
46
+ done
47
+
48
+ # Scratch-blocks does not use generators
49
+ empty_lines
50
+ echo Removing generators...
51
+ generated_langs="dart javascript lua php python"
52
+ for lang in $generated_langs
53
+ do
54
+ echo 'Cleaning up' $lang | indent
55
+ # Directories containing block generators.
56
+ git rm -rf generators/${lang} | indent_more
57
+ done
58
+
59
+ # Built stuff that we should get rid of.
60
+ empty_lines
61
+ echo Removing built files...
62
+ built_files="blockly_compressed.js \
63
+ blockly_uncompressed.js \
64
+ blockly_accessible_compressed.js \
65
+ blockly_accessible_uncompressed.js \
66
+ blocks_compressed.js \
67
+ dart_compressed.js \
68
+ php_compressed.js \
69
+ python_compressed.js \
70
+ javascript_compressed.js \
71
+ lua_compressed.js"
72
+
73
+ for filename in $built_files
74
+ do
75
+ git rm $filename | indent_more
76
+ done
77
+
78
+ empty_lines
79
+ echo Miscellaneous cleanup...
80
+ # Use ours.
81
+ keep_ours=".github/ISSUE_TEMPLATE.md \
82
+ .github/PULL_REQUEST_TEMPLATE.md \
83
+ .gitignore \
84
+ .travis.yml \
85
+ core/block_animations.js \
86
+ msg/messages.js \
87
+ msg/js/en.js \
88
+ msg/json/en.json"
89
+
90
+
91
+ for filename in $keep_ours
92
+ do
93
+ git checkout --ours $filename && git add $filename | indent_more
94
+ done
95
+
96
+ # Scratch-blocks has separate vertical and horizontal playgrounds and block
97
+ # rendering.
98
+ git rm -f tests/playground.html core/block_render_svg.js | indent_more
99
+
100
+ empty_lines
101
+ echo Done with cleanup.
core/block.js ADDED
@@ -0,0 +1,1841 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2011 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview The class representing one block.
23
+ * @author [email protected] (Neil Fraser)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Block');
28
+
29
+ goog.require('Blockly.Blocks');
30
+ goog.require('Blockly.Colours');
31
+ goog.require('Blockly.Comment');
32
+ goog.require('Blockly.ScratchBlockComment');
33
+ goog.require('Blockly.Connection');
34
+ goog.require('Blockly.Events.BlockChange');
35
+ goog.require('Blockly.Events.BlockCreate');
36
+ goog.require('Blockly.Events.BlockDelete');
37
+ goog.require('Blockly.Events.BlockMove');
38
+ goog.require('Blockly.Extensions');
39
+ goog.require('Blockly.FieldLabelSerializable');
40
+ goog.require('Blockly.FieldVariableGetter');
41
+ goog.require('Blockly.Input');
42
+ goog.require('Blockly.Mutator');
43
+ goog.require('Blockly.Warning');
44
+ goog.require('Blockly.Workspace');
45
+ goog.require('Blockly.Xml');
46
+ goog.require('goog.array');
47
+ goog.require('goog.asserts');
48
+ goog.require('goog.math.Coordinate');
49
+ goog.require('goog.string');
50
+
51
+
52
+ /**
53
+ * Class for one block.
54
+ * Not normally called directly, workspace.newBlock() is preferred.
55
+ * @param {!Blockly.Workspace} workspace The block's workspace.
56
+ * @param {?string} prototypeName Name of the language object containing
57
+ * type-specific functions for this block.
58
+ * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
59
+ * create a new ID. If the ID conflicts with an in-use ID, a new one will
60
+ * be generated.
61
+ * @constructor
62
+ */
63
+ Blockly.Block = function(workspace, prototypeName, opt_id) {
64
+ var flyoutWorkspace = workspace && workspace.getFlyout && workspace.getFlyout() ?
65
+ workspace.getFlyout().getWorkspace() : null;
66
+ /** @type {string} */
67
+ this.id = (opt_id && !workspace.getBlockById(opt_id) &&
68
+ (!flyoutWorkspace || !flyoutWorkspace.getBlockById(opt_id))) ?
69
+ opt_id : Blockly.utils.genUid();
70
+ workspace.blockDB_[this.id] = this;
71
+ /** @type {Blockly.Connection} */
72
+ this.outputConnection = null;
73
+ /** @type {Blockly.Connection} */
74
+ this.nextConnection = null;
75
+ /** @type {Blockly.Connection} */
76
+ this.previousConnection = null;
77
+ /** @type {!Array.<!Blockly.Input>} */
78
+ this.inputList = [];
79
+ /** @type {boolean|undefined} */
80
+ this.inputsInline = true;
81
+ /** @type {boolean} */
82
+ this.disabled = false;
83
+ /** @type {string|!Function} */
84
+ this.tooltip = '';
85
+ /** @type {boolean} */
86
+ this.contextMenu = true;
87
+
88
+ /**
89
+ * @type {Blockly.Block}
90
+ * @protected
91
+ */
92
+ this.parentBlock_ = null;
93
+
94
+ /**
95
+ * @type {!Array.<!Blockly.Block>}
96
+ * @protected
97
+ */
98
+ this.childBlocks_ = [];
99
+
100
+ /**
101
+ * @type {boolean}
102
+ * @private
103
+ */
104
+ this.deletable_ = true;
105
+
106
+ /**
107
+ * @type {boolean}
108
+ * @private
109
+ */
110
+ this.movable_ = true;
111
+
112
+ /**
113
+ * @type {boolean}
114
+ * @private
115
+ */
116
+ this.editable_ = true;
117
+
118
+ /**
119
+ * @type {boolean}
120
+ * @private
121
+ */
122
+ this.isShadow_ = false;
123
+
124
+ /**
125
+ * @type {boolean}
126
+ * @protected
127
+ */
128
+ this.collapsed_ = false;
129
+
130
+ /**
131
+ * @type {boolean}
132
+ * @private
133
+ */
134
+ this.checkboxInFlyout_ = false;
135
+
136
+ /**
137
+ * @type {boolean} pm: Determines whether or not this block will duplicate on drag.
138
+ * @private
139
+ */
140
+ this.canDragDuplicate_ = false;
141
+
142
+ /** @type {string|Blockly.Comment} */
143
+ this.comment = null;
144
+
145
+ /**
146
+ * @type {?number}
147
+ * @private
148
+ */
149
+ this.outputShape_ = null;
150
+
151
+ /**
152
+ * @type {?string}
153
+ * @private
154
+ */
155
+ this.category_ = null;
156
+
157
+ /**
158
+ * The block's position in workspace units. (0, 0) is at the workspace's
159
+ * origin; scale does not change this value.
160
+ * @type {!goog.math.Coordinate}
161
+ * @private
162
+ */
163
+ this.xy_ = new goog.math.Coordinate(0, 0);
164
+
165
+ /** @type {!Blockly.Workspace} */
166
+ this.workspace = workspace;
167
+ /** @type {boolean} */
168
+ this.isInFlyout = workspace.isFlyout;
169
+ /** @type {boolean} */
170
+ this.isInMutator = workspace.isMutator;
171
+
172
+ /** @type {boolean} */
173
+ this.RTL = workspace.RTL;
174
+
175
+ /** @type {boolean} */
176
+ this.isInsertionMarker_ = false;
177
+
178
+ // Copy the type-specific functions and data from the prototype.
179
+ if (prototypeName) {
180
+ /** @type {string} */
181
+ this.type = prototypeName;
182
+ var prototype = Blockly.Blocks[prototypeName];
183
+ goog.asserts.assertObject(prototype,
184
+ 'Error: Unknown block type "%s".', prototypeName);
185
+ goog.mixin(this, prototype);
186
+ }
187
+
188
+ workspace.addTopBlock(this);
189
+
190
+ // Call an initialization function, if it exists.
191
+ if (goog.isFunction(this.init)) {
192
+ this.init();
193
+ }
194
+ // Record initial inline state.
195
+ /** @type {boolean|undefined} */
196
+ this.inputsInlineDefault = this.inputsInline;
197
+
198
+ // Fire a create event.
199
+ if (Blockly.Events.isEnabled()) {
200
+ var existingGroup = Blockly.Events.getGroup();
201
+ if (!existingGroup) {
202
+ Blockly.Events.setGroup(true);
203
+ }
204
+ try {
205
+ Blockly.Events.fire(new Blockly.Events.BlockCreate(this));
206
+ } finally {
207
+ if (!existingGroup) {
208
+ Blockly.Events.setGroup(false);
209
+ }
210
+ }
211
+
212
+ }
213
+ // Bind an onchange function, if it exists.
214
+ if (goog.isFunction(this.onchange)) {
215
+ this.setOnChange(this.onchange);
216
+ }
217
+ };
218
+
219
+ /**
220
+ * Optional text data that round-trips beween blocks and XML.
221
+ * Has no effect. May be used by 3rd parties for meta information.
222
+ * @type {?string}
223
+ */
224
+ Blockly.Block.prototype.data = null;
225
+
226
+ /**
227
+ * Colour of the block in '#RRGGBB' format.
228
+ * @type {string}
229
+ * @private
230
+ */
231
+ Blockly.Block.prototype.colour_ = '#FF0000';
232
+
233
+ /**
234
+ * Secondary colour of the block in '#RRGGBB' format.
235
+ * @type {string}
236
+ * @private
237
+ */
238
+ Blockly.Block.prototype.colourSecondary_ = '#FF0000';
239
+
240
+ /**
241
+ * Tertiary colour of the block in '#RRGGBB' format.
242
+ * @type {string}
243
+ * @private
244
+ */
245
+ Blockly.Block.prototype.colourTertiary_ = '#FF0000';
246
+
247
+ /**
248
+ * Fill colour used to override default shadow colour behaviour.
249
+ * @type {string}
250
+ * @private
251
+ */
252
+ Blockly.Block.prototype.shadowColour_ = null;
253
+
254
+ /**
255
+ * Dispose of this block.
256
+ * @param {boolean} healStack If true, then try to heal any gap by connecting
257
+ * the next statement with the previous statement. Otherwise, dispose of
258
+ * all children of this block.
259
+ */
260
+ Blockly.Block.prototype.dispose = function(healStack) {
261
+ if (!this.workspace) {
262
+ // Already deleted.
263
+ return;
264
+ }
265
+ // Terminate onchange event calls.
266
+ if (this.onchangeWrapper_) {
267
+ this.workspace.removeChangeListener(this.onchangeWrapper_);
268
+ }
269
+ this.unplug(healStack);
270
+ if (Blockly.Events.isEnabled()) {
271
+ Blockly.Events.fire(new Blockly.Events.BlockDelete(this));
272
+ }
273
+ Blockly.Events.disable();
274
+
275
+ try {
276
+ // This block is now at the top of the workspace.
277
+ // Remove this block from the workspace's list of top-most blocks.
278
+ if (this.workspace) {
279
+ this.workspace.removeTopBlock(this);
280
+ // Remove from block database.
281
+ delete this.workspace.blockDB_[this.id];
282
+ this.workspace = null;
283
+ }
284
+
285
+ // Just deleting this block from the DOM would result in a memory leak as
286
+ // well as corruption of the connection database. Therefore we must
287
+ // methodically step through the blocks and carefully disassemble them.
288
+
289
+ if (Blockly.selected == this) {
290
+ Blockly.selected = null;
291
+ }
292
+
293
+ // First, dispose of all my children.
294
+ for (var i = this.childBlocks_.length - 1; i >= 0; i--) {
295
+ this.childBlocks_[i].dispose(false);
296
+ }
297
+ // Then dispose of myself.
298
+ // Dispose of all inputs and their fields.
299
+ for (var i = 0, input; input = this.inputList[i]; i++) {
300
+ input.dispose();
301
+ }
302
+ this.inputList.length = 0;
303
+ // Dispose of any remaining connections (next/previous/output).
304
+ var connections = this.getConnections_(true);
305
+ for (var i = 0; i < connections.length; i++) {
306
+ var connection = connections[i];
307
+ if (connection.isConnected()) {
308
+ connection.disconnect();
309
+ }
310
+ connections[i].dispose();
311
+ }
312
+ } finally {
313
+ Blockly.Events.enable();
314
+ }
315
+ };
316
+
317
+ /**
318
+ * Call initModel on all fields on the block.
319
+ * May be called more than once.
320
+ * Either initModel or initSvg must be called after creating a block and before
321
+ * the first interaction with it. Interactions include UI actions
322
+ * (e.g. clicking and dragging) and firing events (e.g. create, delete, and
323
+ * change).
324
+ * @public
325
+ */
326
+ Blockly.Block.prototype.initModel = function() {
327
+ for (var i = 0, input; input = this.inputList[i]; i++) {
328
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
329
+ if (field.initModel) {
330
+ field.initModel();
331
+ }
332
+ }
333
+ }
334
+ };
335
+
336
+ /**
337
+ * Unplug this block from its superior block. If this block is a statement,
338
+ * optionally reconnect the block underneath with the block on top.
339
+ * @param {boolean=} opt_healStack Disconnect child statement and reconnect
340
+ * stack. Defaults to false.
341
+ */
342
+ Blockly.Block.prototype.unplug = function(opt_healStack) {
343
+ if (this.outputConnection) {
344
+ if (this.outputConnection.isConnected()) {
345
+ // Disconnect from any superior block.
346
+ this.outputConnection.disconnect();
347
+ }
348
+ } else {
349
+ if (this.previousConnection) {
350
+ var previousTarget = null;
351
+ if (this.previousConnection.isConnected()) {
352
+ // Remember the connection that any next statements need to connect to.
353
+ previousTarget = this.previousConnection.targetConnection;
354
+ // Detach this block from the parent's tree.
355
+ this.previousConnection.disconnect();
356
+ }
357
+ }
358
+ var nextBlock = this.getNextBlock();
359
+ if (opt_healStack && nextBlock) {
360
+ // Disconnect the next statement.
361
+ var nextTarget = this.nextConnection.targetConnection;
362
+ nextTarget.disconnect();
363
+ if (previousTarget && previousTarget.checkType_(nextTarget)) {
364
+ // Attach the next statement to the previous statement.
365
+ previousTarget.connect(nextTarget);
366
+ }
367
+ }
368
+ }
369
+ };
370
+
371
+ /**
372
+ * Returns all connections originating from this block.
373
+ * @return {!Array.<!Blockly.Connection>} Array of connections.
374
+ * @private
375
+ */
376
+ Blockly.Block.prototype.getConnections_ = function() {
377
+ var myConnections = [];
378
+ if (this.outputConnection) {
379
+ myConnections.push(this.outputConnection);
380
+ }
381
+ if (this.previousConnection) {
382
+ myConnections.push(this.previousConnection);
383
+ }
384
+ if (this.nextConnection) {
385
+ myConnections.push(this.nextConnection);
386
+ }
387
+ for (var i = 0, input; input = this.inputList[i]; i++) {
388
+ if (input.connection) {
389
+ myConnections.push(input.connection);
390
+ }
391
+ }
392
+ return myConnections;
393
+ };
394
+
395
+ /**
396
+ * Walks down a stack of blocks and finds the last next connection on the stack.
397
+ * @return {Blockly.Connection} The last next connection on the stack, or null.
398
+ * @package
399
+ */
400
+ Blockly.Block.prototype.lastConnectionInStack = function() {
401
+ var nextConnection = this.nextConnection;
402
+ while (nextConnection) {
403
+ var nextBlock = nextConnection.targetBlock();
404
+ if (!nextBlock) {
405
+ // Found a next connection with nothing on the other side.
406
+ return nextConnection;
407
+ }
408
+ nextConnection = nextBlock.nextConnection;
409
+ }
410
+ // Ran out of next connections.
411
+ return null;
412
+ };
413
+
414
+ /**
415
+ * Bump unconnected blocks out of alignment. Two blocks which aren't actually
416
+ * connected should not coincidentally line up on screen.
417
+ * @protected
418
+ */
419
+ Blockly.Block.prototype.bumpNeighbours_ = function() {
420
+ console.warn('Not expected to reach this bumpNeighbours_ function. The ' +
421
+ 'BlockSvg function for bumpNeighbours_ was expected to be called instead.');
422
+ };
423
+
424
+ /**
425
+ * Return the parent block or null if this block is at the top level.
426
+ * @return {Blockly.Block} The block that holds the current block.
427
+ */
428
+ Blockly.Block.prototype.getParent = function() {
429
+ // Look at the DOM to see if we are nested in another block.
430
+ return this.parentBlock_;
431
+ };
432
+
433
+ /**
434
+ * Return the input that connects to the specified block.
435
+ * @param {!Blockly.Block} block A block connected to an input on this block.
436
+ * @return {Blockly.Input} The input that connects to the specified block.
437
+ */
438
+ Blockly.Block.prototype.getInputWithBlock = function(block) {
439
+ for (var i = 0, input; input = this.inputList[i]; i++) {
440
+ if (input.connection && input.connection.targetBlock() == block) {
441
+ return input;
442
+ }
443
+ }
444
+ return null;
445
+ };
446
+
447
+ /**
448
+ * Return the input that contains the specified connection
449
+ * @param {!Blockly.Connection} conn A connection on this block.
450
+ * @return {Blockly.Input} The input that contains the specified connection.
451
+ */
452
+ Blockly.Block.prototype.getInputWithConnection = function(conn) {
453
+ for (var i = 0, input; input = this.inputList[i]; i++) {
454
+ if (input.connection == conn) {
455
+ return input;
456
+ }
457
+ }
458
+ return null;
459
+ };
460
+
461
+ /**
462
+ * Return the parent block that surrounds the current block, or null if this
463
+ * block has no surrounding block. A parent block might just be the previous
464
+ * statement, whereas the surrounding block is an if statement, while loop, etc.
465
+ * @return {Blockly.Block} The block that surrounds the current block.
466
+ */
467
+ Blockly.Block.prototype.getSurroundParent = function() {
468
+ var block = this;
469
+ do {
470
+ var prevBlock = block;
471
+ block = block.getParent();
472
+ if (!block) {
473
+ // Ran off the top.
474
+ return null;
475
+ }
476
+ } while (block.getNextBlock() == prevBlock);
477
+ // This block is an enclosing parent, not just a statement in a stack.
478
+ return block;
479
+ };
480
+
481
+ /**
482
+ * Return the next statement block directly connected to this block.
483
+ * @return {Blockly.Block} The next statement block or null.
484
+ */
485
+ Blockly.Block.prototype.getNextBlock = function() {
486
+ return this.nextConnection && this.nextConnection.targetBlock();
487
+ };
488
+
489
+ /**
490
+ * Return the previous statement block directly connected to this block.
491
+ * @return {Blockly.Block} The previous statement block or null.
492
+ */
493
+ Blockly.Block.prototype.getPreviousBlock = function() {
494
+ return this.previousConnection && this.previousConnection.targetBlock();
495
+ };
496
+
497
+ /**
498
+ * Return the connection on the first statement input on this block, or null if
499
+ * there are none.
500
+ * @return {Blockly.Connection} The first statement connection or null.
501
+ */
502
+ Blockly.Block.prototype.getFirstStatementConnection = function() {
503
+ for (var i = 0, input; input = this.inputList[i]; i++) {
504
+ if (input.connection && input.connection.type == Blockly.NEXT_STATEMENT) {
505
+ return input.connection;
506
+ }
507
+ }
508
+ return null;
509
+ };
510
+
511
+ /**
512
+ * Return the top-most block in this block's tree.
513
+ * This will return itself if this block is at the top level.
514
+ * @return {!Blockly.Block} The root block.
515
+ */
516
+ Blockly.Block.prototype.getRootBlock = function() {
517
+ var rootBlock;
518
+ var block = this;
519
+ do {
520
+ rootBlock = block;
521
+ block = rootBlock.parentBlock_;
522
+ } while (block);
523
+ return rootBlock;
524
+ };
525
+
526
+ /**
527
+ * Find all the blocks that are directly nested inside this one.
528
+ * Includes value and statement inputs, as well as any following statement.
529
+ * Excludes any connection on an output tab or any preceding statement.
530
+ * Blocks are optionally sorted by position; top to bottom.
531
+ * @param {boolean} ordered Sort the list if true.
532
+ * @return {!Array.<!Blockly.Block>} Array of blocks.
533
+ */
534
+ Blockly.Block.prototype.getChildren = function(ordered) {
535
+ if (!ordered) {
536
+ return this.childBlocks_;
537
+ }
538
+ var blocks = [];
539
+ for (var i = 0, input; input = this.inputList[i]; i++) {
540
+ if (input.connection) {
541
+ var child = input.connection.targetBlock();
542
+ if (child) {
543
+ blocks.push(child);
544
+ }
545
+ }
546
+ }
547
+ var next = this.getNextBlock();
548
+ if (next) {
549
+ blocks.push(next);
550
+ }
551
+ return blocks;
552
+ };
553
+
554
+ /**
555
+ * Set parent of this block to be a new block or null.
556
+ * @param {Blockly.Block} newParent New parent block.
557
+ */
558
+ Blockly.Block.prototype.setParent = function(newParent) {
559
+ if (newParent == this.parentBlock_) {
560
+ return;
561
+ }
562
+ if (this.parentBlock_) {
563
+ // Remove this block from the old parent's child list.
564
+ goog.array.remove(this.parentBlock_.childBlocks_, this);
565
+
566
+ // Disconnect from superior blocks.
567
+ if (this.previousConnection && this.previousConnection.isConnected()) {
568
+ throw 'Still connected to previous block.';
569
+ }
570
+ if (this.outputConnection && this.outputConnection.isConnected()) {
571
+ throw 'Still connected to parent block.';
572
+ }
573
+ this.parentBlock_ = null;
574
+ // This block hasn't actually moved on-screen, so there's no need to update
575
+ // its connection locations.
576
+ } else {
577
+ // Remove this block from the workspace's list of top-most blocks.
578
+ this.workspace.removeTopBlock(this);
579
+ }
580
+
581
+ this.parentBlock_ = newParent;
582
+ if (newParent) {
583
+ // Add this block to the new parent's child list.
584
+ newParent.childBlocks_.push(this);
585
+ } else {
586
+ this.workspace.addTopBlock(this);
587
+ }
588
+ };
589
+
590
+ /**
591
+ * Find all the blocks that are directly or indirectly nested inside this one.
592
+ * Includes this block in the list.
593
+ * Includes value and statement inputs, as well as any following statements.
594
+ * Excludes any connection on an output tab or any preceding statements.
595
+ * Blocks are optionally sorted by position, top to bottom.
596
+ * @param {boolean} ordered Sort the list if true.
597
+ * @param {boolean=} opt_ignoreShadows If set, don't include shadow blocks.
598
+ * @return {!Array.<!Blockly.Block>} Flattened array of blocks.
599
+ */
600
+ Blockly.Block.prototype.getDescendants = function(ordered, opt_ignoreShadows) {
601
+ var blocks = [this];
602
+ var childBlocks = this.getChildren(ordered);
603
+ for (var child, i = 0; child = childBlocks[i]; i++) {
604
+ if (!opt_ignoreShadows || !child.isShadow_) {
605
+ blocks.push.apply(
606
+ blocks, child.getDescendants(ordered, opt_ignoreShadows));
607
+ }
608
+ }
609
+ return blocks;
610
+ };
611
+
612
+ /**
613
+ * Get whether this block is deletable or not.
614
+ * @return {boolean} True if deletable.
615
+ */
616
+ Blockly.Block.prototype.isDeletable = function() {
617
+ return this.deletable_ && !this.isShadow_ &&
618
+ !(this.workspace && this.workspace.options.readOnly);
619
+ };
620
+
621
+ /**
622
+ * Set whether this block is deletable or not.
623
+ * @param {boolean} deletable True if deletable.
624
+ */
625
+ Blockly.Block.prototype.setDeletable = function(deletable) {
626
+ this.deletable_ = deletable;
627
+ };
628
+
629
+ /**
630
+ * Get whether this block is movable or not.
631
+ * @return {boolean} True if movable.
632
+ */
633
+ Blockly.Block.prototype.isMovable = function() {
634
+ return this.movable_ && !this.isShadow_ &&
635
+ !(this.workspace && this.workspace.options.readOnly);
636
+ };
637
+
638
+ /**
639
+ * Set whether this block is movable or not.
640
+ * @param {boolean} movable True if movable.
641
+ */
642
+ Blockly.Block.prototype.setMovable = function(movable) {
643
+ this.movable_ = movable;
644
+ };
645
+
646
+ /**
647
+ * Get whether this block is a shadow block or not.
648
+ * @return {boolean} True if a shadow.
649
+ */
650
+ Blockly.Block.prototype.isShadow = function() {
651
+ return this.isShadow_;
652
+ };
653
+
654
+ /**
655
+ * Set whether this block is a shadow block or not.
656
+ * @param {boolean} shadow True if a shadow.
657
+ */
658
+ Blockly.Block.prototype.setShadow = function(shadow) {
659
+ this.isShadow_ = shadow;
660
+ };
661
+
662
+ /**
663
+ * Get whether this block is an insertion marker block or not.
664
+ * @return {boolean} True if an insertion marker.
665
+ */
666
+ Blockly.Block.prototype.isInsertionMarker = function() {
667
+ return this.isInsertionMarker_;
668
+ };
669
+
670
+ /**
671
+ * Set whether this block is an insertion marker block or not.
672
+ * @param {boolean} insertionMarker True if an insertion marker.
673
+ */
674
+ Blockly.Block.prototype.setInsertionMarker = function(insertionMarker) {
675
+ if (this.isInsertionMarker_ == insertionMarker) {
676
+ return; // No change.
677
+ }
678
+ this.isInsertionMarker_ = insertionMarker;
679
+ // TODO: handle removing insertion marker status.
680
+ if (this.isInsertionMarker_) {
681
+ this.setColour(Blockly.Colours.insertionMarker);
682
+ this.setOpacity(Blockly.Colours.insertionMarkerOpacity);
683
+ Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
684
+ 'blocklyInsertionMarker');
685
+ }
686
+ };
687
+
688
+ /**
689
+ * Get whether this block is editable or not.
690
+ * @return {boolean} True if editable.
691
+ */
692
+ Blockly.Block.prototype.isEditable = function() {
693
+ return this.editable_ && !(this.workspace && this.workspace.options.readOnly);
694
+ };
695
+
696
+ /**
697
+ * Set whether this block is editable or not.
698
+ * @param {boolean} editable True if editable.
699
+ */
700
+ Blockly.Block.prototype.setEditable = function(editable) {
701
+ this.editable_ = editable;
702
+ for (var i = 0, input; input = this.inputList[i]; i++) {
703
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
704
+ field.updateEditable();
705
+ }
706
+ }
707
+ };
708
+
709
+ /**
710
+ * Set whether the connections are hidden (not tracked in a database) or not.
711
+ * Recursively walk down all child blocks (except collapsed blocks).
712
+ * @param {boolean} hidden True if connections are hidden.
713
+ */
714
+ Blockly.Block.prototype.setConnectionsHidden = function(hidden) {
715
+ if (!hidden && this.isCollapsed()) {
716
+ if (this.outputConnection) {
717
+ this.outputConnection.setHidden(hidden);
718
+ }
719
+ if (this.previousConnection) {
720
+ this.previousConnection.setHidden(hidden);
721
+ }
722
+ if (this.nextConnection) {
723
+ this.nextConnection.setHidden(hidden);
724
+ var child = this.nextConnection.targetBlock();
725
+ if (child) {
726
+ child.setConnectionsHidden(hidden);
727
+ }
728
+ }
729
+ } else {
730
+ var myConnections = this.getConnections_(true);
731
+ for (var i = 0, connection; connection = myConnections[i]; i++) {
732
+ connection.setHidden(hidden);
733
+ if (connection.isSuperior()) {
734
+ var child = connection.targetBlock();
735
+ if (child) {
736
+ child.setConnectionsHidden(hidden);
737
+ }
738
+ }
739
+ }
740
+ }
741
+ };
742
+
743
+ /**
744
+ * Find the connection on this block that corresponds to the given connection
745
+ * on the other block.
746
+ * Used to match connections between a block and its insertion marker.
747
+ * @param {!Blockly.Block} otherBlock The other block to match against.
748
+ * @param {!Blockly.Connection} conn The other connection to match.
749
+ * @return {Blockly.Connection} the matching connection on this block, or null.
750
+ */
751
+ Blockly.Block.prototype.getMatchingConnection = function(otherBlock, conn) {
752
+ var connections = this.getConnections_(true);
753
+ var otherConnections = otherBlock.getConnections_(true);
754
+ if (connections.length != otherConnections.length) {
755
+ throw "Connection lists did not match in length.";
756
+ }
757
+ for (var i = 0; i < otherConnections.length; i++) {
758
+ if (otherConnections[i] == conn) {
759
+ return connections[i];
760
+ }
761
+ }
762
+ return null;
763
+ };
764
+
765
+ /**
766
+ * Set the URL of this block's help page.
767
+ * @param {string|Function} url URL string for block help, or function that
768
+ * returns a URL. Null for no help.
769
+ */
770
+ Blockly.Block.prototype.setHelpUrl = function(url) {
771
+ this.helpUrl = url;
772
+ };
773
+
774
+ /**
775
+ * Change the tooltip text for a block.
776
+ * @param {string|!Function} newTip Text for tooltip or a parent element to
777
+ * link to for its tooltip. May be a function that returns a string.
778
+ */
779
+ Blockly.Block.prototype.setTooltip = function(newTip) {
780
+ this.tooltip = newTip;
781
+ };
782
+
783
+ /**
784
+ * Get the colour of a block.
785
+ * @return {string} #RRGGBB string.
786
+ */
787
+ Blockly.Block.prototype.getColour = function() {
788
+ return this.colour_;
789
+ };
790
+
791
+ /**
792
+ * Get the secondary colour of a block.
793
+ * @return {string} #RRGGBB string.
794
+ */
795
+ Blockly.Block.prototype.getColourSecondary = function() {
796
+ return this.colourSecondary_;
797
+ };
798
+
799
+ /**
800
+ * Get the tertiary colour of a block.
801
+ * @return {string} #RRGGBB string.
802
+ */
803
+ Blockly.Block.prototype.getColourTertiary = function() {
804
+ return this.colourTertiary_;
805
+ };
806
+
807
+ /**
808
+ * Get the shadow colour of a block.
809
+ * @return {string} #RRGGBB string.
810
+ */
811
+ Blockly.Block.prototype.getShadowColour = function() {
812
+ return this.shadowColour_;
813
+ };
814
+
815
+ /**
816
+ * Set the shadow colour of a block.
817
+ * @param {number|string} colour HSV hue value, or #RRGGBB string.
818
+ */
819
+ Blockly.Block.prototype.setShadowColour = function(colour) {
820
+ this.shadowColour_ = this.makeColour_(colour);
821
+ if (this.rendered) {
822
+ this.updateColour();
823
+ }
824
+ };
825
+
826
+ /**
827
+ * Clear the shadow colour of a block.
828
+ */
829
+ Blockly.Block.prototype.clearShadowColour = function() {
830
+ this.shadowColour_ = null;
831
+ if (this.rendered) {
832
+ this.updateColour();
833
+ }
834
+ };
835
+
836
+ /**
837
+ * Create an #RRGGBB string colour from a colour HSV hue value or #RRGGBB string.
838
+ * @param {number|string} colour HSV hue value, or #RRGGBB string.
839
+ * @return {string} #RRGGBB string.
840
+ * @private
841
+ */
842
+ Blockly.Block.prototype.makeColour_ = function(colour) {
843
+ var hue = Number(colour);
844
+ if (!isNaN(hue)) {
845
+ return Blockly.hueToRgb(hue);
846
+ } else if (goog.isString(colour) && colour.match(/^#[0-9a-fA-F]{6,8}$/)) {
847
+ return colour;
848
+ } else {
849
+ throw 'Invalid colour: ' + colour;
850
+ }
851
+ };
852
+
853
+ /**
854
+ * Change the colour of a block, and optional secondary/teriarty colours.
855
+ * @param {number|string} colour HSV hue value, or #RRGGBB string.
856
+ * @param {number|string} colourSecondary HSV hue value, or #RRGGBB string.
857
+ * @param {number|string} colourTertiary HSV hue value, or #RRGGBB string.
858
+ */
859
+ Blockly.Block.prototype.setColour = function(colour, colourSecondary, colourTertiary) {
860
+ this.colour_ = this.makeColour_(colour);
861
+ if (colourSecondary !== undefined) {
862
+ this.colourSecondary_ = this.makeColour_(colourSecondary);
863
+ } else {
864
+ this.colourSecondary_ = goog.color.rgbArrayToHex(
865
+ goog.color.darken(goog.color.hexToRgb(this.colour_), 0.1));
866
+ }
867
+ if (colourTertiary !== undefined) {
868
+ this.colourTertiary_ = this.makeColour_(colourTertiary);
869
+ } else {
870
+ this.colourTertiary_ = goog.color.rgbArrayToHex(
871
+ goog.color.darken(goog.color.hexToRgb(this.colour_), 0.2));
872
+ }
873
+ if (this.rendered) {
874
+ this.updateColour();
875
+ }
876
+ };
877
+
878
+ /**
879
+ * Sets a callback function to use whenever the block's parent workspace
880
+ * changes, replacing any prior onchange handler. This is usually only called
881
+ * from the constructor, the block type initializer function, or an extension
882
+ * initializer function.
883
+ * @param {function(Blockly.Events.Abstract)} onchangeFn The callback to call
884
+ * when the block's workspace changes.
885
+ * @throws {Error} if onchangeFn is not falsey or a function.
886
+ */
887
+ Blockly.Block.prototype.setOnChange = function(onchangeFn) {
888
+ if (onchangeFn && !goog.isFunction(onchangeFn)) {
889
+ throw new Error("onchange must be a function.");
890
+ }
891
+ if (this.onchangeWrapper_) {
892
+ this.workspace.removeChangeListener(this.onchangeWrapper_);
893
+ }
894
+ this.onchange = onchangeFn;
895
+ if (this.onchange) {
896
+ this.onchangeWrapper_ = onchangeFn.bind(this);
897
+ this.workspace.addChangeListener(this.onchangeWrapper_);
898
+ }
899
+ };
900
+
901
+ /**
902
+ * Returns the named field from a block.
903
+ * @param {string} name The name of the field.
904
+ * @return {Blockly.Field} Named field, or null if field does not exist.
905
+ */
906
+ Blockly.Block.prototype.getField = function(name) {
907
+ for (var i = 0, input; input = this.inputList[i]; i++) {
908
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
909
+ if (field.name === name) {
910
+ return field;
911
+ }
912
+ }
913
+ }
914
+ return null;
915
+ };
916
+
917
+ /**
918
+ * Return all variables referenced by this block.
919
+ * @return {!Array.<string>} List of variable names.
920
+ * @package
921
+ */
922
+ Blockly.Block.prototype.getVars = function() {
923
+ var vars = [];
924
+ for (var i = 0, input; input = this.inputList[i]; i++) {
925
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
926
+ if (field.referencesVariables()) {
927
+ vars.push(field.getValue());
928
+ }
929
+ }
930
+ }
931
+ return vars;
932
+ };
933
+
934
+ /**
935
+ * Return all variables referenced by this block.
936
+ * @return {!Array.<!Blockly.VariableModel>} List of variable models.
937
+ * @package
938
+ */
939
+ Blockly.Block.prototype.getVarModels = function() {
940
+ var vars = [];
941
+ for (var i = 0, input; input = this.inputList[i]; i++) {
942
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
943
+ if (field.referencesVariables()) {
944
+ var model = this.workspace.getVariableById(field.getValue());
945
+ // Check if the variable actually exists (and isn't just a potential
946
+ // variable).
947
+ if (model) {
948
+ vars.push(model);
949
+ }
950
+ }
951
+ }
952
+ }
953
+ return vars;
954
+ };
955
+
956
+ /**
957
+ * Notification that a variable is renaming but keeping the same ID. If the
958
+ * variable is in use on this block, rerender to show the new name.
959
+ * @param {!Blockly.VariableModel} variable The variable being renamed.
960
+ * @package
961
+ */
962
+ Blockly.Block.prototype.updateVarName = function(variable) {
963
+ for (var i = 0, input; input = this.inputList[i]; i++) {
964
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
965
+ if (field.referencesVariables() &&
966
+ variable.getId() == field.getValue()) {
967
+ field.setText(variable.name);
968
+ }
969
+ }
970
+ }
971
+ };
972
+
973
+ /**
974
+ * Notification that a variable is renaming.
975
+ * If the ID matches one of this block's variables, rename it.
976
+ * @param {string} oldId ID of variable to rename.
977
+ * @param {string} newId ID of new variable. May be the same as oldId, but with
978
+ * an updated name.
979
+ */
980
+ Blockly.Block.prototype.renameVarById = function(oldId, newId) {
981
+ for (var i = 0, input; input = this.inputList[i]; i++) {
982
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
983
+ if (field.referencesVariables() &&
984
+ oldId == field.getValue()) {
985
+ field.setValue(newId);
986
+ }
987
+ }
988
+ }
989
+ };
990
+
991
+ /**
992
+ * Returns the language-neutral value from the field of a block.
993
+ * @param {string} name The name of the field.
994
+ * @return {?string} Value from the field or null if field does not exist.
995
+ */
996
+ Blockly.Block.prototype.getFieldValue = function(name) {
997
+ var field = this.getField(name);
998
+ if (field) {
999
+ return field.getValue();
1000
+ }
1001
+ return null;
1002
+ };
1003
+
1004
+ /**
1005
+ * Change the field value for a block (e.g. 'CHOOSE' or 'REMOVE').
1006
+ * @param {string} newValue Value to be the new field.
1007
+ * @param {string} name The name of the field.
1008
+ */
1009
+ Blockly.Block.prototype.setFieldValue = function(newValue, name) {
1010
+ var field = this.getField(name);
1011
+ goog.asserts.assertObject(field, 'Field "%s" not found.', name);
1012
+ field.setValue(newValue);
1013
+ };
1014
+
1015
+ /**
1016
+ * Set whether this block can chain onto the bottom of another block.
1017
+ * @param {boolean} newBoolean True if there can be a previous statement.
1018
+ * @param {(string|Array.<string>|null)=} opt_check Statement type or
1019
+ * list of statement types. Null/undefined if any type could be connected.
1020
+ */
1021
+ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
1022
+ if (newBoolean) {
1023
+ if (opt_check === undefined) {
1024
+ opt_check = null;
1025
+ }
1026
+ if (!this.previousConnection) {
1027
+ goog.asserts.assert(!this.outputConnection,
1028
+ 'Remove output connection prior to adding previous connection.');
1029
+ this.previousConnection =
1030
+ this.makeConnection_(Blockly.PREVIOUS_STATEMENT);
1031
+ }
1032
+ this.previousConnection.setCheck(opt_check);
1033
+ } else {
1034
+ if (this.previousConnection) {
1035
+ goog.asserts.assert(!this.previousConnection.isConnected(),
1036
+ 'Must disconnect previous statement before removing connection.');
1037
+ this.previousConnection.dispose();
1038
+ this.previousConnection = null;
1039
+ }
1040
+ }
1041
+ };
1042
+
1043
+ /**
1044
+ * Set whether another block can chain onto the bottom of this block.
1045
+ * @param {boolean} newBoolean True if there can be a next statement.
1046
+ * @param {(string|Array.<string>|null)=} opt_check Statement type or
1047
+ * list of statement types. Null/undefined if any type could be connected.
1048
+ */
1049
+ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) {
1050
+ if (newBoolean) {
1051
+ if (opt_check === undefined) {
1052
+ opt_check = null;
1053
+ }
1054
+ if (!this.nextConnection) {
1055
+ this.nextConnection = this.makeConnection_(Blockly.NEXT_STATEMENT);
1056
+ }
1057
+ this.nextConnection.setCheck(opt_check);
1058
+ } else {
1059
+ if (this.nextConnection) {
1060
+ goog.asserts.assert(!this.nextConnection.isConnected(),
1061
+ 'Must disconnect next statement before removing connection.');
1062
+ this.nextConnection.dispose();
1063
+ this.nextConnection = null;
1064
+ }
1065
+ }
1066
+ };
1067
+
1068
+ /**
1069
+ * Set whether this block returns a value.
1070
+ * @param {boolean} newBoolean True if there is an output.
1071
+ * @param {(string|Array.<string>|null)=} opt_check Returned type or list
1072
+ * of returned types. Null or undefined if any type could be returned
1073
+ * (e.g. variable get).
1074
+ */
1075
+ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) {
1076
+ if (newBoolean) {
1077
+ if (opt_check === undefined) {
1078
+ opt_check = null;
1079
+ }
1080
+ if (!this.outputConnection) {
1081
+ goog.asserts.assert(!this.previousConnection,
1082
+ 'Remove previous connection prior to adding output connection.');
1083
+ this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE);
1084
+ }
1085
+ this.outputConnection.setCheck(opt_check);
1086
+ } else {
1087
+ if (this.outputConnection) {
1088
+ goog.asserts.assert(!this.outputConnection.isConnected(),
1089
+ 'Must disconnect output value before removing connection.');
1090
+ this.outputConnection.dispose();
1091
+ this.outputConnection = null;
1092
+ }
1093
+ }
1094
+ };
1095
+
1096
+ /**
1097
+ * Set whether value inputs are arranged horizontally or vertically.
1098
+ * @param {boolean} newBoolean True if inputs are horizontal.
1099
+ */
1100
+ Blockly.Block.prototype.setInputsInline = function(newBoolean) {
1101
+ if (this.inputsInline != newBoolean) {
1102
+ Blockly.Events.fire(new Blockly.Events.BlockChange(
1103
+ this, 'inline', null, this.inputsInline, newBoolean));
1104
+ this.inputsInline = newBoolean;
1105
+ }
1106
+ };
1107
+
1108
+ /**
1109
+ * Get whether value inputs are arranged horizontally or vertically.
1110
+ * @return {boolean} True if inputs are horizontal.
1111
+ */
1112
+ Blockly.Block.prototype.getInputsInline = function() {
1113
+ if (this.inputsInline != undefined) {
1114
+ // Set explicitly.
1115
+ return this.inputsInline;
1116
+ }
1117
+ // Not defined explicitly. Figure out what would look best.
1118
+ for (var i = 1; i < this.inputList.length; i++) {
1119
+ if (this.inputList[i - 1].type == Blockly.DUMMY_INPUT &&
1120
+ this.inputList[i].type == Blockly.DUMMY_INPUT) {
1121
+ // Two dummy inputs in a row. Don't inline them.
1122
+ return false;
1123
+ }
1124
+ }
1125
+ for (var i = 1; i < this.inputList.length; i++) {
1126
+ if (this.inputList[i - 1].type == Blockly.INPUT_VALUE &&
1127
+ this.inputList[i].type == Blockly.DUMMY_INPUT) {
1128
+ // Dummy input after a value input. Inline them.
1129
+ return true;
1130
+ }
1131
+ }
1132
+ return false;
1133
+ };
1134
+
1135
+ /**
1136
+ * Set whether the block is disabled or not.
1137
+ * @param {boolean} disabled True if disabled.
1138
+ */
1139
+ Blockly.Block.prototype.setDisabled = function(disabled) {
1140
+ if (this.disabled != disabled) {
1141
+ Blockly.Events.fire(new Blockly.Events.BlockChange(
1142
+ this, 'disabled', null, this.disabled, disabled));
1143
+ this.disabled = disabled;
1144
+ }
1145
+ };
1146
+
1147
+ /**
1148
+ * Get whether the block is disabled or not due to parents.
1149
+ * The block's own disabled property is not considered.
1150
+ * @return {boolean} True if disabled.
1151
+ */
1152
+ Blockly.Block.prototype.getInheritedDisabled = function() {
1153
+ var ancestor = this.getSurroundParent();
1154
+ while (ancestor) {
1155
+ if (ancestor.disabled) {
1156
+ return true;
1157
+ }
1158
+ ancestor = ancestor.getSurroundParent();
1159
+ }
1160
+ // Ran off the top.
1161
+ return false;
1162
+ };
1163
+
1164
+ /**
1165
+ * Get whether the block is collapsed or not.
1166
+ * @return {boolean} True if collapsed.
1167
+ */
1168
+ Blockly.Block.prototype.isCollapsed = function() {
1169
+ return this.collapsed_;
1170
+ };
1171
+
1172
+ /**
1173
+ * Set whether the block is collapsed or not.
1174
+ * @param {boolean} collapsed True if collapsed.
1175
+ */
1176
+ Blockly.Block.prototype.setCollapsed = function(collapsed) {
1177
+ if (this.collapsed_ != collapsed) {
1178
+ Blockly.Events.fire(new Blockly.Events.BlockChange(
1179
+ this, 'collapsed', null, this.collapsed_, collapsed));
1180
+ this.collapsed_ = collapsed;
1181
+ }
1182
+ };
1183
+
1184
+ /**
1185
+ * Create a human-readable text representation of this block and any children.
1186
+ * @param {number=} opt_maxLength Truncate the string to this length.
1187
+ * @param {string=} opt_emptyToken The placeholder string used to denote an
1188
+ * empty field. If not specified, '?' is used.
1189
+ * @return {string} Text of block.
1190
+ */
1191
+ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) {
1192
+ var text = [];
1193
+ var emptyFieldPlaceholder = opt_emptyToken || '?';
1194
+ if (this.collapsed_) {
1195
+ text.push(this.getInput('_TEMP_COLLAPSED_INPUT').fieldRow[0].text_);
1196
+ } else {
1197
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1198
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
1199
+ if (field instanceof Blockly.FieldDropdown && !field.getValue()) {
1200
+ text.push(emptyFieldPlaceholder);
1201
+ } else {
1202
+ text.push(field.getText());
1203
+ }
1204
+ }
1205
+ if (input.connection) {
1206
+ var child = input.connection.targetBlock();
1207
+ if (child) {
1208
+ text.push(child.toString(undefined, opt_emptyToken));
1209
+ } else {
1210
+ text.push(emptyFieldPlaceholder);
1211
+ }
1212
+ }
1213
+ }
1214
+ }
1215
+ text = goog.string.trim(text.join(' ')) || '???';
1216
+ if (opt_maxLength) {
1217
+ // TODO: Improve truncation so that text from this block is given priority.
1218
+ // E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...".
1219
+ // E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
1220
+ text = goog.string.truncate(text, opt_maxLength);
1221
+ }
1222
+ return text;
1223
+ };
1224
+
1225
+ /**
1226
+ * Shortcut for appending a value input row.
1227
+ * @param {string} name Language-neutral identifier which may used to find this
1228
+ * input again. Should be unique to this block.
1229
+ * @return {!Blockly.Input} The input object created.
1230
+ */
1231
+ Blockly.Block.prototype.appendValueInput = function(name) {
1232
+ return this.appendInput_(Blockly.INPUT_VALUE, name);
1233
+ };
1234
+
1235
+ /**
1236
+ * Shortcut for appending a statement input row.
1237
+ * @param {string} name Language-neutral identifier which may used to find this
1238
+ * input again. Should be unique to this block.
1239
+ * @return {!Blockly.Input} The input object created.
1240
+ */
1241
+ Blockly.Block.prototype.appendStatementInput = function(name) {
1242
+ return this.appendInput_(Blockly.NEXT_STATEMENT, name);
1243
+ };
1244
+
1245
+ /**
1246
+ * Shortcut for appending a dummy input row.
1247
+ * @param {string=} opt_name Language-neutral identifier which may used to find
1248
+ * this input again. Should be unique to this block.
1249
+ * @return {!Blockly.Input} The input object created.
1250
+ */
1251
+ Blockly.Block.prototype.appendDummyInput = function(opt_name) {
1252
+ return this.appendInput_(Blockly.DUMMY_INPUT, opt_name || '');
1253
+ };
1254
+
1255
+ /**
1256
+ * Initialize this block using a cross-platform, internationalization-friendly
1257
+ * JSON description.
1258
+ * @param {!Object} json Structured data describing the block.
1259
+ */
1260
+ Blockly.Block.prototype.jsonInit = function(json) {
1261
+ var warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : '';
1262
+
1263
+ // Validate inputs.
1264
+ goog.asserts.assert(
1265
+ json['output'] == undefined || json['previousStatement'] == undefined,
1266
+ warningPrefix + 'Must not have both an output and a previousStatement.');
1267
+
1268
+ // Set basic properties of block.
1269
+ if (json['colour'] !== undefined) {
1270
+ this.setColourFromJson_(json);
1271
+ }
1272
+
1273
+ // Interpolate the message blocks.
1274
+ var i = 0;
1275
+ while (json['message' + i] !== undefined) {
1276
+ this.interpolate_(json['message' + i], json['args' + i] || [],
1277
+ json['lastDummyAlign' + i]);
1278
+ i++;
1279
+ }
1280
+
1281
+ if (json['inputsInline'] !== undefined) {
1282
+ this.setInputsInline(json['inputsInline']);
1283
+ }
1284
+ // Set output and previous/next connections.
1285
+ if (json['output'] !== undefined) {
1286
+ this.setOutput(true, json['output']);
1287
+ }
1288
+ if (json['previousStatement'] !== undefined) {
1289
+ this.setPreviousStatement(true, json['previousStatement']);
1290
+ }
1291
+ if (json['nextStatement'] !== undefined) {
1292
+ this.setNextStatement(true, json['nextStatement']);
1293
+ }
1294
+ if (json['tooltip'] !== undefined) {
1295
+ var rawValue = json['tooltip'];
1296
+ var localizedText = Blockly.utils.replaceMessageReferences(rawValue);
1297
+ this.setTooltip(localizedText);
1298
+ }
1299
+ if (json['enableContextMenu'] !== undefined) {
1300
+ var rawValue = json['enableContextMenu'];
1301
+ this.contextMenu = !!rawValue;
1302
+ }
1303
+ if (json['helpUrl'] !== undefined) {
1304
+ var rawValue = json['helpUrl'];
1305
+ var localizedValue = Blockly.utils.replaceMessageReferences(rawValue);
1306
+ this.setHelpUrl(localizedValue);
1307
+ }
1308
+ if (goog.isString(json['extensions'])) {
1309
+ console.warn('JSON attribute \'extensions\' should be an array of ' +
1310
+ 'strings. Found raw string in JSON for \'' + json['type'] + '\' block.');
1311
+ json['extensions'] = [json['extensions']]; // Correct and continue.
1312
+ }
1313
+
1314
+ // Add the mutator to the block
1315
+ if (json['mutator'] !== undefined) {
1316
+ Blockly.Extensions.apply(json['mutator'], this, true);
1317
+ }
1318
+
1319
+ if (Array.isArray(json['extensions'])) {
1320
+ var extensionNames = json['extensions'];
1321
+ for (var i = 0; i < extensionNames.length; ++i) {
1322
+ var extensionName = extensionNames[i];
1323
+ Blockly.Extensions.apply(extensionName, this, false);
1324
+ }
1325
+ }
1326
+ if (json['outputShape'] !== undefined) {
1327
+ this.setOutputShape(json['outputShape']);
1328
+ }
1329
+ if (json['canDragDuplicate'] !== undefined) {
1330
+ this.setDragDuplication(json['canDragDuplicate']);
1331
+ }
1332
+ if (json['checkboxInFlyout'] !== undefined) {
1333
+ this.setCheckboxInFlyout(json['checkboxInFlyout']);
1334
+ }
1335
+ if (json['category'] !== undefined) {
1336
+ this.setCategory(json['category']);
1337
+ }
1338
+ };
1339
+
1340
+ /**
1341
+ * Add key/values from mixinObj to this block object. By default, this method
1342
+ * will check that the keys in mixinObj will not overwrite existing values in
1343
+ * the block, including prototype values. This provides some insurance against
1344
+ * mixin / extension incompatibilities with future block features. This check
1345
+ * can be disabled by passing true as the second argument.
1346
+ * @param {!Object} mixinObj The key/values pairs to add to this block object.
1347
+ * @param {boolean=} opt_disableCheck Option flag to disable overwrite checks.
1348
+ */
1349
+ Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) {
1350
+ if (goog.isDef(opt_disableCheck) && !goog.isBoolean(opt_disableCheck)) {
1351
+ throw new Error("opt_disableCheck must be a boolean if provided");
1352
+ }
1353
+ if (!opt_disableCheck) {
1354
+ var overwrites = [];
1355
+ for (var key in mixinObj) {
1356
+ if (this[key] !== undefined) {
1357
+ overwrites.push(key);
1358
+ }
1359
+ }
1360
+ if (overwrites.length) {
1361
+ throw new Error('Mixin will overwrite block members: ' +
1362
+ JSON.stringify(overwrites));
1363
+ }
1364
+ }
1365
+ goog.mixin(this, mixinObj);
1366
+ };
1367
+
1368
+ /**
1369
+ * Set the colour of the block from strings or string table references.
1370
+ * @param {string|?} primary Primary colour, which may be a string that contains
1371
+ * string table references.
1372
+ * @param {string|?} secondary Secondary colour, which may be a string that
1373
+ * contains string table references.
1374
+ * @param {string|?} tertiary Tertiary colour, which may be a string that
1375
+ * contains string table references.
1376
+ * @private
1377
+ */
1378
+ Blockly.Block.prototype.setColourFromRawValues_ = function(primary, secondary,
1379
+ tertiary) {
1380
+ primary = goog.isString(primary) ?
1381
+ Blockly.utils.replaceMessageReferences(primary) : primary;
1382
+ secondary = goog.isString(secondary) ?
1383
+ Blockly.utils.replaceMessageReferences(secondary) : secondary;
1384
+ tertiary = goog.isString(tertiary) ?
1385
+ Blockly.utils.replaceMessageReferences(tertiary) : tertiary;
1386
+
1387
+ this.setColour(primary, secondary, tertiary);
1388
+ };
1389
+
1390
+ /**
1391
+ * Set the colour of the block from JSON, replacing message references as
1392
+ * needed.
1393
+ * @param {!Object} json Structured data describing the block.
1394
+ * @private
1395
+ */
1396
+ Blockly.Block.prototype.setColourFromJson_ = function(json) {
1397
+ this.setColourFromRawValues_(json['colour'], json['colourSecondary'],
1398
+ json['colourTertiary']);
1399
+ };
1400
+
1401
+ /**
1402
+ * Interpolate a message description onto the block.
1403
+ * @param {string} message Text contains interpolation tokens (%1, %2, ...)
1404
+ * that match with fields or inputs defined in the args array.
1405
+ * @param {!Array} args Array of arguments to be interpolated.
1406
+ * @param {string=} lastDummyAlign If a dummy input is added at the end,
1407
+ * how should it be aligned?
1408
+ * @private
1409
+ */
1410
+ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
1411
+ var tokens = Blockly.utils.tokenizeInterpolation(message);
1412
+ // Interpolate the arguments. Build a list of elements.
1413
+ var indexDup = [];
1414
+ var indexCount = 0;
1415
+ var elements = [];
1416
+ for (var i = 0; i < tokens.length; i++) {
1417
+ var token = tokens[i];
1418
+ if (typeof token == 'number') {
1419
+ if (token <= 0 || token > args.length) {
1420
+ throw new Error('Block "' + this.type + '": ' +
1421
+ 'Message index %' + token + ' out of range.');
1422
+ }
1423
+ if (indexDup[token]) {
1424
+ throw new Error('Block "' + this.type + '": ' +
1425
+ 'Message index %' + token + ' duplicated.');
1426
+ }
1427
+ indexDup[token] = true;
1428
+ indexCount++;
1429
+ elements.push(args[token - 1]);
1430
+ } else {
1431
+ token = token.trim();
1432
+ if (token) {
1433
+ elements.push(token);
1434
+ }
1435
+ }
1436
+ }
1437
+ if (indexCount != args.length) {
1438
+ throw new Error('Block "' + this.type + '": ' +
1439
+ 'Message does not reference all ' + args.length + ' arg(s).');
1440
+ }
1441
+ // Add last dummy input if needed.
1442
+ if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
1443
+ goog.string.startsWith(
1444
+ elements[elements.length - 1]['type'], 'field_'))) {
1445
+ var dummyInput = {type: 'input_dummy'};
1446
+ if (lastDummyAlign) {
1447
+ dummyInput['align'] = lastDummyAlign;
1448
+ }
1449
+ elements.push(dummyInput);
1450
+ }
1451
+ // Lookup of alignment constants.
1452
+ var alignmentLookup = {
1453
+ 'LEFT': Blockly.ALIGN_LEFT,
1454
+ 'RIGHT': Blockly.ALIGN_RIGHT,
1455
+ 'CENTRE': Blockly.ALIGN_CENTRE
1456
+ };
1457
+ // Populate block with inputs and fields.
1458
+ var fieldStack = [];
1459
+ for (var i = 0; i < elements.length; i++) {
1460
+ var element = elements[i];
1461
+ if (typeof element == 'string') {
1462
+ fieldStack.push([element, undefined]);
1463
+ } else {
1464
+ var field = null;
1465
+ var input = null;
1466
+ do {
1467
+ var altRepeat = false;
1468
+ if (typeof element == 'string') {
1469
+ field = new Blockly.FieldLabel(element);
1470
+ } else {
1471
+ switch (element['type']) {
1472
+ case 'input_value':
1473
+ input = this.appendValueInput(element['name']);
1474
+ break;
1475
+ case 'input_statement':
1476
+ input = this.appendStatementInput(element['name']);
1477
+ break;
1478
+ case 'input_dummy':
1479
+ input = this.appendDummyInput(element['name']);
1480
+ break;
1481
+ default:
1482
+ field = Blockly.Field.fromJson(element);
1483
+
1484
+ // Unknown field.
1485
+ if (!field) {
1486
+ if (element['alt']) {
1487
+ element = element['alt'];
1488
+ altRepeat = true;
1489
+ } else {
1490
+ console.warn('Blockly could not create a field of type ' +
1491
+ element['type'] +
1492
+ '. You may need to register your custom field. See ' +
1493
+ 'github.com/google/blockly/issues/1584');
1494
+ }
1495
+ }
1496
+ }
1497
+ }
1498
+ } while (altRepeat);
1499
+ if (field) {
1500
+ fieldStack.push([field, element['name']]);
1501
+ } else if (input) {
1502
+ if (element['shape']) {
1503
+ input.setShape(element['shape']);
1504
+ }
1505
+ if (element['check']) {
1506
+ input.setCheck(element['check']);
1507
+ }
1508
+ if (element['align']) {
1509
+ input.setAlign(alignmentLookup[element['align']]);
1510
+ }
1511
+ for (var j = 0; j < fieldStack.length; j++) {
1512
+ input.appendField(fieldStack[j][0], fieldStack[j][1]);
1513
+ }
1514
+ fieldStack.length = 0;
1515
+ }
1516
+ }
1517
+ }
1518
+ };
1519
+
1520
+ /**
1521
+ * Add a value input, statement input or local variable to this block.
1522
+ * @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or
1523
+ * Blockly.DUMMY_INPUT.
1524
+ * @param {string} name Language-neutral identifier which may used to find this
1525
+ * input again. Should be unique to this block.
1526
+ * @return {!Blockly.Input} The input object created.
1527
+ * @protected
1528
+ */
1529
+ Blockly.Block.prototype.appendInput_ = function(type, name) {
1530
+ var connection = null;
1531
+ if (type == Blockly.INPUT_VALUE || type == Blockly.NEXT_STATEMENT) {
1532
+ connection = this.makeConnection_(type);
1533
+ }
1534
+ var input = new Blockly.Input(type, name, this, connection);
1535
+ // Append input to list.
1536
+ this.inputList.push(input);
1537
+ return input;
1538
+ };
1539
+
1540
+ /**
1541
+ * Move a named input to a different location on this block.
1542
+ * @param {string} name The name of the input to move.
1543
+ * @param {?string} refName Name of input that should be after the moved input,
1544
+ * or null to be the input at the end.
1545
+ */
1546
+ Blockly.Block.prototype.moveInputBefore = function(name, refName) {
1547
+ if (name == refName) {
1548
+ return;
1549
+ }
1550
+ // Find both inputs.
1551
+ var inputIndex = -1;
1552
+ var refIndex = refName ? -1 : this.inputList.length;
1553
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1554
+ if (input.name == name) {
1555
+ inputIndex = i;
1556
+ if (refIndex != -1) {
1557
+ break;
1558
+ }
1559
+ } else if (refName && input.name == refName) {
1560
+ refIndex = i;
1561
+ if (inputIndex != -1) {
1562
+ break;
1563
+ }
1564
+ }
1565
+ }
1566
+ goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name);
1567
+ goog.asserts.assert(
1568
+ refIndex != -1, 'Reference input "%s" not found.', refName);
1569
+ this.moveNumberedInputBefore(inputIndex, refIndex);
1570
+ };
1571
+
1572
+ /**
1573
+ * Move a numbered input to a different location on this block.
1574
+ * @param {number} inputIndex Index of the input to move.
1575
+ * @param {number} refIndex Index of input that should be after the moved input.
1576
+ */
1577
+ Blockly.Block.prototype.moveNumberedInputBefore = function(
1578
+ inputIndex, refIndex) {
1579
+ // Validate arguments.
1580
+ goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.');
1581
+ goog.asserts.assert(inputIndex < this.inputList.length,
1582
+ 'Input index ' + inputIndex + ' out of bounds.');
1583
+ goog.asserts.assert(refIndex <= this.inputList.length,
1584
+ 'Reference input ' + refIndex + ' out of bounds.');
1585
+ // Remove input.
1586
+ var input = this.inputList[inputIndex];
1587
+ this.inputList.splice(inputIndex, 1);
1588
+ if (inputIndex < refIndex) {
1589
+ refIndex--;
1590
+ }
1591
+ // Reinsert input.
1592
+ this.inputList.splice(refIndex, 0, input);
1593
+ };
1594
+
1595
+ /**
1596
+ * Remove an input from this block.
1597
+ * @param {string} name The name of the input.
1598
+ * @param {boolean=} opt_quiet True to prevent error if input is not present.
1599
+ * @throws {goog.asserts.AssertionError} if the input is not present and
1600
+ * opt_quiet is not true.
1601
+ */
1602
+ Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
1603
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1604
+ if (input.name == name) {
1605
+ if (input.connection && input.connection.isConnected()) {
1606
+ input.connection.setShadowDom(null);
1607
+ var block = input.connection.targetBlock();
1608
+ if (block.isShadow()) {
1609
+ // Destroy any attached shadow block.
1610
+ block.dispose();
1611
+ } else {
1612
+ // Disconnect any attached normal block.
1613
+ block.unplug();
1614
+ }
1615
+ }
1616
+ input.dispose();
1617
+ this.inputList.splice(i, 1);
1618
+ return;
1619
+ }
1620
+ }
1621
+ if (!opt_quiet) {
1622
+ goog.asserts.fail('Input "%s" not found.', name);
1623
+ }
1624
+ };
1625
+
1626
+ /**
1627
+ * Fetches the named input object.
1628
+ * @param {string} name The name of the input.
1629
+ * @return {Blockly.Input} The input object, or null if input does not exist.
1630
+ */
1631
+ Blockly.Block.prototype.getInput = function(name) {
1632
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1633
+ if (input.name == name) {
1634
+ return input;
1635
+ }
1636
+ }
1637
+ // This input does not exist.
1638
+ return null;
1639
+ };
1640
+
1641
+ /**
1642
+ * Fetches the block attached to the named input.
1643
+ * @param {string} name The name of the input.
1644
+ * @return {Blockly.Block} The attached value block, or null if the input is
1645
+ * either disconnected or if the input does not exist.
1646
+ */
1647
+ Blockly.Block.prototype.getInputTargetBlock = function(name) {
1648
+ var input = this.getInput(name);
1649
+ return input && input.connection && input.connection.targetBlock();
1650
+ };
1651
+
1652
+ /**
1653
+ * Returns the comment on this block (or '' if none).
1654
+ * @return {string} Block's comment.
1655
+ */
1656
+ Blockly.Block.prototype.getCommentText = function() {
1657
+ return this.comment || '';
1658
+ };
1659
+
1660
+ /**
1661
+ * Set this block's comment text.
1662
+ * @param {?string} text The text, or null to delete.
1663
+ */
1664
+ Blockly.Block.prototype.setCommentText = function(text) {
1665
+ if (this.comment != text) {
1666
+ Blockly.Events.fire(new Blockly.Events.BlockChange(
1667
+ this, 'comment', null, this.comment, text || ''));
1668
+ this.comment = text;
1669
+ }
1670
+ };
1671
+
1672
+ /**
1673
+ * Set this block's output shape.
1674
+ * e.g., null, OUTPUT_SHAPE_HEXAGONAL, OUTPUT_SHAPE_ROUND, OUTPUT_SHAPE_SQUARE, etc.
1675
+ * @param {?number} outputShape Value representing output shape
1676
+ * (see constants.js).
1677
+ */
1678
+ Blockly.Block.prototype.setOutputShape = function(outputShape) {
1679
+ this.outputShape_ = outputShape;
1680
+ };
1681
+
1682
+ /**
1683
+ * Get this block's output shape.
1684
+ * @return {?number} Value representing output shape (see constants.js).
1685
+ */
1686
+ Blockly.Block.prototype.getOutputShape = function() {
1687
+ return this.outputShape_;
1688
+ };
1689
+
1690
+ /**
1691
+ * Set this block's category (for styling purposes)
1692
+ * @param {?string} category The block's category (see constants.js).
1693
+ */
1694
+ Blockly.Block.prototype.setCategory = function(category) {
1695
+ this.category_ = category;
1696
+ };
1697
+
1698
+ /**
1699
+ * Get this block's category (for styling purposes)
1700
+ * @return {?string} category The block's category (see constants.js).
1701
+ */
1702
+ Blockly.Block.prototype.getCategory = function() {
1703
+ return this.category_;
1704
+ };
1705
+
1706
+ /**
1707
+ * Set whether this block has a checkbox next to it in the flyout.
1708
+ * @param {boolean} hasCheckbox True if this block should have a checkbox.
1709
+ */
1710
+ Blockly.Block.prototype.setCheckboxInFlyout = function(hasCheckbox) {
1711
+ this.checkboxInFlyout_ = hasCheckbox;
1712
+ };
1713
+
1714
+ /**
1715
+ * Get whether this block has a checkbox next to it in the flyout.
1716
+ * @return {boolean} True if this block should have a checkbox.
1717
+ */
1718
+ Blockly.Block.prototype.hasCheckboxInFlyout = function() {
1719
+ return this.checkboxInFlyout_;
1720
+ };
1721
+
1722
+ /**
1723
+ * pm: Set whether this block can duplicate on drag.
1724
+ * Note that a block must be a shadow block to duplicate on drag.
1725
+ * @param {boolean} canDragDuplicate True if this block should duplicate on drag.
1726
+ */
1727
+ Blockly.Block.prototype.setDragDuplication = function(canDragDuplicate) {
1728
+ this.canDragDuplicate_ = canDragDuplicate;
1729
+ };
1730
+
1731
+ /**
1732
+ * pm: Get whether this block can duplicate on drag.
1733
+ * This will only return true if the block is also a shadow block.
1734
+ * @return {boolean} True if this block can duplicate on drag.
1735
+ */
1736
+ Blockly.Block.prototype.canDragDuplicate = function() {
1737
+ return this.canDragDuplicate_ && this.isShadow();
1738
+ };
1739
+
1740
+ /**
1741
+ * Set this block's warning text.
1742
+ * @param {?string} text The text, or null to delete.
1743
+ * @abstract
1744
+ */
1745
+ Blockly.Block.prototype.setWarningText = function(/* text */) {
1746
+ // NOP.
1747
+ };
1748
+
1749
+ /**
1750
+ * Give this block a mutator dialog.
1751
+ * @param {Blockly.Mutator} mutator A mutator dialog instance or null to remove.
1752
+ * @abstract
1753
+ */
1754
+ Blockly.Block.prototype.setMutator = function(/* mutator */) {
1755
+ // NOP.
1756
+ };
1757
+
1758
+ /**
1759
+ * Return the coordinates of the top-left corner of this block relative to the
1760
+ * drawing surface's origin (0,0), in workspace units.
1761
+ * @return {!goog.math.Coordinate} Object with .x and .y properties.
1762
+ */
1763
+ Blockly.Block.prototype.getRelativeToSurfaceXY = function() {
1764
+ return this.xy_;
1765
+ };
1766
+
1767
+ /**
1768
+ * Move a block by a relative offset.
1769
+ * @param {number} dx Horizontal offset, in workspace units.
1770
+ * @param {number} dy Vertical offset, in workspace units.
1771
+ */
1772
+ Blockly.Block.prototype.moveBy = function(dx, dy) {
1773
+ goog.asserts.assert(!this.parentBlock_, 'Block has parent.');
1774
+ var event = new Blockly.Events.BlockMove(this);
1775
+ this.xy_.translate(dx, dy);
1776
+ event.recordNew();
1777
+ Blockly.Events.fire(event);
1778
+ };
1779
+
1780
+ /**
1781
+ * Create a connection of the specified type.
1782
+ * @param {number} type The type of the connection to create.
1783
+ * @return {!Blockly.Connection} A new connection of the specified type.
1784
+ * @private
1785
+ */
1786
+ Blockly.Block.prototype.makeConnection_ = function(type) {
1787
+ return new Blockly.Connection(this, type);
1788
+ };
1789
+
1790
+ /**
1791
+ * Recursively checks whether all statement and value inputs are filled with
1792
+ * blocks. Also checks all following statement blocks in this stack.
1793
+ * @param {boolean=} opt_shadowBlocksAreFilled An optional argument controlling
1794
+ * whether shadow blocks are counted as filled. Defaults to true.
1795
+ * @return {boolean} True if all inputs are filled, false otherwise.
1796
+ */
1797
+ Blockly.Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) {
1798
+ // Account for the shadow block filledness toggle.
1799
+ if (opt_shadowBlocksAreFilled === undefined) {
1800
+ opt_shadowBlocksAreFilled = true;
1801
+ }
1802
+ if (!opt_shadowBlocksAreFilled && this.isShadow()) {
1803
+ return false;
1804
+ }
1805
+
1806
+ // Recursively check each input block of the current block.
1807
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1808
+ if (!input.connection) {
1809
+ continue;
1810
+ }
1811
+ var target = input.connection.targetBlock();
1812
+ if (!target || !target.allInputsFilled(opt_shadowBlocksAreFilled)) {
1813
+ return false;
1814
+ }
1815
+ }
1816
+
1817
+ // Recursively check the next block after the current block.
1818
+ var next = this.getNextBlock();
1819
+ if (next) {
1820
+ return next.allInputsFilled(opt_shadowBlocksAreFilled);
1821
+ }
1822
+
1823
+ return true;
1824
+ };
1825
+
1826
+ /**
1827
+ * This method returns a string describing this Block in developer terms (type
1828
+ * name and ID; English only).
1829
+ *
1830
+ * Intended to on be used in console logs and errors. If you need a string that
1831
+ * uses the user's native language (including block text, field values, and
1832
+ * child blocks), use [toString()]{@link Blockly.Block#toString}.
1833
+ * @return {string} The description.
1834
+ */
1835
+ Blockly.Block.prototype.toDevString = function() {
1836
+ var msg = this.type ? '"' + this.type + '" block' : 'Block';
1837
+ if (this.id) {
1838
+ msg += ' (id="' + this.id + '")';
1839
+ }
1840
+ return msg;
1841
+ };
core/block_animations.js ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2018 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Methods animating a block on connection and disconnection.
23
+ * @author [email protected] (Rachel Fenichel)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.BlockAnimations');
28
+
29
+
30
+ /**
31
+ * Play some UI effects (sound, animation) when disposing of a block.
32
+ * @param {!Blockly.BlockSvg} block The block being disposed of.
33
+ * @package
34
+ */
35
+ Blockly.BlockAnimations.disposeUiEffect = function(block) {
36
+ var workspace = block.workspace;
37
+ var svgGroup = block.getSvgRoot();
38
+ workspace.getAudioManager().play('delete');
39
+
40
+ var xy = workspace.getSvgXY(svgGroup);
41
+ // Deeply clone the current block.
42
+ var clone = svgGroup.cloneNode(true);
43
+ clone.translateX_ = xy.x;
44
+ clone.translateY_ = xy.y;
45
+ clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')');
46
+ workspace.getParentSvg().appendChild(clone);
47
+ clone.bBox_ = clone.getBBox();
48
+ // Start the animation.
49
+ Blockly.BlockAnimations.disposeUiStep_(clone, workspace.RTL, new Date,
50
+ workspace.scale);
51
+ };
52
+
53
+ /**
54
+ * Animate a cloned block and eventually dispose of it.
55
+ * This is a class method, not an instance method since the original block has
56
+ * been destroyed and is no longer accessible.
57
+ * @param {!Element} clone SVG element to animate and dispose of.
58
+ * @param {boolean} rtl True if RTL, false if LTR.
59
+ * @param {!Date} start Date of animation's start.
60
+ * @param {number} workspaceScale Scale of workspace.
61
+ * @private
62
+ */
63
+ Blockly.BlockAnimations.disposeUiStep_ = function(clone, rtl, start,
64
+ workspaceScale) {
65
+ var ms = new Date - start;
66
+ var percent = ms / 150;
67
+ if (percent > 1) {
68
+ goog.dom.removeNode(clone);
69
+ } else {
70
+ var x = clone.translateX_ +
71
+ (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent;
72
+ var y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent;
73
+ var scale = (1 - percent) * workspaceScale;
74
+ clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' +
75
+ ' scale(' + scale + ')');
76
+ setTimeout(Blockly.BlockAnimations.disposeUiStep_, 10, clone, rtl, start,
77
+ workspaceScale);
78
+ }
79
+ };
80
+
81
+ /**
82
+ * Play some UI effects (sound, ripple) after a connection has been established.
83
+ * @param {!Blockly.BlockSvg} block The block being connected.
84
+ * @package
85
+ */
86
+ Blockly.BlockAnimations.connectionUiEffect = function(block) {
87
+ block.workspace.getAudioManager().play('click');
88
+ };
89
+
90
+ /**
91
+ * Play some UI effects (sound, animation) when disconnecting a block.
92
+ * No-op in scratch-blocks, which has no disconnect animation.
93
+ * @param {!Blockly.BlockSvg} _block The block being disconnected.
94
+ * @package
95
+ */
96
+ Blockly.BlockAnimations.disconnectUiEffect = function(
97
+ /* eslint-disable no-unused-vars */ _block
98
+ /* eslint-enable no-unused-vars */) {
99
+ };
100
+
101
+ /**
102
+ * Stop the disconnect UI animation immediately.
103
+ * No-op in scratch-blocks, which has no disconnect animation.
104
+ * @package
105
+ */
106
+ Blockly.BlockAnimations.disconnectUiStop = function() {
107
+ };
core/block_drag_surface.js ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview A class that manages a surface for dragging blocks. When a
23
+ * block drag is started, we move the block (and children) to a separate DOM
24
+ * element that we move around using translate3d. At the end of the drag, the
25
+ * blocks are put back in into the SVG they came from. This helps performance by
26
+ * avoiding repainting the entire SVG on every mouse move while dragging blocks.
27
+ * @author picklesrus
28
+ */
29
+
30
+ 'use strict';
31
+
32
+ goog.provide('Blockly.BlockDragSurfaceSvg');
33
+ goog.require('Blockly.utils');
34
+ goog.require('goog.asserts');
35
+ goog.require('goog.math.Coordinate');
36
+
37
+
38
+ /**
39
+ * Class for a drag surface for the currently dragged block. This is a separate
40
+ * SVG that contains only the currently moving block, or nothing.
41
+ * @param {!Element} container Containing element.
42
+ * @constructor
43
+ */
44
+ Blockly.BlockDragSurfaceSvg = function(container) {
45
+ /**
46
+ * @type {!Element}
47
+ * @private
48
+ */
49
+ this.container_ = container;
50
+ this.createDom();
51
+ };
52
+
53
+ /**
54
+ * The SVG drag surface. Set once by Blockly.BlockDragSurfaceSvg.createDom.
55
+ * @type {Element}
56
+ * @private
57
+ */
58
+ Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null;
59
+
60
+ /**
61
+ * This is where blocks live while they are being dragged if the drag surface
62
+ * is enabled.
63
+ * @type {Element}
64
+ * @private
65
+ */
66
+ Blockly.BlockDragSurfaceSvg.prototype.dragGroup_ = null;
67
+
68
+ /**
69
+ * Containing HTML element; parent of the workspace and the drag surface.
70
+ * @type {Element}
71
+ * @private
72
+ */
73
+ Blockly.BlockDragSurfaceSvg.prototype.container_ = null;
74
+
75
+ /**
76
+ * Cached value for the scale of the drag surface.
77
+ * Used to set/get the correct translation during and after a drag.
78
+ * @type {number}
79
+ * @private
80
+ */
81
+ Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1;
82
+
83
+ /**
84
+ * Cached value for the translation of the drag surface.
85
+ * This translation is in pixel units, because the scale is applied to the
86
+ * drag group rather than the top-level SVG.
87
+ * @type {goog.math.Coordinate}
88
+ * @private
89
+ */
90
+ Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null;
91
+
92
+ /**
93
+ * ID for the drag shadow filter, set in createDom.
94
+ * Belongs in Scratch Blocks but not Blockly.
95
+ * @type {string}
96
+ * @private
97
+ */
98
+ Blockly.BlockDragSurfaceSvg.prototype.dragShadowFilterId_ = '';
99
+
100
+ /**
101
+ * Standard deviation for gaussian blur on drag shadow, in px.
102
+ * Belongs in Scratch Blocks but not Blockly.
103
+ * @type {number}
104
+ * @const
105
+ */
106
+ Blockly.BlockDragSurfaceSvg.SHADOW_STD_DEVIATION = 6;
107
+
108
+ /**
109
+ * Create the drag surface and inject it into the container.
110
+ */
111
+ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() {
112
+ if (this.SVG_) {
113
+ return; // Already created.
114
+ }
115
+ this.SVG_ = Blockly.utils.createSvgElement('svg',
116
+ {
117
+ 'xmlns': Blockly.SVG_NS,
118
+ 'xmlns:html': Blockly.HTML_NS,
119
+ 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
120
+ 'version': '1.1',
121
+ 'class': 'blocklyBlockDragSurface'
122
+ }, this.container_);
123
+ this.dragGroup_ = Blockly.utils.createSvgElement('g', {}, this.SVG_);
124
+ // Belongs in Scratch Blocks, but not Blockly.
125
+ var defs = Blockly.utils.createSvgElement('defs', {}, this.SVG_);
126
+ this.dragShadowFilterId_ = this.createDropShadowDom_(defs);
127
+ this.dragGroup_.setAttribute(
128
+ 'filter', 'url(#' + this.dragShadowFilterId_ + ')');
129
+ };
130
+
131
+ /**
132
+ * Scratch-specific: Create the SVG def for the drop shadow.
133
+ * @param {Element} defs Defs element to insert the shadow filter definition
134
+ * @return {string} ID for the filter element
135
+ * @private
136
+ */
137
+ Blockly.BlockDragSurfaceSvg.prototype.createDropShadowDom_ = function(defs) {
138
+ var rnd = String(Math.random()).substring(2);
139
+ // Adjust these width/height, x/y properties to stop the shadow from clipping
140
+ var dragShadowFilter = Blockly.utils.createSvgElement('filter',
141
+ {
142
+ 'id': 'blocklyDragShadowFilter' + rnd,
143
+ 'height': '140%',
144
+ 'width': '140%',
145
+ 'y': '-20%',
146
+ 'x': '-20%'
147
+ },
148
+ defs);
149
+ Blockly.utils.createSvgElement('feGaussianBlur',
150
+ {
151
+ 'in': 'SourceAlpha',
152
+ 'stdDeviation': Blockly.BlockDragSurfaceSvg.SHADOW_STD_DEVIATION
153
+ },
154
+ dragShadowFilter);
155
+ var componentTransfer = Blockly.utils.createSvgElement(
156
+ 'feComponentTransfer', {'result': 'offsetBlur'}, dragShadowFilter);
157
+ // Shadow opacity is specified in the adjustable colour library,
158
+ // since the darkness of the shadow largely depends on the workspace colour.
159
+ Blockly.utils.createSvgElement('feFuncA',
160
+ {
161
+ 'type': 'linear',
162
+ 'slope': Blockly.Colours.dragShadowOpacity
163
+ },
164
+ componentTransfer);
165
+ Blockly.utils.createSvgElement('feComposite',
166
+ {
167
+ 'in': 'SourceGraphic',
168
+ 'in2': 'offsetBlur',
169
+ 'operator': 'over'
170
+ },
171
+ dragShadowFilter);
172
+ return dragShadowFilter.id;
173
+ };
174
+
175
+ /**
176
+ * Set the SVG blocks on the drag surface's group and show the surface.
177
+ * Only one block group should be on the drag surface at a time.
178
+ * @param {!Element} blocks Block or group of blocks to place on the drag
179
+ * surface.
180
+ */
181
+ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
182
+ goog.asserts.assert(
183
+ this.dragGroup_.childNodes.length == 0, 'Already dragging a block.');
184
+ // appendChild removes the blocks from the previous parent
185
+ this.dragGroup_.appendChild(blocks);
186
+ this.SVG_.style.display = 'block';
187
+ this.surfaceXY_ = new goog.math.Coordinate(0, 0);
188
+ // This allows blocks to be dragged outside of the blockly svg space.
189
+ // This should be reset to hidden at the end of the block drag.
190
+ // Note that this behavior is different from blockly where block disappear
191
+ // "under" the blockly area.
192
+ var injectionDiv = document.getElementsByClassName('injectionDiv')[0];
193
+ injectionDiv.style.overflow = 'visible';
194
+ };
195
+
196
+ /**
197
+ * Translate and scale the entire drag surface group to the given position, to
198
+ * keep in sync with the workspace.
199
+ * @param {number} x X translation in workspace coordinates.
200
+ * @param {number} y Y translation in workspace coordinates.
201
+ * @param {number} scale Scale of the group.
202
+ */
203
+ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) {
204
+ this.scale_ = scale;
205
+ // This is a work-around to prevent a the blocks from rendering
206
+ // fuzzy while they are being dragged on the drag surface.
207
+ var fixedX = x.toFixed(0);
208
+ var fixedY = y.toFixed(0);
209
+ this.dragGroup_.setAttribute('transform',
210
+ 'translate(' + fixedX + ',' + fixedY + ') scale(' + scale + ')');
211
+ };
212
+
213
+ /**
214
+ * Translate the drag surface's SVG based on its internal state.
215
+ * @private
216
+ */
217
+ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() {
218
+ var x = this.surfaceXY_.x;
219
+ var y = this.surfaceXY_.y;
220
+ // This is a work-around to prevent a the blocks from rendering
221
+ // fuzzy while they are being dragged on the drag surface.
222
+ x = x.toFixed(0);
223
+ y = y.toFixed(0);
224
+ this.SVG_.style.display = 'block';
225
+
226
+ Blockly.utils.setCssTransform(this.SVG_,
227
+ 'translate(' + x + 'px, ' + y + 'px)');
228
+ };
229
+
230
+ /**
231
+ * Translate the entire drag surface during a drag.
232
+ * We translate the drag surface instead of the blocks inside the surface
233
+ * so that the browser avoids repainting the SVG.
234
+ * Because of this, the drag coordinates must be adjusted by scale.
235
+ * @param {number} x X translation for the entire surface.
236
+ * @param {number} y Y translation for the entire surface.
237
+ */
238
+ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) {
239
+ this.surfaceXY_ = new goog.math.Coordinate(x * this.scale_, y * this.scale_);
240
+ this.translateSurfaceInternal_();
241
+ };
242
+
243
+ /**
244
+ * Reports the surface translation in scaled workspace coordinates.
245
+ * Use this when finishing a drag to return blocks to the correct position.
246
+ * @return {!goog.math.Coordinate} Current translation of the surface.
247
+ */
248
+ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
249
+ var xy = Blockly.utils.getRelativeXY(this.SVG_);
250
+ return new goog.math.Coordinate(xy.x / this.scale_, xy.y / this.scale_);
251
+ };
252
+
253
+ /**
254
+ * Provide a reference to the drag group (primarily for
255
+ * BlockSvg.getRelativeToSurfaceXY).
256
+ * @return {Element} Drag surface group element.
257
+ */
258
+ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() {
259
+ return this.dragGroup_;
260
+ };
261
+
262
+ /**
263
+ * Get the current blocks on the drag surface, if any (primarily
264
+ * for BlockSvg.getRelativeToSurfaceXY).
265
+ * @return {!Element|undefined} Drag surface block DOM element, or undefined
266
+ * if no blocks exist.
267
+ */
268
+ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
269
+ return this.dragGroup_.firstChild;
270
+ };
271
+
272
+ /**
273
+ * Clear the group and hide the surface; move the blocks off onto the provided
274
+ * element.
275
+ * If the block is being deleted it doesn't need to go back to the original
276
+ * surface, since it would be removed immediately during dispose.
277
+ * @param {Element=} opt_newSurface Surface the dragging blocks should be moved
278
+ * to, or null if the blocks should be removed from this surface without
279
+ * being moved to a different surface.
280
+ */
281
+ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) {
282
+ if (opt_newSurface) {
283
+ // appendChild removes the node from this.dragGroup_
284
+ opt_newSurface.appendChild(this.getCurrentBlock());
285
+ } else {
286
+ this.dragGroup_.removeChild(this.getCurrentBlock());
287
+ }
288
+ this.SVG_.style.display = 'none';
289
+ goog.asserts.assert(
290
+ this.dragGroup_.childNodes.length == 0, 'Drag group was not cleared.');
291
+ this.surfaceXY_ = null;
292
+
293
+ // Reset the overflow property back to hidden so that nothing appears outside
294
+ // of the blockly area.
295
+ // Note that this behavior is different from blockly. See note in
296
+ // setBlocksAndShow.
297
+ var injectionDiv = document.getElementsByClassName('injectionDiv')[0];
298
+ injectionDiv.style.overflow = 'hidden';
299
+ };
core/block_dragger.js ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2017 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Methods for dragging a block visually.
23
+ * @author [email protected] (Rachel Fenichel)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.BlockDragger');
28
+
29
+ goog.require('Blockly.BlockAnimations');
30
+ goog.require('Blockly.Events.BlockMove');
31
+ goog.require('Blockly.Events.DragBlockOutside');
32
+ goog.require('Blockly.Events.EndBlockDrag');
33
+ goog.require('Blockly.InsertionMarkerManager');
34
+
35
+ goog.require('goog.math.Coordinate');
36
+ goog.require('goog.asserts');
37
+
38
+
39
+ /**
40
+ * Class for a block dragger. It moves blocks around the workspace when they
41
+ * are being dragged by a mouse or touch.
42
+ * @param {!Blockly.BlockSvg} block The block to drag.
43
+ * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on.
44
+ * @constructor
45
+ */
46
+ Blockly.BlockDragger = function(block, workspace) {
47
+ /**
48
+ * The top block in the stack that is being dragged.
49
+ * @type {!Blockly.BlockSvg}
50
+ * @private
51
+ */
52
+ this.draggingBlock_ = block;
53
+
54
+ /**
55
+ * The workspace on which the block is being dragged.
56
+ * @type {!Blockly.WorkspaceSvg}
57
+ * @private
58
+ */
59
+ this.workspace_ = workspace;
60
+
61
+ /**
62
+ * Object that keeps track of connections on dragged blocks.
63
+ * @type {!Blockly.InsertionMarkerManager}
64
+ * @private
65
+ */
66
+ this.draggedConnectionManager_ = new Blockly.InsertionMarkerManager(
67
+ this.draggingBlock_);
68
+
69
+ /**
70
+ * Which delete area the mouse pointer is over, if any.
71
+ * One of {@link Blockly.DELETE_AREA_TRASH},
72
+ * {@link Blockly.DELETE_AREA_TOOLBOX}, or {@link Blockly.DELETE_AREA_NONE}.
73
+ * @type {?number}
74
+ * @private
75
+ */
76
+ this.deleteArea_ = null;
77
+
78
+ /**
79
+ * Whether the block would be deleted if dropped immediately.
80
+ * @type {boolean}
81
+ * @private
82
+ */
83
+ this.wouldDeleteBlock_ = false;
84
+
85
+ /**
86
+ * Whether the currently dragged block is outside of the workspace. Keep
87
+ * track so that we can fire events only when this changes.
88
+ * @type {boolean}
89
+ * @private
90
+ */
91
+ this.wasOutside_ = false;
92
+
93
+ /**
94
+ * The location of the top left corner of the dragging block at the beginning
95
+ * of the drag in workspace coordinates.
96
+ * @type {!goog.math.Coordinate}
97
+ * @private
98
+ */
99
+ this.startXY_ = this.draggingBlock_.getRelativeToSurfaceXY();
100
+
101
+ /**
102
+ * A list of all of the icons (comment, warning, and mutator) that are
103
+ * on this block and its descendants. Moving an icon moves the bubble that
104
+ * extends from it if that bubble is open.
105
+ * @type {Array.<!Object>}
106
+ * @private
107
+ */
108
+ this.dragIconData_ = Blockly.BlockDragger.initIconData_(block);
109
+ };
110
+
111
+ /**
112
+ * Sever all links from this object.
113
+ * @package
114
+ */
115
+ Blockly.BlockDragger.prototype.dispose = function() {
116
+ this.draggingBlock_ = null;
117
+ this.workspace_ = null;
118
+ this.startWorkspace_ = null;
119
+ this.dragIconData_.length = 0;
120
+
121
+ if (this.draggedConnectionManager_) {
122
+ this.draggedConnectionManager_.dispose();
123
+ this.draggedConnectionManager_ = null;
124
+ }
125
+ };
126
+
127
+ /**
128
+ * Make a list of all of the icons (comment, warning, and mutator) that are
129
+ * on this block and its descendants. Moving an icon moves the bubble that
130
+ * extends from it if that bubble is open.
131
+ * @param {!Blockly.BlockSvg} block The root block that is being dragged.
132
+ * @return {!Array.<!Object>} The list of all icons and their locations.
133
+ * @private
134
+ */
135
+ Blockly.BlockDragger.initIconData_ = function(block) {
136
+ // Build a list of icons that need to be moved and where they started.
137
+ var dragIconData = [];
138
+ var descendants = block.getDescendants(false);
139
+ for (var i = 0, descendant; descendant = descendants[i]; i++) {
140
+ var icons = descendant.getIcons();
141
+ for (var j = 0; j < icons.length; j++) {
142
+ var data = {
143
+ // goog.math.Coordinate with x and y properties (workspace coordinates).
144
+ location: icons[j].getIconLocation(),
145
+ // Blockly.Icon
146
+ icon: icons[j]
147
+ };
148
+ dragIconData.push(data);
149
+ }
150
+ }
151
+ return dragIconData;
152
+ };
153
+
154
+ /**
155
+ * Start dragging a block. This includes moving it to the drag surface.
156
+ * @param {!goog.math.Coordinate} currentDragDeltaXY How far the pointer has
157
+ * moved from the position at mouse down, in pixel units.
158
+ * @package
159
+ */
160
+ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY) {
161
+ if (!Blockly.Events.getGroup()) {
162
+ Blockly.Events.setGroup(true);
163
+ }
164
+
165
+ this.workspace_.setResizesEnabled(false);
166
+ Blockly.BlockAnimations.disconnectUiStop();
167
+
168
+ if (this.draggingBlock_.getParent()) {
169
+ this.draggingBlock_.unplug();
170
+ var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
171
+ var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
172
+
173
+ this.draggingBlock_.translate(newLoc.x, newLoc.y);
174
+ Blockly.BlockAnimations.disconnectUiEffect(this.draggingBlock_);
175
+ }
176
+ this.draggingBlock_.setDragging(true);
177
+ // For future consideration: we may be able to put moveToDragSurface inside
178
+ // the block dragger, which would also let the block not track the block drag
179
+ // surface.
180
+ this.draggingBlock_.moveToDragSurface_();
181
+
182
+ var toolbox = this.workspace_.getToolbox();
183
+ if (toolbox) {
184
+ var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' :
185
+ 'blocklyToolboxGrab';
186
+ toolbox.addStyle(style);
187
+ }
188
+ };
189
+
190
+ /**
191
+ * Execute a step of block dragging, based on the given event. Update the
192
+ * display accordingly.
193
+ * @param {!Event} e The most recent move event.
194
+ * @param {!goog.math.Coordinate} currentDragDeltaXY How far the pointer has
195
+ * moved from the position at the start of the drag, in pixel units.
196
+ * @package
197
+ * @return {boolean} True if the event should be propagated, false if not.
198
+ */
199
+ Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) {
200
+ var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
201
+ var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
202
+
203
+ this.draggingBlock_.moveDuringDrag(newLoc);
204
+ this.dragIcons_(delta);
205
+
206
+ this.deleteArea_ = this.workspace_.isDeleteArea(e);
207
+ var isOutside = !this.workspace_.isInsideBlocksArea(e);
208
+ this.draggedConnectionManager_.update(delta, this.deleteArea_, isOutside);
209
+ if (isOutside !== this.wasOutside_) {
210
+ this.fireDragOutsideEvent_(isOutside);
211
+ this.wasOutside_ = isOutside;
212
+ }
213
+
214
+ this.updateCursorDuringBlockDrag_(isOutside);
215
+ return isOutside;
216
+ };
217
+
218
+ /**
219
+ * Finish a block drag and put the block back on the workspace.
220
+ * @param {!Event} e The mouseup/touchend event.
221
+ * @param {!goog.math.Coordinate} currentDragDeltaXY How far the pointer has
222
+ * moved from the position at the start of the drag, in pixel units.
223
+ * @package
224
+ */
225
+ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
226
+ // Make sure internal state is fresh.
227
+ this.dragBlock(e, currentDragDeltaXY);
228
+ this.dragIconData_ = [];
229
+ var isOutside = this.wasOutside_;
230
+ this.fireEndDragEvent_(isOutside);
231
+ this.draggingBlock_.setMouseThroughStyle(false);
232
+
233
+ Blockly.BlockAnimations.disconnectUiStop();
234
+
235
+ var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
236
+ var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
237
+ this.draggingBlock_.moveOffDragSurface_(newLoc);
238
+
239
+ // Scratch-specific: note possible illegal definition deletion for rollback below.
240
+ var isDeletingProcDef = this.wouldDeleteBlock_ &&
241
+ (this.draggingBlock_.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE ||
242
+ this.draggingBlock_.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return');
243
+ if (isDeletingProcDef) {
244
+ var procCodeBeingDeleted = this.draggingBlock_.getInput('custom_block').connection.targetBlock().getProcCode();
245
+ }
246
+
247
+ var deleted = this.maybeDeleteBlock_();
248
+ if (!deleted) {
249
+ // These are expensive and don't need to be done if we're deleting.
250
+ this.draggingBlock_.moveConnections_(delta.x, delta.y);
251
+ this.draggingBlock_.setDragging(false);
252
+ this.fireMoveEvent_();
253
+ if (this.draggedConnectionManager_.wouldConnectBlock()) {
254
+ // Applying connections also rerenders the relevant blocks.
255
+ this.draggedConnectionManager_.applyConnections();
256
+ } else {
257
+ this.draggingBlock_.render();
258
+ }
259
+ this.draggingBlock_.scheduleSnapAndBump();
260
+ }
261
+ this.workspace_.setResizesEnabled(true);
262
+
263
+ var toolbox = this.workspace_.getToolbox();
264
+ if (toolbox) {
265
+ var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' :
266
+ 'blocklyToolboxGrab';
267
+ toolbox.removeStyle(style);
268
+ }
269
+ Blockly.Events.setGroup(false);
270
+
271
+ if (isOutside) {
272
+ var ws = this.workspace_;
273
+ // Reset a drag to outside of scratch-blocks
274
+ setTimeout(function() {
275
+ ws.undo();
276
+ });
277
+ }
278
+
279
+ // Scratch-specific: roll back deletes that create call blocks with defines.
280
+ // Have to wait for connections to be re-established, so put in setTimeout.
281
+ // Only do this if we deleted a proc def.
282
+ if (isDeletingProcDef) {
283
+ var ws = this.workspace_;
284
+ setTimeout(function() {
285
+ var allBlocks = ws.getAllBlocks();
286
+ for (var i = 0; i < allBlocks.length; i++) {
287
+ var block = allBlocks[i];
288
+ if (block.type == Blockly.PROCEDURES_CALL_BLOCK_TYPE) {
289
+ var procCode = block.getProcCode();
290
+ // Check for call blocks with no associated define block.
291
+ if (procCode === procCodeBeingDeleted) {
292
+ alert(Blockly.Msg.PROCEDURE_USED);
293
+ ws.undo();
294
+ return; // There can only be one define deletion at a time.
295
+ }
296
+ }
297
+ }
298
+ // The proc deletion was valid, update the toolbox.
299
+ ws.refreshToolboxSelection_();
300
+ });
301
+ }
302
+ };
303
+
304
+ /**
305
+ * Fire an event when the dragged blocks move outside or back into the blocks workspace
306
+ * @param {?boolean} isOutside True if the drag is going outside the visible area.
307
+ * @private
308
+ */
309
+ Blockly.BlockDragger.prototype.fireDragOutsideEvent_ = function(isOutside) {
310
+ var event = new Blockly.Events.DragBlockOutside(this.draggingBlock_);
311
+ event.isOutside = isOutside;
312
+ Blockly.Events.fire(event);
313
+ };
314
+
315
+ /**
316
+ * Fire an end drag event at the end of a block drag.
317
+ * @param {?boolean} isOutside True if the drag is going outside the visible area.
318
+ * @private
319
+ */
320
+ Blockly.BlockDragger.prototype.fireEndDragEvent_ = function(isOutside) {
321
+ var event = new Blockly.Events.EndBlockDrag(this.draggingBlock_, isOutside);
322
+ Blockly.Events.fire(event);
323
+ };
324
+
325
+ /**
326
+ * Fire a move event at the end of a block drag.
327
+ * @private
328
+ */
329
+ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() {
330
+ var event = new Blockly.Events.BlockMove(this.draggingBlock_);
331
+ event.oldCoordinate = this.startXY_;
332
+ event.recordNew();
333
+ Blockly.Events.fire(event);
334
+ };
335
+
336
+ /**
337
+ * Shut the trash can and, if necessary, delete the dragging block.
338
+ * Should be called at the end of a block drag.
339
+ * @return {boolean} whether the block was deleted.
340
+ * @private
341
+ */
342
+ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() {
343
+ var trashcan = this.workspace_.trashcan;
344
+
345
+ if (this.wouldDeleteBlock_) {
346
+ if (trashcan) {
347
+ goog.Timer.callOnce(trashcan.close, 100, trashcan);
348
+ }
349
+ // Fire a move event, so we know where to go back to for an undo.
350
+ this.fireMoveEvent_();
351
+ this.draggingBlock_.dispose(false, true);
352
+ } else if (trashcan) {
353
+ // Make sure the trash can is closed.
354
+ trashcan.close();
355
+ }
356
+ return this.wouldDeleteBlock_;
357
+ };
358
+
359
+ /**
360
+ * Update the cursor (and possibly the trash can lid) to reflect whether the
361
+ * dragging block would be deleted if released immediately.
362
+ * @param {boolean} isOutside True if the cursor is outside of the blocks workspace
363
+ * @private
364
+ */
365
+ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function(isOutside) {
366
+ this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock();
367
+ var trashcan = this.workspace_.trashcan;
368
+ if (this.wouldDeleteBlock_) {
369
+ this.draggingBlock_.setDeleteStyle(true);
370
+ if (this.deleteArea_ == Blockly.DELETE_AREA_TRASH && trashcan) {
371
+ trashcan.setOpen_(true);
372
+ }
373
+ } else {
374
+ this.draggingBlock_.setDeleteStyle(false);
375
+ if (trashcan) {
376
+ trashcan.setOpen_(false);
377
+ }
378
+ }
379
+
380
+ if (isOutside) {
381
+ // Let mouse events through to GUI
382
+ this.draggingBlock_.setMouseThroughStyle(true);
383
+ } else {
384
+ this.draggingBlock_.setMouseThroughStyle(false);
385
+ }
386
+ };
387
+
388
+ /**
389
+ * Convert a coordinate object from pixels to workspace units, including a
390
+ * correction for mutator workspaces.
391
+ * This function does not consider differing origins. It simply scales the
392
+ * input's x and y values.
393
+ * @param {!goog.math.Coordinate} pixelCoord A coordinate with x and y values
394
+ * in css pixel units.
395
+ * @return {!goog.math.Coordinate} The input coordinate divided by the workspace
396
+ * scale.
397
+ * @private
398
+ */
399
+ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
400
+ var result = new goog.math.Coordinate(pixelCoord.x / this.workspace_.scale,
401
+ pixelCoord.y / this.workspace_.scale);
402
+ if (this.workspace_.isMutator) {
403
+ // If we're in a mutator, its scale is always 1, purely because of some
404
+ // oddities in our rendering optimizations. The actual scale is the same as
405
+ // the scale on the parent workspace.
406
+ // Fix that for dragging.
407
+ var mainScale = this.workspace_.options.parentWorkspace.scale;
408
+ result = result.scale(1 / mainScale);
409
+ }
410
+ return result;
411
+ };
412
+
413
+ /**
414
+ * Move all of the icons connected to this drag.
415
+ * @param {!goog.math.Coordinate} dxy How far to move the icons from their
416
+ * original positions, in workspace units.
417
+ * @private
418
+ */
419
+ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) {
420
+ // Moving icons moves their associated bubbles.
421
+ for (var i = 0; i < this.dragIconData_.length; i++) {
422
+ var data = this.dragIconData_[i];
423
+ data.icon.setIconLocation(goog.math.Coordinate.sum(data.location, dxy));
424
+ }
425
+ };
core/block_events.js ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2018 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Classes for all types of block events.
23
+ * @author [email protected] (Rachel Fenichel)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.Events.BlockBase');
28
+ goog.provide('Blockly.Events.BlockChange');
29
+ goog.provide('Blockly.Events.BlockCreate');
30
+ goog.provide('Blockly.Events.BlockDelete');
31
+ goog.provide('Blockly.Events.BlockMove');
32
+ goog.provide('Blockly.Events.Change'); // Deprecated.
33
+ goog.provide('Blockly.Events.Create'); // Deprecated.
34
+ goog.provide('Blockly.Events.Delete'); // Deprecated.
35
+ goog.provide('Blockly.Events.Move'); // Deprecated.
36
+
37
+ goog.require('Blockly.Events');
38
+ goog.require('Blockly.Events.Abstract');
39
+
40
+ goog.require('goog.array');
41
+ goog.require('goog.math.Coordinate');
42
+
43
+
44
+ /**
45
+ * Abstract class for a block event.
46
+ * @param {Blockly.Block} block The block this event corresponds to.
47
+ * @extends {Blockly.Events.Abstract}
48
+ * @constructor
49
+ */
50
+ Blockly.Events.BlockBase = function(block) {
51
+ Blockly.Events.BlockBase.superClass_.constructor.call(this);
52
+
53
+ /**
54
+ * The block id for the block this event pertains to
55
+ * @type {string}
56
+ */
57
+ this.blockId = block.id;
58
+ this.workspaceId = block.workspace.id;
59
+ };
60
+ goog.inherits(Blockly.Events.BlockBase, Blockly.Events.Abstract);
61
+
62
+ /**
63
+ * Encode the event as JSON.
64
+ * @return {!Object} JSON representation.
65
+ */
66
+ Blockly.Events.BlockBase.prototype.toJson = function() {
67
+ var json = Blockly.Events.BlockBase.superClass_.toJson.call(this);
68
+ json['blockId'] = this.blockId;
69
+ return json;
70
+ };
71
+
72
+ /**
73
+ * Decode the JSON event.
74
+ * @param {!Object} json JSON representation.
75
+ */
76
+ Blockly.Events.BlockBase.prototype.fromJson = function(json) {
77
+ Blockly.Events.BlockBase.superClass_.toJson.call(this);
78
+ this.blockId = json['blockId'];
79
+ };
80
+
81
+ /**
82
+ * Class for a block change event.
83
+ * @param {Blockly.Block} block The changed block. Null for a blank event.
84
+ * @param {string} element One of 'field', 'comment', 'disabled', etc.
85
+ * @param {?string} name Name of input or field affected, or null.
86
+ * @param {*} oldValue Previous value of element.
87
+ * @param {*} newValue New value of element.
88
+ * @extends {Blockly.Events.BlockBase}
89
+ * @constructor
90
+ */
91
+ Blockly.Events.Change = function(block, element, name, oldValue, newValue) {
92
+ if (!block) {
93
+ return; // Blank event to be populated by fromJson.
94
+ }
95
+ Blockly.Events.Change.superClass_.constructor.call(this, block);
96
+ this.element = element;
97
+ this.name = name;
98
+ this.oldValue = oldValue;
99
+ this.newValue = newValue;
100
+ };
101
+ goog.inherits(Blockly.Events.Change, Blockly.Events.BlockBase);
102
+
103
+ /**
104
+ * Class for a block change event.
105
+ * @param {Blockly.Block} block The changed block. Null for a blank event.
106
+ * @param {string} element One of 'field', 'comment', 'disabled', etc.
107
+ * @param {?string} name Name of input or field affected, or null.
108
+ * @param {*} oldValue Previous value of element.
109
+ * @param {*} newValue New value of element.
110
+ * @extends {Blockly.Events.BlockBase}
111
+ * @constructor
112
+ */
113
+ Blockly.Events.BlockChange = Blockly.Events.Change;
114
+
115
+ /**
116
+ * Type of this event.
117
+ * @type {string}
118
+ */
119
+ Blockly.Events.Change.prototype.type = Blockly.Events.CHANGE;
120
+
121
+ /**
122
+ * Encode the event as JSON.
123
+ * @return {!Object} JSON representation.
124
+ */
125
+ Blockly.Events.Change.prototype.toJson = function() {
126
+ var json = Blockly.Events.Change.superClass_.toJson.call(this);
127
+ json['element'] = this.element;
128
+ if (this.name) {
129
+ json['name'] = this.name;
130
+ }
131
+ json['newValue'] = this.newValue;
132
+ return json;
133
+ };
134
+
135
+ /**
136
+ * Decode the JSON event.
137
+ * @param {!Object} json JSON representation.
138
+ */
139
+ Blockly.Events.Change.prototype.fromJson = function(json) {
140
+ Blockly.Events.Change.superClass_.fromJson.call(this, json);
141
+ this.element = json['element'];
142
+ this.name = json['name'];
143
+ this.newValue = json['newValue'];
144
+ };
145
+
146
+ /**
147
+ * Does this event record any change of state?
148
+ * @return {boolean} False if something changed.
149
+ */
150
+ Blockly.Events.Change.prototype.isNull = function() {
151
+ return this.oldValue == this.newValue;
152
+ };
153
+
154
+ /**
155
+ * Run a change event.
156
+ * @param {boolean} forward True if run forward, false if run backward (undo).
157
+ */
158
+ Blockly.Events.Change.prototype.run = function(forward) {
159
+ var workspace = this.getEventWorkspace_();
160
+ var block = workspace.getBlockById(this.blockId);
161
+ if (!block) {
162
+ console.warn("Can't change non-existent block: " + this.blockId);
163
+ return;
164
+ }
165
+ if (block.mutator) {
166
+ // Close the mutator (if open) since we don't want to update it.
167
+ block.mutator.setVisible(false);
168
+ }
169
+ var value = forward ? this.newValue : this.oldValue;
170
+ switch (this.element) {
171
+ case 'field':
172
+ var field = block.getField(this.name);
173
+ if (field) {
174
+ // Run the validator for any side-effects it may have.
175
+ // The validator's opinion on validity is ignored.
176
+ field.callValidator(value);
177
+ field.setValue(value);
178
+ } else {
179
+ console.warn("Can't set non-existent field: " + this.name);
180
+ }
181
+ break;
182
+ case 'comment':
183
+ block.setCommentText(value || null);
184
+ break;
185
+ case 'collapsed':
186
+ block.setCollapsed(value);
187
+ break;
188
+ case 'disabled':
189
+ block.setDisabled(value);
190
+ break;
191
+ case 'inline':
192
+ block.setInputsInline(value);
193
+ break;
194
+ case 'mutation':
195
+ var oldMutation = '';
196
+ if (block.mutationToDom) {
197
+ var oldMutationDom = block.mutationToDom();
198
+ oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom);
199
+ }
200
+ if (block.domToMutation) {
201
+ value = value || '<mutation></mutation>';
202
+ var dom = Blockly.Xml.textToDom('<xml>' + value + '</xml>');
203
+ block.domToMutation(dom.firstChild);
204
+ }
205
+ Blockly.Events.fire(new Blockly.Events.Change(
206
+ block, 'mutation', null, oldMutation, value));
207
+ break;
208
+ default:
209
+ console.warn('Unknown change type: ' + this.element);
210
+ }
211
+ };
212
+
213
+ /**
214
+ * Class for a block creation event.
215
+ * @param {Blockly.Block} block The created block. Null for a blank event.
216
+ * @extends {Blockly.Events.BlockBase}
217
+ * @constructor
218
+ */
219
+ Blockly.Events.Create = function(block) {
220
+ if (!block) {
221
+ return; // Blank event to be populated by fromJson.
222
+ }
223
+ Blockly.Events.Create.superClass_.constructor.call(this, block);
224
+
225
+ if (block.workspace.rendered) {
226
+ this.xml = Blockly.Xml.blockToDomWithXY(block);
227
+ } else {
228
+ this.xml = Blockly.Xml.blockToDom(block);
229
+ }
230
+ this.ids = Blockly.Events.getDescendantIds_(block);
231
+ };
232
+ goog.inherits(Blockly.Events.Create, Blockly.Events.BlockBase);
233
+
234
+ /**
235
+ * Class for a block creation event.
236
+ * @param {Blockly.Block} block The created block. Null for a blank event.
237
+ * @extends {Blockly.Events.BlockBase}
238
+ * @constructor
239
+ */
240
+ Blockly.Events.BlockCreate = Blockly.Events.Create;
241
+
242
+ /**
243
+ * Type of this event.
244
+ * @type {string}
245
+ */
246
+ Blockly.Events.Create.prototype.type = Blockly.Events.CREATE;
247
+
248
+ /**
249
+ * Encode the event as JSON.
250
+ * @return {!Object} JSON representation.
251
+ */
252
+ Blockly.Events.Create.prototype.toJson = function() {
253
+ var json = Blockly.Events.Create.superClass_.toJson.call(this);
254
+ json['xml'] = Blockly.Xml.domToText(this.xml);
255
+ json['ids'] = this.ids;
256
+ return json;
257
+ };
258
+
259
+ /**
260
+ * Decode the JSON event.
261
+ * @param {!Object} json JSON representation.
262
+ */
263
+ Blockly.Events.Create.prototype.fromJson = function(json) {
264
+ Blockly.Events.Create.superClass_.fromJson.call(this, json);
265
+ this.xml = Blockly.Xml.textToDom('<xml>' + json['xml'] + '</xml>').firstChild;
266
+ this.ids = json['ids'];
267
+ };
268
+
269
+ /**
270
+ * Run a creation event.
271
+ * @param {boolean} forward True if run forward, false if run backward (undo).
272
+ */
273
+ Blockly.Events.Create.prototype.run = function(forward) {
274
+ var workspace = this.getEventWorkspace_();
275
+ if (forward) {
276
+ var xml = goog.dom.createDom('xml');
277
+ xml.appendChild(this.xml);
278
+ Blockly.Xml.domToWorkspace(xml, workspace);
279
+ } else {
280
+ for (var i = 0, id; id = this.ids[i]; i++) {
281
+ var block = workspace.getBlockById(id);
282
+ if (block) {
283
+ block.dispose(false, false);
284
+ } else if (id == this.blockId) {
285
+ // Only complain about root-level block.
286
+ console.warn("Can't uncreate non-existent block: " + id);
287
+ }
288
+ }
289
+ }
290
+ };
291
+
292
+ /**
293
+ * Class for a block deletion event.
294
+ * @param {Blockly.Block} block The deleted block. Null for a blank event.
295
+ * @extends {Blockly.Events.BlockBase}
296
+ * @constructor
297
+ */
298
+ Blockly.Events.Delete = function(block) {
299
+ if (!block) {
300
+ return; // Blank event to be populated by fromJson.
301
+ }
302
+ if (block.getParent()) {
303
+ throw 'Connected blocks cannot be deleted.';
304
+ }
305
+ Blockly.Events.Delete.superClass_.constructor.call(this, block);
306
+
307
+ if (block.workspace.rendered) {
308
+ this.oldXml = Blockly.Xml.blockToDomWithXY(block);
309
+ } else {
310
+ this.oldXml = Blockly.Xml.blockToDom(block);
311
+ }
312
+ this.ids = Blockly.Events.getDescendantIds_(block);
313
+ };
314
+ goog.inherits(Blockly.Events.Delete, Blockly.Events.BlockBase);
315
+
316
+ /**
317
+ * Class for a block deletion event.
318
+ * @param {Blockly.Block} block The deleted block. Null for a blank event.
319
+ * @extends {Blockly.Events.BlockBase}
320
+ * @constructor
321
+ */
322
+ Blockly.Events.BlockDelete = Blockly.Events.Delete;
323
+
324
+ /**
325
+ * Type of this event.
326
+ * @type {string}
327
+ */
328
+ Blockly.Events.Delete.prototype.type = Blockly.Events.DELETE;
329
+
330
+ /**
331
+ * Encode the event as JSON.
332
+ * @return {!Object} JSON representation.
333
+ */
334
+ Blockly.Events.Delete.prototype.toJson = function() {
335
+ var json = Blockly.Events.Delete.superClass_.toJson.call(this);
336
+ json['ids'] = this.ids;
337
+ return json;
338
+ };
339
+
340
+ /**
341
+ * Decode the JSON event.
342
+ * @param {!Object} json JSON representation.
343
+ */
344
+ Blockly.Events.Delete.prototype.fromJson = function(json) {
345
+ Blockly.Events.Delete.superClass_.fromJson.call(this, json);
346
+ this.ids = json['ids'];
347
+ };
348
+
349
+ /**
350
+ * Run a deletion event.
351
+ * @param {boolean} forward True if run forward, false if run backward (undo).
352
+ */
353
+ Blockly.Events.Delete.prototype.run = function(forward) {
354
+ var workspace = this.getEventWorkspace_();
355
+ if (forward) {
356
+ for (var i = 0, id; id = this.ids[i]; i++) {
357
+ var block = workspace.getBlockById(id);
358
+ if (block) {
359
+ block.dispose(false, false);
360
+ } else if (id == this.blockId) {
361
+ // Only complain about root-level block.
362
+ console.warn("Can't delete non-existent block: " + id);
363
+ }
364
+ }
365
+ } else {
366
+ var xml = goog.dom.createDom('xml');
367
+ xml.appendChild(this.oldXml);
368
+ Blockly.Xml.domToWorkspace(xml, workspace);
369
+ }
370
+ };
371
+
372
+ /**
373
+ * Class for a block move event. Created before the move.
374
+ * @param {Blockly.Block} block The moved block. Null for a blank event.
375
+ * @extends {Blockly.Events.BlockBase}
376
+ * @constructor
377
+ */
378
+ Blockly.Events.Move = function(block) {
379
+ if (!block) {
380
+ return; // Blank event to be populated by fromJson.
381
+ }
382
+ Blockly.Events.Move.superClass_.constructor.call(this, block);
383
+ var location = this.currentLocation_();
384
+ this.oldParentId = location.parentId;
385
+ this.oldInputName = location.inputName;
386
+ this.oldCoordinate = location.coordinate;
387
+ };
388
+ goog.inherits(Blockly.Events.Move, Blockly.Events.BlockBase);
389
+
390
+ /**
391
+ * Class for a block move event. Created before the move.
392
+ * @param {Blockly.Block} block The moved block. Null for a blank event.
393
+ * @extends {Blockly.Events.BlockBase}
394
+ * @constructor
395
+ */
396
+ Blockly.Events.BlockMove = Blockly.Events.Move;
397
+
398
+ /**
399
+ * Type of this event.
400
+ * @type {string}
401
+ */
402
+ Blockly.Events.Move.prototype.type = Blockly.Events.MOVE;
403
+
404
+ /**
405
+ * Encode the event as JSON.
406
+ * @return {!Object} JSON representation.
407
+ */
408
+ Blockly.Events.Move.prototype.toJson = function() {
409
+ var json = Blockly.Events.Move.superClass_.toJson.call(this);
410
+ if (this.newParentId) {
411
+ json['newParentId'] = this.newParentId;
412
+ }
413
+ if (this.newInputName) {
414
+ json['newInputName'] = this.newInputName;
415
+ }
416
+ if (this.newCoordinate) {
417
+ json['newCoordinate'] = Math.round(this.newCoordinate.x) + ',' +
418
+ Math.round(this.newCoordinate.y);
419
+ }
420
+ return json;
421
+ };
422
+
423
+ /**
424
+ * Decode the JSON event.
425
+ * @param {!Object} json JSON representation.
426
+ */
427
+ Blockly.Events.Move.prototype.fromJson = function(json) {
428
+ Blockly.Events.Move.superClass_.fromJson.call(this, json);
429
+ this.newParentId = json['newParentId'];
430
+ this.newInputName = json['newInputName'];
431
+ if (json['newCoordinate']) {
432
+ var xy = json['newCoordinate'].split(',');
433
+ this.newCoordinate =
434
+ new goog.math.Coordinate(parseFloat(xy[0]), parseFloat(xy[1]));
435
+ }
436
+ };
437
+
438
+ /**
439
+ * Record the block's new location. Called after the move.
440
+ */
441
+ Blockly.Events.Move.prototype.recordNew = function() {
442
+ var location = this.currentLocation_();
443
+ this.newParentId = location.parentId;
444
+ this.newInputName = location.inputName;
445
+ this.newCoordinate = location.coordinate;
446
+ };
447
+
448
+ /**
449
+ * Returns the parentId and input if the block is connected,
450
+ * or the XY location if disconnected.
451
+ * @return {!Object} Collection of location info.
452
+ * @private
453
+ */
454
+ Blockly.Events.Move.prototype.currentLocation_ = function() {
455
+ var workspace = Blockly.Workspace.getById(this.workspaceId);
456
+ var block = workspace.getBlockById(this.blockId);
457
+ var location = {};
458
+ var parent = block.getParent();
459
+ if (parent) {
460
+ location.parentId = parent.id;
461
+ var input = parent.getInputWithBlock(block);
462
+ if (input) {
463
+ location.inputName = input.name;
464
+ }
465
+ } else {
466
+ var blockXY = block.getRelativeToSurfaceXY();
467
+ // The X position in the block move event should be the language agnostic
468
+ // position of the block. I.e. it should not be different in LTR vs. RTL.
469
+ var rtlAwareX = workspace.RTL ? workspace.getWidth() - blockXY.x : blockXY.x;
470
+ location.coordinate = new goog.math.Coordinate(rtlAwareX, blockXY.y);
471
+ }
472
+ return location;
473
+ };
474
+
475
+ /**
476
+ * Does this event record any change of state?
477
+ * @return {boolean} False if something changed.
478
+ */
479
+ Blockly.Events.Move.prototype.isNull = function() {
480
+ return this.oldParentId == this.newParentId &&
481
+ this.oldInputName == this.newInputName &&
482
+ goog.math.Coordinate.equals(this.oldCoordinate, this.newCoordinate);
483
+ };
484
+
485
+ /**
486
+ * Run a move event.
487
+ * @param {boolean} forward True if run forward, false if run backward (undo).
488
+ */
489
+ Blockly.Events.Move.prototype.run = function(forward) {
490
+ var workspace = this.getEventWorkspace_();
491
+ var block = workspace.getBlockById(this.blockId);
492
+ if (!block) {
493
+ console.warn("Can't move non-existent block: " + this.blockId);
494
+ return;
495
+ }
496
+ var parentId = forward ? this.newParentId : this.oldParentId;
497
+ var inputName = forward ? this.newInputName : this.oldInputName;
498
+ var coordinate = forward ? this.newCoordinate : this.oldCoordinate;
499
+ var parentBlock = null;
500
+ if (parentId) {
501
+ parentBlock = workspace.getBlockById(parentId);
502
+ if (!parentBlock) {
503
+ console.warn("Can't connect to non-existent block: " + parentId);
504
+ return;
505
+ }
506
+ }
507
+ if (block.getParent()) {
508
+ block.unplug();
509
+ }
510
+ if (coordinate) {
511
+ var xy = block.getRelativeToSurfaceXY();
512
+ var rtlAwareX = workspace.RTL ? workspace.getWidth() - coordinate.x : coordinate.x;
513
+ block.moveBy(rtlAwareX - xy.x, coordinate.y - xy.y);
514
+ } else {
515
+ var blockConnection = block.outputConnection || block.previousConnection;
516
+ var parentConnection;
517
+ if (inputName) {
518
+ var input = parentBlock.getInput(inputName);
519
+ if (input) {
520
+ parentConnection = input.connection;
521
+ }
522
+ } else if (blockConnection.type == Blockly.PREVIOUS_STATEMENT) {
523
+ parentConnection = parentBlock.nextConnection;
524
+ }
525
+ if (parentConnection) {
526
+ blockConnection.connect(parentConnection);
527
+ } else {
528
+ console.warn("Can't connect to non-existent input: " + inputName);
529
+ }
530
+ }
531
+ };
core/block_render.js ADDED
The diff for this file is too large to render. See raw diff
 
core/block_svg.js ADDED
@@ -0,0 +1,1369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2012 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Methods for graphically rendering a block as SVG.
23
+ * @author [email protected] (Neil Fraser)
24
+ */
25
+ 'use strict';
26
+
27
+ goog.provide('Blockly.BlockSvg');
28
+
29
+ goog.require('Blockly.Block');
30
+ goog.require('Blockly.BlockAnimations');
31
+ goog.require('Blockly.ContextMenu');
32
+ goog.require('Blockly.Events.Ui');
33
+ goog.require('Blockly.Events.BlockMove');
34
+ goog.require('Blockly.Grid');
35
+ goog.require('Blockly.RenderedConnection');
36
+ goog.require('Blockly.scratchBlocksUtils');
37
+ goog.require('Blockly.Tooltip');
38
+ goog.require('Blockly.Touch');
39
+ goog.require('Blockly.utils');
40
+
41
+ goog.require('goog.Timer');
42
+ goog.require('goog.asserts');
43
+ goog.require('goog.dom');
44
+ goog.require('goog.math.Coordinate');
45
+
46
+
47
+ /**
48
+ * Class for a block's SVG representation.
49
+ * Not normally called directly, workspace.newBlock() is preferred.
50
+ * @param {!Blockly.Workspace} workspace The block's workspace.
51
+ * @param {?string} prototypeName Name of the language object containing
52
+ * type-specific functions for this block.
53
+ * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
54
+ * create a new ID. If the ID conflicts with an in-use ID, a new one will
55
+ * be generated.
56
+ * @extends {Blockly.Block}
57
+ * @constructor
58
+ */
59
+ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
60
+ // Create core elements for the block.
61
+ /**
62
+ * @type {SVGElement}
63
+ * @private
64
+ */
65
+ this.svgGroup_ = Blockly.utils.createSvgElement('g', {}, null);
66
+ /** @type {SVGElement} */
67
+ this.svgPath_ = Blockly.utils.createSvgElement('path',
68
+ {'class': 'blocklyPath blocklyBlockBackground'},
69
+ this.svgGroup_);
70
+ this.svgPath_.tooltip = this;
71
+
72
+ /** @type {boolean} */
73
+ this.rendered = false;
74
+
75
+ /**
76
+ * Whether to move the block to the drag surface when it is dragged.
77
+ * True if it should move, false if it should be translated directly.
78
+ * @type {boolean}
79
+ * @private
80
+ */
81
+ this.useDragSurface_ = Blockly.utils.is3dSupported() && !!workspace.blockDragSurface_;
82
+
83
+ Blockly.Tooltip.bindMouseEvents(this.svgPath_);
84
+ Blockly.BlockSvg.superClass_.constructor.call(this,
85
+ workspace, prototypeName, opt_id);
86
+
87
+ // Expose this block's ID on its top-level SVG group.
88
+ if (this.svgGroup_.dataset) {
89
+ this.svgGroup_.dataset.id = this.id;
90
+ }
91
+ };
92
+ goog.inherits(Blockly.BlockSvg, Blockly.Block);
93
+
94
+ /**
95
+ * Height of this block, not including any statement blocks above or below.
96
+ * Height is in workspace units.
97
+ */
98
+ Blockly.BlockSvg.prototype.height = 0;
99
+
100
+ /**
101
+ * Width of this block, including any connected value blocks.
102
+ * Width is in workspace units.
103
+ */
104
+ Blockly.BlockSvg.prototype.width = 0;
105
+
106
+ /**
107
+ * Minimum width of block if insertion marker; comes from inserting block.
108
+ * @type {number}
109
+ */
110
+ Blockly.BlockSvg.prototype.insertionMarkerMinWidth_ = 0;
111
+
112
+ /**
113
+ * Opacity of this block between 0 and 1.
114
+ * @type {number}
115
+ * @private
116
+ */
117
+ Blockly.BlockSvg.prototype.opacity_ = 1;
118
+
119
+ /**
120
+ * Original location of block being dragged.
121
+ * @type {goog.math.Coordinate}
122
+ * @private
123
+ */
124
+ Blockly.BlockSvg.prototype.dragStartXY_ = null;
125
+
126
+ /**
127
+ * Whether the block glows as if running.
128
+ * @type {boolean}
129
+ * @private
130
+ */
131
+ Blockly.BlockSvg.prototype.isGlowingBlock_ = false;
132
+
133
+ /**
134
+ * Whether the block's whole stack glows as if running.
135
+ * @type {boolean}
136
+ * @private
137
+ */
138
+ Blockly.BlockSvg.prototype.isGlowingStack_ = false;
139
+
140
+ /**
141
+ * Constant for identifying rows that are to be rendered inline.
142
+ * Don't collide with Blockly.INPUT_VALUE and friends.
143
+ * @const
144
+ */
145
+ Blockly.BlockSvg.INLINE = -1;
146
+
147
+ /**
148
+ * Create and initialize the SVG representation of the block.
149
+ * May be called more than once.
150
+ */
151
+ Blockly.BlockSvg.prototype.initSvg = function() {
152
+ goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
153
+ if (!this.isInsertionMarker()) { // Insertion markers not allowed to have inputs or icons
154
+ // Input shapes are empty holes drawn when a value input is not connected.
155
+ for (var i = 0, input; input = this.inputList[i]; i++) {
156
+ input.init();
157
+ input.initOutlinePath(this.svgGroup_);
158
+ }
159
+ var icons = this.getIcons();
160
+ for (i = 0; i < icons.length; i++) {
161
+ icons[i].createIcon();
162
+ }
163
+ }
164
+ this.updateColour();
165
+ this.updateMovable();
166
+ if (!this.workspace.options.readOnly && !this.eventsInit_) {
167
+ Blockly.bindEventWithChecks_(
168
+ this.getSvgRoot(), 'mousedown', this, this.onMouseDown_);
169
+ }
170
+ this.eventsInit_ = true;
171
+
172
+ if (!this.getSvgRoot().parentNode) {
173
+ this.workspace.getCanvas().appendChild(this.getSvgRoot());
174
+ }
175
+ };
176
+
177
+ /**
178
+ * Select this block. Highlight it visually.
179
+ */
180
+ Blockly.BlockSvg.prototype.select = function() {
181
+ if (this.isShadow() && this.getParent()) {
182
+ // Shadow blocks should not be selected.
183
+ this.getParent().select();
184
+ return;
185
+ }
186
+ if (Blockly.selected == this) {
187
+ return;
188
+ }
189
+ var oldId = null;
190
+ if (Blockly.selected) {
191
+ oldId = Blockly.selected.id;
192
+ // Unselect any previously selected block.
193
+ Blockly.Events.disable();
194
+ try {
195
+ Blockly.selected.unselect();
196
+ } finally {
197
+ Blockly.Events.enable();
198
+ }
199
+ }
200
+ var event = new Blockly.Events.Ui(null, 'selected', oldId, this.id);
201
+ event.workspaceId = this.workspace.id;
202
+ Blockly.Events.fire(event);
203
+ Blockly.selected = this;
204
+ this.addSelect();
205
+ };
206
+
207
+ /**
208
+ * Unselect this block. Remove its highlighting.
209
+ */
210
+ Blockly.BlockSvg.prototype.unselect = function() {
211
+ if (Blockly.selected != this) {
212
+ return;
213
+ }
214
+ var event = new Blockly.Events.Ui(null, 'selected', this.id, null);
215
+ event.workspaceId = this.workspace.id;
216
+ Blockly.Events.fire(event);
217
+ Blockly.selected = null;
218
+ this.removeSelect();
219
+ };
220
+
221
+ /**
222
+ * Glow only this particular block, to highlight it visually as if it's running.
223
+ * @param {boolean} isGlowingBlock Whether the block should glow.
224
+ */
225
+ Blockly.BlockSvg.prototype.setGlowBlock = function(isGlowingBlock) {
226
+ this.isGlowingBlock_ = isGlowingBlock;
227
+ this.updateColour();
228
+ };
229
+
230
+ /**
231
+ * Glow the stack starting with this block, to highlight it visually as if it's running.
232
+ * @param {boolean} isGlowingStack Whether the stack starting with this block should glow.
233
+ */
234
+ Blockly.BlockSvg.prototype.setGlowStack = function(isGlowingStack) {
235
+ this.isGlowingStack_ = isGlowingStack;
236
+ // Update the applied SVG filter if the property has changed
237
+ var svg = this.getSvgRoot();
238
+ if (this.isGlowingStack_ && !svg.hasAttribute('filter')) {
239
+ var stackGlowFilterId = this.workspace.options.stackGlowFilterId || 'blocklyStackGlowFilter';
240
+ svg.setAttribute('filter', 'url(#' + stackGlowFilterId + ')');
241
+ } else if (!this.isGlowingStack_ && svg.hasAttribute('filter')) {
242
+ svg.removeAttribute('filter');
243
+ }
244
+ };
245
+
246
+ /**
247
+ * Glow the stack starting with this block, to highlight it visually as if it's errored.
248
+ * @param {boolean} isGlowingStack Whether the stack starting with this block should glow.
249
+ */
250
+ Blockly.BlockSvg.prototype.setErrorStack = function(isGlowingStack) {
251
+ this.isGlowingStack_ = isGlowingStack;
252
+ // Update the applied SVG filter if the property has changed
253
+ var svg = this.getSvgRoot();
254
+ if (this.isGlowingStack_ && !svg.hasAttribute('filter')) {
255
+ var stackGlowFilterId = this.workspace.options.stackGlowFilterErrorId || 'blocklyStackGlowFilterError';
256
+ svg.setAttribute('filter', 'url(#' + stackGlowFilterId + ')');
257
+ } else if (!this.isGlowingStack_ && svg.hasAttribute('filter')) {
258
+ svg.removeAttribute('filter');
259
+ }
260
+ };
261
+
262
+ /**
263
+ * Block's mutator icon (if any).
264
+ * @type {Blockly.Mutator}
265
+ */
266
+ Blockly.BlockSvg.prototype.mutator = null;
267
+
268
+ /**
269
+ * Block's comment icon (if any).
270
+ * @type {Blockly.Comment}
271
+ */
272
+ Blockly.BlockSvg.prototype.comment = null;
273
+
274
+ /**
275
+ * Block's warning icon (if any).
276
+ * @type {Blockly.Warning}
277
+ */
278
+ Blockly.BlockSvg.prototype.warning = null;
279
+
280
+ /**
281
+ * Returns a list of mutator, comment, and warning icons.
282
+ * @return {!Array} List of icons.
283
+ */
284
+ Blockly.BlockSvg.prototype.getIcons = function() {
285
+ var icons = [];
286
+ if (this.mutator) {
287
+ icons.push(this.mutator);
288
+ }
289
+ if (this.comment) {
290
+ icons.push(this.comment);
291
+ }
292
+ if (this.warning) {
293
+ icons.push(this.warning);
294
+ }
295
+ return icons;
296
+ };
297
+
298
+ Blockly.BlockSvg.prototype.intersects_ = true;
299
+
300
+ Blockly.BlockSvg.prototype.setIntersects = function(intersects) {
301
+ if (intersects === this.intersects_) {
302
+ return;
303
+ }
304
+ this.intersects_ = intersects;
305
+ var root = this.getSvgRoot();
306
+ if (!root) {
307
+ return;
308
+ }
309
+ if (intersects) {
310
+ root.style.display = '';
311
+ } else {
312
+ root.style.display = 'none';
313
+ }
314
+ };
315
+
316
+ Blockly.BlockSvg.prototype.updateIntersectionObserver = function() {
317
+ if (this.workspace.intersectionObserver) {
318
+ if (this.getParent()) {
319
+ this.workspace.intersectionObserver.unobserve(this);
320
+ if (!this.intersects_) {
321
+ this.setIntersects(true);
322
+ }
323
+ } else {
324
+ this.workspace.intersectionObserver.observe(this);
325
+ }
326
+ }
327
+ };
328
+
329
+ /**
330
+ * Set parent of this block to be a new block or null.
331
+ * @param {Blockly.BlockSvg} newParent New parent block.
332
+ */
333
+ Blockly.BlockSvg.prototype.setParent = function(newParent) {
334
+ var oldParent = this.parentBlock_;
335
+ if (newParent == oldParent) {
336
+ return;
337
+ }
338
+ Blockly.Field.startCache();
339
+ Blockly.BlockSvg.superClass_.setParent.call(this, newParent);
340
+ Blockly.Field.stopCache();
341
+
342
+ var svgRoot = this.getSvgRoot();
343
+
344
+ // Bail early if workspace is clearing, or we aren't rendered.
345
+ // We won't need to reattach ourselves anywhere.
346
+ if (this.workspace.isClearing || !svgRoot) {
347
+ return;
348
+ }
349
+
350
+ this.updateIntersectionObserver();
351
+
352
+ var oldXY = this.getRelativeToSurfaceXY();
353
+ if (newParent) {
354
+ newParent.getSvgRoot().appendChild(svgRoot);
355
+ var newXY = this.getRelativeToSurfaceXY();
356
+ // Move the connections to match the child's new position.
357
+ this.moveConnections_(newXY.x - oldXY.x, newXY.y - oldXY.y);
358
+ // If we are a shadow block, inherit tertiary colour.
359
+ if (this.isShadow()) {
360
+ this.setColour(this.getColour(), this.getColourSecondary(),
361
+ newParent.getColourTertiary());
362
+ }
363
+ }
364
+ // If we are losing a parent, we want to move our DOM element to the
365
+ // root of the workspace.
366
+ else if (oldParent) {
367
+ this.workspace.getCanvas().appendChild(svgRoot);
368
+ this.translate(oldXY.x, oldXY.y);
369
+ }
370
+
371
+ };
372
+
373
+ /**
374
+ * Return the coordinates of the top-left corner of this block relative to the
375
+ * drawing surface's origin (0,0), in workspace units.
376
+ * If the block is on the workspace, (0, 0) is the origin of the workspace
377
+ * coordinate system.
378
+ * This does not change with workspace scale.
379
+ * @return {!goog.math.Coordinate} Object with .x and .y properties in
380
+ * workspace coordinates.
381
+ */
382
+ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
383
+ // The drawing surface is relative to either the workspace canvas
384
+ // or to the drag surface group.
385
+ var x = 0;
386
+ var y = 0;
387
+
388
+ var dragSurfaceGroup = this.useDragSurface_ ?
389
+ this.workspace.blockDragSurface_.getGroup() : null;
390
+
391
+ var element = this.getSvgRoot();
392
+ if (element) {
393
+ do {
394
+ // Loop through this block and every parent.
395
+ var xy = Blockly.utils.getRelativeXY(element);
396
+ x += xy.x;
397
+ y += xy.y;
398
+ // If this element is the current element on the drag surface, include
399
+ // the translation of the drag surface itself.
400
+ if (this.useDragSurface_ &&
401
+ this.workspace.blockDragSurface_.getCurrentBlock() == element) {
402
+ var surfaceTranslation = this.workspace.blockDragSurface_.getSurfaceTranslation();
403
+ x += surfaceTranslation.x;
404
+ y += surfaceTranslation.y;
405
+ }
406
+ element = element.parentNode;
407
+ } while (element && element != this.workspace.getCanvas() &&
408
+ element != dragSurfaceGroup);
409
+ }
410
+ return new goog.math.Coordinate(x, y);
411
+ };
412
+
413
+ /**
414
+ * Move a block by a relative offset.
415
+ * @param {number} dx Horizontal offset in workspace units.
416
+ * @param {number} dy Vertical offset in workspace units.
417
+ */
418
+ Blockly.BlockSvg.prototype.moveBy = function(dx, dy) {
419
+ goog.asserts.assert(!this.parentBlock_, 'Block has parent.');
420
+ var eventsEnabled = Blockly.Events.isEnabled();
421
+ if (eventsEnabled) {
422
+ var event = new Blockly.Events.BlockMove(this);
423
+ }
424
+ var xy = this.getRelativeToSurfaceXY();
425
+ this.translate(xy.x + dx, xy.y + dy);
426
+ this.moveConnections_(dx, dy);
427
+ if (eventsEnabled) {
428
+ event.recordNew();
429
+ Blockly.Events.fire(event);
430
+ }
431
+ this.workspace.resizeContents();
432
+ };
433
+
434
+ /**
435
+ * Transforms a block by setting the translation on the transform attribute
436
+ * of the block's SVG.
437
+ * @param {number} x The x coordinate of the translation in workspace units.
438
+ * @param {number} y The y coordinate of the translation in workspace units.
439
+ */
440
+ Blockly.BlockSvg.prototype.translate = function(x, y) {
441
+ this.getSvgRoot().setAttribute('transform',
442
+ 'translate(' + x + ',' + y + ')');
443
+ };
444
+
445
+ /**
446
+ * Move this block to its workspace's drag surface, accounting for positioning.
447
+ * Generally should be called at the same time as setDragging_(true).
448
+ * Does nothing if useDragSurface_ is false.
449
+ * @private
450
+ */
451
+ Blockly.BlockSvg.prototype.moveToDragSurface_ = function() {
452
+ if (!this.useDragSurface_) {
453
+ return;
454
+ }
455
+ // The translation for drag surface blocks,
456
+ // is equal to the current relative-to-surface position,
457
+ // to keep the position in sync as it move on/off the surface.
458
+ // This is in workspace coordinates.
459
+ var xy = this.getRelativeToSurfaceXY();
460
+ this.clearTransformAttributes_();
461
+ this.workspace.blockDragSurface_.translateSurface(xy.x, xy.y);
462
+ // Execute the move on the top-level SVG component
463
+ this.workspace.blockDragSurface_.setBlocksAndShow(this.getSvgRoot());
464
+ };
465
+
466
+ /**
467
+ * Move this block back to the workspace block canvas.
468
+ * Generally should be called at the same time as setDragging_(false).
469
+ * Does nothing if useDragSurface_ is false.
470
+ * @param {!goog.math.Coordinate} newXY The position the block should take on
471
+ * on the workspace canvas, in workspace coordinates.
472
+ * @private
473
+ */
474
+ Blockly.BlockSvg.prototype.moveOffDragSurface_ = function(newXY) {
475
+ if (!this.useDragSurface_) {
476
+ return;
477
+ }
478
+ // Translate to current position, turning off 3d.
479
+ this.translate(newXY.x, newXY.y);
480
+ this.workspace.blockDragSurface_.clearAndHide(this.workspace.getCanvas());
481
+ };
482
+
483
+ /**
484
+ * Move this block during a drag, taking into account whether we are using a
485
+ * drag surface to translate blocks.
486
+ * This block must be a top-level block.
487
+ * @param {!goog.math.Coordinate} newLoc The location to translate to, in
488
+ * workspace coordinates.
489
+ * @package
490
+ */
491
+ Blockly.BlockSvg.prototype.moveDuringDrag = function(newLoc) {
492
+ if (this.useDragSurface_) {
493
+ this.workspace.blockDragSurface_.translateSurface(newLoc.x, newLoc.y);
494
+ } else {
495
+ this.svgGroup_.translate_ = 'translate(' + newLoc.x + ',' + newLoc.y + ')';
496
+ this.svgGroup_.setAttribute('transform',
497
+ this.svgGroup_.translate_ + this.svgGroup_.skew_);
498
+ }
499
+ };
500
+
501
+ /**
502
+ * Clear the block of transform="..." attributes.
503
+ * Used when the block is switching from 3d to 2d transform or vice versa.
504
+ * @private
505
+ */
506
+ Blockly.BlockSvg.prototype.clearTransformAttributes_ = function() {
507
+ Blockly.utils.removeAttribute(this.getSvgRoot(), 'transform');
508
+ };
509
+
510
+ /**
511
+ * Snap this block to the nearest grid point.
512
+ */
513
+ Blockly.BlockSvg.prototype.snapToGrid = function() {
514
+ if (!this.workspace) {
515
+ return; // Deleted block.
516
+ }
517
+ if (this.workspace.isDragging()) {
518
+ return; // Don't bump blocks during a drag.
519
+ }
520
+ if (this.getParent()) {
521
+ return; // Only snap top-level blocks.
522
+ }
523
+ if (this.isInFlyout) {
524
+ return; // Don't move blocks around in a flyout.
525
+ }
526
+ var grid = this.workspace.getGrid();
527
+ if (!grid || !grid.shouldSnap()) {
528
+ return; // Config says no snapping.
529
+ }
530
+ var spacing = grid.getSpacing();
531
+ var half = spacing / 2;
532
+ var xy = this.getRelativeToSurfaceXY();
533
+ var dx = Math.round((xy.x - half) / spacing) * spacing + half - xy.x;
534
+ var dy = Math.round((xy.y - half) / spacing) * spacing + half - xy.y;
535
+ dx = Math.round(dx);
536
+ dy = Math.round(dy);
537
+ if (dx != 0 || dy != 0) {
538
+ this.moveBy(dx, dy);
539
+ }
540
+ };
541
+
542
+ /**
543
+ * Returns the coordinates of a bounding box describing the dimensions of this
544
+ * block and any blocks stacked below it.
545
+ * Coordinate system: workspace coordinates.
546
+ * @return {!{topLeft: goog.math.Coordinate, bottomRight: goog.math.Coordinate}}
547
+ * Object with top left and bottom right coordinates of the bounding box.
548
+ */
549
+ Blockly.BlockSvg.prototype.getBoundingRectangle = function() {
550
+ var blockXY = this.getRelativeToSurfaceXY(this);
551
+ var blockBounds = this.getHeightWidth();
552
+ var topLeft;
553
+ var bottomRight;
554
+ if (this.RTL) {
555
+ topLeft = new goog.math.Coordinate(blockXY.x - blockBounds.width,
556
+ blockXY.y);
557
+ bottomRight = new goog.math.Coordinate(blockXY.x,
558
+ blockXY.y + blockBounds.height);
559
+ } else {
560
+ topLeft = new goog.math.Coordinate(blockXY.x, blockXY.y);
561
+ bottomRight = new goog.math.Coordinate(blockXY.x + blockBounds.width,
562
+ blockXY.y + blockBounds.height);
563
+ }
564
+
565
+ return {topLeft: topLeft, bottomRight: bottomRight};
566
+ };
567
+
568
+ /**
569
+ * Set block opacity for SVG rendering.
570
+ * @param {number} opacity Intended opacity, betweeen 0 and 1
571
+ */
572
+ Blockly.BlockSvg.prototype.setOpacity = function(opacity) {
573
+ this.opacity_ = opacity;
574
+ if (this.rendered) {
575
+ this.updateColour();
576
+ }
577
+ };
578
+
579
+ /**
580
+ * Get block opacity for SVG rendering.
581
+ * @return {number} Intended opacity, betweeen 0 and 1
582
+ */
583
+ Blockly.BlockSvg.prototype.getOpacity = function() {
584
+ return this.opacity_;
585
+ };
586
+
587
+ /**
588
+ * Set whether the block is collapsed or not.
589
+ * @param {boolean} collapsed True if collapsed.
590
+ */
591
+ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
592
+ if (this.collapsed_ == collapsed) {
593
+ return;
594
+ }
595
+ var renderList = [];
596
+ // Show/hide the inputs.
597
+ for (var i = 0, input; input = this.inputList[i]; i++) {
598
+ renderList.push.apply(renderList, input.setVisible(!collapsed));
599
+ }
600
+
601
+ var COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
602
+ if (collapsed) {
603
+ var icons = this.getIcons();
604
+ for (var i = 0; i < icons.length; i++) {
605
+ icons[i].setVisible(false);
606
+ }
607
+ var text = this.toString(Blockly.COLLAPSE_CHARS);
608
+ this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(text).init();
609
+ } else {
610
+ this.removeInput(COLLAPSED_INPUT_NAME);
611
+ // Clear any warnings inherited from enclosed blocks.
612
+ this.setWarningText(null);
613
+ }
614
+ Blockly.BlockSvg.superClass_.setCollapsed.call(this, collapsed);
615
+
616
+ if (!renderList.length) {
617
+ // No child blocks, just render this block.
618
+ renderList[0] = this;
619
+ }
620
+ if (this.rendered) {
621
+ for (var i = 0, block; block = renderList[i]; i++) {
622
+ block.render();
623
+ }
624
+ // Don't bump neighbours.
625
+ // Although bumping neighbours would make sense, users often collapse
626
+ // all their functions and store them next to each other. Expanding and
627
+ // bumping causes all their definitions to go out of alignment.
628
+ }
629
+ };
630
+
631
+ /**
632
+ * Open the next (or previous) FieldTextInput.
633
+ * @param {Blockly.Field|Blockly.Block} start Current location.
634
+ * @param {boolean} forward If true go forward, otherwise backward.
635
+ */
636
+ Blockly.BlockSvg.prototype.tab = function(start, forward) {
637
+ var list = this.createTabList_();
638
+ var i = list.indexOf(start);
639
+ if (i == -1) {
640
+ // No start location, start at the beginning or end.
641
+ i = forward ? -1 : list.length;
642
+ }
643
+ var target = list[forward ? i + 1 : i - 1];
644
+ if (!target) {
645
+ // Ran off of list.
646
+ // If there is an output, tab up to that block.
647
+ var outputBlock = this.outputConnection && this.outputConnection.targetBlock();
648
+ if (outputBlock) {
649
+ outputBlock.tab(this, forward);
650
+ } else { // Otherwise, go to next / previous block, depending on value of `forward`
651
+ var block = forward ? this.getNextBlock() : this.getPreviousBlock();
652
+ if (block) {
653
+ block.tab(this, forward);
654
+ }
655
+ }
656
+ } else if (target instanceof Blockly.Field) {
657
+ target.showEditor_();
658
+ } else {
659
+ target.tab(null, forward);
660
+ }
661
+ };
662
+
663
+ /**
664
+ * Create an ordered list of all text fields and connected inputs.
665
+ * @return {!Array.<!Blockly.FieldTextInput|!Blockly.Input>} The ordered list.
666
+ * @private
667
+ */
668
+ Blockly.BlockSvg.prototype.createTabList_ = function() {
669
+ // This function need not be efficient since it runs once on a keypress.
670
+ var list = [];
671
+ for (var i = 0, input; input = this.inputList[i]; i++) {
672
+ for (var j = 0, field; field = input.fieldRow[j]; j++) {
673
+ if (field instanceof Blockly.FieldTextInput) {
674
+ // TODO(# 1276): Also support dropdown fields.
675
+ list.push(field);
676
+ }
677
+ }
678
+ if (input.connection) {
679
+ var block = input.connection.targetBlock();
680
+ if (block) {
681
+ list.push(block);
682
+ }
683
+ }
684
+ }
685
+ return list;
686
+ };
687
+
688
+ /**
689
+ * Handle a mouse-down on an SVG block.
690
+ * @param {!Event} e Mouse down event or touch start event.
691
+ * @private
692
+ */
693
+ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
694
+ if (this.workspace && this.workspace.isDragging()) {
695
+ return;
696
+ }
697
+ var gesture = this.workspace && this.workspace.getGesture(e);
698
+ if (gesture) {
699
+ gesture.handleBlockStart(e, this);
700
+ }
701
+ };
702
+
703
+ /**
704
+ * Load the block's help page in a new window.
705
+ * @private
706
+ */
707
+ Blockly.BlockSvg.prototype.showHelp_ = function() {
708
+ var url = goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl;
709
+ if (url) {
710
+ // @todo rewrite
711
+ alert(url);
712
+ }
713
+ };
714
+
715
+
716
+ /**
717
+ * Show the context menu for this block.
718
+ * @param {!Event} e Mouse event.
719
+ * @private
720
+ */
721
+ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
722
+ if (this.workspace.options.readOnly || !this.contextMenu) {
723
+ return;
724
+ }
725
+ // Save the current block in a variable for use in closures.
726
+ var block = this;
727
+ var menuOptions = [];
728
+ if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
729
+ menuOptions.push(Blockly.ContextMenu.blockDuplicateOption(block, e));
730
+ if (this.isEditable() && this.workspace.options.comments) {
731
+ menuOptions.push(Blockly.ContextMenu.blockCommentOption(block));
732
+ }
733
+ //menuOptions.push(Blockly.ContextMenu.blockCollapseOption(block));
734
+ menuOptions.push(Blockly.ContextMenu.blockDeleteOption(block));
735
+ } else if (this.parentBlock_ && this.isShadow_ && this.type !== 'polygon') {
736
+ this.parentBlock_.showContextMenu_(e);
737
+ return;
738
+ }
739
+
740
+ // Allow the block to add or modify menuOptions.
741
+ if (this.customContextMenu) {
742
+ this.customContextMenu(menuOptions);
743
+ }
744
+ Blockly.ContextMenu.show(e, menuOptions, this.RTL);
745
+ Blockly.ContextMenu.currentBlock = this;
746
+ };
747
+
748
+ /**
749
+ * Move the connections for this block and all blocks attached under it.
750
+ * Also update any attached bubbles.
751
+ * @param {number} dx Horizontal offset from current location, in workspace
752
+ * units.
753
+ * @param {number} dy Vertical offset from current location, in workspace
754
+ * units.
755
+ * @private
756
+ */
757
+ Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
758
+ if (!this.rendered) {
759
+ // Rendering is required to lay out the blocks.
760
+ // This is probably an invisible block attached to a collapsed block.
761
+ return;
762
+ }
763
+ var myConnections = this.getConnections_(false);
764
+ for (var i = 0; i < myConnections.length; i++) {
765
+ myConnections[i].moveBy(dx, dy);
766
+ }
767
+ var icons = this.getIcons();
768
+ for (i = 0; i < icons.length; i++) {
769
+ icons[i].computeIconLocation();
770
+ }
771
+
772
+ // Recurse through all blocks attached under this one.
773
+ for (i = 0; i < this.childBlocks_.length; i++) {
774
+ this.childBlocks_[i].moveConnections_(dx, dy);
775
+ }
776
+ };
777
+
778
+ /**
779
+ * Recursively adds or removes the dragging class to this node and its children.
780
+ * @param {boolean} adding True if adding, false if removing.
781
+ * @package
782
+ */
783
+ Blockly.BlockSvg.prototype.setDragging = function(adding) {
784
+ if (adding) {
785
+ var group = this.getSvgRoot();
786
+ group.translate_ = '';
787
+ group.skew_ = '';
788
+ Blockly.draggingConnections_ =
789
+ Blockly.draggingConnections_.concat(this.getConnections_(true));
790
+ Blockly.utils.addClass(
791
+ /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging');
792
+ } else {
793
+ Blockly.draggingConnections_ = [];
794
+ Blockly.utils.removeClass(
795
+ /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging');
796
+ }
797
+ // Recurse through all blocks attached under this one.
798
+ for (var i = 0; i < this.childBlocks_.length; i++) {
799
+ this.childBlocks_[i].setDragging(adding);
800
+ }
801
+ };
802
+
803
+ /**
804
+ * Add or remove the UI indicating if this block is movable or not.
805
+ */
806
+ Blockly.BlockSvg.prototype.updateMovable = function() {
807
+ if (this.isMovable()) {
808
+ Blockly.utils.addClass(
809
+ /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable');
810
+ } else {
811
+ Blockly.utils.removeClass(
812
+ /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable');
813
+ }
814
+ };
815
+
816
+ /**
817
+ * Set whether this block is movable or not.
818
+ * @param {boolean} movable True if movable.
819
+ */
820
+ Blockly.BlockSvg.prototype.setMovable = function(movable) {
821
+ Blockly.BlockSvg.superClass_.setMovable.call(this, movable);
822
+ this.updateMovable();
823
+ };
824
+
825
+ /**
826
+ * Set whether this block is editable or not.
827
+ * @param {boolean} editable True if editable.
828
+ */
829
+ Blockly.BlockSvg.prototype.setEditable = function(editable) {
830
+ Blockly.BlockSvg.superClass_.setEditable.call(this, editable);
831
+ var icons = this.getIcons();
832
+ for (var i = 0; i < icons.length; i++) {
833
+ icons[i].updateEditable();
834
+ }
835
+ };
836
+
837
+ /**
838
+ * Set whether this block is a shadow block or not.
839
+ * @param {boolean} shadow True if a shadow.
840
+ */
841
+ Blockly.BlockSvg.prototype.setShadow = function(shadow) {
842
+ Blockly.BlockSvg.superClass_.setShadow.call(this, shadow);
843
+ this.updateColour();
844
+ };
845
+
846
+ /**
847
+ * Set whether this block is an insertion marker block or not.
848
+ * @param {boolean} insertionMarker True if an insertion marker.
849
+ * @param {Number=} opt_minWidth Optional minimum width of the marker.
850
+ */
851
+ Blockly.BlockSvg.prototype.setInsertionMarker = function(insertionMarker, opt_minWidth) {
852
+ Blockly.BlockSvg.superClass_.setInsertionMarker.call(this, insertionMarker);
853
+ this.insertionMarkerMinWidth_ = opt_minWidth;
854
+ this.updateColour();
855
+ };
856
+
857
+ /**
858
+ * Return the root node of the SVG or null if none exists.
859
+ * @return {Element} The root SVG node (probably a group).
860
+ */
861
+ Blockly.BlockSvg.prototype.getSvgRoot = function() {
862
+ return this.svgGroup_;
863
+ };
864
+
865
+ /**
866
+ * Dispose of this block.
867
+ * @param {boolean} healStack If true, then try to heal any gap by connecting
868
+ * the next statement with the previous statement. Otherwise, dispose of
869
+ * all children of this block.
870
+ * @param {boolean} animate If true, show a disposal animation and sound.
871
+ */
872
+ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
873
+ if (!this.workspace) {
874
+ // The block has already been deleted.
875
+ return;
876
+ }
877
+ Blockly.Tooltip.hide();
878
+ Blockly.Field.startCache();
879
+ // Save the block's workspace temporarily so we can resize the
880
+ // contents once the block is disposed.
881
+ var blockWorkspace = this.workspace;
882
+ // If this block is being dragged, unlink the mouse events.
883
+ if (Blockly.selected == this) {
884
+ this.unselect();
885
+ this.workspace.cancelCurrentGesture();
886
+ }
887
+ // If this block has a context menu open, close it.
888
+ if (Blockly.ContextMenu.currentBlock == this) {
889
+ Blockly.ContextMenu.hide();
890
+ }
891
+
892
+ if (animate && this.rendered) {
893
+ this.unplug(healStack);
894
+ Blockly.BlockAnimations.disposeUiEffect(this);
895
+ }
896
+ // Stop rerendering.
897
+ this.rendered = false;
898
+
899
+ Blockly.Events.disable();
900
+ try {
901
+ var icons = this.getIcons();
902
+ for (var i = 0; i < icons.length; i++) {
903
+ icons[i].dispose();
904
+ }
905
+ } finally {
906
+ Blockly.Events.enable();
907
+ }
908
+ Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
909
+
910
+ if (blockWorkspace.intersectionObserver) {
911
+ blockWorkspace.intersectionObserver.unobserve(this);
912
+ }
913
+ goog.dom.removeNode(this.svgGroup_);
914
+ blockWorkspace.resizeContents();
915
+ // Sever JavaScript to DOM connections.
916
+ this.svgGroup_ = null;
917
+ this.svgPath_ = null;
918
+ Blockly.Field.stopCache();
919
+ };
920
+
921
+ /**
922
+ * Enable or disable a block.
923
+ */
924
+ Blockly.BlockSvg.prototype.updateDisabled = function() {
925
+ // not supported
926
+ };
927
+
928
+ /**
929
+ * Returns the comment on this block (or '' if none).
930
+ * @return {string} Block's comment.
931
+ */
932
+ Blockly.BlockSvg.prototype.getCommentText = function() {
933
+ if (this.comment) {
934
+ var comment = this.comment.getText();
935
+ // Trim off trailing whitespace.
936
+ return comment.replace(/\s+$/, '').replace(/ +\n/g, '\n');
937
+ }
938
+ return '';
939
+ };
940
+
941
+ /**
942
+ * Set this block's comment text.
943
+ * @param {?string} text The text, or null to delete.
944
+ * @param {string=} commentId Id of the comment, or a new one will be generated if not provided.
945
+ * @param {number=} commentX Optional x position for scratch comment in workspace coordinates
946
+ * @param {number=} commentY Optional y position for scratch comment in workspace coordinates
947
+ * @param {boolean=} minimized Optional minimized state for scratch comment, defaults to false
948
+ */
949
+ Blockly.BlockSvg.prototype.setCommentText = function(text, commentId,
950
+ commentX, commentY, minimized) {
951
+ var changedState = false;
952
+ if (goog.isString(text)) {
953
+ if (!this.comment) {
954
+ this.comment = new Blockly.ScratchBlockComment(this, text, commentId,
955
+ commentX, commentY, minimized);
956
+ changedState = true;
957
+ } else {
958
+ this.comment.setText(/** @type {string} */ (text));
959
+ }
960
+ } else {
961
+ if (this.comment) {
962
+ this.comment.dispose();
963
+ changedState = true;
964
+ }
965
+ }
966
+ if (changedState && this.rendered) {
967
+ this.render();
968
+ if (goog.isString(text)) {
969
+ this.comment.setVisible(true);
970
+ }
971
+ // Adding or removing a comment icon will cause the block to change shape.
972
+ this.bumpNeighbours_();
973
+ }
974
+ };
975
+
976
+ /**
977
+ * Set this block's warning text.
978
+ * @param {?string} text The text, or null to delete.
979
+ * @param {string=} opt_id An optional ID for the warning text to be able to
980
+ * maintain multiple warnings.
981
+ */
982
+ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
983
+ if (!this.setWarningText.pid_) {
984
+ // Create a database of warning PIDs.
985
+ // Only runs once per block (and only those with warnings).
986
+ this.setWarningText.pid_ = Object.create(null);
987
+ }
988
+ var id = opt_id || '';
989
+ if (!id) {
990
+ // Kill all previous pending processes, this edit supersedes them all.
991
+ for (var n in this.setWarningText.pid_) {
992
+ clearTimeout(this.setWarningText.pid_[n]);
993
+ delete this.setWarningText.pid_[n];
994
+ }
995
+ } else if (this.setWarningText.pid_[id]) {
996
+ // Only queue up the latest change. Kill any earlier pending process.
997
+ clearTimeout(this.setWarningText.pid_[id]);
998
+ delete this.setWarningText.pid_[id];
999
+ }
1000
+ if (this.workspace.isDragging()) {
1001
+ // Don't change the warning text during a drag.
1002
+ // Wait until the drag finishes.
1003
+ var thisBlock = this;
1004
+ this.setWarningText.pid_[id] = setTimeout(function() {
1005
+ if (thisBlock.workspace) { // Check block wasn't deleted.
1006
+ delete thisBlock.setWarningText.pid_[id];
1007
+ thisBlock.setWarningText(text, id);
1008
+ }
1009
+ }, 100);
1010
+ return;
1011
+ }
1012
+ if (this.isInFlyout) {
1013
+ text = null;
1014
+ }
1015
+
1016
+ var changedState = false;
1017
+ if (goog.isString(text)) {
1018
+ if (!this.warning) {
1019
+ this.warning = new Blockly.Warning(this);
1020
+ changedState = true;
1021
+ }
1022
+ this.warning.setText(/** @type {string} */ (text), id);
1023
+ } else {
1024
+ // Dispose all warnings if no ID is given.
1025
+ if (this.warning && !id) {
1026
+ this.warning.dispose();
1027
+ changedState = true;
1028
+ } else if (this.warning) {
1029
+ var oldText = this.warning.getText();
1030
+ this.warning.setText('', id);
1031
+ var newText = this.warning.getText();
1032
+ if (!newText) {
1033
+ this.warning.dispose();
1034
+ }
1035
+ changedState = oldText != newText;
1036
+ }
1037
+ }
1038
+ if (changedState && this.rendered) {
1039
+ this.render();
1040
+ // Adding or removing a warning icon will cause the block to change shape.
1041
+ this.bumpNeighbours_();
1042
+ }
1043
+ };
1044
+
1045
+ /**
1046
+ * Give this block a mutator dialog.
1047
+ * @param {Blockly.Mutator} mutator A mutator dialog instance or null to remove.
1048
+ */
1049
+ Blockly.BlockSvg.prototype.setMutator = function(mutator) {
1050
+ if (this.mutator && this.mutator !== mutator) {
1051
+ this.mutator.dispose();
1052
+ }
1053
+ if (mutator) {
1054
+ mutator.block_ = this;
1055
+ this.mutator = mutator;
1056
+ mutator.createIcon();
1057
+ }
1058
+ };
1059
+
1060
+ /**
1061
+ * Select this block. Highlight it visually.
1062
+ */
1063
+ Blockly.BlockSvg.prototype.addSelect = function() {
1064
+ Blockly.utils.addClass(
1065
+ /** @type {!Element} */ (this.svgGroup_), 'blocklySelected');
1066
+ };
1067
+
1068
+ /**
1069
+ * Unselect this block. Remove its highlighting.
1070
+ */
1071
+ Blockly.BlockSvg.prototype.removeSelect = function() {
1072
+ Blockly.utils.removeClass(
1073
+ /** @type {!Element} */ (this.svgGroup_), 'blocklySelected');
1074
+ };
1075
+
1076
+ /**
1077
+ * Update the cursor over this block by adding or removing a class.
1078
+ * @param {boolean} letMouseThrough True if the blocks should ignore pointer
1079
+ * events, false otherwise.
1080
+ * @package
1081
+ */
1082
+ Blockly.BlockSvg.prototype.setMouseThroughStyle = function(letMouseThrough) {
1083
+ if (letMouseThrough) {
1084
+ Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
1085
+ 'blocklyDraggingMouseThrough');
1086
+ } else {
1087
+ Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
1088
+ 'blocklyDraggingMouseThrough');
1089
+ }
1090
+ };
1091
+
1092
+ /**
1093
+ * Update the cursor over this block by adding or removing a class.
1094
+ * @param {boolean} enable True if the delete cursor should be shown, false
1095
+ * otherwise.
1096
+ * @package
1097
+ */
1098
+ Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) {
1099
+ if (enable) {
1100
+ Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
1101
+ 'blocklyDraggingDelete');
1102
+ } else {
1103
+ Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
1104
+ 'blocklyDraggingDelete');
1105
+ }
1106
+ };
1107
+
1108
+ // Overrides of functions on Blockly.Block that take into account whether the
1109
+ // block has been rendered.
1110
+
1111
+ /**
1112
+ * Change the colour of a block.
1113
+ * @param {number|string} colour HSV hue value, or #RRGGBB string.
1114
+ * @param {number|string} colourSecondary Secondary HSV hue value, or #RRGGBB
1115
+ * string.
1116
+ * @param {number|string} colourTertiary Tertiary HSV hue value, or #RRGGBB
1117
+ * string.
1118
+ */
1119
+ Blockly.BlockSvg.prototype.setColour = function(colour, colourSecondary,
1120
+ colourTertiary) {
1121
+ Blockly.BlockSvg.superClass_.setColour.call(this, colour, colourSecondary,
1122
+ colourTertiary);
1123
+
1124
+ if (this.rendered) {
1125
+ this.updateColour();
1126
+ }
1127
+ };
1128
+
1129
+ /**
1130
+ * Move this block to the front of the visible workspace.
1131
+ * <g> tags do not respect z-index so SVG renders them in the
1132
+ * order that they are in the DOM. By placing this block first within the
1133
+ * block group's <g>, it will render on top of any other blocks.
1134
+ * @package
1135
+ */
1136
+ Blockly.BlockSvg.prototype.bringToFront = function() {
1137
+ var block = this;
1138
+ do {
1139
+ var root = block.getSvgRoot();
1140
+ root.parentNode.appendChild(root);
1141
+ block = block.getParent();
1142
+ } while (block);
1143
+ };
1144
+
1145
+ /**
1146
+ * Set whether this block can chain onto the bottom of another block.
1147
+ * @param {boolean} newBoolean True if there can be a previous statement.
1148
+ * @param {(string|Array.<string>|null)=} opt_check Statement type or
1149
+ * list of statement types. Null/undefined if any type could be connected.
1150
+ */
1151
+ Blockly.BlockSvg.prototype.setPreviousStatement = function(newBoolean,
1152
+ opt_check) {
1153
+ Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean,
1154
+ opt_check);
1155
+
1156
+ if (this.rendered) {
1157
+ this.render();
1158
+ this.bumpNeighbours_();
1159
+ }
1160
+ };
1161
+
1162
+ /**
1163
+ * Set whether another block can chain onto the bottom of this block.
1164
+ * @param {boolean} newBoolean True if there can be a next statement.
1165
+ * @param {(string|Array.<string>|null)=} opt_check Statement type or
1166
+ * list of statement types. Null/undefined if any type could be connected.
1167
+ */
1168
+ Blockly.BlockSvg.prototype.setNextStatement = function(newBoolean, opt_check) {
1169
+ Blockly.BlockSvg.superClass_.setNextStatement.call(this, newBoolean,
1170
+ opt_check);
1171
+
1172
+ if (this.rendered) {
1173
+ this.render();
1174
+ this.bumpNeighbours_();
1175
+ }
1176
+ };
1177
+
1178
+ /**
1179
+ * Set whether this block returns a value.
1180
+ * @param {boolean} newBoolean True if there is an output.
1181
+ * @param {(string|Array.<string>|null)=} opt_check Returned type or list
1182
+ * of returned types. Null or undefined if any type could be returned
1183
+ * (e.g. variable get).
1184
+ */
1185
+ Blockly.BlockSvg.prototype.setOutput = function(newBoolean, opt_check) {
1186
+ Blockly.BlockSvg.superClass_.setOutput.call(this, newBoolean, opt_check);
1187
+
1188
+ if (this.rendered) {
1189
+ this.render();
1190
+ this.bumpNeighbours_();
1191
+ }
1192
+ };
1193
+
1194
+ /**
1195
+ * Set whether value inputs are arranged horizontally or vertically.
1196
+ * @param {boolean} newBoolean True if inputs are horizontal.
1197
+ */
1198
+ Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) {
1199
+ Blockly.BlockSvg.superClass_.setInputsInline.call(this, newBoolean);
1200
+
1201
+ if (this.rendered) {
1202
+ this.render();
1203
+ this.bumpNeighbours_();
1204
+ }
1205
+ };
1206
+
1207
+ /**
1208
+ * Remove an input from this block.
1209
+ * @param {string} name The name of the input.
1210
+ * @param {boolean=} opt_quiet True to prevent error if input is not present.
1211
+ * @throws {goog.asserts.AssertionError} if the input is not present and
1212
+ * opt_quiet is not true.
1213
+ */
1214
+ Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) {
1215
+ Blockly.BlockSvg.superClass_.removeInput.call(this, name, opt_quiet);
1216
+
1217
+ if (this.rendered) {
1218
+ this.render();
1219
+ // Removing an input will cause the block to change shape.
1220
+ this.bumpNeighbours_();
1221
+ }
1222
+ };
1223
+
1224
+ /**
1225
+ * Move a numbered input to a different location on this block.
1226
+ * @param {number} inputIndex Index of the input to move.
1227
+ * @param {number} refIndex Index of input that should be after the moved input.
1228
+ */
1229
+ Blockly.BlockSvg.prototype.moveNumberedInputBefore = function(
1230
+ inputIndex, refIndex) {
1231
+ Blockly.BlockSvg.superClass_.moveNumberedInputBefore.call(this, inputIndex,
1232
+ refIndex);
1233
+
1234
+ if (this.rendered) {
1235
+ this.render();
1236
+ // Moving an input will cause the block to change shape.
1237
+ this.bumpNeighbours_();
1238
+ }
1239
+ };
1240
+
1241
+ /**
1242
+ * Add a value input, statement input or local variable to this block.
1243
+ * @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or
1244
+ * Blockly.DUMMY_INPUT.
1245
+ * @param {string} name Language-neutral identifier which may used to find this
1246
+ * input again. Should be unique to this block.
1247
+ * @return {!Blockly.Input} The input object created.
1248
+ * @private
1249
+ */
1250
+ Blockly.BlockSvg.prototype.appendInput_ = function(type, name) {
1251
+ var input = Blockly.BlockSvg.superClass_.appendInput_.call(this, type, name);
1252
+
1253
+ if (this.rendered) {
1254
+ this.render();
1255
+ // Adding an input will cause the block to change shape.
1256
+ this.bumpNeighbours_();
1257
+ }
1258
+ return input;
1259
+ };
1260
+
1261
+ /**
1262
+ * Returns connections originating from this block.
1263
+ * @param {boolean} all If true, return all connections even hidden ones.
1264
+ * Otherwise, for a non-rendered block return an empty list, and for a
1265
+ * collapsed block don't return inputs connections.
1266
+ * @return {!Array.<!Blockly.Connection>} Array of connections.
1267
+ * @package
1268
+ */
1269
+ Blockly.BlockSvg.prototype.getConnections_ = function(all) {
1270
+ var myConnections = [];
1271
+ if (all || this.rendered) {
1272
+ if (this.outputConnection) {
1273
+ myConnections.push(this.outputConnection);
1274
+ }
1275
+ if (this.previousConnection) {
1276
+ myConnections.push(this.previousConnection);
1277
+ }
1278
+ if (this.nextConnection) {
1279
+ myConnections.push(this.nextConnection);
1280
+ }
1281
+ if (all || !this.collapsed_) {
1282
+ for (var i = 0, input; input = this.inputList[i]; i++) {
1283
+ if (input.connection) {
1284
+ myConnections.push(input.connection);
1285
+ }
1286
+ }
1287
+ }
1288
+ }
1289
+ return myConnections;
1290
+ };
1291
+
1292
+ /**
1293
+ * Create a connection of the specified type.
1294
+ * @param {number} type The type of the connection to create.
1295
+ * @return {!Blockly.RenderedConnection} A new connection of the specified type.
1296
+ * @private
1297
+ */
1298
+ Blockly.BlockSvg.prototype.makeConnection_ = function(type) {
1299
+ return new Blockly.RenderedConnection(this, type);
1300
+ };
1301
+
1302
+ /**
1303
+ * Bump unconnected blocks out of alignment. Two blocks which aren't actually
1304
+ * connected should not coincidentally line up on screen.
1305
+ * @private
1306
+ */
1307
+ Blockly.BlockSvg.prototype.bumpNeighbours_ = function() {
1308
+ if (!this.workspace) {
1309
+ return; // Deleted block.
1310
+ }
1311
+ if (this.workspace.isDragging()) {
1312
+ return; // Don't bump blocks during a drag.
1313
+ }
1314
+ var rootBlock = this.getRootBlock();
1315
+ if (rootBlock.isInFlyout) {
1316
+ return; // Don't move blocks around in a flyout.
1317
+ }
1318
+ // Loop through every connection on this block.
1319
+ var myConnections = this.getConnections_(false);
1320
+ for (var i = 0, connection; connection = myConnections[i]; i++) {
1321
+
1322
+ // Spider down from this block bumping all sub-blocks.
1323
+ if (connection.isConnected() && connection.isSuperior()) {
1324
+ connection.targetBlock().bumpNeighbours_();
1325
+ }
1326
+
1327
+ var neighbours = connection.neighbours_(Blockly.SNAP_RADIUS);
1328
+ for (var j = 0, otherConnection; otherConnection = neighbours[j]; j++) {
1329
+
1330
+ // If both connections are connected, that's probably fine. But if
1331
+ // either one of them is unconnected, then there could be confusion.
1332
+ if (!connection.isConnected() || !otherConnection.isConnected()) {
1333
+ // Only bump blocks if they are from different tree structures.
1334
+ if (otherConnection.getSourceBlock().getRootBlock() != rootBlock) {
1335
+
1336
+ // Always bump the inferior block.
1337
+ if (connection.isSuperior()) {
1338
+ otherConnection.bumpAwayFrom_(connection);
1339
+ } else {
1340
+ connection.bumpAwayFrom_(otherConnection);
1341
+ }
1342
+ }
1343
+ }
1344
+ }
1345
+ }
1346
+ };
1347
+
1348
+ /**
1349
+ * Schedule snapping to grid and bumping neighbours to occur after a brief
1350
+ * delay.
1351
+ * @package
1352
+ */
1353
+ Blockly.BlockSvg.prototype.scheduleSnapAndBump = function() {
1354
+ var block = this;
1355
+ // Ensure that any snap and bump are part of this move's event group.
1356
+ var group = Blockly.Events.getGroup();
1357
+
1358
+ setTimeout(function() {
1359
+ Blockly.Events.setGroup(group);
1360
+ block.snapToGrid();
1361
+ Blockly.Events.setGroup(false);
1362
+ }, Blockly.BUMP_DELAY / 2);
1363
+
1364
+ setTimeout(function() {
1365
+ Blockly.Events.setGroup(group);
1366
+ block.bumpNeighbours_();
1367
+ Blockly.Events.setGroup(false);
1368
+ }, Blockly.BUMP_DELAY);
1369
+ };
core/blockly.js ADDED
@@ -0,0 +1,675 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2011 Google Inc.
6
+ * https://developers.google.com/blockly/
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ /**
22
+ * @fileoverview Core JavaScript library for Blockly.
23
+ * @author [email protected] (Neil Fraser)
24
+ */
25
+ 'use strict';
26
+
27
+ /**
28
+ * The top level namespace used to access the Blockly library.
29
+ * @namespace Blockly
30
+ **/
31
+ goog.provide('Blockly');
32
+
33
+ goog.require('Blockly.BlockSvg.render');
34
+ goog.require('Blockly.DropDownDiv');
35
+ goog.require('Blockly.Events');
36
+ goog.require('Blockly.FieldAngle');
37
+ goog.require('Blockly.FieldButton');
38
+ goog.require('Blockly.FieldCheckbox');
39
+ goog.require('Blockly.FieldCheckboxOriginal');
40
+ goog.require('Blockly.FieldColour');
41
+ goog.require('Blockly.FieldColourSlider');
42
+ // Date picker commented out since it increases footprint by 60%.
43
+ // Add it only if you need it.
44
+ //goog.require('Blockly.FieldDate');
45
+ goog.require('Blockly.FieldDropdown');
46
+ goog.require('Blockly.FieldExpandableAdd');
47
+ goog.require('Blockly.FieldExpandableRemove');
48
+ goog.require('Blockly.FieldIconMenu');
49
+ goog.require('Blockly.FieldImage');
50
+ goog.require('Blockly.FieldNote');
51
+ goog.require('Blockly.FieldTextInput');
52
+ goog.require('Blockly.FieldTextInputRemovable');
53
+ goog.require('Blockly.FieldTextDropdown');
54
+ goog.require('Blockly.FieldNumber');
55
+ goog.require('Blockly.FieldNumberDropdown');
56
+ goog.require('Blockly.FieldMatrix');
57
+ goog.require('Blockly.FieldVariable');
58
+ goog.require('Blockly.FieldVerticalSeparator');
59
+ goog.require('Blockly.FieldCustom');
60
+ goog.require('Blockly.Generator');
61
+ goog.require('Blockly.Msg');
62
+ goog.require('Blockly.Procedures');
63
+ goog.require('Blockly.ScratchMsgs');
64
+ goog.require('Blockly.Toolbox');
65
+ goog.require('Blockly.Touch');
66
+ goog.require('Blockly.WidgetDiv');
67
+ goog.require('Blockly.WorkspaceSvg');
68
+ goog.require('Blockly.constants');
69
+ goog.require('Blockly.inject');
70
+ goog.require('Blockly.utils');
71
+ goog.require('goog.color');
72
+
73
+
74
+ // Turn off debugging when compiled.
75
+ /* eslint-disable no-unused-vars */
76
+ var CLOSURE_DEFINES = {'goog.DEBUG': false};
77
+ /* eslint-enable no-unused-vars */
78
+
79
+ /**
80
+ * The main workspace most recently used.
81
+ * Set by Blockly.WorkspaceSvg.prototype.markFocused
82
+ * @type {Blockly.Workspace}
83
+ */
84
+ Blockly.mainWorkspace = null;
85
+
86
+ /**
87
+ * Currently selected block.
88
+ * @type {Blockly.Block}
89
+ */
90
+ Blockly.selected = null;
91
+
92
+ /**
93
+ * All of the connections on blocks that are currently being dragged.
94
+ * @type {!Array.<!Blockly.Connection>}
95
+ * @private
96
+ */
97
+ Blockly.draggingConnections_ = [];
98
+
99
+ /**
100
+ * Contents of the local clipboard.
101
+ * @type {Element}
102
+ * @private
103
+ */
104
+ Blockly.clipboardXml_ = null;
105
+
106
+ /**
107
+ * Source of the local clipboard.
108
+ * @type {Blockly.WorkspaceSvg}
109
+ * @private
110
+ */
111
+ Blockly.clipboardSource_ = null;
112
+
113
+ /**
114
+ * Cached value for whether 3D is supported.
115
+ * @type {!boolean}
116
+ * @private
117
+ */
118
+ Blockly.cache3dSupported_ = null;
119
+
120
+ /**
121
+ * Convert a hue (HSV model) into an RGB hex triplet.
122
+ * @param {number} hue Hue on a colour wheel (0-360).
123
+ * @return {string} RGB code, e.g. '#5ba65b'.
124
+ */
125
+ Blockly.hueToRgb = function(hue) {
126
+ return goog.color.hsvToHex(hue, Blockly.HSV_SATURATION,
127
+ Blockly.HSV_VALUE * 255);
128
+ };
129
+
130
+ /**
131
+ * constrains a number to a specified range
132
+ * @param {Number} number the number to constrain
133
+ * @param {Number} min the lower wall
134
+ * @param {Number} max the uper wall
135
+ * @returns {Number} the constrained number
136
+ */
137
+ goog.constrain = function(number, min, max) {
138
+ var num = Math.min(Math.max(number, min), max)
139
+ if (!num && num !== 0) num = 0
140
+ return num
141
+ }
142
+
143
+ /**
144
+ * converts hsva to rgba
145
+ * @param {Number} hue the color
146
+ * @param {Number} saturation the saturation
147
+ * @param {Number} value the brightness
148
+ * @param {Number} alpha the transparency
149
+ * @returns {Number} the hex color
150
+ */
151
+ goog.color.hsvaToHex = function(hue, saturation, value, alpha) {
152
+ var hex = goog.color.hsvToHex(hue, saturation, value)
153
+ var alpha = goog.constrain(Math.floor(alpha * 255), 0, 255).toString(16)
154
+ if (alpha.length === 1) alpha = '0' + alpha
155
+ return hex + alpha
156
+ }
157
+
158
+ /**
159
+ * convert hex to hsva
160
+ * @param {String|Number} hex the hex
161
+ * @returns {Array} the hsva
162
+ */
163
+ goog.color.hexToHsva = function(decimal) {
164
+ var alpha = (() => {
165
+ if (typeof decimal === 'string') return parseInt(decimal.slice(7, 9), 16)
166
+ return decimal & 0xFF
167
+ })() / 255
168
+
169
+ var [hue, saturation, value] = goog.color.hexToHsv(decimal.slice(0, 7))
170
+ return [hue,saturation,value,alpha];
171
+ }
172
+
173
+ /**
174
+ * Returns the dimensions of the specified SVG image.
175
+ * @param {!Element} svg SVG image.
176
+ * @return {!Object} Contains width and height properties.
177
+ */
178
+ Blockly.svgSize = function(svg) {
179
+ return {
180
+ width: svg.cachedWidth_,
181
+ height: svg.cachedHeight_
182
+ };
183
+ };
184
+
185
+ /**
186
+ * Size the workspace when the contents change. This also updates
187
+ * scrollbars accordingly.
188
+ * @param {!Blockly.WorkspaceSvg} workspace The workspace to resize.
189
+ */
190
+ Blockly.resizeSvgContents = function(workspace) {
191
+ workspace.resizeContents();
192
+ };
193
+
194
+ /**
195
+ * Size the SVG image to completely fill its container. Call this when the view
196
+ * actually changes sizes (e.g. on a window resize/device orientation change).
197
+ * See Blockly.resizeSvgContents to resize the workspace when the contents
198
+ * change (e.g. when a block is added or removed).
199
+ * Record the height/width of the SVG image.
200
+ * @param {!Blockly.WorkspaceSvg} workspace Any workspace in the SVG.
201
+ */
202
+ Blockly.svgResize = function(workspace) {
203
+ var mainWorkspace = workspace;
204
+ while (mainWorkspace.options.parentWorkspace) {
205
+ mainWorkspace = mainWorkspace.options.parentWorkspace;
206
+ }
207
+ var svg = mainWorkspace.getParentSvg();
208
+ var div = svg.parentNode;
209
+ if (!div) {
210
+ // Workspace deleted, or something.
211
+ return;
212
+ }
213
+ var width = div.offsetWidth;
214
+ var height = div.offsetHeight;
215
+ if (svg.cachedWidth_ != width) {
216
+ svg.setAttribute('width', width + 'px');
217
+ svg.cachedWidth_ = width;
218
+ }
219
+ if (svg.cachedHeight_ != height) {
220
+ svg.setAttribute('height', height + 'px');
221
+ svg.cachedHeight_ = height;
222
+ }
223
+ mainWorkspace.resize();
224
+ };
225
+
226
+ /**
227
+ * Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.
228
+ * @param {!Event} e Key down event.
229
+ * @private
230
+ */
231
+ // TODO (https://github.com/google/blockly/issues/1998) handle cases where there are multiple workspaces
232
+ // and non-main workspaces are able to accept input.
233
+ Blockly.onKeyDown_ = function(e) {
234
+ if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)
235
+ || (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {
236
+ // No key actions on readonly workspaces.
237
+ // When focused on an HTML text input widget, don't trap any keys.
238
+ // Ignore keypresses on rendered workspaces that have been explicitly
239
+ // hidden.
240
+ return;
241
+ }
242
+ var deleteBlock = false;
243
+ if (e.keyCode == 27) {
244
+ // Pressing esc closes the context menu and any drop-down
245
+ Blockly.hideChaff();
246
+ Blockly.DropDownDiv.hide();
247
+ } else if (e.keyCode == 8 || e.keyCode == 46) {
248
+ // Delete or backspace.
249
+ // Stop the browser from going back to the previous page.
250
+ // Do this first to prevent an error in the delete code from resulting in
251
+ // data loss.
252
+ e.preventDefault();
253
+ // Don't delete while dragging. Jeez.
254
+ if (Blockly.mainWorkspace.isDragging()) {
255
+ return;
256
+ }
257
+ if (Blockly.selected && Blockly.selected.isDeletable()) {
258
+ deleteBlock = true;
259
+ }
260
+ } else if (e.altKey || e.ctrlKey || e.metaKey) {
261
+ // Don't use meta keys during drags.
262
+ if (Blockly.mainWorkspace.isDragging()) {
263
+ return;
264
+ }
265
+ if (Blockly.selected &&
266
+ Blockly.selected.isDeletable() && Blockly.selected.isMovable()) {
267
+ // Don't allow copying immovable or undeletable blocks. The next step
268
+ // would be to paste, which would create additional undeletable/immovable
269
+ // blocks on the workspace.
270
+ if (e.keyCode == 67) {
271
+ // 'c' for copy.
272
+ Blockly.hideChaff();
273
+ Blockly.copy_(Blockly.selected);
274
+ } else if (e.keyCode == 88 && !Blockly.selected.workspace.isFlyout) {
275
+ // 'x' for cut, but not in a flyout.
276
+ // Don't even copy the selected item in the flyout.
277
+ Blockly.copy_(Blockly.selected);
278
+ deleteBlock = true;
279
+ }
280
+ }
281
+ if (e.keyCode == 86) {
282
+ // 'v' for paste.
283
+ if (Blockly.clipboardXml_) {
284
+ Blockly.Events.setGroup(true);
285
+ // Pasting always pastes to the main workspace, even if the copy started
286
+ // in a flyout workspace.
287
+ var workspace = Blockly.clipboardSource_;
288
+ if (workspace.isFlyout) {
289
+ workspace = workspace.targetWorkspace;
290
+ }
291
+ workspace.paste(Blockly.clipboardXml_);
292
+ Blockly.Events.setGroup(false);
293
+ }
294
+ } else if (e.keyCode == 90 || e.keyCode === 89) {
295
+ // 'z' for undo 'Z' is for redo. 'y' is always redo.
296
+ e.preventDefault();
297
+ Blockly.hideChaff();
298
+ Blockly.mainWorkspace.undo(e.shiftKey || e.keyCode === 89);
299
+ }
300
+ }
301
+ // Common code for delete and cut.
302
+ // Don't delete in the flyout.
303
+ if (deleteBlock && !Blockly.selected.workspace.isFlyout) {
304
+ Blockly.Events.setGroup(true);
305
+ Blockly.hideChaff();
306
+ Blockly.selected.dispose(/* heal */ true, true);
307
+ Blockly.Events.setGroup(false);
308
+ }
309
+ };
310
+
311
+ /**
312
+ * Copy a block or workspace comment onto the local clipboard.
313
+ * @param {!Blockly.Block | !Blockly.WorkspaceComment} toCopy Block or Workspace Comment
314
+ * to be copied.
315
+ * @private
316
+ */
317
+ Blockly.copy_ = function(toCopy) {
318
+ if (toCopy.isComment) {
319
+ var xml = toCopy.toXmlWithXY();
320
+ } else {
321
+ var xml = Blockly.Xml.blockToDom(toCopy);
322
+ // Encode start position in XML.
323
+ var xy = toCopy.getRelativeToSurfaceXY();
324
+ xml.setAttribute('x', toCopy.RTL ? -xy.x : xy.x);
325
+ xml.setAttribute('y', xy.y);
326
+ }
327
+ Blockly.clipboardXml_ = xml;
328
+ Blockly.clipboardSource_ = toCopy.workspace;
329
+ };
330
+
331
+ /**
332
+ * Duplicate this block and its children, or a workspace comment.
333
+ * @param {!Blockly.Block | !Blockly.WorkspaceComment} toDuplicate Block or
334
+ * Workspace Comment to be copied.
335
+ * @private
336
+ */
337
+ Blockly.duplicate_ = function(toDuplicate) {
338
+ // Save the clipboard.
339
+ var clipboardXml = Blockly.clipboardXml_;
340
+ var clipboardSource = Blockly.clipboardSource_;
341
+
342
+ // Create a duplicate via a copy/paste operation.
343
+ Blockly.copy_(toDuplicate);
344
+ toDuplicate.workspace.paste(Blockly.clipboardXml_);
345
+
346
+ // Restore the clipboard.
347
+ Blockly.clipboardXml_ = clipboardXml;
348
+ Blockly.clipboardSource_ = clipboardSource;
349
+ };
350
+
351
+ /**
352
+ * Cancel the native context menu, unless the focus is on an HTML input widget.
353
+ * @param {!Event} e Mouse down event.
354
+ * @private
355
+ */
356
+ Blockly.onContextMenu_ = function(e) {
357
+ if (!Blockly.utils.isTargetInput(e)) {
358
+ // When focused on an HTML text input widget, don't cancel the context menu.
359
+ e.preventDefault();
360
+ }
361
+ };
362
+
363
+ /**
364
+ * Close tooltips, context menus, dropdown selections, etc.
365
+ * @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
366
+ */
367
+ Blockly.hideChaff = function(opt_allowToolbox) {
368
+ Blockly.hideChaffInternal_(opt_allowToolbox);
369
+ Blockly.WidgetDiv.hide(true);
370
+ };
371
+
372
+ /**
373
+ * Close tooltips, context menus, dropdown selections, etc.
374
+ * For some elements (e.g. field text inputs), rather than hiding, it will
375
+ * move them.
376
+ * @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
377
+ */
378
+ Blockly.hideChaffOnResize = function(opt_allowToolbox) {
379
+ Blockly.hideChaffInternal_(opt_allowToolbox);
380
+ Blockly.WidgetDiv.repositionForWindowResize();
381
+ };
382
+
383
+ /**
384
+ * Does a majority of the work for hideChaff including tooltips, dropdowns,
385
+ * toolbox, etc. It does not deal with the WidgetDiv.
386
+ * @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
387
+ * @private
388
+ */
389
+ Blockly.hideChaffInternal_ = function(opt_allowToolbox) {
390
+ Blockly.Tooltip.hide();
391
+ Blockly.DropDownDiv.hideWithoutAnimation();
392
+ if (!opt_allowToolbox) {
393
+ var workspace = Blockly.getMainWorkspace();
394
+ if (workspace.toolbox_ &&
395
+ workspace.toolbox_.flyout_ &&
396
+ workspace.toolbox_.flyout_.autoClose) {
397
+ workspace.toolbox_.clearSelection();
398
+ }
399
+ }
400
+ };
401
+
402
+ /**
403
+ * Returns the main workspace. Returns the last used main workspace (based on
404
+ * focus). Try not to use this function, particularly if there are multiple
405
+ * Blockly instances on a page.
406
+ * @return {!Blockly.Workspace} The main workspace.
407
+ */
408
+ Blockly.getMainWorkspace = function() {
409
+ return Blockly.mainWorkspace;
410
+ };
411
+
412
+ /**
413
+ * Wrapper to window.alert() that app developers may override to
414
+ * provide alternatives to the modal browser window.
415
+ * @param {string} message The message to display to the user.
416
+ * @param {function()=} opt_callback The callback when the alert is dismissed.
417
+ */
418
+ Blockly.alert = function(message, opt_callback) {
419
+ window.alert(message);
420
+ if (opt_callback) {
421
+ opt_callback();
422
+ }
423
+ };
424
+
425
+ /**
426
+ * Wrapper to window.confirm() that app developers may override to
427
+ * provide alternatives to the modal browser window.
428
+ * @param {string} message The message to display to the user.
429
+ * @param {!function(boolean)} callback The callback for handling user response.
430
+ */
431
+ Blockly.confirm = function(message, callback) {
432
+ callback(window.confirm(message));
433
+ };
434
+
435
+ /**
436
+ * Wrapper to window.prompt() that app developers may override to provide
437
+ * alternatives to the modal browser window. Built-in browser prompts are
438
+ * often used for better text input experience on mobile device. We strongly
439
+ * recommend testing mobile when overriding this.
440
+ * @param {string} message The message to display to the user.
441
+ * @param {string} defaultValue The value to initialize the prompt with.
442
+ * @param {!function(string)} callback The callback for handling user response.
443
+ * @param {?string} _opt_title An optional title for the prompt.
444
+ * @param {?string} _opt_varType An optional variable type for variable specific
445
+ * prompt behavior.
446
+ */
447
+ Blockly.prompt = function(message, defaultValue, callback, _opt_title,
448
+ _opt_varType) {
449
+ // opt_title and opt_varType are unused because we only need them to pass
450
+ // information to the scratch-gui, which overwrites this function
451
+ callback(window.prompt(message, defaultValue));
452
+ };
453
+
454
+ /**
455
+ * A callback for status buttons. The window.alert is here for testing and
456
+ * should be overridden.
457
+ * @param {string} id An identifier.
458
+ */
459
+ Blockly.statusButtonCallback = function(id) {
460
+ window.alert('status button was pressed for ' + id);
461
+ };
462
+
463
+ /**
464
+ * Refresh the visual state of a status button in all extension category headers.
465
+ * @param {Blockly.Workspace} workspace A workspace.
466
+ */
467
+ Blockly.refreshStatusButtons = function(workspace) {
468
+ var buttons = workspace.getFlyout().buttons_;
469
+ for (var i = 0; i < buttons.length; i++) {
470
+ if (buttons[i] instanceof Blockly.FlyoutExtensionCategoryHeader) {
471
+ buttons[i].refreshStatus();
472
+ }
473
+ }
474
+ };
475
+
476
+ /**
477
+ * Helper function for defining a block from JSON. The resulting function has
478
+ * the correct value of jsonDef at the point in code where jsonInit is called.
479
+ * @param {!Object} jsonDef The JSON definition of a block.
480
+ * @return {function()} A function that calls jsonInit with the correct value
481
+ * of jsonDef.
482
+ * @private
483
+ */
484
+ Blockly.jsonInitFactory_ = function(jsonDef) {
485
+ return function() {
486
+ this.jsonInit(jsonDef);
487
+ };
488
+ };
489
+
490
+ /**
491
+ * Define blocks from an array of JSON block definitions, as might be generated
492
+ * by the Blockly Developer Tools.
493
+ * @param {!Array.<!Object>} jsonArray An array of JSON block definitions.
494
+ */
495
+ Blockly.defineBlocksWithJsonArray = function(jsonArray, ignoreOverites) {
496
+ for (var i = 0; i < jsonArray.length; i++) {
497
+ var elem = jsonArray[i];
498
+ if (!elem) {
499
+ console.warn(
500
+ 'Block definition #' + i + ' in JSON array is ' + elem + '. ' +
501
+ 'Skipping.');
502
+ } else {
503
+ var typename = elem.type;
504
+ if (typename == null || typename === '') {
505
+ console.warn(
506
+ 'Block definition #' + i +
507
+ ' in JSON array is missing a type attribute. Skipping.');
508
+ } else {
509
+ if (Blockly.Blocks[typename]) {
510
+ if (!ignoreOverites) {
511
+ console.warn(
512
+ 'Block definition #' + i + ' in JSON array' +
513
+ ' overwrites prior definition of "' + typename + '".');
514
+ }
515
+ }
516
+ Blockly.Blocks[typename] = {
517
+ init: Blockly.jsonInitFactory_(elem)
518
+ };
519
+ }
520
+ }
521
+ }
522
+ };
523
+
524
+ /**
525
+ * Bind an event to a function call. When calling the function, verifies that
526
+ * it belongs to the touch stream that is currently being processed, and splits
527
+ * multitouch events into multiple events as needed.
528
+ * @param {!EventTarget} node Node upon which to listen.
529
+ * @param {string} name Event name to listen to (e.g. 'mousedown').
530
+ * @param {Object} thisObject The value of 'this' in the function.
531
+ * @param {!Function} func Function to call when event is triggered.
532
+ * @param {boolean=} opt_noCaptureIdentifier True if triggering on this event
533
+ * should not block execution of other event handlers on this touch or other
534
+ * simultaneous touches.
535
+ * @param {boolean=} opt_noPreventDefault True if triggering on this event
536
+ * should prevent the default handler. False by default. If
537
+ * opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be
538
+ * provided.
539
+ * @return {!Array.<!Array>} Opaque data that can be passed to unbindEvent_.
540
+ */
541
+ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func,
542
+ opt_noCaptureIdentifier, opt_noPreventDefault) {
543
+ var handled = false;
544
+ var wrapFunc = function(e) {
545
+ var captureIdentifier = !opt_noCaptureIdentifier;
546
+ // Handle each touch point separately. If the event was a mouse event, this
547
+ // will hand back an array with one element, which we're fine handling.
548
+ var events = Blockly.Touch.splitEventByTouches(e);
549
+ for (var i = 0, event; event = events[i]; i++) {
550
+ if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
551
+ continue;
552
+ }
553
+ Blockly.Touch.setClientFromTouch(event);
554
+ if (thisObject) {
555
+ func.call(thisObject, event);
556
+ } else {
557
+ func(event);
558
+ }
559
+ handled = true;
560
+ }
561
+ };
562
+
563
+ node.addEventListener(name, wrapFunc, false);
564
+ var bindData = [[node, name, wrapFunc]];
565
+
566
+ // Add equivalent touch event.
567
+ if (name in Blockly.Touch.TOUCH_MAP) {
568
+ var touchWrapFunc = function(e) {
569
+ wrapFunc(e);
570
+ // Calling preventDefault stops the browser from scrolling/zooming the
571
+ // page.
572
+ var preventDef = !opt_noPreventDefault;
573
+ if (handled && preventDef) {
574
+ e.preventDefault();
575
+ }
576
+ };
577
+ for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) {
578
+ node.addEventListener(type, touchWrapFunc, false);
579
+ bindData.push([node, type, touchWrapFunc]);
580
+ }
581
+ }
582
+ return bindData;
583
+ };
584
+
585
+
586
+ /**
587
+ * Bind an event to a function call. Handles multitouch events by using the
588
+ * coordinates of the first changed touch, and doesn't do any safety checks for
589
+ * simultaneous event processing.
590
+ * @deprecated in favor of bindEventWithChecks_, but preserved for external
591
+ * users.
592
+ * @param {!EventTarget} node Node upon which to listen.
593
+ * @param {string} name Event name to listen to (e.g. 'mousedown').
594
+ * @param {Object} thisObject The value of 'this' in the function.
595
+ * @param {!Function} func Function to call when event is triggered.
596
+ * @return {!Array.<!Array>} Opaque data that can be passed to unbindEvent_.
597
+ * @private
598
+ */
599
+ Blockly.bindEvent_ = function(node, name, thisObject, func) {
600
+ var wrapFunc = function(e) {
601
+ if (thisObject) {
602
+ func.call(thisObject, e);
603
+ } else {
604
+ func(e);
605
+ }
606
+ };
607
+
608
+ node.addEventListener(name, wrapFunc, false);
609
+ var bindData = [[node, name, wrapFunc]];
610
+
611
+ // Add equivalent touch event.
612
+ if (name in Blockly.Touch.TOUCH_MAP) {
613
+ var touchWrapFunc = function(e) {
614
+ // Punt on multitouch events.
615
+ if (e.changedTouches.length == 1) {
616
+ // Map the touch event's properties to the event.
617
+ var touchPoint = e.changedTouches[0];
618
+ e.clientX = touchPoint.clientX;
619
+ e.clientY = touchPoint.clientY;
620
+ }
621
+ wrapFunc(e);
622
+
623
+ // Stop the browser from scrolling/zooming the page.
624
+ e.preventDefault();
625
+ };
626
+ for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) {
627
+ node.addEventListener(type, touchWrapFunc, false);
628
+ bindData.push([node, type, touchWrapFunc]);
629
+ }
630
+ }
631
+ return bindData;
632
+ };
633
+
634
+ /**
635
+ * Unbind one or more events event from a function call.
636
+ * @param {!Array.<!Array>} bindData Opaque data from bindEvent_.
637
+ * This list is emptied during the course of calling this function.
638
+ * @return {!Function} The function call.
639
+ * @private
640
+ */
641
+ Blockly.unbindEvent_ = function(bindData) {
642
+ while (bindData.length) {
643
+ var bindDatum = bindData.pop();
644
+ var node = bindDatum[0];
645
+ var name = bindDatum[1];
646
+ var func = bindDatum[2];
647
+ node.removeEventListener(name, func, false);
648
+ }
649
+ return func;
650
+ };
651
+
652
+ /**
653
+ * Is the given string a number (includes negative and decimals).
654
+ * @param {string} str Input string.
655
+ * @return {boolean} True if number, false otherwise.
656
+ */
657
+ Blockly.isNumber = function(str) {
658
+ return !!str.match(/^\s*-?\d+(\.\d+)?\s*$/);
659
+ };
660
+
661
+ // IE9 does not have a console. Create a stub to stop errors.
662
+ if (!goog.global['console']) {
663
+ goog.global['console'] = {
664
+ 'log': function() {},
665
+ 'warn': function() {}
666
+ };
667
+ }
668
+
669
+ // Export symbols that would otherwise be renamed by Closure compiler.
670
+ if (!goog.global['Blockly']) {
671
+ goog.global['Blockly'] = {};
672
+ }
673
+ goog.global['Blockly']['getMainWorkspace'] = Blockly.getMainWorkspace;
674
+ goog.global['Blockly']['goog'] = goog;
675
+ Blockly.goog = goog;