Skip to content

Commit f43cf75

Browse files
committed
fix: blips not working
With the previous commit, I forgot to change a few thiings. Now everything should be working fine.
1 parent 9f270b1 commit f43cf75

File tree

7 files changed

+76
-65
lines changed

7 files changed

+76
-65
lines changed

index.php

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
// number that is set
8080
var _SETTINGS_socketUrl = "ws://localhost:30121"
8181

82+
// Set to false if you don't want to show the player's identifiers (this may be their IP)
83+
var _SETTINGS_showIdentifiers = true;
84+
8285
// Do not remove unless you know what you're doing (and you have a google api key)
8386
// Hack from https://stackoverflow.com/questions/38148097/google-maps-api-without-key/38809129#38809129
8487
// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)

js/src/init.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ function initPage() {
1212

1313
function initMarkers(debugOnly) {
1414
if (debugOnly) {
15-
createMarker(false, true, new MarkerObject("@DEBUG@@Locator", new Coordinates(0, 500, 0), MarkerTypes.debug, "", ""), "")
15+
createMarker(false, true, new MarkerObject("@DEBUG@@Locator", new Coordinates(0, 500, 0), MarkerTypes[999], "", ""), "")
16+
console.log("MarkerType: " + MarkerTypes[999]);
1617
} else {
17-
createMarker(false, false, new MarkerObject("True Map Center", new Coordinates(0, 0, 0), MarkerTypes.normal, "", ""), "");
18+
createMarker(false, false, new MarkerObject("True Map Center", new Coordinates(0, 0, 0), MarkerTypes[6], "", ""), "");
1819
}
1920
}

js/src/map.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,7 @@ function mapInit(elementID) {
149149
}
150150

151151
function createMarker(animated, draggable, objectRef, title) {
152-
if (title != "") {
153-
var splitTitle = title.split(" - ");
154-
if (splitTitle.length >= 4) {
155-
var posSplit = splitTitle[1].split(" ");
156-
var x1 = posSplit[0].replace("X{", "");
157-
var xResult = x1.replace("}", "");
158-
var y1 = posSplit[1].replace("Y{", "");
159-
var yResult = y1.replace("}", "");
160-
var z1 = posSplit[2].replace("Z{", "");
161-
var zResult = z1.replace("}", "");
162-
objectRef.position = new Coordinates(xResult, yResult, zResult);
163-
var noSpaceHash = splitTitle[2].replace(/\s+/g, "");
164-
var hash = noSpaceHash.replace("Hash:", "");
165-
objectRef.hash = hash;
166-
var noSpaceModel = splitTitle[3].replace(/\s+/g, "");
167-
var model = noSpaceModel.replace("ModelName:", "");
168-
objectRef.modelname = model
169-
}
170-
}
152+
171153
var name = objectRef.reference;
172154
if (name == "@DEBUG@@Locator") {
173155
name = "@Locator"
@@ -179,12 +161,6 @@ function createMarker(animated, draggable, objectRef, title) {
179161
//console.log(JSON.stringify(locationType));
180162

181163
var html = '<div class="row info-body-row"><strong>Position:</strong>&nbsp;X {' + objectRef.position.x.toFixed(4) + "} Y {" + objectRef.position.y.toFixed(4) + "} Z {" + objectRef.position.z.toFixed(4) + "}</div>";
182-
if (objectRef.hash != "") {
183-
html += '<div class="row info-body-row"><strong>Hash:</strong>&nbsp;' + objectRef.hash + "</div>"
184-
}
185-
if (objectRef.modelname != "") {
186-
html += '<div class="row info-body-row"><strong>Model Name:</strong>&nbsp;' + objectRef.modelname + "</div>"
187-
}
188164

189165
if (objectRef.description != ""){
190166
html += '<div class="row info-body-row"><strong>Description:</strong>&nbsp;' + objectRef.description + "</div>"

js/src/markers.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ var customImageWidth = 64 / 2; // 64 = sheetWidth / 16
33
var customImageHeight = 64 / 2; // 64 = sheetHeight / 16
44

55
var MarkerTypes = {
6-
none: {
6+
0: {
77
icon: "blank.png",
88
size: new google.maps.Size(0, 0),
99
origin: new google.maps.Point(0, 0),
1010
anchor: new google.maps.Point(0, 0)
1111
},
12-
debug: {
12+
999: {
1313
icon: "debug.png",
1414
size: new google.maps.Size(23, 32),
1515
origin: new google.maps.Point(0, 0),
1616
anchor: new google.maps.Point(11.5, 32)
1717
},
18-
normal: {
18+
// Apparently players have an icon of "6" so, might as well make normal that
19+
6: {
1920
icon: "normal.png",
2021
size: new google.maps.Size(22, 32),
2122
origin: new google.maps.Point(0, 0),

js/src/objects.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ function EuclideanProjection() {
88
this.offsetLat = 0;
99
this.offsetLng = 0
1010
}
11+
1112
EuclideanProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) {
1213
var point = opt_point || new google.maps.Point(0, 0);
1314
var origin = this.pixelOrigin_;
1415
point.x = (origin.x + (latLng.lng() + this.offsetLng) * this.scaleLng * this.pixelsPerLonDegree_);
1516
point.y = (origin.y + (-1 * latLng.lat() + this.offsetLat) * this.scaleLat * this.pixelsPerLonDegree_);
1617
return point
1718
};
19+
1820
EuclideanProjection.prototype.fromPointToLatLng = function(point) {
1921
var me = this;
2022
var origin = me.pixelOrigin_;
@@ -29,11 +31,10 @@ function Coordinates(x, y, z) {
2931
this.z = z
3032
}
3133

32-
function MarkerObject(reference, position, type, description, hash, modelname) {
34+
function MarkerObject(reference, position, type, description, data) {
3335
this.reference = reference;
3436
this.position = position;
3537
this.type = type;
3638
this.description = description;
37-
this.hash = hash;
38-
this.modelname = modelname
39+
this.data = data;
3940
};

js/src/socket.js

+58-29
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function onOpen(e){
2424
_isConnected = true;
2525
console.log("_isConnected: " + _isConnected);
2626
// Get blips?
27-
webSocket.send("getBlips");
28-
webSocket.send("getLocations"); // Get any players connected to the server
27+
//TODO: Ajax request the blips
28+
29+
webSocket.send("getPlayerData"); // Get any players connected to the server
2930

3031
$("#connection").removeClass("label-danger")
3132
.removeClass("label-warning")
@@ -38,14 +39,13 @@ function onMessage(e){
3839
var byteSize = e.data.length + (m ? m.length : 0);
3940

4041
console.log("recieved message (" + byteSize/1024 + " kB)");
42+
console.log("data: " + e.data);
4143
var data = JSON.parse(e.data);
4244

4345
if(data.type == "blips"){
44-
console.log("creating blips");
45-
initBlips(data.payload);
4646

47-
}else if (data.type == "players") {
48-
console.log("updating players");
47+
}else if (data.type == "playerData") {
48+
console.log("updating players: " + JSON.stringify(data));
4949
doPlayerUpdate(data.payload);
5050

5151
}else if(data.type == "playerLeft"){
@@ -143,32 +143,56 @@ function playerLeft(playerName){
143143
}
144144
}
145145

146+
function getPlayerInfoHtml(plr){
147+
var html = '<div class="row info-body-row"><strong>Position:</strong>&nbsp;X {' + plr.pos.x.toFixed(4) + "} Y {" + plr.pos.y.toFixed(4) + "} Z {" + plr.pos.z.toFixed(4) + "}</div>"
148+
for(var key in plr){
149+
console.log("found key: "+ key);
150+
if (key == "name" || key == "pos" || key == "icon"){ // I should probably turn this into a array or something
151+
continue; // We're already displaying this info
152+
}
153+
if(_SETTINGS_showIdentifiers && key == "identifer"){
154+
html += '<div class="row info-body-row"><strong>Identifer:</strong>&nbsp;' + plr[key] + '</div>';
155+
}else{
156+
// some other info.. Show it
157+
html += '<div class="row info-body-row"><strong>' + key + ':</strong>&nbsp;' + plr[key] + '</div>';
158+
}
159+
}
160+
161+
return html;
162+
}
163+
146164
function doPlayerUpdate(players){
165+
console.log(players);
147166
var playerCount = 0;
148167
players.forEach(function(plr){
149168
playerCount ++;
150169
if (plr == null) return;
151170

152-
if ( !(plr.id in localCache) ){
153-
localCache[plr.id] = { marker: null };
171+
if ( !(plr.identifer in localCache) ){
172+
// "localCache" literally just keeps track of the marker.. I should rename it
173+
//TODO: Rename "localCache" to something better
174+
localCache[plr.identifer] = { marker: null };
154175
}
155176

156-
if ($("#playerSelect option[value='" + plr.id + "']").length <= 0){
177+
if ($("#playerSelect option[value='" + plr.identifer + "']").length <= 0){
178+
// Ooo look, we have players. Let's add them to the "tracker" drop-down
157179
$("#playerSelect").append($("<option>", {
158-
value: plr.id,
159-
text: plr.name
180+
value: plr.identifer, // Should be unique
181+
text: plr.name // Their name.. Might not be unique?
160182
}));
161183
}
162184

163-
if (_trackPlayer != null && _trackPlayer == plr.id){
164-
map.panTo(convertToMapGMAP(plr.x, plr.y));
185+
if (_trackPlayer != null && _trackPlayer == plr.identifer){
186+
// If we're tracking a player, make sure we center them
187+
map.panTo(convertToMapGMAP(plr.pos.x, plr.pos.y));
165188
}
166189

167-
if (localCache[plr.id].marker != null || localCache[plr.id].marker != undefined){
168-
169-
if (plr.vehicle){
170-
var t = MarkerTypes[plr.vehicle];
171-
_MAP_markerStore[localCache[plr.id].marker].setIcon({
190+
if (localCache[plr.identifer].marker != null || localCache[plr.identifer].marker != undefined){
191+
// If we have a custom icon (we should) use it!!
192+
if (plr.icon){
193+
var t = MarkerTypes[plr.icon];
194+
console.log("Got icon of :" + plr.icon);
195+
_MAP_markerStore[localCache[plr.identifer].marker].setIcon({
172196
url: _MAP_iconURL + t.icon,
173197
size: t.size,
174198
origin: t.origin,
@@ -177,26 +201,31 @@ function doPlayerUpdate(players){
177201
});
178202
}
179203

180-
_MAP_markerStore[localCache[plr.id].marker].setPosition( convertToMapGMAP(plr.x, plr.y) );
204+
// Update the player's location on the map :)
205+
_MAP_markerStore[localCache[plr.identifer].marker].setPosition( convertToMapGMAP(plr.pos.x, plr.pos.y) );
181206

182-
//update popup
183-
var html = '<div class="row info-body-row"><strong>Position:</strong>&nbsp;X {' + plr.x.toFixed(4) + "} Y {" + plr.y.toFixed(4) + "} Z {" + plr.z.toFixed(4) + "}</div>"
184-
185-
if (plr.vehicle && plr.vehicle != "normal")
186-
html += '<div class="row info-body-row"><strong>Vehicle:</strong>&nbsp;' + plr.vehicle_name + '</div>';
207+
//update popup with the information we have been sent
208+
var html = getPlayerInfoHtml(plr);
187209

188210
var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-icon"></div><div class="info-header">' + plr.name + '</div></div><div class="clear"></div><div id=info-body>' + html + "</div></div>";
189211
var infoBox = new google.maps.InfoWindow({
190212
content: infoContent
191213
});
192-
_MAP_markerStore[localCache[plr.id].marker].popup.setContent(infoContent);
193-
214+
_MAP_markerStore[localCache[plr.identifer].marker].popup.setContent(infoContent);
194215

195216
}else{
196-
var obj = new MarkerObject(plr.name, new Coordinates(plr.x, plr.y, plr.z), MarkerTypes.normal, "A player", "", "");
197-
createMarker(false, false, obj, plr.name);
198217

199-
localCache[plr.id].marker = _MAP_markerStore.length - 1;
218+
var obj = new MarkerObject(plr.name, new Coordinates(plr.pos.x, plr.pos.y, plr.pos.z), MarkerTypes[6], "", "", "");
219+
var m = localCache[plr.identifer].marker = createMarker(false, false, obj, plr.name) - 1;
220+
221+
var html = getPlayerInfoHtml(plr);
222+
223+
var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-icon"></div><div class="info-header">' + plr.name + '</div></div><div class="clear"></div><div id=info-body>' + html + "</div></div>";
224+
var infoBox = new google.maps.InfoWindow({
225+
content: infoContent
226+
});
227+
_MAP_markerStore[m].popup.setContent(infoContent);
228+
200229
}
201230

202231
});

utils/minifier.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ function printCss($debug){
6262
}
6363

6464
function printFirstJs($debug){
65-
$jsFiles = array("js/src/init.js", "js/src/objects.js",
66-
"js/src/utils.js", "js/src/map.js",
67-
"js/src/markers.js", "js/src/socket.js");
65+
$jsFiles = array("js/src/objects.js", "js/src/utils.js",
66+
"js/src/map.js", "js/src/markers.js",
67+
"js/src/init.js", "js/src/socket.js");
6868

6969
if($debug){
7070
foreach($jsFiles as $fname){

0 commit comments

Comments
 (0)