Skip to content

Commit

Permalink
Fix bug in shared template and upgrade jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
dichternebel committed Jan 5, 2024
1 parent 752ecd9 commit 9bd5a4c
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 126 deletions.
15 changes: 14 additions & 1 deletion App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@
<appSettings>
<add key="address" value="localhost" />
<add key="port" value="6969" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
</configuration>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
5 changes: 3 additions & 2 deletions TelemetryJsonService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -24,7 +25,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down Expand Up @@ -67,6 +67,7 @@
<Reference Include="System.Security" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Deployment" />
Expand Down Expand Up @@ -142,7 +143,7 @@
<Content Include="overlays\images\tyre-icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="overlays\js\jquery-3.6.2.min.js">
<Content Include="overlays\js\jquery-3.7.1.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="overlays\js\shared.js">
Expand Down
2 changes: 1 addition & 1 deletion overlays/dummy.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<link rel="stylesheet" href="css/table.css">
<script src="js/jquery-3.6.2.min.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
<script src="js/shared.js"></script>
<script>
function executeOverlay() {
Expand Down
2 changes: 0 additions & 2 deletions overlays/js/jquery-3.6.2.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions overlays/js/jquery-3.7.1.min.js

Large diffs are not rendered by default.

230 changes: 113 additions & 117 deletions overlays/js/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// WARNING: All edits here will be lost!!!
// Do not edit this file manually, because it will be overwritten on application start to keep the port in sync!
//
Expand All @@ -7,9 +7,9 @@
//

// Define colors
var colorScsLight = '#d7d7d7';
var colorScsYellow = '#fdad01';
var colorRed = '#FF0000';
var colorScsLight = "#d7d7d7";
var colorScsYellow = "#fdad01";
var colorRed = "#FF0000";

// Prepare polling vars
var pollingInterval;
Expand All @@ -28,146 +28,142 @@ var train = false;
var ferry = false;

$(function () {
console.log("Document ready!");
setPollingInterval();
console.log("Document ready!");
setPollingInterval();
});

function setPollingInterval() {
clearInterval(pollingInterval);
pollingInterval = setInterval(function () {
execute();
}, timer);
clearInterval(pollingInterval);
pollingInterval = setInterval(function () {
execute();
}, timer);
}

// Slow down polling interval when connection is lost
function checkPollingInterval() {
if (retryCounter === 10 && timer === 100) {
isServiceConnected = false;
console.log("Too many connection errors: changing interval to 1sec...");
timer = 1000;
setPollingInterval();
}
if (retryCounter === 19 && timer === 1000) {
console.log("Too many connection errors: changing interval to 10secs and hiding '.game-connected'...");
timer = 10000;
setPollingInterval();

$('.game-connected').css({
'visibility': 'hidden'
});
}
else if (retryCounter === 0 && timer > 100) {
isServiceConnected = true;
console.log("We are back to business! Changing interval to 100ms...");
timer = 100;
setPollingInterval();
}
if (retryCounter === 10 && timer === 100) {
isServiceConnected = false;
console.log("Too many connection errors: changing interval to 1sec...");
timer = 1000;
setPollingInterval();
}
if (retryCounter === 19 && timer === 1000) {
console.log(
"Too many connection errors: changing interval to 10secs and hiding '.game-connected'...",
);
timer = 10000;
setPollingInterval();

$(".game-connected").css({
visibility: "hidden",
});
} else if (retryCounter === 0 && timer > 100) {
isServiceConnected = true;
console.log("We are back to business! Changing interval to 100ms...");
timer = 100;
setPollingInterval();
}
}

// Run that creepy thing!
function execute() {
$.getJSON("http://localhost:6969/", function (json) {
data = json;
$.getJSON("http://localhost:6969/", function (json) {
data = json;
})
.done(function () {
retryCounter = 0;
checkPollingInterval();
})
.fail(function () {
retryCounter++;
checkPollingInterval();
})
.done(function () {
retryCounter = 0;
checkPollingInterval();
})
.fail(function () {
retryCounter++;
checkPollingInterval();
})
.always(function () {
updateStatus();
if (typeof executeOverlay === "function" && data !== undefined) {
// This function should be used inside the overlay html to be executed
// no idea if that makes sense to anybody...
executeOverlay();
}
});
.always(function () {
updateStatus();
if (typeof executeOverlay === "function" && data !== undefined) {
// This function should be used inside the overlay html to be executed
// no idea if that makes sense to anybody...
executeOverlay();
}
});
}

// Some helper functions
function getReadableTime(time) {
var days = time.getUTCDate() - 1 > 0 ? time.getUTCDate() - 1 + "d:" : '';
var hours = time.getUTCHours() > 0 ? time.getUTCHours() + "h:" : '';
var minutes = time.getUTCMinutes() > 0 ? time.getUTCMinutes() + "m" : '';
var days = time.getUTCDate() - 1 > 0 ? time.getUTCDate() - 1 + "d:" : "";
var hours = time.getUTCHours() > 0 ? time.getUTCHours() + "h:" : "";
var minutes = time.getUTCMinutes() > 0 ? time.getUTCMinutes() + "m" : "";

return days + hours + minutes;
return days + hours + minutes;
}

function getRealMinutes(absMinutes) {
//if (data.CommonValues.Scale > 0 && absMinutes < 10)
// return "(" + Math.round(absMinutes / data.CommonValues.Scale).toFixed() + "m)";
return "(" + Math.round(absMinutes / 19).toFixed() + "m)";
//if (data.CommonValues.Scale > 0 && absMinutes < 10)
// return "(" + Math.round(absMinutes / data.CommonValues.Scale).toFixed() + "m)";
return "(" + Math.round(absMinutes / 19).toFixed() + "m)";
}

// Set some variables and manipulate styles
// Honestly! No clue how to do this in a proper way...
function updateStatus() {
$('.on-job').css({
'visibility': ''
$(".on-job").css({
visibility: "",
});
$(".train").css({
visibility: "",
});
$(".ferry").css({
visibility: "",
});
$(".game-paused").css({
visibility: "",
});
$(".game-connected").css({
visibility: "",
});

if (data !== undefined && data.SpecialEventsValues.OnJob) {
onJob = true;
} else {
$(".on-job").css({
visibility: "hidden",
});
$('.train').css({
'visibility': ''
onJob = false;
}

if (data !== undefined && data.SpecialEventsValues.Train) {
$(".train").css({
visibility: "hidden",
});
$('.ferry').css({
'visibility': ''
train = true;
} else {
train = false;
}

if (data !== undefined && data.SpecialEventsValues.Ferry) {
$(".ferry").css({
visibility: "hidden",
});
$('.game-paused').css({
'visibility': ''
ferry = true;
} else {
ferry = false;
}

if (data !== undefined && data.Paused) {
$(".game-paused").css({
visibility: "hidden",
});
$('.game-connected').css({
'visibility': ''
isGamePaused = true;
} else {
isGamePaused = false;
}

if (data !== undefined && data.SdkActive && isServiceConnected) {
isGameConnected = true;
} else {
$(".game-connected").css({
visibility: "hidden",
});

if (data !== undefined && data.SpecialEventsValues.OnJob) {
onJob = true;
}
else {
$('.on-job').css({
'visibility': 'hidden'
});
onJob = false;
}

if (data !== undefined && data.SpecialEventsValues.Train) {
$('.train').css({
'visibility': 'hidden'
});
train = true;
}
else {
train = false;
}

if (data !== undefined && data.SpecialEventsValues.Ferry) {
$('.ferry').css({
'visibility': 'hidden'
});
ferry = true;
}
else {
ferry = false;
}

if (data !== undefined && data.Paused) {
$('.game-paused').css({
'visibility': 'hidden'
});
isGamePaused = true;
}
else {
isGamePaused = false;
}

if (data !== undefined && data.SdkActive && isServiceConnected) {
isGameConnected = true;
}
else {
$('.game-connected').css({
'visibility': 'hidden'
});
isGameConnected = false;
}
}
isGameConnected = false;
}
}
2 changes: 1 addition & 1 deletion overlays/overlay-job.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<link rel="stylesheet" href="css/overlay-job.css">
<script src="js/jquery-3.6.2.min.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
<script src="js/shared.js"></script>
<script>
function executeOverlay() {
Expand Down
2 changes: 1 addition & 1 deletion overlays/overlay-status.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<link rel="stylesheet" href="css/overlay-status.css">
<script src="js/jquery-3.6.2.min.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
<script src="js/shared.js"></script>
<script>
function executeOverlay() {
Expand Down
2 changes: 1 addition & 1 deletion shared-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function checkPollingInterval() {

// Run that creepy thing!
function execute() {
$.getJSON("http://{{address}:{{port}}/", function (json) {
$.getJSON("http://{{address}}:{{port}}/", function (json) {
data = json;
})
.done(function () {
Expand Down

0 comments on commit 9bd5a4c

Please sign in to comment.