summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/wall.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-29 21:01:45 -0400
committerJules Laplace <jules@okfoc.us>2014-08-29 21:01:45 -0400
commit8abb36413413363f226486c78e7c01e7c37632bd (patch)
treea4aaecc918050b5c10c63a1d5b4cd02f8d2c48ab /public/assets/javascripts/rectangles/models/wall.js
parente35e2f338ee7b14d8396485e58cb5593060add8e (diff)
store wallpaper and undo setting it
Diffstat (limited to 'public/assets/javascripts/rectangles/models/wall.js')
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js99
1 files changed, 29 insertions, 70 deletions
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 61de95e..f04ac2d 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -19,6 +19,7 @@
this.side = opt.side
this.surface = opt.surface
this.mx = opt.mx
+ this.background = ""
}
Wall.prototype.toString = function(){
@@ -63,7 +64,7 @@
e.stopPropagation()
return
}
-
+
UndoStack.push({
type: 'create-scenery',
undo: { id: scenery.id },
@@ -74,7 +75,17 @@
Minotaur.watch( app.router.editorView.settings )
}
else if (Scenery.nextWallpaper) {
- base.wallpaper()
+ var oldState = base.serialize()
+ base.wallpaper(Scenery.nextWallpaper)
+ Scenery.nextWallpaper = null
+
+ UndoStack.push({
+ type: 'update-wallpaper',
+ undo: oldState,
+ redo: base.serialize(),
+ })
+
+ Minotaur.watch( app.router.editorView.settings )
}
else {
app.controller.hideExtras()
@@ -91,6 +102,17 @@
// this.outline(wallColor, outlineColor)
}
+
+ Wall.prototype.serialize = function(){
+ return {
+ id: this.id,
+ background: this.background,
+ }
+ }
+
+ Wall.prototype.deserialize = function(data){
+ this.wallpaper( data.background )
+ }
// wall
@@ -147,69 +169,26 @@
position.a -= dimension.a / 2
position.b -= dimension.b / 2
}
-// if (mx.width) { position.a -= mx.width / 2 }
-// if (mx.height) { position.b -= mx.height / 2 }
return position
}
- Wall.prototype.bounds_for = function(img, scale) {
- scale = scale || 1
- var coord = this.side & FRONT_BACK ? this.rect.x : this.rect.y
- var halfWidth = img.width/2 * scale
- var halfHeight = img.height/2 * scale
-
- return new Rect( new vec2( coord.a + halfWidth, coord.b - halfWidth ),
- new vec2( halfHeight, Rooms.list[this.room].height - halfHeight ) )
- }
-
- Wall.prototype.fits = function(img, scale){
- if (this.side & FRONT_BACK && this.rect.x.length() < img.width * scale) {
- return false
- }
- if (this.side & LEFT_RIGHT && this.rect.y.length() < img.width * scale) {
- return false
- }
- return true
- }
-
- Wall.prototype.center = function(offset){
-
- switch (this.side) {
- case FRONT:
- x = this.vec.midpoint()
- z = this.edge + painting_distance_from_wall
- break
- case BACK:
- x = this.vec.midpoint()
- z = this.edge - painting_distance_from_wall
- break
- case LEFT:
- x = this.edge + painting_distance_from_wall
- z = this.vec.midpoint()
- break
- case RIGHT:
- x = this.edge - painting_distance_from_wall
- z = this.vec.midpoint()
- break
- }
-
- return new vec2 (x, z)
- }
-
Wall.prototype.color = function(color){
this.$walls.css("background-color", color)
}
- Wall.prototype.wallpaper = function(){
+ Wall.prototype.wallpaper = function(background){
var useX = this.side & FRONT_BACK
var shouldFlip = this.side & (LEFT | BACK)
+
+ this.background = background || "none"
+
this.mx.forEach(function(mx){
var partitionOffset = useX ? mx.x : mx.z
if (shouldFlip) partitionOffset *= -1
partitionOffset += mx.width/2
var floorOffset = mx.y + mx.height/2
- mx.el.style.backgroundImage = Scenery.nextWallpaper
+ mx.el.style.backgroundImage = background
mx.el.style.backgroundPosition = (~~partitionOffset) + "px " + (~~floorOffset) + "px"
})
}
@@ -250,26 +229,6 @@
})
}
- Wall.prototype.siblings = function(){
- return this
- }
-
- Wall.prototype.stroke_colors = function(){
- var color = "#fff"
- var len = this.mx.length-1
- this.mx.forEach(function(mx, i){
- w.color(color)
- if (i == 0) {
- mx.el.css("border-left", "1px solid #000")
- }
- if (i == len) {
- mx.el.css("border-right", "1px solid #000")
- }
- mx.el.css("border-top", "1px solid #000")
- mx.el.css("border-bottom", "1px solid #000")
- })
- }
-
if ('window' in this) {
window.Wall = Wall
}