@@ -136,6 +136,42 @@ Blockly.JavaScript[GET_PROPERTY_OF_FIGHTER] = (block: Blockly.Block) => [
136136 Blockly . JavaScript . ORDER_MEMBER ,
137137] ;
138138
139+ // 定数
140+
141+ export const CONSTANT = "constant" ;
142+ const constantNames = {
143+ armLength : "0" ,
144+ stageWidth : "1" ,
145+ stageHeight : "2" ,
146+ maxHp : "3" ,
147+ maxStamina : "4" ,
148+ weaponRange : "5" ,
149+ } ;
150+ const constants = [ 40 , 800 , 600 , 100 , 100 , 400 ] ;
151+ const CONSTANT_NAME = "constantName" ;
152+ Blockly . Blocks [ CONSTANT ] = {
153+ init ( this : Blockly . Block ) {
154+ this . appendDummyInput ( ) . appendField (
155+ new Blockly . FieldDropdown ( [
156+ [ "腕の長さ(40)" , constantNames . armLength ] ,
157+ [ "ステージの横の長さ(800)" , constantNames . stageWidth ] ,
158+ [ "ステージの縦の長さ(600)" , constantNames . stageHeight ] ,
159+ [ "最大HP(100)" , constantNames . maxHp ] ,
160+ [ "最大元気(100)" , constantNames . maxStamina ] ,
161+ [ "武器の射程(400)" , constantNames . weaponRange ] ,
162+ ] ) ,
163+ CONSTANT_NAME
164+ ) ;
165+ this . setOutput ( true , Number ) ;
166+ this . setColour ( 20 ) ;
167+ this . setTooltip ( "ルールで決められている定数です。" ) ;
168+ } ,
169+ } ;
170+ Blockly . JavaScript [ CONSTANT ] = ( block : Blockly . Block ) => [
171+ `${ constants [ block . getFieldValue ( CONSTANT_NAME ) ] } ` ,
172+ Blockly . JavaScript . ORDER_ATOMIC ,
173+ ] ;
174+
139175// 意思決定
140176
141177const TARGET = "target" ;
@@ -329,11 +365,58 @@ Blockly.JavaScript[CLOSEST_WEAPON] = () => [
329365] ;
330366
331367// 日本語訳がおかしい物の修正など
332- // while
368+ // if
333369
334370const STATEMENT = "statement" ;
335371const CONDITION = "condition" ;
336372
373+ export const CUSTOM_IF = "custom_if" ;
374+ Blockly . Blocks [ CUSTOM_IF ] = {
375+ init ( this : Blockly . Block ) {
376+ this . appendValueInput ( CONDITION ) . setCheck ( Boolean ) . appendField ( "もし" ) ;
377+ this . appendDummyInput ( ) . appendField ( "なら" ) ;
378+ this . appendStatementInput ( STATEMENT ) ;
379+ this . setPreviousStatement ( true ) ;
380+ this . setNextStatement ( true ) ;
381+ this . setColour ( 210 ) ;
382+ this . setTooltip ( "条件が満たされる場合、内部の文を実行します。" ) ;
383+ } ,
384+ } ;
385+ Blockly . JavaScript [ CUSTOM_IF ] = ( block : Blockly . Block ) =>
386+ `if(${ Blockly . JavaScript . valueToCode (
387+ block ,
388+ CONDITION ,
389+ Blockly . JavaScript . ORDER_NONE
390+ ) } ){${ Blockly . JavaScript . statementToCode ( block , STATEMENT ) } };`;
391+
392+ const STATEMENT2 = "statement2" ;
393+ export const CUSTOM_IFELSE = "custom_ifelse" ;
394+ Blockly . Blocks [ CUSTOM_IFELSE ] = {
395+ init ( this : Blockly . Block ) {
396+ this . appendValueInput ( CONDITION ) . setCheck ( Boolean ) . appendField ( "もし" ) ;
397+ this . appendDummyInput ( ) . appendField ( "なら" ) ;
398+ this . appendStatementInput ( STATEMENT ) ;
399+ this . appendDummyInput ( ) . appendField ( "そうでなければ" ) ;
400+ this . appendStatementInput ( STATEMENT2 ) ;
401+ this . setPreviousStatement ( true ) ;
402+ this . setNextStatement ( true ) ;
403+ this . setColour ( 210 ) ;
404+ this . setTooltip (
405+ "条件が満たされる場合は1番目の文を、満たされない場合は2番目の文を実行します。"
406+ ) ;
407+ } ,
408+ } ;
409+ Blockly . JavaScript [ CUSTOM_IFELSE ] = ( block : Blockly . Block ) =>
410+ `if(${ Blockly . JavaScript . valueToCode (
411+ block ,
412+ CONDITION ,
413+ Blockly . JavaScript . ORDER_NONE
414+ ) } ){${ Blockly . JavaScript . statementToCode ( block , STATEMENT ) } }else{
415+ ${ Blockly . JavaScript . statementToCode ( block , STATEMENT2 ) }
416+ };` ;
417+
418+ // while
419+
337420export const CUSTOM_WHILE = "custom_while" ;
338421Blockly . Blocks [ CUSTOM_WHILE ] = {
339422 init ( this : Blockly . Block ) {
0 commit comments