Skip to content

Commit

Permalink
new blocks and other stuff lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium committed Sep 23, 2024
1 parent 42eb4ff commit ec16820
Show file tree
Hide file tree
Showing 7 changed files with 827 additions and 766 deletions.
9 changes: 8 additions & 1 deletion src/blocks/scratch3_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Scratch3DataBlocks {
data_lengthoflist: this.lengthOfList,
data_listcontainsitem: this.listContainsItem,
data_hidelist: this.hideList,
data_showlist: this.showList
data_showlist: this.showList,
data_listjson: this.listjson
};
}

Expand Down Expand Up @@ -213,6 +214,12 @@ class Scratch3DataBlocks {
return 0;
}

listjson (args, util) {
const list = util.target.lookupOrCreateList(
args.LIST.id, args.LIST.name);
return JSON.stringify(list.value);
}

lengthOfList (args, util) {
const list = util.target.lookupOrCreateList(
args.LIST.id, args.LIST.name);
Expand Down
10 changes: 10 additions & 0 deletions src/blocks/scratch3_operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Scratch3OperatorsBlocks {
operator_length: this.length,
operator_contains: this.contains,
operator_mod: this.mod,
operator_pi: this.pi,
operator_newline: this.newline,
operator_round: this.round,
operator_mathop: this.mathop
};
Expand Down Expand Up @@ -127,6 +129,14 @@ class Scratch3OperatorsBlocks {
return result;
}

pi () {
return Math.PI;
}

newline () {
return '\n';
}

round (args) {
return Math.round(Cast.toNumber(args.NUM));
}
Expand Down
16 changes: 15 additions & 1 deletion src/compiler/irgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ class ScriptTreeGenerator {
kind: 'list.contents',
list: this.descendVariable(block, 'LIST', LIST_TYPE)
};

case 'data_listjson':
return {
kind: 'list.json',
list: this.descendVariable(block, 'LIST', LIST_TYPE)
};
case 'event_broadcast_menu': {
const broadcastOption = block.fields.BROADCAST_OPTION;
const broadcastVariable = this.target.lookupBroadcastMsg(broadcastOption.id, broadcastOption.value);
Expand Down Expand Up @@ -445,6 +449,16 @@ class ScriptTreeGenerator {
left: this.descendInputOfBlock(block, 'NUM1'),
right: this.descendInputOfBlock(block, 'NUM2')
};
case 'operator_pi':
return {
kind: 'constant',
value: Math.PI,

Check failure on line 455 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
}

Check failure on line 456 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
case 'operator_newline':
return {
kind: 'constant',
value: '\n'
};
case 'operator_multiply':
return {
kind: 'op.multiply',
Expand Down
Loading

0 comments on commit ec16820

Please sign in to comment.