Commit e4a7ac8d authored by Stefan Kraus's avatar Stefan Kraus
Browse files

Add coordinate compression for cipmap-user

parent dab76903
......@@ -861,9 +861,60 @@ $(document).ready(function(){
* Map related functions
*/
function compressSingleCoordinate(coord_list){
var mi = 10e9
var ma = -10e9
var used_coords = new Set()
for(var i = 0; i < coord_list.length; i++){
var coord = coord_list[i];
mi = Math.min(mi, coord)
ma = Math.max(ma, coord)
used_coords.add(coord)
}
var transformed_coors = {}
var cur = mi;
if(Cookies.get('cipmap-beamer-user') == 'True'){
for(var i = mi; i <= ma; i++){
transformed_coors[i] = cur;
if(used_coords.has(i)){
cur += 1;
} else {
cur += 0.5;
}
}
} else {
for(var i = mi; i <= ma; i++){
transformed_coors[i] = i;
}
}
return transformed_coors;
}
function compressCoordinates(curMap){
var xs = []
var ys = []
for(var i = 0; i < curMap.length; i++){
xs.push(curMap[i].x)
ys.push(curMap[i].y)
}
var trans_xs = compressSingleCoordinate(xs)
var trans_ys = compressSingleCoordinate(ys)
return [trans_xs, trans_ys];
}
//Draws the map on first load
function drawMapFirst(){
var room = getCurrentRoom();
if(room === undefined) return; //not in ciproom but faq, optin etc.
drawMap(room);
populateMap();
......@@ -881,11 +932,15 @@ function drawMap(cip) {
var pcSize = 110;
var pcSpace = 10;
var trans_coords = compressCoordinates(curMap);
var trans_xs = trans_coords[0]
var trans_ys = trans_coords[1]
for(var i=0; i<curMap.length;i++){
var d = document.createElement("div");
var top_pos = curMap[i].y*(pcSize + pcSpace) + roomMargin;
var left_pos = curMap[i].x*(pcSize + pcSpace) + roomMargin;
var top_pos = trans_ys[curMap[i].y]*(pcSize + pcSpace) + roomMargin;
var left_pos = trans_xs[curMap[i].x]*(pcSize + pcSpace) + roomMargin;
//Set new element's attributes and append to main content div
$("#roomBorder").append(
......@@ -913,22 +968,30 @@ function drawMap(cip) {
if(door){
var doorWidth = 10;
var doorStart = 0;
var doorEnd = 0;
if(door.position%2){
mapHeight += doorWidth * 2;
doorStart = trans_xs[door.offset];
doorEnd = trans_xs[door.offset+1];
} else {
mapWidth += doorWidth * 2;
doorStart = trans_ys[door.offset];
doorEnd = trans_ys[door.offset+1];
}
var doorPos = roomMargin + (door.offset)*(pcSize+pcSpace);
var leftOffset = [-2, doorPos, mapWidth-doorWidth+2, doorPos];
var topOffset = [doorPos, mapHeight-doorWidth+2, doorPos, -2];
var doorStartPos = roomMargin + (doorStart)*(pcSize+pcSpace);
var doorEndPos = roomMargin + (doorEnd)*(pcSize+pcSpace) - pcSpace;
var leftOffset = [-2, doorStartPos, mapWidth-doorWidth+2, doorStartPos];
var topOffset = [doorStartPos, mapHeight-doorWidth+2, doorStartPos, -2];
$("#roomBorder").append(
$(document.createElement("div")).css({
"display": "none",
"position": "absolute",
"height": (door.position%2)?doorWidth:(pcSize),
"width":!(door.position%2)?doorWidth:(pcSize),
"height": (door.position%2)?doorWidth:(doorEndPos-doorStartPos),
"width":!(door.position%2)?doorWidth:(doorEndPos-doorStartPos),
"left": leftOffset[door.position],
"top": topOffset[door.position],
"border": "solid 2px #ddd"
......
......@@ -27,6 +27,13 @@ urlpatterns = [
name='res_map.js',
),
# cipmap user start page
url(
r'^cipmap-beamer-user$',
views.cipmap_beamer_user,
name='index-cipmap-beamer-user',
),
# Tutor pages
url(
r'^tutor/?$',
......@@ -81,5 +88,5 @@ urlpatterns = [
name='tutor_res_sw.js',
),
url(r'^(?P<room>\w+)$', views.index, name='index-room'),
url(r'^(?P<room>[-\w]+)$', views.index, name='index-room'),
]
......@@ -80,6 +80,12 @@ def legalnotice(request):
return render(request, 'server/legalnotice.html', {'rooms': _get_rooms()})
def cipmap_beamer_user(request):
response = redirect('index-room', room='cip2')
response.set_cookie(key='cipmap-beamer-user', value=True, secure=True)
return response
# Disable CSRF-checks to allow automated POST requests to update the state.
@csrf_exempt
def hosts(request):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment