maze-blockly-wrapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 SmartBooksDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # @maze/blockly-wrapper
2
+
3
+ A React-based Blockly wrapper for creating interactive maze programming games. This package provides a complete maze game environment where users can program a spider to navigate through mazes using visual programming blocks.
4
+
5
+ ## Features
6
+
7
+ - **Interactive Maze Game**: Program a spider to navigate through mazes
8
+ - **Visual Programming**: Uses Google Blockly for drag-and-drop programming
9
+ - **Editable Mazes**: Create and customize mazes with an intuitive editor
10
+ - **Real-time Execution**: Watch your code execute step-by-step
11
+ - **Responsive Design**: Works on desktop and mobile devices
12
+ - **TypeScript Support**: Full TypeScript definitions included
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @maze/blockly-wrapper
18
+ ```
19
+
20
+ ## Peer Dependencies
21
+
22
+ This package requires the following peer dependencies:
23
+
24
+ ```json
25
+ {
26
+ "react": "^18.0.0 || ^19.0.0",
27
+ "react-dom": "^18.0.0 || ^19.0.0",
28
+ "blockly": "^12.0.0"
29
+ }
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```tsx
35
+ import React from 'react';
36
+ import { MazeGame } from '@maze/blockly-wrapper';
37
+
38
+ function App() {
39
+ const handleRunFinish = (result) => {
40
+ console.log('Game finished!', result);
41
+ // result contains: steps, reachedFinish, maxMovesExceeded, finalPosition, path, executionTime
42
+ };
43
+
44
+ return (
45
+ <MazeGame
46
+ isEditable={true}
47
+ onRunFinish={handleRunFinish}
48
+ maxMoves={100}
49
+ />
50
+ );
51
+ }
52
+ ```
53
+
54
+ ## Components
55
+
56
+ ### MazeGame
57
+
58
+ The main component that combines the maze, programming interface, and game logic.
59
+
60
+ #### Props
61
+
62
+ | Prop | Type | Default | Description |
63
+ |------|------|---------|-------------|
64
+ | `isEditable` | `boolean` | `false` | Enable maze editing mode |
65
+ | `configuration` | `MazeConfig` | `undefined` | Initial maze configuration |
66
+ | `onChange` | `(config: MazeConfig) => void` | `undefined` | Callback when maze configuration changes |
67
+ | `onRunFinish` | `(result: RunResult) => void` | `undefined` | Callback when game execution finishes |
68
+ | `maxMoves` | `number` | `50` | Maximum moves allowed |
69
+ | `showControls` | `boolean` | `true` | Show game control buttons |
70
+ | `className` | `string` | `undefined` | Additional CSS classes |
71
+
72
+ ### EditableMazeGrid
73
+
74
+ A standalone component for editing maze configurations.
75
+
76
+ ```tsx
77
+ import { EditableMazeGrid } from '@maze/blockly-wrapper';
78
+
79
+ <EditableMazeGrid
80
+ config={mazeConfig}
81
+ onConfigChange={handleConfigChange}
82
+ />
83
+ ```
84
+
85
+ ### MazeBlocklyContainer
86
+
87
+ The Blockly programming interface component.
88
+
89
+ ```tsx
90
+ import { MazeBlocklyContainer } from '@maze/blockly-wrapper';
91
+
92
+ <MazeBlocklyContainer
93
+ config={blocklyConfig}
94
+ onCodeChange={handleCodeChange}
95
+ onExecuteCode={handleExecuteCode}
96
+ />
97
+ ```
98
+
99
+ ## Types
100
+
101
+ ### MazeConfig
102
+
103
+ ```typescript
104
+ interface MazeConfig {
105
+ width: number;
106
+ height: number;
107
+ spiderStart: Position;
108
+ finishPosition: Position;
109
+ walls: Position[];
110
+ estimatedSteps?: number;
111
+ }
112
+ ```
113
+
114
+ ### RunResult
115
+
116
+ ```typescript
117
+ interface RunResult {
118
+ steps: number;
119
+ reachedFinish: boolean;
120
+ maxMovesExceeded: boolean;
121
+ finalPosition: Position;
122
+ path: Position[];
123
+ executionTime: number;
124
+ error?: string;
125
+ }
126
+ ```
127
+
128
+ ### Position
129
+
130
+ ```typescript
131
+ interface Position {
132
+ x: number;
133
+ y: number;
134
+ }
135
+ ```
136
+
137
+ ## Usage Examples
138
+
139
+ ### Basic Game
140
+
141
+ ```tsx
142
+ import { MazeGame } from '@maze/blockly-wrapper';
143
+
144
+ <MazeGame />
145
+ ```
146
+
147
+ ### Editable Maze with Configuration
148
+
149
+ ```tsx
150
+ import { MazeGame } from '@maze/blockly-wrapper';
151
+
152
+ const initialConfig = {
153
+ width: 12,
154
+ height: 10,
155
+ spiderStart: { x: 1, y: 1 },
156
+ finishPosition: { x: 10, y: 8 },
157
+ walls: [
158
+ { x: 3, y: 2 },
159
+ { x: 4, y: 3 },
160
+ { x: 7, y: 5 }
161
+ ]
162
+ };
163
+
164
+ <MazeGame
165
+ isEditable={true}
166
+ configuration={initialConfig}
167
+ onChange={(config) => console.log('Maze changed:', config)}
168
+ onRunFinish={(result) => console.log('Game result:', result)}
169
+ maxMoves={75}
170
+ />
171
+ ```
172
+
173
+ ### Custom Blockly Configuration
174
+
175
+ ```tsx
176
+ import { MazeBlocklyContainer } from '@maze/blockly-wrapper';
177
+
178
+ const customConfig = {
179
+ allowedTypes: new Set(['maze_move_forward', 'maze_turn_left']),
180
+ limits: { maze_move_forward: 10, maze_turn_left: 5 },
181
+ toolbox: `<xml>...</xml>`,
182
+ initialXml: `<xml>...</xml>`
183
+ };
184
+
185
+ <MazeBlocklyContainer
186
+ config={customConfig}
187
+ onCodeChange={(code) => console.log('Code:', code)}
188
+ onExecuteCode={(commands) => console.log('Commands:', commands)}
189
+ />
190
+ ```
191
+
192
+ ## Development
193
+
194
+ ### Building the Package
195
+
196
+ ```bash
197
+ # Build library for distribution
198
+ npm run build:lib
199
+
200
+ # Build types
201
+ npm run build:types
202
+
203
+ # Build both library and app
204
+ npm run build
205
+ ```
206
+
207
+ ### Development Mode
208
+
209
+ ```bash
210
+ npm run dev
211
+ ```
212
+
213
+ ## Contributing
214
+
215
+ 1. Fork the repository
216
+ 2. Create a feature branch
217
+ 3. Make your changes
218
+ 4. Add tests if applicable
219
+ 5. Submit a pull request
220
+
221
+ ## License
222
+
223
+ MIT License - see [LICENSE](LICENSE) file for details.
224
+
225
+ ## Support
226
+
227
+ For issues and questions, please use the GitLab issue tracker at:
228
+ https://gitlab.com/smartbooksdev/blocklysbwrapper