Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/speak-mentaiko/kousien' into sp…
Browse files Browse the repository at this point in the history
…eak-mentaiko-kousien
  • Loading branch information
takaokouji committed Aug 17, 2024
2 parents 28a3963 + f9c541d commit 644636f
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 3 deletions.
78 changes: 78 additions & 0 deletions src/containers/ruby-tab/koshien-snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"koshien.move_to": {
"snippet": "koshien.move_to([${1:0},${2:0}])",
"description": "x座標 (0) y座標 (0) に移動する"
},
"koshien.get_map_area": {
"snippet": "koshien.get_map_area([${1:0},${2:0}])",
"description": "x座標 (0) y座標 (0) 付近のマップ情報を取得"
},
"koshien.calc_route": {
"snippet": "koshien.calc_route(src:'${1:0:0}',dst:'${2:0:0}' except_cells:${3:1}])",
"description": "2点間の最短距離 始点 x座標 (0) y座標 (0) 終点 x座標 (0) y座標 (0) 通らない道 リスト (0)"
},
"koshien.set_dynamite": {
"snippet": "koshien.set_dynamite([${1:0},${2:0}])",
"description": "ダイナマイトをx座標 (0) y座標 (0) に置く"
},
"koshien.set_bomb": {
"snippet": "koshien.set_bomb([${1:0},${2:0}])",
"description": "爆弾をx座標 (0) y座標 (0) に置く"
},
"koshien.map": {
"snippet": "koshien.map(${1:0},${2:0} on:${3:'map_1'})",
"description": "x座標 (0) y座標 (0) のマップ情報を('map_1')に保存"
},
"koshien.map_all": {
"snippet": "koshien.map_all(save_as:${'map_1'})",
"description": "マップ情報を('map_1')に保存"
},
"koshien.other_player_x": {
"snippet": "koshien.other_player_x",
"description": "対戦キャラクタの x座標"
},
"koshien.other_player_y": {
"snippet": "koshien.other_player_y",
"description": "対戦キャラクタの y座標"
},
"koshien.player_x": {
"snippet": "koshien.player_x",
"description": "プレイヤーの x座標"
},
"koshien.player_y": {
"snippet": "koshien.player_y",
"description": "プレイヤーの y座標"
},
"koshien.enemy_x": {
"snippet": "koshien.enemy_x",
"description": "妨害キャラクタの x座標"
},
"koshien.enemy_y": {
"snippet": "koshien.enemy_y",
"description": "妨害キャラクタの y座標"
},
"koshien.goal_x": {
"snippet": "koshien.goal_x",
"description": "ゴールの x座標"
},
"koshien.goal_y": {
"snippet": "koshien.goal_y",
"description": "ゴールの y座標"
},
"koshien.turn_over": {
"snippet": "koshien.turn_over",
"description": "ターンを終了する"
},
"koshien.connect_game": {
"snippet": "koshien.connect_game(player_name:${1:'test'})",
"description": "プレイヤー名('test')ゲームに接続する"
},
"koshien.position_x": {
"snippet": "koshien.position_x(${1:'0:0'})",
"description": "('0:0')のx座標"
},
"koshien.position_y": {
"snippet": "koshien.position_y(${1:'0:0'})",
"description": "('0:0')のy座標"
}
}
5 changes: 3 additions & 2 deletions src/containers/ruby-tab/snippets-completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import MicrobitSnippets from './microbit-snippets.json';
import MeshSnippets from './mesh-snippets.json';
import SmalrubotS1Snippets from './smalrubot-s1-snippets.json';
import MicrobitMoreSnippets from './microbit-more-snippets.json';

import KoshienSnippets from './koshien-snippets.json';
class SnippetsCompleter extends BaseCompleter {
#completions = [];

Expand All @@ -45,7 +45,8 @@ class SnippetsCompleter extends BaseCompleter {
MicrobitSnippets,
MeshSnippets,
SmalrubotS1Snippets,
MicrobitMoreSnippets
MicrobitMoreSnippets,
KoshienSnippets
];
snippetsList.forEach(snippets => {
for (const [caption, item] of Object.entries(snippets)) {
Expand Down
20 changes: 20 additions & 0 deletions src/lib/libraries/extensions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,26 @@ const extensions = [
/>
),
helpLink: 'https://github.com/smalruby/smalruby3-gui/wiki/SmalrubotS1'
},
{
name: (
<FormattedMessage
defaultMessage="甲子園"
description="Name for the 'koshien' extension"
id="gui.extension.koshien.name"
/>
),
extensionId: 'koshien',
iconURL: musicIconURL,
insetIconURL: musicInsetIconURL,
description: (
<FormattedMessage
defaultMessage="Play instruments and drums."
description="Description for the 'koshien' extension"
id="gui.extension.koshien.description"
/>
),
featured: true
}
];

Expand Down
2 changes: 2 additions & 0 deletions src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import WeDo2Blocks from './wedo2.js';
import GdxForBlocks from './gdx_for.js';
import MeshBlocks from './mesh.js';
import SmalrubotS1Blocks from './smalrubot_s1.js';
import koshien from './koshien.js';

const SCALAR_TYPE = '';
const LIST_TYPE = 'list';
Expand Down Expand Up @@ -462,5 +463,6 @@ WeDo2Blocks(RubyGenerator);
GdxForBlocks(RubyGenerator);
MeshBlocks(RubyGenerator);
SmalrubotS1Blocks(RubyGenerator);
koshien(RubyGenerator);

export default RubyGenerator;
70 changes: 70 additions & 0 deletions src/lib/ruby-generator/koshien.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Define Ruby code generator for Microbit More Blocks
* @param {RubyGenerator} Generator The RubyGenerator
* @return {RubyGenerator} same as param.
*/

export default function (Generator) {

Check failure on line 7 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc comment
Generator.koshien_move_to = function (block) {
const x = Generator.valueToCode(block, 'X', Generator.ORDER_NONE) || 0;
const y = Generator.valueToCode(block, 'Y', Generator.ORDER_NONE) || 0;
return `koshien.move_to([${x},${y}])\n`;
};
Generator.koshien_calc_route = function (block) {
const src_x = Generator.valueToCode(block, 'SRC_X', Generator.ORDER_NONE) || 0;

Check failure on line 14 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'src_x' is not in camel case
const src_y = Generator.valueToCode(block, 'SRC_Y', Generator.ORDER_NONE) || 0;

Check failure on line 15 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'src_y' is not in camel case
const dst_x = Generator.valueToCode(block, 'DST_X', Generator.ORDER_NONE) || 0;

Check failure on line 16 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'dst_x' is not in camel case
const dst_y = Generator.valueToCode(block, 'DST_Y', Generator.ORDER_NONE) || 0;

Check failure on line 17 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'dst_y' is not in camel case
const list = Generator.valueToCode(block, 'LIST', Generator.ORDER_NONE) || 0;

return [`koshien.calc_route(src:"${src_x}:${src_y}",dst:"${dst_x}:${dst_y}",except_cells:${list})`];

Check failure on line 20 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'src_x' is not in camel case

Check failure on line 20 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'src_y' is not in camel case

Check failure on line 20 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'dst_x' is not in camel case

Check failure on line 20 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

Identifier 'dst_y' is not in camel case
};
Generator.koshien_get_map_area = function (block) {
const x = Generator.valueToCode(block, 'X', Generator.ORDER_NONE) || 0;
const y = Generator.valueToCode(block, 'Y', Generator.ORDER_NONE) || 0;
return `koshien.get_map_area([${x},${y}])\n`;
};
Generator.koshien_set_item = function (block) {
const item = Generator.getFieldValue(block, 'ITEM') || null;
const x = Generator.valueToCode(block, 'X', Generator.ORDER_NONE) || 0;
const y = Generator.valueToCode(block, 'Y', Generator.ORDER_NONE) || 0;
return `koshien.set_${item}([${x},${y}])\n`;
};
Generator.koshien_map = function (block) {
const x = Generator.valueToCode(block, 'X', Generator.ORDER_NONE) || 0;
const y = Generator.valueToCode(block, 'Y', Generator.ORDER_NONE) || 0;
const location = Generator.valueToCode(block, 'LOCATION', Generator.ORDER_NONE) || Generator.quote_('map_1');
return [`koshien.map(${x},${y}, on: ${location})`];
};
Generator.koshien_map_all = function (block) {
const location = Generator.valueToCode(block, 'LOCATION', Generator.ORDER_NONE) || Generator.quote_('map_1');
return [`koshien.map_all(save_as: ${location})`];
};
Generator.koshien_locate_objects = function (block) {
const x = Generator.valueToCode(block, 'X', Generator.ORDER_NONE) || 0;
const y = Generator.valueToCode(block, 'Y', Generator.ORDER_NONE) || 0;
const size = Generator.valueToCode(block, 'SIZE', Generator.ORDER_NONE) || 5;
const item = Generator.valueToCode(block, 'ITEM', Generator.ORDER_NONE) || Generator.quote_('["A","B","C","D"]');

Check failure on line 47 in src/lib/ruby-generator/koshien.js

View workflow job for this annotation

GitHub Actions / setup

This line has a length of 121. Maximum allowed is 120

return [`koshien.locate_objects(sq_size:${size},cent:"${x}:${y}",objects:${item})`];
};
Generator.koshien_target_coordinate = function (block) {
const target = Generator.getFieldValue(block, 'TARGET') || null;
const coordinate = Generator.getFieldValue(block, 'COORDINATE') || null;
return [`koshien.${target}_${coordinate}`];
};
Generator.koshien_turn_over = function () {
return `koshien.turn_over\n`;
};
Generator.koshien_connect_game = function (block) {
const name = Generator.valueToCode(block, 'NAME', Generator.ORDER_NONE) || Generator.quote_('test');
return `koshien.connect_game(player_name:${name})\n`;
};
Generator.koshien_position_coordinate = function (block) {
const where = Generator.valueToCode(block, 'WHERE', Generator.ORDER_NONE) || Generator.quote_('0:0');
const coordinate = Generator.getFieldValue(block, 'COORDINATE') || null;
return [`koshien.position_${coordinate}(${where})`];
};

return Generator;
}
4 changes: 3 additions & 1 deletion src/lib/ruby-to-blocks-converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import TranslateConverter from './translate';
import MakeyMakeyConverter from './makeymakey';
import VideoConverter from './video';
import Text2SpeechConverter from './text2speech';
import KoshienConverter from './koshien';

const messages = defineMessages({
couldNotConvertPrimitive: {
Expand Down Expand Up @@ -113,7 +114,8 @@ class RubyToBlocksConverter {
Text2SpeechConverter,
Wedo2Converter,
MicrobitMoreConverter,
MeshConverter
MeshConverter,
KoshienConverter
].forEach(x => x.register(this));
}

Expand Down
Loading

0 comments on commit 644636f

Please sign in to comment.