move getTypeByGuid to utils_misc.js and clean it up a little

This commit is contained in:
Stefan Breunig
2013-02-10 00:26:27 +01:00
parent 5762b8cb79
commit 53ff334fe1
2 changed files with 31 additions and 30 deletions

View File

@ -165,36 +165,6 @@ window.cleanUp = function() {
console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields'); console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields');
} }
// translates guids to entity types
window.getTypeByGuid = function(guid) {
// portals end in “.11” or “.12“, links in “.9", fields in “.b”
// .11 == portals
// .12 == portals
// .9 == links
// .b == fields
// .c == player/creator
// .d == chat messages
switch(guid.slice(33)) {
case '11':
case '12':
return TYPE_PORTAL;
break;
case '9':
return TYPE_LINK;
break;
case 'b':
return TYPE_FIELD;
break;
case 'c':
return TYPE_PLAYER;
break;
case 'd':
return TYPE_CHAT;
break;
default:
return TYPE_UNKNOWN;
}
}
// removes given entity from map // removes given entity from map
window.removeByGuid = function(guid) { window.removeByGuid = function(guid) {

View File

@ -138,6 +138,37 @@ window.zoomToAndShowPortal = function(guid, latlng) {
map.setView(latlng, 17); map.setView(latlng, 17);
} }
// translates guids to entity types
window.getTypeByGuid = function(guid) {
// portals end in “.11” or “.12“, links in “.9", fields in “.b”
// .11 == portals
// .12 == portals
// .9 == links
// .b == fields
// .c == player/creator
// .d == chat messages
switch(guid.slice(33)) {
case '11':
case '12':
return TYPE_PORTAL;
case '9':
return TYPE_LINK;
case 'b':
return TYPE_FIELD;
case 'c':
return TYPE_PLAYER;
case 'd':
return TYPE_CHAT;
default:
return TYPE_UNKNOWN;
}
}
String.prototype.capitalize = function() { String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase(); return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
} }