summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/map
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/map')
-rw-r--r--public/assets/javascripts/rectangles/engine/map/draw.js4
-rw-r--r--public/assets/javascripts/rectangles/engine/map/ui_editor.js106
2 files changed, 94 insertions, 16 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js
index 8e1fe5a..3e185d2 100644
--- a/public/assets/javascripts/rectangles/engine/map/draw.js
+++ b/public/assets/javascripts/rectangles/engine/map/draw.js
@@ -29,7 +29,7 @@ Map.Draw = function(map, opt){
ctx.translate( map.center.a, map.center.b )
ctx.scale( -1, 1 )
- draw.regions(Rooms.regions, colors)
+ draw.regions(Rooms.regions, [ "#f8f8f8" ])
draw.mouse(map.ui.mouse.cursor)
draw.coords()
scene && draw.camera(scene.camera)
@@ -55,7 +55,7 @@ Map.Draw = function(map, opt){
}
draw.clear = function(){
- ctx.fillStyle = "rgba(255,255,255,0.9)"
+ ctx.fillStyle = "rgba(255,255,255,0.98)"
ctx.clearRect(0, 0, map.dimensions.a, map.dimensions.b)
ctx.fillRect(0, 0, map.dimensions.a, map.dimensions.b)
}
diff --git a/public/assets/javascripts/rectangles/engine/map/ui_editor.js b/public/assets/javascripts/rectangles/engine/map/ui_editor.js
index 577ea32..9a557b9 100644
--- a/public/assets/javascripts/rectangles/engine/map/ui_editor.js
+++ b/public/assets/javascripts/rectangles/engine/map/ui_editor.js
@@ -30,6 +30,7 @@ Map.UI.Editor = function(map){
//
function down (e, cursor){
+ var room
cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a)
cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b)
@@ -52,22 +53,28 @@ Map.UI.Editor = function(map){
if (intersects.length && base.permissions.destroy) {
base.mouse.down = false
- Rooms.remove(intersects[0])
- app.tube("builder-destroy-room", intersects[0])
+
+ room = intersects[0]
+
+ UndoStack.push({
+ type: "destroy-room",
+ undo: room.copy(),
+ redo: { id: room.id },
+ })
+
+ Rooms.remove(room)
+ app.tube("builder-destroy-room", room)
return
}
- else if (intersects.length && (base.permissions.move || base.permissions.resize)) {
+ else if (intersects.length) {
base.dragging = intersects[0]
- base.resizing = base.permissions.resize && base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom)
+ base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom)
base.dragging.rect.translation.sides = base.resizing
app.tube("builder-pick-room", intersects[0])
}
else if (base.permissions.create) {
base.creating = true
}
- else if (intersects.length) {
- app.tube("builder-pick-room", intersects[0])
- }
if (e.shiftKey && base.dragging) {
base.dragging.rect.quantize(10/map.zoom)
@@ -77,6 +84,45 @@ Map.UI.Editor = function(map){
function move (e, cursor) {
cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a)
cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b)
+
+ var intersects = Rooms.filter(function(r){
+ return r.rect.contains(cursor.x.a, cursor.y.a)
+ })
+
+ if (base.permissions.destroy) {
+ map.el.className = "destroy"
+ }
+ else if (intersects.length) {
+ var edges = intersects[0].rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom)
+ switch (edges) {
+ case FRONT_LEFT:
+ case BACK_RIGHT:
+ map.el.className = "nesw-resize"
+ break
+
+ case FRONT_RIGHT:
+ case BACK_LEFT:
+ map.el.className = "nwse-resize"
+ break
+
+ case FRONT:
+ case BACK:
+ map.el.className = "ns-resize"
+ break
+
+ case LEFT:
+ case RIGHT:
+ map.el.className = "ew-resize"
+ break
+
+ default:
+ map.el.className = "move"
+ break
+ }
+ }
+ else {
+ map.el.className = ""
+ }
}
function drag (e, cursor) {
@@ -115,20 +161,40 @@ Map.UI.Editor = function(map){
cursor.x.abs().quantize(1)
cursor.y.abs().quantize(1)
var room = Rooms.add_with_rect( cursor )
+
+ UndoStack.push({
+ type: "create-room",
+ undo: { id: room.id },
+ redo: room.copy()
+ })
+
app.tube("builder-pick-room", room)
}
}
- if (base.resizing) {
- base.dragging.rect.resize()
- }
- else if (base.dragging) {
- base.dragging.rect.translate()
- }
+ if (base.resizing || base.dragging) {
+ var oldState = base.dragging.copy()
+
+ if (base.resizing) {
+ base.dragging.rect.resize()
+ }
+ else if (base.dragging) {
+ base.dragging.rect.translate()
+ }
+
+ UndoStack.push({
+ type: "update-room",
+ undo: oldState,
+ redo: base.dragging.copy()
+ })
+ }
+
base.creating = base.dragging = base.resizing = false
}
+ var wheelState, wheelTimeout
+
function mousewheel (e, val, delta){
var cursor = base.mouse.cursor
@@ -137,8 +203,20 @@ Map.UI.Editor = function(map){
})
if (intersects.length) {
+ wheelState = wheelState || intersects[0].copy()
+
intersects[0].height = clamp( ~~(intersects[0].height - delta), height_min, height_max )
- Rooms.clipper.update()
+
+ clearTimeout(wheelTimeout)
+ wheelTimeout = setTimeout(function(){
+ UndoStack.push({
+ type: "update-room",
+ undo: wheelState,
+ redo: intersects[0].copy()
+ })
+ Rooms.clipper.update()
+ wheelState = null
+ }, 500)
}
else {
map.set_zoom(map.zoom_exponent - delta/20)