@@ -39,6 +39,7 @@ const KoshienItemName = {
39
39
* @enum {string}
40
40
*/
41
41
const KoshienCoordinateName = {
42
+ POSITION : 'position' ,
42
43
X : 'x' ,
43
44
Y : 'y'
44
45
} ;
@@ -55,6 +56,30 @@ const KoshienTargetName = {
55
56
PLAYER : 'player'
56
57
} ;
57
58
59
+ /**
60
+ * Enum for object
61
+ * @readonly
62
+ * @enum {string}
63
+ */
64
+ const KoshienObjectName = {
65
+ UNKNOWN : 'unknown' ,
66
+ SPACE : 'space' ,
67
+ WALL : 'wall' ,
68
+ STOREHOUSE : 'storehouse' ,
69
+ GOAL : 'goal' ,
70
+ WATER : 'water' ,
71
+ BREAKABLE_WALL : 'breakable wall' ,
72
+ TEA : 'tea' ,
73
+ SWEETS : 'sweets' ,
74
+ COIN : 'COIN' ,
75
+ DOLPHIN : 'dolphin' ,
76
+ SWORD : 'sword' ,
77
+ POISON : 'poison' ,
78
+ SNAKE : 'snake' ,
79
+ TRAP : 'trap' ,
80
+ BOMB : 'bomb'
81
+ } ;
82
+
58
83
/**
59
84
* A client of Smalruby Koshien game server.
60
85
*/
@@ -97,8 +122,9 @@ class KoshienClient {
97
122
return new Promise ( resolve => resolve ( ) ) ;
98
123
}
99
124
100
- // eslint-disable-next-line no-unused-vars
101
- calcRoute ( src , dst , exceptCells , path ) {
125
+ calcRoute ( props ) {
126
+ // eslint-disable-next-line no-unused-vars
127
+ const { src, dst, exceptCells, result} = props ;
102
128
return new Promise ( resolve => resolve ( ) ) ;
103
129
}
104
130
}
@@ -214,6 +240,152 @@ class KoshienBlocks {
214
240
] ;
215
241
}
216
242
243
+ get COORDINATES_AND_POSITION_MENU ( ) {
244
+ return [
245
+ {
246
+ text : formatMessage ( {
247
+ id : 'koshien.coordinatesMenu.position' ,
248
+ default : 'position' ,
249
+ description : 'label for position in coordinate picker for koshien extension'
250
+ } ) ,
251
+ value : KoshienCoordinateName . POSITION
252
+ }
253
+ ] . concat ( this . COORDINATES_MENU ) ;
254
+ }
255
+
256
+ get OBJECTS_MENU ( ) {
257
+ return [
258
+ {
259
+ text : formatMessage ( {
260
+ id : 'koshien.objectsMenu.unknown' ,
261
+ default : 'unknown' ,
262
+ description : 'label for unknown in object picker for koshien extension'
263
+ } ) ,
264
+ value : KoshienObjectName . UNKNOWN
265
+ } ,
266
+ {
267
+ text : formatMessage ( {
268
+ id : 'koshien.objectsMenu.space' ,
269
+ default : 'space' ,
270
+ description : 'label for space in object picker for koshien extension'
271
+ } ) ,
272
+ value : KoshienObjectName . SPACE
273
+ } ,
274
+ {
275
+ text : formatMessage ( {
276
+ id : 'koshien.objectsMenu.wall' ,
277
+ default : 'wall' ,
278
+ description : 'label for wall in object picker for koshien extension'
279
+ } ) ,
280
+ value : KoshienObjectName . WALL
281
+ } ,
282
+ {
283
+ text : formatMessage ( {
284
+ id : 'koshien.objectsMenu.storehouse' ,
285
+ default : 'storehouse' ,
286
+ description : 'label for storehouse in object picker for koshien extension'
287
+ } ) ,
288
+ value : KoshienObjectName . STOREHOUSE
289
+ } ,
290
+ {
291
+ text : formatMessage ( {
292
+ id : 'koshien.objectsMenu.goal' ,
293
+ default : 'goal' ,
294
+ description : 'label for goal in object picker for koshien extension'
295
+ } ) ,
296
+ value : KoshienObjectName . GOAL
297
+ } ,
298
+ {
299
+ text : formatMessage ( {
300
+ id : 'koshien.objectsMenu.water' ,
301
+ default : 'water' ,
302
+ description : 'label for water in object picker for koshien extension'
303
+ } ) ,
304
+ value : KoshienObjectName . WATER
305
+ } ,
306
+ {
307
+ text : formatMessage ( {
308
+ id : 'koshien.objectsMenu.breakableWall' ,
309
+ default : 'breakable wall' ,
310
+ description : 'label for breakable_wall in object picker for koshien extension'
311
+ } ) ,
312
+ value : KoshienObjectName . BREAKABLE_WALL
313
+ } ,
314
+ {
315
+ text : formatMessage ( {
316
+ id : 'koshien.objectsMenu.tea' ,
317
+ default : 'tea' ,
318
+ description : 'label for tea in object picker for koshien extension'
319
+ } ) ,
320
+ value : KoshienObjectName . TEA
321
+ } ,
322
+ {
323
+ text : formatMessage ( {
324
+ id : 'koshien.objectsMenu.sweets' ,
325
+ default : 'sweets' ,
326
+ description : 'label for sweets in object picker for koshien extension'
327
+ } ) ,
328
+ value : KoshienObjectName . SWEETS
329
+ } ,
330
+ {
331
+ text : formatMessage ( {
332
+ id : 'koshien.objectsMenu.coin' ,
333
+ default : 'coin' ,
334
+ description : 'label for coin in object picker for koshien extension'
335
+ } ) ,
336
+ value : KoshienObjectName . COIN
337
+ } ,
338
+ {
339
+ text : formatMessage ( {
340
+ id : 'koshien.objectsMenu.dolphin' ,
341
+ default : 'dolphin' ,
342
+ description : 'label for dolphin in object picker for koshien extension'
343
+ } ) ,
344
+ value : KoshienObjectName . DOLPHIN
345
+ } ,
346
+ {
347
+ text : formatMessage ( {
348
+ id : 'koshien.objectsMenu.sword' ,
349
+ default : 'sword' ,
350
+ description : 'label for sword in object picker for koshien extension'
351
+ } ) ,
352
+ value : KoshienObjectName . SWORD
353
+ } ,
354
+ {
355
+ text : formatMessage ( {
356
+ id : 'koshien.objectsMenu.poison' ,
357
+ default : 'poison' ,
358
+ description : 'label for poison in object picker for koshien extension'
359
+ } ) ,
360
+ value : KoshienObjectName . POISON
361
+ } ,
362
+ {
363
+ text : formatMessage ( {
364
+ id : 'koshien.objectsMenu.snake' ,
365
+ default : 'snake' ,
366
+ description : 'label for snake in object picker for koshien extension'
367
+ } ) ,
368
+ value : KoshienObjectName . SNAKE
369
+ } ,
370
+ {
371
+ text : formatMessage ( {
372
+ id : 'koshien.objectsMenu.trap' ,
373
+ default : 'trap' ,
374
+ description : 'label for trap in object picker for koshien extension'
375
+ } ) ,
376
+ value : KoshienObjectName . TRAP
377
+ } ,
378
+ {
379
+ text : formatMessage ( {
380
+ id : 'koshien.objectsMenu.bomb' ,
381
+ default : 'bomb' ,
382
+ description : 'label for bomb in object picker for koshien extension'
383
+ } ) ,
384
+ value : KoshienObjectName . BOMB
385
+ }
386
+ ] ;
387
+ }
388
+
217
389
/**
218
390
* Construct a set of Koshien blocks.
219
391
* @param {Runtime } runtime - the Scratch 3.0 runtime.
@@ -308,6 +480,23 @@ class KoshienBlocks {
308
480
} ,
309
481
filter : [ TargetType . SPRITE ]
310
482
} ,
483
+ {
484
+ opcode : 'calcGoalRoute' ,
485
+ blockType : BlockType . COMMAND ,
486
+ text : formatMessage ( {
487
+ id : 'koshien.calcGoalRoute' ,
488
+ default : 'store shortest goal path to list: [RESULT]' ,
489
+ description : 'store shortest path between player and goal to list'
490
+ } ) ,
491
+ arguments : {
492
+ RESULT : {
493
+ type : ArgumentType . STRING ,
494
+ menu : 'listNames' ,
495
+ defaultValue : ' '
496
+ }
497
+ } ,
498
+ filter : [ TargetType . SPRITE ]
499
+ } ,
311
500
{
312
501
opcode : 'calcRoute' ,
313
502
blockType : BlockType . COMMAND ,
@@ -411,7 +600,7 @@ class KoshienBlocks {
411
600
} ,
412
601
OBJECTS : {
413
602
type : ArgumentType . STRING ,
414
- defaultValue : 'A B C D '
603
+ defaultValue : 'ABCD '
415
604
} ,
416
605
RESULT : {
417
606
type : ArgumentType . STRING ,
@@ -437,8 +626,8 @@ class KoshienBlocks {
437
626
} ,
438
627
COORDINATE : {
439
628
type : ArgumentType . STRING ,
440
- menu : 'coordinateMenu ' ,
441
- defaultValue : KoshienCoordinateName . X
629
+ menu : 'coordinateAndPositionMenu ' ,
630
+ defaultValue : KoshienCoordinateName . POSITION
442
631
}
443
632
} ,
444
633
filter : [ TargetType . SPRITE ]
@@ -493,6 +682,24 @@ class KoshienBlocks {
493
682
defaultValue : KoshienCoordinateName . X
494
683
}
495
684
685
+ } ,
686
+ filter : [ TargetType . SPRITE ]
687
+ } ,
688
+ {
689
+ opcode : 'object' ,
690
+ blockType : BlockType . REPORTER ,
691
+ text : formatMessage ( {
692
+ id : 'koshien.object' ,
693
+ default : '[OBJECT]' ,
694
+ description : 'object of code'
695
+ } ) ,
696
+ arguments : {
697
+ OBJECT : {
698
+ type : ArgumentType . STRING ,
699
+ menu : 'objectMenu' ,
700
+ defaultValue : KoshienObjectName . UNKNOWN
701
+ }
702
+
496
703
} ,
497
704
filter : [ TargetType . SPRITE ]
498
705
}
@@ -514,11 +721,18 @@ class KoshienBlocks {
514
721
acceptReporters : false ,
515
722
items : this . COORDINATES_MENU
516
723
} ,
724
+ coordinateAndPositionMenu : {
725
+ acceptReporters : false ,
726
+ items : this . COORDINATES_AND_POSITION_MENU
727
+ } ,
517
728
targetMenu : {
518
729
acceptReporters : false ,
519
730
items : this . TARGETS_MENU
731
+ } ,
732
+ objectMenu : {
733
+ acceptReporters : false ,
734
+ items : this . OBJECTS_MENU
520
735
}
521
-
522
736
} ,
523
737
translationMap : translations
524
738
} ;
@@ -585,6 +799,17 @@ class KoshienBlocks {
585
799
return this . _client . moveTo ( args . POSITION ) ;
586
800
}
587
801
802
+ /**
803
+ * shortest path between player and goal
804
+ * @param {object } args - the block's arguments.
805
+ * @param {string } args.RESULT - result.
806
+ * @return {Promise } - promise
807
+ */
808
+ // eslint-disable-next-line no-unused-vars
809
+ calcGoalRoute ( args ) {
810
+ return this . _client . calcRoute ( { result : args . RESULT } ) ;
811
+ }
812
+
588
813
/**
589
814
* shortest path between two points
590
815
* @param {object } args - the block's arguments.
@@ -596,8 +821,11 @@ class KoshienBlocks {
596
821
*/
597
822
// eslint-disable-next-line no-unused-vars
598
823
calcRoute ( args ) {
599
- return this . _client . calcRoute ( args . SRC , args . DST , args . EXCEPT_CELLS , args . RESULT ) ;
824
+ return this . _client . calcRoute (
825
+ { src : args . SRC , dst : args . DST , exceptCells : args . EXCEPT_CELLS , result : args . RESULT }
826
+ ) ;
600
827
}
828
+
601
829
/**
602
830
* place an item at position
603
831
* @param {object } args - the block's arguments.
@@ -674,17 +902,61 @@ class KoshienBlocks {
674
902
}
675
903
676
904
/**
677
- * where of coordinate
905
+ * position of coordinate
678
906
* @param {object } args - the block's arguments.
679
907
* @param {string } args.POSITION - position.
680
908
* @param {string } args.COORDINATE - coordinate.
681
909
* @return {number } - position of x or y
682
910
*/
683
- // eslint-disable-next-line no-unused-vars
684
911
positionOf ( args ) {
685
912
const position = args . POSITION . split ( ':' ) ;
686
913
return Number ( args . COORDINATE === 'x' ? position [ 0 ] : position [ 1 ] ) ;
687
914
}
915
+
916
+ /**
917
+ * object of code
918
+ * @param {object } args - the block's arguments.
919
+ * @param {string } args.OBJECT - object.
920
+ * @return {number } - object of code
921
+ */
922
+ object ( args ) {
923
+ switch ( args . OBJECT ) {
924
+ case KoshienObjectName . UNKNOWN :
925
+ return - 1 ;
926
+ case KoshienObjectName . SPACE :
927
+ return 0 ;
928
+ case KoshienObjectName . WALL :
929
+ return 1 ;
930
+ case KoshienObjectName . STOREHOUSE :
931
+ return 2 ;
932
+ case KoshienObjectName . GOAL :
933
+ return 3 ;
934
+ case KoshienObjectName . WATER :
935
+ return 4 ;
936
+ case KoshienObjectName . BREAKABLE_WALL :
937
+ return 5 ;
938
+ case KoshienObjectName . TEA :
939
+ return 'a' ;
940
+ case KoshienObjectName . SWEETS :
941
+ return 'b' ;
942
+ case KoshienObjectName . COIN :
943
+ return 'c' ;
944
+ case KoshienObjectName . DOLPHIN :
945
+ return 'd' ;
946
+ case KoshienObjectName . SWORD :
947
+ return 'e' ;
948
+ case KoshienObjectName . POISON :
949
+ return 'A' ;
950
+ case KoshienObjectName . SNAKE :
951
+ return 'B' ;
952
+ case KoshienObjectName . TRAP :
953
+ return 'C' ;
954
+ case KoshienObjectName . BOMB :
955
+ return 'D' ;
956
+ default :
957
+ return - 1 ;
958
+ }
959
+ }
688
960
}
689
961
690
962
export {
0 commit comments