Skip to content

Commit 63141ec

Browse files
committed
Use the proper image path for the robot animation on the code/ page
1 parent 8d54472 commit 63141ec

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

code/animatevillage.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
this.node = outer.appendChild(doc.createElement("div"))
3434
this.node.style.cssText = "position: relative; line-height: 0.1; margin-left: 10px"
3535
this.map = this.node.appendChild(doc.createElement("img"))
36-
let imgPath = "img/"
37-
if (/\/code($|\/)/.test(outer.ownerDocument.defaultView.location)) imgPath = "../" + imgPath
38-
console.log(outer.ownerDocument.defaultView.location.toString(), /\/code($|\/)/.test(outer.ownerDocument.defaultView.localation), imgPath)
39-
this.map.src = imgPath + "village2x.png"
36+
this.imgPath = "img/"
37+
if (/\/code($|\/)/.test(outer.ownerDocument.defaultView.location)) this.imgPath = "../" + this.imgPath
38+
console.log(outer.ownerDocument.defaultView.location.toString(), /\/code($|\/)/.test(outer.ownerDocument.defaultView.localation), this.imgPath)
39+
this.map.src = this.imgPath + "village2x.png"
4040
this.map.style.cssText = "vertical-align: -8px"
4141
this.robotElt = this.node.appendChild(doc.createElement("div"))
4242
this.robotElt.style.cssText = `position: absolute; transition: left ${0.8 / speed}s, top ${0.8 / speed}s;`
4343
let robotPic = this.robotElt.appendChild(doc.createElement("img"))
44-
robotPic.src = imgPath + "robot_moving2x.gif"
44+
robotPic.src = this.imgPath + "robot_moving2x.gif"
4545
this.parcels = []
4646

4747
this.text = this.node.appendChild(doc.createElement("span"))
@@ -75,7 +75,7 @@
7575
heights[place] += 14
7676
let node = document.createElement("div")
7777
let offset = placeKeys.indexOf(address) * 16
78-
node.style.cssText = "position: absolute; height: 16px; width: 16px; background-image: url(img/parcel2x.png); background-position: 0 -" + offset + "px";
78+
node.style.cssText = `position: absolute; height: 16px; width: 16px; background-image: url(${this.imgPath}parcel2x.png); background-position: 0 -${offset}px`;
7979
if (place == this.worldState.place) {
8080
node.style.left = "25px"
8181
node.style.bottom = (20 + height) + "px"
@@ -99,7 +99,7 @@
9999
if (this.worldState.parcels.length == 0) {
100100
this.button.remove()
101101
this.text.textContent = ` Finished after ${this.turn} turns`
102-
this.robotElt.firstChild.src = "img/robot_idle2x.png"
102+
this.robotElt.firstChild.src = this.imgPath + "robot_idle2x.png"
103103
} else {
104104
this.schedule()
105105
}
@@ -113,12 +113,12 @@
113113
if (this.timeout == null) {
114114
this.schedule()
115115
this.button.textContent = "Stop"
116-
this.robotElt.firstChild.src = "img/robot_moving2x.gif"
116+
this.robotElt.firstChild.src = this.imgPath + "robot_moving2x.gif"
117117
} else {
118118
clearTimeout(this.timeout)
119119
this.timeout = null
120120
this.button.textContent = "Start"
121-
this.robotElt.firstChild.src = "img/robot_idle2x.png"
121+
this.robotElt.firstChild.src = this.imgPath + "robot_idle2x.png"
122122
}
123123
}
124124
}

0 commit comments

Comments
 (0)