diff --git a/extensions/Lily/Cast.js b/extensions/Lily/Cast.js new file mode 100644 index 0000000000..5035acae5a --- /dev/null +++ b/extensions/Lily/Cast.js @@ -0,0 +1,73 @@ +(function (Scratch) { + 'use strict'; + + const Cast = Scratch.Cast; + + class CastUtil { + getInfo() { + return { + id: 'lmsCast', + name: 'Cast', + blocks: [ + { + opcode: 'toType', + blockType: Scratch.BlockType.REPORTER, + text: 'cast [INPUT] to [TYPE]', + allowDropAnywhere: true, + disableMonitor: true, + arguments: { + INPUT: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'apple' + }, + TYPE: { + type: Scratch.ArgumentType.STRING, + menu: 'type' + } + } + }, + { + opcode: 'typeOf', + blockType: Scratch.BlockType.REPORTER, + text: 'type of [INPUT]', + disableMonitor: true, + arguments: { + INPUT: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'apple' + } + } + } + ], + menus: { + type: { + acceptReporters: true, + items: ['number', 'string', 'boolean', 'default'] + } + } + }; + } + + toType(args) { + const input = args.INPUT; + switch (args.TYPE) { + case ('number'): return Cast.toNumber(input); + case ('string'): return Cast.toString(input); + case ('boolean'): return Cast.toBoolean(input); + default: return input; + } + } + + typeOf(args) { + const input = args.INPUT; + switch (typeof input) { + case ('number'): return 'number'; + case ('string'): return 'string'; + case ('boolean'): return 'boolean'; + default: return ''; + } + } + } + + Scratch.extensions.register(new CastUtil()); +})(Scratch); diff --git a/images/Lily/Cast.svg b/images/Lily/Cast.svg new file mode 100644 index 0000000000..c133d27df6 --- /dev/null +++ b/images/Lily/Cast.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/website/index.ejs b/website/index.ejs index 0b926d08d2..278605ae10 100644 --- a/website/index.ejs +++ b/website/index.ejs @@ -566,6 +566,12 @@

A few adapter blocks. Created by TrueFantom.

+
+ <%- banner('Lily/Cast') %> +

Cast

+

Convert values between types. Created by LilyMakesThings

+
+
<%- banner('-SIPC-/time') %>

Time