diff --git a/README.md b/README.md index c3c543bcd2..303f1d588a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Euro Truck Simulator 2 / American Truck Simulator's Route Advisor, for mobile de The mobile Route Advisor is planned to include all features that Euro Truck Simulator 2 / American Truck Simulator's Route Advisor currently has. These features are: - Navigation - - Mini-map (ETS2 only) + - Mini-map - Fixed on truck, up is always north - Fixed on truck, map rotates so up is direction truck is facing - Free view/rotate/zoom @@ -25,7 +25,7 @@ The mobile Route Advisor is planned to include all features that Euro Truck Simu ## Requirements - Euro Truck Simulator 2 and/or American Truck Simulator -- [ETS2 Telemetry Server](https://github.com/Funbit/ets2-telemetry-server/releases/tag/3.2.3) 3.2.3 or later +- [ETS2 Telemetry Server](https://github.com/Funbit/ets2-telemetry-server) 3.2.3 or later ## How to Install 1. Download the latest version of the Mobile Route Advisor from either the [official website](http://www.mikekoch.me/ets2-mobile-route-advisor), or from the [releases page](https://www.github.com/mike-koch/ets2-mobile-route-advisor/releases). @@ -35,7 +35,7 @@ The mobile Route Advisor is planned to include all features that Euro Truck Simu If you require any type of support, please looking at the [contributing guidelines](https://github.com/mike-koch/ets2-mobile-route-advisor/blob/master/CONTRIBUTING.md) to see where you should post your request. **Please do not contact me directly via e-mail, as your e-mail will be ignored.** ## Languages -A list of supported languages are available on the [repository's wiki](https://github.com/mike-koch/ets2-mobile-route-advisor/wiki/config.json-Parameters). If you would like to submit a translation, please submit a pull request. +A list of supported languages are available on the [ets2-mobile-route-advisor website](http://mikekoch.me/ets2-mobile-route-advisor). If you would like to submit a translation, please submit a pull request. ## Screenshots ![Navigation Information](screenshots/nav.png) @@ -54,6 +54,7 @@ A list of supported languages are available on the [repository's wiki](https://g @@ -65,11 +66,13 @@ A list of supported languages are available on the [repository's wiki](https://g
  • MinecraftMarioGuy53
  • SchorschiBW
  • denilsonsa
  • +
  • Frank Kristensen
  • diff --git a/config.json b/config.json index 3ea072be7f..d0afc361f3 100644 --- a/config.json +++ b/config.json @@ -26,12 +26,18 @@ "language": "en-US.json", "timeFormat": "24h", - "distanceUnits": "km", - "weightUnits": "kg", - "currencyCodeEts2": "EUR", - "currencyCodeAts": "USD", "checkForUpdates": true, - "mapPackEts2": "ets2", - "mapPackAts": "ats" + "ats": { + "distanceUnits": "mi", + "weightUnits": "lb", + "currencyCode": "USD", + "mapPack": "ats" + }, + "ets2": { + "distanceUnits": "km", + "weightUnits": "kg", + "currencyCode": "EUR", + "mapPack": "ets2" + } } } diff --git a/dashboard.css b/dashboard.css index fa0f356ea4..25d8dcb3ac 100644 --- a/dashboard.css +++ b/dashboard.css @@ -119,6 +119,11 @@ a { -ms-flex-preferred-size: 5em; flex-basis: 5em; } +.dashboard > aside > div._speed { + background: #7F0000; + background: -webkit-linear-gradient(top, rgba(127,0,0,0) 0%, rgba(255,0,0,0) 50%, rgba(127,0,0,0) 100%); + background: linear-gradient(to bottom, rgba(127,0,0,0) 0%, rgba(255,0,0,0) 50%, rgba(127,0,0,0) 100%); +} /* The main area. */ .dashboard > ._tabs > article { diff --git a/dashboard.html b/dashboard.html index 1df4e08daa..1a9c3d6051 100644 --- a/dashboard.html +++ b/dashboard.html @@ -102,6 +102,7 @@
    +

    @@ -189,8 +190,6 @@
    diff --git a/dashboard.jpg b/dashboard.jpg index 85f38d4e8e..a276c44ebe 100644 Binary files a/dashboard.jpg and b/dashboard.jpg differ diff --git a/dashboard.js b/dashboard.js index 3a035dbdeb..0f409f0809 100644 --- a/dashboard.js +++ b/dashboard.js @@ -16,7 +16,11 @@ Funbit.Ets.Telemetry.Dashboard.prototype.filter = function (data) { return data; } - g_runningGame = data.game.gameName; + // Process DOM changes here now that we have data. We should only do this once. + if (!g_processedDomChanges) { + processDomChanges(data); + } + data.isEts2 = g_runningGame == 'ETS2'; data.isAts = !data.isEts2; @@ -34,7 +38,11 @@ Funbit.Ets.Telemetry.Dashboard.prototype.filter = function (data) { data.gameTime12h = getTime(data.game.time, 12); var originalTime = data.game.time; data.game.time = getTime(data.game.time, 24); - data.trailerMassTons = data.trailer.attached ? ((data.trailer.mass / 1000.0) + ' t') : ''; + var tons = (data.trailer.mass / 1000.0).toFixed(2); + if (tons.substr(tons.length - 2) === "00") { + tons = parseInt(tons); + } + data.trailerMassTons = data.trailer.attached ? (tons + ' t') : ''; data.trailerMassKg = data.trailer.attached ? data.trailer.mass + ' kg' : ''; data.trailerMassLbs = data.trailer.attached ? Math.round(data.trailer.mass * 2.20462) + ' lb' : ''; data.game.nextRestStopTimeArray = getDaysHoursMinutesAndSeconds(data.game.nextRestStopTime); @@ -69,10 +77,6 @@ Funbit.Ets.Telemetry.Dashboard.prototype.filter = function (data) { data.jobIncome = getAtsJobIncome(data.job.income); } - - - - // Non-WoT stuff here if (!data.isWorldOfTrucksContract || data.isAts) { data.jobDeadlineTime12h = getTime(data.job.deadlineTime, 12); @@ -89,6 +93,18 @@ Funbit.Ets.Telemetry.Dashboard.prototype.render = function (data) { return data; } + if (data.game.gameName != null) { + g_lastRunningGame = g_runningGame; + g_runningGame = data.game.gameName; + + + if (g_runningGame != g_lastRunningGame + && g_lastRunningGame !== undefined) { + setLocalStorageItem('currentTab', $('._tabs').find('article:visible:first').attr('id')); + location.reload(); + } + } + // data - same data object as in the filter function $('.fillingIcon.truckDamage .top').css('height', (100 - data.scsTruckDamage) + '%'); $('.fillingIcon.trailerDamage .top').css('height', (100 - data.trailer.wear * 100) + '%'); @@ -146,6 +162,9 @@ Funbit.Ets.Telemetry.Dashboard.prototype.render = function (data) { // Set the current game attribute for any properties that are game-specific $('.game-specific').attr('data-game-name', data.game.gameName); + // Update red bar if speeding + updateSpeedIndicator(data.navigation.speedLimit, data.truck.speed); + return data; } @@ -157,64 +176,10 @@ Funbit.Ets.Telemetry.Dashboard.prototype.initialize = function (skinConfig) { // so you may perform any DOM or resource initializations here g_skinConfig = skinConfig; - - // Initialize JavaScript - g_pathPrefix = 'skins/' + skinConfig.name; - var ets2MapPack = skinConfig.mapPackEts2; - var atsMapPack = skinConfig.mapPackAts; - - // Process map JSON - $.getJSON(g_pathPrefix + '/maps/' + skinConfig.ets2MapPack + '/config.json', function(json) { - g_ets2MapPackConfig = json; - var scriptsToLoad = json['scripts']; - $.each(scriptsToLoad, function() { - $.getScript(g_pathPrefix + '/maps/' + skinConfig.ets2MapPack + '/' + this); - }); - }); - $.getJSON(g_pathPrefix + '/maps/' + skinConfig.atsMapPack + '/config.json', function(json) { - g_atsMapPackConfig = json; - var scriptsToLoad = json['scripts']; - $.each(scriptsToLoad, function() { - $.getScript(g_pathPrefix + '/maps/' + skinConfig.atsMapPack + '/' + this); - }); - }); - - // Process Speed Units - var distanceUnits = skinConfig.distanceUnits; - if (distanceUnits === 'km') { - $('.speedUnits').text('km/h'); - $('.distanceUnits').text('km'); - $('.truckSpeedRoundedKmhMph').addClass('truckSpeedRounded').removeClass('truckSpeedRoundedKmhMph'); - $('.speedLimitRoundedKmhMph').addClass('navigation-speedLimit').removeClass('speedLimitRoundedKmhMph'); - $('.navigationEstimatedDistanceKmMi').addClass('navigation-estimatedDistanceKmRounded').removeClass('navigationEstimatedDistanceKmMi'); - } else if (distanceUnits === 'mi') { - $('.speedUnits').text('mph'); - $('.distanceUnits').text('mi'); - $('.truckSpeedRoundedKmhMph').addClass('truckSpeedMphRounded').removeClass('truckSpeedRoundedKmhMph'); - $('.speedLimitRoundedKmhMph').addClass('navigation-speedLimitMphRounded').removeClass('speedLimitRoundedKmhMph'); - $('.navigationEstimatedDistanceKmMi').addClass('navigation-estimatedDistanceMiRounded').removeClass('navigationEstimatedDistanceKmMi'); - } - - // Process kg vs tons - var weightUnits = skinConfig.weightUnits; - if (weightUnits === 'kg') { - $('.trailerMassKgOrT').addClass('trailerMassKg').removeClass('trailerMassKgOrT'); - } else if (weightUnits === 't') { - $('.trailerMassKgOrT').addClass('trailerMassTons').removeClass('trailerMassKgOrT'); - } else if (weightUnits === 'lb') { - $('.trailerMassKgOrT').addClass('trailerMassLbs').removeClass('trailerMassKgOrT'); - } - - // Process 12 vs 24 hr time - var timeFormat = skinConfig.timeFormat; - if (timeFormat === '12h') { - $('.game-time').addClass('gameTime12h').removeClass('game-time'); - $('.job-deadlineTime').addClass('jobDeadlineTime12h').removeClass('job-deadlineTime'); - $('.navigation-estimatedTime').addClass('navigation-estimatedTime12h').removeClass('navigation-estimatedTime'); - } + g_pathPrefix = 'skins/' + g_skinConfig.name; // Process language JSON - $.getJSON(g_pathPrefix+'/language/'+skinConfig.language, function(json) { + $.getJSON(g_pathPrefix + '/language/' + g_skinConfig.language, function(json) { g_translations = json; $.each(json, function(key, value) { updateLanguage(key, value); @@ -235,7 +200,12 @@ Funbit.Ets.Telemetry.Dashboard.prototype.initialize = function (skinConfig) { versionText = $('#version').text(); $('#version').text(versionText + g_currentVersion); - showTab('_cargo'); + var tabToShow = getLocalStorageItem('currentTab', '_cargo'); + if (tabToShow == null) { + tabToShow = '_cargo'; + } + removeLocalStorageItem('currentTab'); + showTab(tabToShow); } function getDaysHoursMinutesAndSeconds(time) { @@ -351,7 +321,7 @@ function getEts2JobIncome(income) { See https://github.com/mike-koch/ets2-mobile-route-advisor/wiki/Side-Notes#currency-code-multipliers for more information. */ - var currencyCode = g_skinConfig.currencyCodeEts2; + var currencyCode = g_skinConfig[g_configPrefix].currencyCode; var currencyCodes = []; currencyCodes['EUR'] = buildCurrencyCode(1, '', '€', ''); currencyCodes['GBP'] = buildCurrencyCode(0.8, '', '£', ''); @@ -404,7 +374,7 @@ function getAtsJobIncome(income) { See https://github.com/mike-koch/ets2-mobile-route-advisor/wiki/Side-Notes#currency-code-multipliers for more information. */ - var currencyCode = g_skinConfig.currencyCodeAts; + var currencyCode = g_skinConfig[g_configPrefix].currencyCode; var currencyCodes = []; currencyCodes['USD'] = buildCurrencyCode(1, '', '$', ''); currencyCodes['EUR'] = buildCurrencyCode(.75, '', '€', ''); @@ -437,15 +407,6 @@ function showTab(tabName) { $('#' + tabName + '_button').addClass('_active_tab_button'); } -// The map is loaded when the user tries to view it for the first time. -function goToMap() { - showTab('_map'); - // "g_map" variable is defined in js/map.js. - if (!g_map) { - buildMap('_map'); - } -} - /** Returns the difference between two dates in ISO 8601 format in an [hour, minutes] array */ function getTimeDifference(begin, end) { var beginDate = new Date(begin); @@ -467,6 +428,117 @@ function isWorldOfTrucksContract(data) { && data.job.remainingTime === WORLD_OF_TRUCKS_REMAINING_TIME; } +// Wrapper function to set an item to local storage. +function setLocalStorageItem(key, value) { + if (typeof(Storage) !== "undefined" && localStorage != null) { + localStorage.setItem(key, value); + } +} + +// Wrapper function to get an item from local storage, or default if local storage is not supported. +function getLocalStorageItem(key, defaultValue) { + if (typeof(Storage) !== "undefined" && localStorage != null) { + return localStorage.getItem(key); + } + + return defaultValue; +} + +// Wrapper function to remove an item from local storage +function removeLocalStorageItem(key) { + if (typeof(Storage) !== "undefined" && localStorage != null) { + return localStorage.removeItem(key); + } +} + +function processDomChanges(data) { + g_configPrefix = 'ets2'; + if (data.game.gameName != null) { + g_configPrefix = data.game.gameName.toLowerCase(); + } + + // Initialize JavaScript + var mapPack = g_skinConfig[g_configPrefix].mapPack; + + // Process map pack JSON + $.getJSON(g_pathPrefix + '/maps/' + mapPack + '/config.json', function(json) { + g_mapPackConfig = json; + + loadScripts(mapPack, 0, g_mapPackConfig.scripts); + }); + + // Process Speed Units + var distanceUnits = g_skinConfig[g_configPrefix].distanceUnits; + if (distanceUnits === 'km') { + $('.speedUnits').text('km/h'); + $('.distanceUnits').text('km'); + $('.truckSpeedRoundedKmhMph').addClass('truckSpeedRounded').removeClass('truckSpeedRoundedKmhMph'); + $('.speedLimitRoundedKmhMph').addClass('navigation-speedLimit').removeClass('speedLimitRoundedKmhMph'); + $('.navigationEstimatedDistanceKmMi').addClass('navigation-estimatedDistanceKmRounded').removeClass('navigationEstimatedDistanceKmMi'); + } else if (distanceUnits === 'mi') { + $('.speedUnits').text('mph'); + $('.distanceUnits').text('mi'); + $('.truckSpeedRoundedKmhMph').addClass('truckSpeedMphRounded').removeClass('truckSpeedRoundedKmhMph'); + $('.speedLimitRoundedKmhMph').addClass('navigation-speedLimitMphRounded').removeClass('speedLimitRoundedKmhMph'); + $('.navigationEstimatedDistanceKmMi').addClass('navigation-estimatedDistanceMiRounded').removeClass('navigationEstimatedDistanceKmMi'); + } + + // Process kg vs tons + var weightUnits = g_skinConfig[g_configPrefix].weightUnits; + if (weightUnits === 'kg') { + $('.trailerMassKgOrT').addClass('trailerMassKg').removeClass('trailerMassKgOrT'); + } else if (weightUnits === 't') { + $('.trailerMassKgOrT').addClass('trailerMassTons').removeClass('trailerMassKgOrT'); + } else if (weightUnits === 'lb') { + $('.trailerMassKgOrT').addClass('trailerMassLbs').removeClass('trailerMassKgOrT'); + } + + // Process 12 vs 24 hr time + var timeFormat = g_skinConfig[g_configPrefix].timeFormat; + if (timeFormat === '12h') { + $('.game-time').addClass('gameTime12h').removeClass('game-time'); + $('.job-deadlineTime').addClass('jobDeadlineTime12h').removeClass('job-deadlineTime'); + $('.navigation-estimatedTime').addClass('navigation-estimatedTime12h').removeClass('navigation-estimatedTime'); + } + + g_processedDomChanges = true; +} + +function loadScripts(mapPack, index, array) { + $.getScript(g_pathPrefix + '/maps/' + mapPack + '/' + array[index], function() { + var nextIndex = index + 1; + if (nextIndex != array.length) { + loadScripts(mapPack, nextIndex, array); + } else { + if (buildMap('_map')) { + $('article > p.loading-text').hide(); + } + } + }); +} + +function goToMap() { + showTab('_map'); + g_map.updateSize(); +} + +function updateSpeedIndicator(speedLimit, currentSpeed) { + /* + The game starts the red indication at 1 km/h over, and stays a solid red at 8 km/h over (...I think). + */ + var MAX_SPEED_FOR_FULL_RED = 8; + var difference = parseInt(currentSpeed) - speedLimit; + var opacity = 0; + + if (difference > 0 && speedLimit != 0) { + var opacity = difference / MAX_SPEED_FOR_FULL_RED; + } + + var style = 'linear-gradient(to bottom, rgba(127,0,0,{0}) 0%, rgba(255,0,0,{0}) 50%, rgba(127,0,0,{0}) 100%)'; + style = style.split('{0}').join(opacity); + $('.dashboard').find('aside').find('div._speed').css('background', style); +} + Date.prototype.addDays = function(d) { this.setUTCDate(this.getUTCDate() + d - 1); return this; @@ -487,7 +559,6 @@ Date.prototype.addSeconds = function(s) { return this; } - // Global vars // Gets updated to the actual path in initialize function. @@ -500,11 +571,21 @@ var g_translations; var g_skinConfig; // The current version of ets2-mobile-route-advisor -var g_currentVersion = '3.2.1'; +var g_currentVersion = '3.3.0'; // The currently running game var g_runningGame; +// The prefix for game-specific settings (either "ets2" or "ats") +var g_configPrefix; + +// The running game the last time we checked +var g_lastRunningGame; + // The map pack configuration for the ets2 and ats map packs -var g_ets2MapPackConfig; -var g_atsMapPackConfig; +var g_mapPackConfig; + +// Checked if we have processed the DOM changes already. +var g_processedDomChanges; + +var g_map; diff --git a/language/en-US.json b/language/en-US.json index c769184235..39f9b4bba0 100644 --- a/language/en-US.json +++ b/language/en-US.json @@ -22,5 +22,6 @@ "ThursdayAbbreviated": "Thu", "FridayAbbreviated": "Fri", "SaturdayAbbreviated": "Sat", - "WorldOfTrucksContract": "World of Trucks Contract" + "WorldOfTrucksContract": "World of Trucks Contract", + "LoadingMapPleaseWait": "Loading map, please wait..." } diff --git a/maps/ats/js/map.js b/maps/ats/js/map.js index 57c4f4636d..85a665c92d 100644 --- a/maps/ats/js/map.js +++ b/maps/ats/js/map.js @@ -92,7 +92,7 @@ function buildMap(target_element_id){ g_map = new ol.Map({ target: target_element_id, controls: [ - new ol.control.MousePosition(), // DEBUG + //new ol.control.MousePosition(), // DEBUG new ol.control.Zoom(), rotate_control, speed_limit_control, @@ -144,6 +144,8 @@ function buildMap(target_element_id){ // The user has moved or rotated the map. g_behavior_center_on_player = false; }); + + return true; } function getMapTilesLayer(projection, tileGrid) { @@ -198,7 +200,8 @@ function getTextFeatures() { textAlign: 'center', fill: fill, stroke: stroke, - scale: scale + scale: scale, + offsetY: 15 * scale }) })]; }; @@ -226,7 +229,6 @@ function getTextLayer() { } // Global vars. -var g_map; var g_playerFeature; var g_playerIcon; var g_behavior_center_on_player = true; diff --git a/maps/ets2/config.json b/maps/ets2/config.json index 4b7439977c..ae54ffcbe4 100644 --- a/maps/ets2/config.json +++ b/maps/ets2/config.json @@ -8,8 +8,8 @@ " https://github.com/mike-koch/ets2-mobile-route-advisor/wiki/Creating-a-Map-Pack" ], "scripts": [ - "js/map.js", "js/ol.js", - "js/cities.js" + "js/cities.js", + "js/map.js" ] } diff --git a/maps/ets2/js/map.js b/maps/ets2/js/map.js index 0261dfb727..3cb2da0bbe 100644 --- a/maps/ets2/js/map.js +++ b/maps/ets2/js/map.js @@ -304,6 +304,8 @@ function buildMap(target_element_id){ // map.getView().on('change:rotation', function(ev) { // console.log(ev); // }); + + return true; } function getMapTilesLayer(projection, tileGrid) { @@ -337,7 +339,6 @@ function getMapTilesLayer(projection, tileGrid) { } // Global vars. -var g_map; var g_playerFeature; var g_playerIcon; var g_behavior_center_on_player = true;