瀏覽代碼

更改标记字典常量,将常量迁移到js

liyanbo 6 月之前
父節點
當前提交
15cc5550cf
共有 3 個文件被更改,包括 34 次插入29 次删除
  1. 30 7
      src/api/blockly/blockly.js
  2. 2 15
      src/components/blockly/MapGame.vue
  3. 2 7
      src/views/blockly/MapGame.vue

+ 30 - 7
src/api/blockly/blockly.js

@@ -14,6 +14,28 @@ import pauseImage from '@/assets/images/blockly/component/pause.png';
 import play_soundImage from '@/assets/images/blockly/component/sound.png';
 import constructImage from '@/assets/images/blockly/component/construct.png';
 
+// 积木形状字典
+const BLOCKLY_SHAPE_DICT = {
+  SQUARE_GEM: { value: 'square_gem', label: '正方形宝石' }, // 正方形宝石
+  TRIANGLE_GEM: { value: 'triangle_gem', label: '三角形宝石' }, // 三角形宝石
+  RED_MARK: { value: 'red_mark', label: '红色标记' }, // 红色标记
+  GREEN_MARK: { value: 'green_mark', label: '绿色标记' } // 绿色标记
+};
+
+// 地图元素类型字典
+const BLOCKLY_MAP_TYPE_DICT = {
+  ICE: 'ice', // 冰块
+  TASK: 'task', // 钥匙
+  ITEM: 'item', // 物品
+  TRAP: 'trap' // 陷阱
+};
+
+// 自定义积木字典
+const BLOCKLY_CUSTOMIZE_DICT = {
+  PAUSE: 'pause', // 暂停
+  PLAY_SOUND: 'play_sound', // 播放音效
+  CONSTRUCT: 'construct' // 修建
+};
 
 /**
  * 定义所有可用的自定义积木配置
@@ -235,12 +257,7 @@ const availableBlocks = {
         {
           "type": "field_dropdown",
           "name": "SHAPE",
-          "options": [
-            ["正方形", "square"],
-            ["长方形", "rectangle"],
-            ["圆形", "circle"],
-            ["三角形", "triangle"]
-          ]
+          "options": Object.values(BLOCKLY_SHAPE_DICT).map(shape => [shape.label, shape.value])
         }
       ],
       "output": "Boolean",
@@ -652,6 +669,9 @@ export function getAllPythonGeneratorsConfig() {
   return {...availablePythonGenerators};
 }
 
+// 导出字典常量
+export { BLOCKLY_SHAPE_DICT, BLOCKLY_MAP_TYPE_DICT, BLOCKLY_CUSTOMIZE_DICT };
+
 export default {
   registerCustomBlocks,
   registerJavaScriptGenerators,
@@ -659,5 +679,8 @@ export default {
   setupBlocklyChineseLocale,
   initBlockly,
   getAllBlocksConfig,
-  getAllGeneratorsConfig
+  getAllGeneratorsConfig,
+  BLOCKLY_SHAPE_DICT,
+  BLOCKLY_MAP_TYPE_DICT,
+  BLOCKLY_CUSTOMIZE_DICT
 };

+ 2 - 15
src/components/blockly/MapGame.vue

@@ -153,7 +153,7 @@ import passRouteMp3 from '@/assets/music/blockly/pass_route.MP3';
 import errorMp3 from '@/assets/music/blockly/error.MP3'
 
 // 游戏接口数据
-import { registerCustomBlocks, registerJavaScriptGenerators, registerPythonGenerators, initBlockly } from '@/api/blockly/blockly.js';
+import { registerCustomBlocks, registerJavaScriptGenerators, registerPythonGenerators, initBlockly, BLOCKLY_MAP_TYPE_DICT, BLOCKLY_CUSTOMIZE_DICT } from '@/api/blockly/blockly.js';
 import {playMp3} from "@/api/blockly/music.js";
 
 import cupbg from '@/assets/blockly/cupbg.png' // 通关后奖杯底图
@@ -414,20 +414,7 @@ const gameState = reactive({
 
 // 控制遮罩层显示的状态
 const showOverlay = ref(false);
-// 地图元素类型字典
-const BLOCKLY_MAP_TYPE_DICT = {
-  ICE: 'ice',//冰块
-  TASK: 'task',//钥匙
-  ITEM: 'item',//物品
-  TRAP: 'trap',//陷阱
-
-}
-// 自定义积木字典
-const BLOCKLY_CUSTOMIZE_DICT = {
-  PAUSE: 'pause',//暂停
-  PLAY_SOUND: 'play_sound',//播放音效
-  CONSTRUCT: 'construct',//修建
-}
+// 字典常量已从blockly.js中导入
 
 // 计算属性 - 提高性能和可读性
 const mapBackground = computed(() => gameState.mapConfig.background);

+ 2 - 7
src/views/blockly/MapGame.vue

@@ -124,6 +124,7 @@ import playerImage from '@/assets/images/blockly/user.png';
 
 // 游戏接口数据
 import { getMapGameById } from '@/api/blockly/game.js';
+import { BLOCKLY_MAP_TYPE_DICT, BLOCKLY_CUSTOMIZE_DICT } from '@/api/blockly/blockly.js';
 
 // 配置常量
 const CONFIG = {
@@ -240,13 +241,7 @@ const gameState = reactive({
     originalWalkablePoints: [],
   }
 });
-const BLOCKLY_MAP_TYPE_DICT = {
-  ICE: 'ice',//冰块
-  TASK: 'task',//钥匙
-  ITEM: 'item',//物品
-  TRAP: 'trap',//陷阱
-
-};
+// BLOCKLY_MAP_TYPE_DICT和BLOCKLY_CUSTOMIZE_DICT已从blockly.js导入
 
 // 计算属性 - 提高性能和可读性
 const mapBackground = computed(() => gameState.mapConfig.background);