@@ -43,41 +43,43 @@ Application.prototype.setResolution = function () {
43
43
* 读取图片并生成绘图命令
44
44
*/
45
45
Application . prototype . loadImage = function ( ) {
46
- this . imageReader
47
- . read ( this . $image , this . boxbot . map . columns , this . boxbot . map . rows )
48
- . then ( ( function ( data ) {
49
- var commands = 'mov to 1,1\nmov bot\nmov top\n'
50
- for ( var y = 1 ; y <= data . length ; y += 1 ) {
51
- // 移动到下一个位置
52
- if ( y == data . length ) {
53
- commands += 'tun rig\ntra lef\n'
54
- } else {
55
- commands += 'tra bot\n'
56
- }
57
-
58
- var columns = data [ y - 1 ] . length
59
- for ( var x = 1 ; x <= columns ; x += 1 ) {
60
- // 最后一个方块无法修墙,结束绘图
61
- if ( y == data . length && x == columns ) {
62
- break
46
+ if ( this . $image . files . length > 0 ) {
47
+ this . imageReader
48
+ . read ( this . $image . files [ 0 ] , this . boxbot . map . columns , this . boxbot . map . rows )
49
+ . then ( ( function ( data ) {
50
+ var commands = 'mov to 1,1\nmov bot\nmov top\n'
51
+ for ( var y = 1 ; y <= data . length ; y += 1 ) {
52
+ // 移动到下一个位置
53
+ if ( y == data . length ) {
54
+ commands += 'tun rig\ntra lef\n'
55
+ } else {
56
+ commands += 'tra bot\n'
63
57
}
64
58
65
- var _x = columns - x
66
- var direction = 'lef'
59
+ var columns = data [ y - 1 ] . length
60
+ for ( var x = 1 ; x <= columns ; x += 1 ) {
61
+ // 最后一个方块无法修墙,结束绘图
62
+ if ( y == data . length && x == columns ) {
63
+ break
64
+ }
67
65
68
- if ( y % 2 ) {
69
- _x = [ x - 1 ]
70
- direction = 'rig'
71
- }
66
+ var _x = columns - x
67
+ var direction = 'lef'
68
+
69
+ if ( y % 2 ) {
70
+ _x = [ x - 1 ]
71
+ direction = 'rig'
72
+ }
72
73
73
- if ( x != 1 ) {
74
- commands += 'tra ' + direction + '\n'
74
+ if ( x != 1 ) {
75
+ commands += 'tra ' + direction + '\n'
76
+ }
77
+ commands += 'biud\nbru ' + data [ y - 1 ] [ _x ] + '\n'
75
78
}
76
- commands += 'biud\nbru ' + data [ y - 1 ] [ _x ] + '\n'
77
79
}
78
- }
79
- this . editor . setCodes ( commands )
80
- } ) . bind ( this ) )
80
+ this . editor . setCodes ( commands )
81
+ } ) . bind ( this ) )
82
+ }
81
83
}
82
84
83
85
/**
@@ -159,7 +161,9 @@ Application.prototype.reset = function () {
159
161
this . boxbot . queue = [ ]
160
162
this . boxbot . map . clear ( )
161
163
this . boxbot . bot . init ( )
164
+ this . editor . setCodes ( '' )
162
165
this . editor . clearFlag ( )
166
+ this . $image . value = ''
163
167
}
164
168
165
169
new Application ( )
0 commit comments