summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/wall.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/models/wall.js')
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js41
1 files changed, 25 insertions, 16 deletions
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 7ff9015..542c99a 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -213,7 +213,7 @@
this.$walls.css("background-color", color)
}
- Wall.prototype.wallpaper = function(background){
+ Wall.prototype.wallpaper = function(background, img){
if (! background) {
background = { src: "none" }
}
@@ -235,7 +235,7 @@
return
}
- var img = new Image ()
+ img = img || new Image ()
img.onload = function(){
this.backgroundImage = img
this.wallpaperLoad(this.background.src)
@@ -260,24 +260,34 @@
this.background.y = background.y || this.background.y
this.background.scale = background.scale || this.background.scale || 1
- var useX = this.side & FRONT_BACK
- var shouldFlip = this.side & (LEFT | BACK)
-
var mx, dx, dy
var w = Math.round( this.backgroundImage.naturalWidth * this.background.scale )
var h = Math.round( this.backgroundImage.naturalHeight * this.background.scale )
this.surface.faces.forEach(function(face, i){
-
- if (shouldFlip) {
- mx = this.mx[this.mx.length-1-i]
- dx = Math.round( this.background.x + face.x.a )
- dy = Math.round( this.background.y + face.y.b )
- }
- else {
- mx = this.mx[i]
- dx = Math.round( this.background.x - face.x.b )
- dy = Math.round( this.background.y + face.y.b )
+ // this.mx[i].el.innerHTML = sidesToString(this.side)
+
+ switch (this.side) {
+ case LEFT:
+ mx = this.mx[this.mx.length-1-i]
+ dx = Math.round( this.background.x + face.x.a )
+ dy = Math.round( this.background.y + face.y.b )
+ break
+ case RIGHT:
+ mx = this.mx[this.mx.length-1-i]
+ dx = Math.round( this.background.x + face.x.b )
+ dy = Math.round( this.background.y + face.y.b )
+ break
+ case FRONT:
+ mx = this.mx[this.mx.length-1-i]
+ dx = Math.round( this.background.x + face.x.b )
+ dy = Math.round( this.background.y + face.y.b )
+ break
+ case BACK:
+ mx = this.mx[i]
+ dx = Math.round( this.background.x - face.x.a )
+ dy = Math.round( this.background.y + face.y.b )
+ break
}
mx.el.style.backgroundPosition = dx + 'px ' + dy + 'px'
@@ -286,7 +296,6 @@
}
Wall.prototype.outline = function(wallColor, outlineColor){
- var useX = this.side & FRONT_BACK
var mx = this.mx
var len = this.mx.length