Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apple502j/parse-sb3-blocks
Parse sb3 blocks, and generate scratchblocks formatted code.
https://github.com/apple502j/parse-sb3-blocks
hacktoberfest parser sb3 scratch
Last synced: 3 months ago
JSON representation
Parse sb3 blocks, and generate scratchblocks formatted code.
- Host: GitHub
- URL: https://github.com/apple502j/parse-sb3-blocks
- Owner: apple502j
- License: bsd-3-clause
- Created: 2020-07-06T16:57:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-08T09:27:39.000Z (about 2 years ago)
- Last Synced: 2024-10-11T01:49:34.586Z (4 months ago)
- Topics: hacktoberfest, parser, sb3, scratch
- Language: JavaScript
- Homepage: https://apple502j.github.io/parse-sb3-blocks/
- Size: 3.46 MB
- Stars: 14
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# parse-sb3-blocks
**parse-sb3-blocks** parses Scratch 3.0 block formats, and convert it to [scratchblocks](https://github.com/scratchblocks/scratchblocks) format.## Usage
### Example
```js
import {toScratchblocks} from 'parse-sb3-blocks';const sb3blocks = {
'ND,(]G?KLIy(IZrd2sl.': {
opcode: 'event_whenflagclicked',
...
}
};console.log(toScratchblocks('ND,(]G?KLIy(IZrd2sl.', sb3blocks, 'en', {tabs: ' '.repeat(4)}));
```### toScratchblocks
**toScratchblocks** is a function. This can take three to four arguments:- scriptStart: The block ID to start parsing from. **This must be a block ID of Connectable** (which includes hat blocks.)
- blocks: serialized SB3 format (project.json format) of blocks.
- locale: Locale to use. `en` should always be available.
- opts: Optional. It can be an object (see below)#### Options
`opts` can have these properties.- tabs: Tab characters used by C/E blocks for indenting. **Note that while parse-sb3-blocks can use non-space/tab indent, scratchblocks only accepts tab or spaces.** Pass empty string to remove indents. Defaults to four spaces.
- variableStyle: If set to `none` (default), variables will never have `::variables` at the end. If set to `always`, it will always have `::variables`. If set to `as-needed`, it will have `::variables` if block name conflicts.### Internal Functions and Parsers
It also exports several classes used internally by the parsers. These are not APIs and is subject to changes at any time.#### Inputtable and Connectable
Connectable is an instance that can be connected to a stack block via next-parent, including:
- Block (stack, hat, cap)
- CBlock
- EBlock (if-else)
- Definition
- ProcedureCallInputtable can be used as an argument. Note that `Icon` is not technically an argument, but is Inputtable.
- Stack (for arguments to C/E blocks)
- Menu (includes fields menu and menu block)
- Variable (variable reporters and custom block arguments)
- Icon (greenFlag, turnLeft, turnRight icon)
- BooleanBlock
- ReporterBlock
- Input and its subclasses NumberInput, StringInput, ColorPickerInput, BroadcastMenuInput, EmptyBooleanInputBoth Connectable and Inputtable implement `toScratchblocks` method. It accepts `locale` and `opts`, similar to the exported `toScratchblocks`.
Instances with class name ending with "Block" have these attributes:
- `id` for block ID
- `opcode` for block opcode
- `inputtables` for object of input key to Inputtable### Block Mapping
`block-enum.js` provides an enum for block types.`translations.js` is an auto-generated file which includes all translations. `options.js` is also auto-generated, and contains which block needs options (because of conflicting names).
**Only blocks and menu items in all-blocks.js are supported.**
#### all-blocks.js
all-blocks.js default-exports allBlocks, which is an object with opcode as key and the object (see below) as value.The object has these keys and values:
- noTranslation: If set to `true`, it will be ignored from the translation generator.
- defaultMessage: Message in default language (English).
- type: The block type. Defaults to `BlockEnum.BLOCK`.
- defaultOptions: The block option for the block when using defaultMessage, in case duplicates exist. It can have category key and the category as a value.
- translationKey: Translation key for scratch-l10n. Defaults to the block opcode, upper-cased.
- boolArg: Array of arguments which must be boolean. Used to fill empty arguments with `EmptyBooleanInput`. If omitted, empty array is used.## Building
Node 16+ is required for building. Type `npm run build`, which generates locale files.### env
- `mode`: Unless set to `dev`, the result is minified. Add `docs` to update the JS file used in demo.