Skip to content

Commit

Permalink
Merge branch 'TurboWarp:develop' into Space-Oddities
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings authored Jan 21, 2024
2 parents ca7b281 + dd59330 commit b8f43dd
Show file tree
Hide file tree
Showing 12 changed files with 637 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ python_compressed.js
/*compiler*.jar
/local_blockly_compressed_vertical.js
/chromedriver
# --flagfiles used on Windows
/*.config
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@

## Local development

Requires Node.js (16 or later), Python (2 or 3), and Java. It is known to work in these environments but should work in many others:

- Windows 10, Python 3.12.1 (Microsoft Store), Node.js 20.10.0 (nodejs.org installer), Java 11 (Temurin-11.0.21+9)
- macOS 14.2.1, Python 3.11.6 (Apple), Node.js 20.10.0 (installed manually), Java 21 (Temurin-21.0.1+12)
- Ubuntu 22.04, Python 3.10.12 (python3 package), Node.js 20.10.0 (installed manually), Java 11 (openjdk-11-jre package)

Install dependencies:

```sh
npm ci
```

The playground to use for local testing is tests/vertical_playground.html.
Open tests/vertical_playground.html in a browser for development. You don't need to rebuild compressed versions for most changes. Open tests/vertical_playground_compressed.html instead to test if the compressed versions built properly.

To build, run:
To re-build compressed versions, run:

```sh
npm run prepublish
```

requires Python (2 or 3). scratch-gui development server must be restarted to update linked scratch-blocks.
scratch-gui development server must be restarted to update linked scratch-blocks.

<!--
#### Scratch Blocks is a library for building creative computing interfaces.
Expand Down
18 changes: 17 additions & 1 deletion blocks_vertical/vertical_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,18 @@ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = {
}
};

Blockly.ScratchBlocks.VerticalExtensions.FROM_EXTENSION = function() {
this.isFromExtension = true;
};

Blockly.ScratchBlocks.VerticalExtensions.DEFAULT_EXTENSION_COLORS = function() {
this.usesDefaultExtensionColors = true;
};

Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() {
this.isScratchExtension = true;
};

/**
* Register all extensions for scratch-blocks.
* @package
Expand Down Expand Up @@ -265,7 +273,15 @@ Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() {
Blockly.Extensions.registerMixin('procedure_call_contextmenu',
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU);

// Extension blocks have slightly different block rendering.
// Given to all blocks from an extension.
Blockly.Extensions.register('from_extension',
Blockly.ScratchBlocks.VerticalExtensions.FROM_EXTENSION);

// Given to blocks that use the default extension colors ("pen")
Blockly.Extensions.register('default_extension_colors',
Blockly.ScratchBlocks.VerticalExtensions.DEFAULT_EXTENSION_COLORS);

// Misleading name. Given to blocks that have an extension icon.
Blockly.Extensions.register('scratch_extension',
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION);
};
Expand Down
83 changes: 47 additions & 36 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import sys

import errno, glob, json, os, re, subprocess, threading, codecs, functools
import errno, glob, json, os, re, subprocess, threading, codecs, functools, platform

if sys.version_info[0] == 2:
import httplib
Expand Down Expand Up @@ -116,7 +116,7 @@ def run(self):
if (!isNodeJS) {
// Find name of current directory.
var scripts = document.getElementsByTagName('script');
var re = new RegExp('(.+)[\/]blockly_uncompressed(_vertical|_horizontal|)\.js$');
var re = new RegExp('(.+)[\\/]blockly_uncompressed(_vertical|_horizontal|)\\.js$');
for (var i = 0, script; script = scripts[i]; i++) {
var match = re.exec(script.src);
if (match) {
Expand Down Expand Up @@ -333,9 +333,21 @@ def do_compile_local(self, params, target_filename):
for group in [[CLOSURE_COMPILER_NPM], dash_args]:
args.extend(filter(lambda item: item, group))

# On Windows, the command line is too long, so we save the arguments to a file instead
use_flagfile = platform.system() == "Windows"
if platform.system() == "Windows":
flagfile_name = target_filename + ".config"
with open(flagfile_name, "w") as f:
# \ needs to be escaped still
f.write(" ".join(args[1:]).replace("\\", "\\\\"))
args = [CLOSURE_COMPILER_NPM, "--flagfile", flagfile_name]

proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(stdout, stderr) = proc.communicate()

if use_flagfile:
os.remove(flagfile_name)

# Build the JSON response.
filesizes = [os.path.getsize(value) for (arg, value) in params if arg == "js_file"]
return dict(
Expand Down Expand Up @@ -439,12 +451,12 @@ def write_output(self, target_filename, remove, json_data):
# The Closure Compiler preserves these.
LICENSE = re.compile("""/\\*
[\w ]+
[\\w ]+
Copyright \\d+ Google Inc.
https://developers.google.com/blockly/
Licensed under the Apache License, Version 2.0 \(the "License"\);
Licensed under the Apache License, Version 2.0 \\(the "License"\\);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down Expand Up @@ -583,28 +595,17 @@ def exclude_horizontal(item):

print("Using local compiler: %s ...\n" % CLOSURE_COMPILER_NPM)
except (ImportError, AssertionError):
print("Using remote compiler: closure-compiler.appspot.com ...\n")

try:
closure_dir = CLOSURE_DIR
closure_root = CLOSURE_ROOT
closure_library = CLOSURE_LIBRARY
closure_compiler = CLOSURE_COMPILER

calcdeps = import_path(os.path.join(
closure_root, closure_library, "closure", "bin", "calcdeps.py"))
except ImportError:
if os.path.isdir(os.path.join(os.path.pardir, "closure-library-read-only")):
# Dir got renamed when Closure moved from Google Code to GitHub in 2014.
print("Error: Closure directory needs to be renamed from"
"'closure-library-read-only' to 'closure-library'.\n"
"Please rename this directory.")
elif os.path.isdir(os.path.join(os.path.pardir, "google-closure-library")):
print("Error: Closure directory needs to be renamed from"
"'google-closure-library' to 'closure-library'.\n"
"Please rename this directory.")
else:
print("""Error: Closure not found. Read this:
if os.path.isdir(os.path.join(os.path.pardir, "closure-library-read-only")):
# Dir got renamed when Closure moved from Google Code to GitHub in 2014.
print("Error: Closure directory needs to be renamed from"
"'closure-library-read-only' to 'closure-library'.\n"
"Please rename this directory.")
elif os.path.isdir(os.path.join(os.path.pardir, "google-closure-library")):
print("Error: Closure directory needs to be renamed from"
"'google-closure-library' to 'closure-library'.\n"
"Please rename this directory.")
else:
print("""Error: Closure not found. Usually this means 'npm ci' failed. Try running it again? More resources:
developers.google.com/blockly/guides/modify/web/closure""")
sys.exit(1)

Expand All @@ -624,13 +625,23 @@ def exclude_horizontal(item):
# Run all tasks in parallel threads.
# Uncompressed is limited by processor speed.
# Compressed is limited by network and server speed.
# Vertical:
Gen_uncompressed(search_paths_vertical, True, closure_env).start()
# Horizontal:
Gen_uncompressed(search_paths_horizontal, False, closure_env).start()

# Compressed forms of vertical and horizontal.
Gen_compressed(search_paths_vertical, search_paths_horizontal, closure_env).start()

# This is run locally in a separate thread.
# Gen_langfiles().start()
threads = [
# Vertical:
Gen_uncompressed(search_paths_vertical, True, closure_env),
# Horizontal:
Gen_uncompressed(search_paths_horizontal, False, closure_env),
# Compressed forms of vertical and horizontal.
Gen_compressed(search_paths_vertical, search_paths_horizontal, closure_env),

# This is run locally in a separate thread.
# Gen_langfiles()
]

for thread in threads:
thread.start()

# Need to wait for all threads to finish before the main process ends as in Python 3.12,
# once the main interpreter is being shutdown, trying to spawn more child threads will
# raise "RuntimeError: can't create new thread at interpreter shutdown"
for thread in threads:
thread.join()
2 changes: 1 addition & 1 deletion core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ Blockly.Block.prototype.makeColour_ = function(colour) {
var hue = Number(colour);
if (!isNaN(hue)) {
return Blockly.hueToRgb(hue);
} else if (goog.isString(colour) && colour.match(/^#[0-9a-fA-F]{6}$/)) {
} else if (goog.isString(colour) && colour.match(/^#[0-9a-fA-F]{6,8}$/)) {
return colour;
} else {
throw 'Invalid colour: ' + colour;
Expand Down
1 change: 1 addition & 0 deletions core/colours.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Blockly.Colours = {
"toolboxHover": "#4C97FF",
"toolboxSelected": "#e9eef2",
"toolboxText": "#575E75",
"blackText": "#575E75",
"toolbox": "#FFFFFF",
"flyout": "#F9F9F9",
"scrollbar": "#CECDCE",
Expand Down
7 changes: 4 additions & 3 deletions core/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ Blockly.Css.CONTENT = [
'color: $colour_textFieldText;',
'background-color: $colour_textField;',
'font-weight: 500;',
'color-scheme: light;',
'}',

'.blocklyMainBackground {',
Expand Down Expand Up @@ -986,15 +987,15 @@ Blockly.Css.CONTENT = [
'border: none;',
'width: 100%;',
'text-align: center;',
'border-top: 1px solid #ddd;',
'border-top: 1px solid $colour_valueReportBorder;',
'padding-top: 5px;',
'cursor: pointer;',
'}',

'.scratchColourPickerLabel {',
'font-family: "Helvetica Neue", Helvetica, sans-serif;',
'font-size: 0.65rem;',
'color: $colour_toolboxText;',
'color: $colour_valueReportForeground;',
'margin: 8px;',
'}',

Expand All @@ -1015,7 +1016,7 @@ Blockly.Css.CONTENT = [
'.scratchNotePickerKeyLabel {',
'font-family: "Helvetica Neue", Helvetica, sans-serif;',
'font-size: 0.75rem;',
'fill: $colour_textFieldText;',
'fill: $colour_blackText;',
'pointer-events: none;',
'}',

Expand Down
2 changes: 1 addition & 1 deletion core/field_colour_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Blockly.FieldColourSlider.prototype.showEditor_ = function() {
this.activateEyedropperInternal_);
}

Blockly.DropDownDiv.setColour('#ffffff', '#dddddd');
Blockly.DropDownDiv.setColour(Blockly.Colours.valueReportBackground, Blockly.Colours.valueReportBorder);
Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
Blockly.DropDownDiv.showPositionedByBlock(this, this.sourceBlock_);

Expand Down
4 changes: 2 additions & 2 deletions core/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,12 @@ Blockly.Toolbox.Category.prototype.setColour = function(node) {
var colour = node.getAttribute('colour');
var secondaryColour = node.getAttribute('secondaryColour');
if (goog.isString(colour)) {
if (colour.match(/^#[0-9a-fA-F]{6}$/)) {
if (colour.match(/^#[0-9a-fA-F]{6,8}$/)) {
this.colour_ = colour;
} else {
this.colour_ = Blockly.hueToRgb(colour);
}
if (secondaryColour.match(/^#[0-9a-fA-F]{6}$/)) {
if (secondaryColour.match(/^#[0-9a-fA-F]{6,8}$/)) {
this.secondaryColour_ = secondaryColour;
} else {
this.secondaryColour_ = Blockly.hueToRgb(secondaryColour);
Expand Down
Loading

0 comments on commit b8f43dd

Please sign in to comment.