8000 修正图片读取 bug · HashCoding/boxbot@899c6dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 899c6dc

Browse files
committed
修正图片读取 bug
1 parent eece8d1 commit 899c6dc

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

app.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,43 @@ Application.prototype.setResolution = function () {
4343
* 读取图片并生成绘图命令
4444
*/
4545
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'
6357
}
6458

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+
}
6765

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+
}
7273

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'
7578
}
76-
commands += 'biud\nbru ' + data[y - 1][_x] + '\n'
7779
}
78-
}
79-
this.editor.setCodes(commands)
80-
}).bind(this))
80+
this.editor.setCodes(commands)
81+
}).bind(this))
82+
}
8183
}
8284

8385
/**
@@ -159,7 +161,9 @@ Application.prototype.reset = function () {
159161
this.boxbot.queue = []
160162
this.boxbot.map.clear()
161163
this.boxbot.bot.init()
164+
this.editor.setCodes('')
162165
this.editor.clearFlag()
166+
this.$image.value = ''
163167
}
164168

165169
new Application()

0 commit comments

Comments
 (0)
0