Map Builder Version 1
BIN
static/images/maps/bases/medium/Longchops.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
static/images/maps/bases/small/Farrow-Brigand.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
static/images/maps/bases/small/Gullin.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
static/images/maps/bases/small/Knor.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
static/images/maps/bases/small/Lurk.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
static/images/maps/bases/small/Razor-Boar.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
static/images/maps/bases/small/Slaughterhouser.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
static/images/maps/bases/small/Warlord-Morrg.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
static/images/maps/bases/small/Zocha.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
static/images/maps/tiles/HW-Board-A01.png
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
static/images/maps/tiles/HW-Board-A02.png
Normal file
|
After Width: | Height: | Size: 5.6 MiB |
BIN
static/images/maps/tiles/HW-Board-A03.png
Normal file
|
After Width: | Height: | Size: 4.9 MiB |
BIN
static/images/maps/tiles/HW-Board-A04.png
Normal file
|
After Width: | Height: | Size: 4.3 MiB |
BIN
static/images/maps/tiles/HW-Board-A05.png
Normal file
|
After Width: | Height: | Size: 5.4 MiB |
BIN
static/images/maps/tiles/HW-Board-A06.png
Normal file
|
After Width: | Height: | Size: 4.4 MiB |
BIN
static/images/maps/tiles/HW-Board-A07.png
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
static/images/maps/tiles/HW-Board-A08.png
Normal file
|
After Width: | Height: | Size: 6.1 MiB |
BIN
static/images/maps/tiles/HW-Board-A09.png
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
static/images/maps/tiles/HW-Board-B01.png
Normal file
|
After Width: | Height: | Size: 5.7 MiB |
BIN
static/images/maps/tiles/HW-Board-B02.png
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
static/images/maps/tiles/HW-Board-B03.png
Normal file
|
After Width: | Height: | Size: 5.8 MiB |
BIN
static/images/maps/tiles/HW-Board-B04.png
Normal file
|
After Width: | Height: | Size: 4.7 MiB |
BIN
static/images/maps/tiles/HW-Board-B05.png
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
static/images/maps/tiles/HW-Board-B06.png
Normal file
|
After Width: | Height: | Size: 4.7 MiB |
BIN
static/images/maps/tiles/HW-Board-B07.png
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
static/images/maps/tiles/HW-Board-B08.png
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
static/images/maps/tiles/HW-Board-B09.png
Normal file
|
After Width: | Height: | Size: 5.7 MiB |
BIN
static/images/maps/tokens/elongated/HW-A03.png
Normal file
|
After Width: | Height: | Size: 165 KiB |
BIN
static/images/maps/tokens/elongated/HW-A10.png
Normal file
|
After Width: | Height: | Size: 164 KiB |
BIN
static/images/maps/tokens/elongated/HW-A17.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
static/images/maps/tokens/elongated/HW-A24.png
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
static/images/maps/tokens/elongated/HW-B03.png
Normal file
|
After Width: | Height: | Size: 170 KiB |
BIN
static/images/maps/tokens/elongated/HW-B10.png
Normal file
|
After Width: | Height: | Size: 170 KiB |
BIN
static/images/maps/tokens/elongated/HW-B17.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
static/images/maps/tokens/elongated/HW-B24.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
static/images/maps/tokens/large/HW-A01.png
Normal file
|
After Width: | Height: | Size: 618 KiB |
BIN
static/images/maps/tokens/large/HW-A08.png
Normal file
|
After Width: | Height: | Size: 660 KiB |
BIN
static/images/maps/tokens/large/HW-A15.png
Normal file
|
After Width: | Height: | Size: 661 KiB |
BIN
static/images/maps/tokens/large/HW-A22.png
Normal file
|
After Width: | Height: | Size: 758 KiB |
BIN
static/images/maps/tokens/large/HW-B01.png
Normal file
|
After Width: | Height: | Size: 695 KiB |
BIN
static/images/maps/tokens/large/HW-B08.png
Normal file
|
After Width: | Height: | Size: 632 KiB |
BIN
static/images/maps/tokens/large/HW-B15.png
Normal file
|
After Width: | Height: | Size: 716 KiB |
BIN
static/images/maps/tokens/large/HW-B22.png
Normal file
|
After Width: | Height: | Size: 707 KiB |
BIN
static/images/maps/tokens/medium/HW-A02.png
Normal file
|
After Width: | Height: | Size: 406 KiB |
BIN
static/images/maps/tokens/medium/HW-A09.png
Normal file
|
After Width: | Height: | Size: 412 KiB |
BIN
static/images/maps/tokens/medium/HW-A16.png
Normal file
|
After Width: | Height: | Size: 386 KiB |
BIN
static/images/maps/tokens/medium/HW-A23.png
Normal file
|
After Width: | Height: | Size: 404 KiB |
BIN
static/images/maps/tokens/medium/HW-B02.png
Normal file
|
After Width: | Height: | Size: 430 KiB |
BIN
static/images/maps/tokens/medium/HW-B09.png
Normal file
|
After Width: | Height: | Size: 387 KiB |
BIN
static/images/maps/tokens/medium/HW-B16.png
Normal file
|
After Width: | Height: | Size: 400 KiB |
BIN
static/images/maps/tokens/medium/HW-B23.png
Normal file
|
After Width: | Height: | Size: 422 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-A03.png
Normal file
|
After Width: | Height: | Size: 169 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-A10.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-A17.png
Normal file
|
After Width: | Height: | Size: 169 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-A24.png
Normal file
|
After Width: | Height: | Size: 179 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-B03.png
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-B10.png
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-B17.png
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
static/images/maps/tokens/old-elongated/HW-B24.png
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
static/images/maps/tokens/old-medium/HW-A02.png
Normal file
|
After Width: | Height: | Size: 413 KiB |
BIN
static/images/maps/tokens/old-medium/HW-A09.png
Normal file
|
After Width: | Height: | Size: 425 KiB |
BIN
static/images/maps/tokens/old-medium/HW-A16.png
Normal file
|
After Width: | Height: | Size: 420 KiB |
BIN
static/images/maps/tokens/old-medium/HW-A23.png
Normal file
|
After Width: | Height: | Size: 424 KiB |
BIN
static/images/maps/tokens/old-medium/HW-B02.png
Normal file
|
After Width: | Height: | Size: 441 KiB |
BIN
static/images/maps/tokens/old-medium/HW-B09.png
Normal file
|
After Width: | Height: | Size: 406 KiB |
BIN
static/images/maps/tokens/old-medium/HW-B16.png
Normal file
|
After Width: | Height: | Size: 425 KiB |
BIN
static/images/maps/tokens/old-medium/HW-B23.png
Normal file
|
After Width: | Height: | Size: 419 KiB |
BIN
static/images/maps/tokens/small/HW-A04.png
Normal file
|
After Width: | Height: | Size: 143 KiB |
BIN
static/images/maps/tokens/small/HW-A05.png
Normal file
|
After Width: | Height: | Size: 146 KiB |
BIN
static/images/maps/tokens/small/HW-A06.png
Normal file
|
After Width: | Height: | Size: 147 KiB |
BIN
static/images/maps/tokens/small/HW-A07.png
Normal file
|
After Width: | Height: | Size: 144 KiB |
BIN
static/images/maps/tokens/small/HW-A11.png
Normal file
|
After Width: | Height: | Size: 132 KiB |
BIN
static/images/maps/tokens/small/HW-A12.png
Normal file
|
After Width: | Height: | Size: 132 KiB |
BIN
static/images/maps/tokens/small/HW-A13.png
Normal file
|
After Width: | Height: | Size: 132 KiB |
BIN
static/images/maps/tokens/small/HW-A14.png
Normal file
|
After Width: | Height: | Size: 138 KiB |
BIN
static/images/maps/tokens/small/HW-A18.png
Normal file
|
After Width: | Height: | Size: 135 KiB |
BIN
static/images/maps/tokens/small/HW-A19.png
Normal file
|
After Width: | Height: | Size: 125 KiB |
BIN
static/images/maps/tokens/small/HW-A20.png
Normal file
|
After Width: | Height: | Size: 135 KiB |
BIN
static/images/maps/tokens/small/HW-A21.png
Normal file
|
After Width: | Height: | Size: 142 KiB |
BIN
static/images/maps/tokens/small/HW-A25.png
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
static/images/maps/tokens/small/HW-A26.png
Normal file
|
After Width: | Height: | Size: 145 KiB |
BIN
static/images/maps/tokens/small/HW-A27.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
static/images/maps/tokens/small/HW-A28.png
Normal file
|
After Width: | Height: | Size: 144 KiB |
BIN
static/images/maps/tokens/small/HW-B04.png
Normal file
|
After Width: | Height: | Size: 144 KiB |
BIN
static/images/maps/tokens/small/HW-B05.png
Normal file
|
After Width: | Height: | Size: 147 KiB |
BIN
static/images/maps/tokens/small/HW-B06.png
Normal file
|
After Width: | Height: | Size: 146 KiB |
BIN
static/images/maps/tokens/small/HW-B07.png
Normal file
|
After Width: | Height: | Size: 150 KiB |
BIN
static/images/maps/tokens/small/HW-B11.png
Normal file
|
After Width: | Height: | Size: 134 KiB |
BIN
static/images/maps/tokens/small/HW-B12.png
Normal file
|
After Width: | Height: | Size: 129 KiB |
BIN
static/images/maps/tokens/small/HW-B13.png
Normal file
|
After Width: | Height: | Size: 147 KiB |
BIN
static/images/maps/tokens/small/HW-B14.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
static/images/maps/tokens/small/HW-B18.png
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
static/images/maps/tokens/small/HW-B19.png
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
static/images/maps/tokens/small/HW-B20.png
Normal file
|
After Width: | Height: | Size: 118 KiB |
BIN
static/images/maps/tokens/small/HW-B21.png
Normal file
|
After Width: | Height: | Size: 113 KiB |
BIN
static/images/maps/tokens/small/HW-B25.png
Normal file
|
After Width: | Height: | Size: 169 KiB |
BIN
static/images/maps/tokens/small/HW-B26.png
Normal file
|
After Width: | Height: | Size: 162 KiB |
BIN
static/images/maps/tokens/small/HW-B27.png
Normal file
|
After Width: | Height: | Size: 165 KiB |
BIN
static/images/maps/tokens/small/HW-B28.png
Normal file
|
After Width: | Height: | Size: 165 KiB |
422
static/javascripts/maps.js
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
// global
|
||||
// var ikrpg
|
||||
|
||||
var ikrpg = ikrpg || {};
|
||||
|
||||
(function() {
|
||||
|
||||
var db2 = new PouchDB('maps.ikrpg');
|
||||
|
||||
listMaps();
|
||||
|
||||
fillLibrary();
|
||||
|
||||
makeRemover($('#img-library'));
|
||||
|
||||
$('#img-library .lib-img.tile').each(function(index, el) {
|
||||
var $el = $(el);
|
||||
makeDraggableCreator(8, '#map-area .tile', 90, 250)($el);
|
||||
});
|
||||
|
||||
$('#img-library .lib-img.token, #img-library .lib-img.base').each(function(index, el) {
|
||||
var $el = $(el);
|
||||
makeDraggableCreator(1, '#map-area .token, #map-area .base', 22.5, 125)($el);
|
||||
});
|
||||
|
||||
makeMapSaver($('#save-as'));
|
||||
|
||||
|
||||
|
||||
function fillLibrary() {
|
||||
appendTiles();
|
||||
append10x3tokens();
|
||||
append1x1Stokens();
|
||||
append4x3tokens();
|
||||
append1x1Ltokens();
|
||||
appendSmallBases();
|
||||
appendMediumBases();
|
||||
|
||||
function appendTiles() {
|
||||
$.each(['01', '02', '03', '04', '05', '06', '07', '08', '09'], function(i, id) {
|
||||
$.each(['A', 'B'], function(j, key) {
|
||||
$('#tiles').append('\
|
||||
<li class="tile">\
|
||||
<h4>HW Board '+key+id+'</h4>\
|
||||
<img class="lib-img tile" src="/static/images/maps/tiles/HW-Board-'+key+id+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function append10x3tokens() {
|
||||
$.each(['03', '10', '17', '24'], function(i, id) {
|
||||
$.each(['A', 'B'], function(j, key) {
|
||||
$('#tokens10x3').append('\
|
||||
<li class="token10x3">\
|
||||
<h4>HW '+key+id+'</h4>\
|
||||
<img class="lib-img token token10x3" src="/static/images/maps/tokens/elongated/HW-'+key+id+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function append1x1Stokens() {
|
||||
$.each(['04', '05', '06', '07', '11', '12', '13', '14', '18', '19', '20', '21', '25', '26', '27', '28'], function(i, id) {
|
||||
$.each(['A', 'B'], function(j, key) {
|
||||
$('#tokens1x1s').append('\
|
||||
<li class="token1x1s">\
|
||||
<h4>HW '+key+id+'</h4>\
|
||||
<img class="lib-img token token1x1s" src="/static/images/maps/tokens/small/HW-'+key+id+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function append4x3tokens() {
|
||||
$.each(['02', '09', '16', '23'], function(i, id) {
|
||||
$.each(['A', 'B'], function(j, key) {
|
||||
$('#tokens4x3').append('\
|
||||
<li class="token4x3">\
|
||||
<h4>HW Board '+key+id+'</h4>\
|
||||
<img class="lib-img token token4x3" src="/static/images/maps/tokens/medium/HW-'+key+id+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function append1x1Ltokens() {
|
||||
$.each(['01', '08', '15', '22'], function(i, id) {
|
||||
$.each(['A', 'B'], function(j, key) {
|
||||
$('#tokens1x1l').append('\
|
||||
<li class="token1x1l">\
|
||||
<h4>HW '+key+id+'</h4>\
|
||||
<img class="lib-img token token1x1l" src="/static/images/maps/tokens/large/HW-'+key+id+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function appendSmallBases() {
|
||||
$.each(['Farrow-Brigand', 'Gullin', 'Knor', 'Lurk', 'Razor-Boar', 'Slaughterhouser', 'Warlord-Morrg', 'Zocha'], function(i, name) {
|
||||
$('#bases-small').append('\
|
||||
<li class="base-small">\
|
||||
<img class="lib-img base base-small" src="/static/images/maps/bases/small/'+name+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
}
|
||||
|
||||
function appendMediumBases() {
|
||||
$.each(['Longchops'], function(i, name) {
|
||||
$('#bases-medium').append('\
|
||||
<li class="base-medium">\
|
||||
<img class="lib-img base base-medium" src="/static/images/maps/bases/medium/'+name+'.png" />\
|
||||
</li>\
|
||||
');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function makeRemover($el) {
|
||||
$el.droppable({
|
||||
accept: 'img',
|
||||
drop: function(event, ui) {
|
||||
$(ui.draggable).remove();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function makeDraggableCreator(step, stackSelector, angle, duration) {
|
||||
return function($el) {
|
||||
$el.click(function(event) {
|
||||
var $img = createImg($el.attr('class'), $el.attr('src'));
|
||||
|
||||
$img.offset({
|
||||
top: event.pageY - $img.height() / 2,
|
||||
left: event.pageX - $img.width() / 2
|
||||
});
|
||||
|
||||
makeDraggable(step, stackSelector)($img);
|
||||
makeRotateable(angle, duration)($img);
|
||||
disableContextMenu($img);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function makeMapSaver($el) {
|
||||
$el.click(function(event) {
|
||||
event.preventDefault();
|
||||
var map = currentMapData();
|
||||
var _id = $('#map-name').val();
|
||||
|
||||
var json = { '_id': _id, 'data': map };
|
||||
|
||||
db2.get(_id, function(error, doc) {
|
||||
if(error) { // map not in db yet
|
||||
doc = json;
|
||||
doc["_id"] = _id;
|
||||
db2.put(doc);
|
||||
} else { // map already in db
|
||||
json["_id"] = doc["_id"];
|
||||
json["_rev"] = doc["_rev"];
|
||||
db2.put(json);
|
||||
}
|
||||
listMaps();
|
||||
$('#map-area img').remove();
|
||||
setTimeout(function() {
|
||||
fill(false, json);
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function listMaps() {
|
||||
$("#load-maps > tbody").remove();
|
||||
|
||||
$("#load-maps").append("<tbody>");
|
||||
|
||||
db2.allDocs({include_docs: true}, function(error, results) {
|
||||
if(!error) {
|
||||
var rows = results.rows;
|
||||
|
||||
$.each(rows, function(index, row) {
|
||||
var map = row.doc;
|
||||
|
||||
function appendTr() {
|
||||
$("#load-maps > tbody").append("<tr>");
|
||||
}
|
||||
|
||||
function appendTd() {
|
||||
$("#load-maps > tbody > tr:last-of-type").append("<td>");
|
||||
}
|
||||
|
||||
function lastTd() {
|
||||
return $("#load-maps > tbody > tr:last-of-type > td:last-of-type");
|
||||
}
|
||||
|
||||
appendTr();
|
||||
appendTd();
|
||||
lastTd().text(map["_id"]);
|
||||
appendTd();
|
||||
lastTd().html("<a href=\"#\">Load</a>");
|
||||
lastTd().find('a').click(showMap(map['_id']));
|
||||
appendTd();
|
||||
lastTd().html("<a href=\"#\"><strong>Delete</strong></a>");
|
||||
lastTd().find('a').click(deleteMap(map['_id'], map['_rev']));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showMap(_id) {
|
||||
return function(event) {
|
||||
event.preventDefault();
|
||||
$('#map-name').val(_id);
|
||||
db2.get(_id, fill);
|
||||
};
|
||||
};
|
||||
|
||||
function fill(error, json) {
|
||||
if(!error) {
|
||||
var map = json.data;
|
||||
$('#map-area img').remove();
|
||||
var mapAreaOffset = $('#map-area').offset();
|
||||
|
||||
$.each(map, function(index, img) {
|
||||
var top = img.top;
|
||||
var left = img.left;
|
||||
var angle = img.angle;
|
||||
var src = img.src;
|
||||
var classes = img.classes;
|
||||
|
||||
var $img = createImg(classes, src);
|
||||
|
||||
console.log('up', mapAreaOffset.top, mapAreaOffset.left)
|
||||
|
||||
// TODO: SUUUPER dirty! Refactor this!
|
||||
if(classes.indexOf('tile') > 0) {
|
||||
makeDraggable(8, '#map-area .tile')($img);
|
||||
makeRotateable(90, 250)($img);
|
||||
} else if(classes.indexOf('token') > 0 || classes.indexOf('base') > 0) {
|
||||
makeDraggable(1, '#map-area .token, #map-area .base')($img);
|
||||
makeRotateable(22.5, 125)($img);
|
||||
}
|
||||
|
||||
$img.offset({
|
||||
top: top + $('#map-area').offset().top,
|
||||
left: left + $('#map-area').offset().left
|
||||
});
|
||||
|
||||
$img.css({ transform: "rotate(" + angle + "deg)" });
|
||||
$img.data('angle', angle);
|
||||
|
||||
disableContextMenu($img);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function deleteMap(_id, _rev) {
|
||||
return function(event) {
|
||||
event.preventDefault();
|
||||
if(confirm("This will delete your map. Do you want to proceed?")) {
|
||||
db2.remove(_id, _rev, function(error, code) {
|
||||
var map = currentMapData();
|
||||
listMaps();
|
||||
$('#map-area img').remove();
|
||||
var json = { 'data': map };
|
||||
setTimeout(function() {
|
||||
fill(false, json);
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function createImg(classes, src) {
|
||||
var $img = $('<img />');
|
||||
$img.addClass(classes);
|
||||
$img.attr('src', src);
|
||||
$('#map-area').append($img);
|
||||
return $img;
|
||||
}
|
||||
|
||||
function makeDraggable(step, stackSelector) {
|
||||
return function($el) {
|
||||
$el.draggable({
|
||||
cursor: 'crosshair',
|
||||
cursorAt: { left: $el.width() / 2, top: $el.height() / 2 },
|
||||
opacity: 0.5,
|
||||
drag: grid(),
|
||||
stack: stackSelector
|
||||
});
|
||||
|
||||
function grid() {
|
||||
var $parent = $el.parent();
|
||||
var parentOffset = $parent.offset();
|
||||
|
||||
var compensation = {
|
||||
top: parentOffset.top % step,
|
||||
left: parentOffset.left % step
|
||||
};
|
||||
|
||||
return function(event, ui) {
|
||||
var remainder = {
|
||||
top: ui.position.top % step,
|
||||
left: ui.position.left % step
|
||||
};
|
||||
|
||||
ui.position = {
|
||||
top: ui.position.top - remainder.top + compensation.top,
|
||||
left: ui.position.left - remainder.left + compensation.left
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
function makeRotateable(degree, duration) {
|
||||
return function($el) {
|
||||
// Idea: If $el is clicked but not moved, it is rotated
|
||||
|
||||
$el.data('angle', 0);
|
||||
|
||||
$el.mousedown(function(event) {
|
||||
var offset = $el.offset();
|
||||
$el.data('moved', false);
|
||||
});
|
||||
$el.mousemove(function(event) {
|
||||
$el.data('moved', true);
|
||||
});
|
||||
$el.mouseup(function(event) {
|
||||
var offset = $el.offset();
|
||||
if(!$el.data('moved')) {
|
||||
// Rotate element clockwise if it did not move. On right click, rotate counterclockwise.
|
||||
rotateElement($el, event.button === 2 ? -degree : degree, duration);
|
||||
}
|
||||
$el.removeData('moved');
|
||||
});
|
||||
|
||||
return $el;
|
||||
};
|
||||
|
||||
function rotateElement($el, degree, duration) {
|
||||
var w = $el.css('width');
|
||||
var h = $el.css('height');
|
||||
|
||||
var currentAngle = getCurrentRotationAngle($el);
|
||||
var angle = currentAngle + degree;
|
||||
|
||||
$({deg: currentAngle}).animate({deg: angle}, {
|
||||
duration: duration,
|
||||
step: function(now){
|
||||
$el.css({ transform: "rotate(" + now + "deg)" });
|
||||
}
|
||||
});
|
||||
|
||||
$el.data('angle', angle);
|
||||
}
|
||||
|
||||
function getCurrentRotationAngle($el) {
|
||||
var st = window.getComputedStyle($el[0], null);
|
||||
var tr = st.getPropertyValue("-webkit-transform") ||
|
||||
st.getPropertyValue("-moz-transform") ||
|
||||
st.getPropertyValue("-ms-transform") ||
|
||||
st.getPropertyValue("-o-transform") ||
|
||||
st.getPropertyValue("transform") ||
|
||||
'none';
|
||||
|
||||
if(tr === 'none') {
|
||||
tr = 'matrix(0.0, 0.0, 0.0, 0.0, 0px, 0px)';
|
||||
}
|
||||
|
||||
var values = tr.split('(')[1].split(')')[0].split(',');
|
||||
var a = values[0];
|
||||
var b = values[1];
|
||||
|
||||
var scale = Math.sqrt(a*a + b*b);
|
||||
var sin = b/scale;
|
||||
var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));
|
||||
|
||||
return angle;
|
||||
}
|
||||
};
|
||||
|
||||
function disableContextMenu($el) {
|
||||
$el[0].oncontextmenu = function() { return false; }
|
||||
}
|
||||
|
||||
function currentMapData($mapArea) {
|
||||
var data = [];
|
||||
|
||||
var $mapArea = $('#map-area');
|
||||
|
||||
var areaOffset = $mapArea.offset();
|
||||
$mapArea.find('img').each(function(i, img) {
|
||||
var $img = $(img);
|
||||
$img.css('width', 0);
|
||||
$img.css('height', 0);
|
||||
$img.css({ transform: 'rotate(0deg)' });
|
||||
var imgOffset = $img.offset();
|
||||
|
||||
console.log('down', areaOffset.top, areaOffset.left)
|
||||
|
||||
var entry = {
|
||||
top: imgOffset.top - areaOffset.top,
|
||||
left: imgOffset.left - areaOffset.left,
|
||||
angle: $img.data('angle'),
|
||||
src: $img.attr('src'),
|
||||
classes: $img.attr('class')
|
||||
};
|
||||
|
||||
data.push(entry);
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
})();
|
||||