diff --git a/client/economy.pug b/client/economy.pug index 0a7257a..27745e9 100644 --- a/client/economy.pug +++ b/client/economy.pug @@ -15,7 +15,7 @@ block content th= month tbody.table-group-divider each fillType in economy.prices - if fillType.formattedPrices.length>0 + if fillType.formattedPrices.some(fp => fp.length > 0) tr td=__("product_"+fillType.name) - var nextPrice = 0 diff --git a/client/index.pug b/client/index.pug index 83ffe27..ff7c557 100644 --- a/client/index.pug +++ b/client/index.pug @@ -6,7 +6,7 @@ html(lang="en").h-100 title=server.name + " - Oasis " + config.VERSION meta(charset="utf-8") meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no') - meta(name="description", content=server.name + " - Farming Simulator 22 Server - " + server.version + " - Oasis #{config.VERSION} - Farming Simulator 22 Live Map") + meta(name="description", content=server.name + " - " + server.game + " Server - " + server.version + " - Oasis #{config.VERSION} - " + server.game + " Live Map") meta(name="author", content="msdigital.ch") link(rel='shortcut icon', href='/images/Oasis_Favicon.png') link(rel='icon', type='image/png', href='/images/Oasis_Favicon.png', sizes='32x32') diff --git a/client/layout.pug b/client/layout.pug index a7862f7..c0cfeb0 100644 --- a/client/layout.pug +++ b/client/layout.pug @@ -35,10 +35,12 @@ mixin scripts() mixin footer() footer.footer.mt-auto.py-3 .container - span.text-muted Code & Design: © 2020 + span.text-muted Code & Design: © 2026 a(href='http://www.msdigital.ch', target='_blank') msdigital.ch + | & + a(href='https://github.com/msdigital/oasis/graphs/contributors', target='_blank') Contributors span.text-muted.float-end - | Oasis #{config.VERSION} - Farming Simulator 22 Live Map + | Oasis #{config.VERSION} - Farming Simulator Live Map mixin newServerError() if isNewServer diff --git a/package.json b/package.json index 0cf7570..3473f50 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "oasis", - "version": "1.22.8", - "description": "Live Map for Farming Simulator 22", + "version": "1.23.0", + "description": "Live Map for Farming Simulator", "main": "server/app.js", "private": false, "scripts": { diff --git a/server/lib/appversion.js b/server/lib/appversion.js index 0be49ec..4d1ee78 100644 --- a/server/lib/appversion.js +++ b/server/lib/appversion.js @@ -1,2 +1,2 @@ // Generated by genversion. -module.exports = '1.22.8' +module.exports = '1.23.0' diff --git a/server/model/economy.js b/server/model/economy.js index 123afde..c455ca0 100644 --- a/server/model/economy.js +++ b/server/model/economy.js @@ -10,23 +10,25 @@ var EXCLUDED_PRODUCTS = [ "LIME", "FORAGE", "FORAGE_MIXING", "TREESAPLINGS", "OILSEEDRADISH", "POPLAR", "DIESEL", "DEF", "ELECTRICCHARGE", "METHANE", "ROUNDBALE", "ROUNDBALE_GRASS", "ROUNDBALE_DRYGRASS", "ROUNDBALE_COTTON", - "LIQUIDFERTILIZER", + "LIQUIDFERTILIZER", "UNKNOWN" ] -var ECONOMY_MONTHS = [ - {}, - { "month": 2, "name": "Mar." }, - { "month": 3, "name": "Apr." }, - { "month": 4, "name": "May" }, - { "month": 5, "name": "Jun." }, - { "month": 6, "name": "Jul." }, - { "month": 7, "name": "Aug." }, - { "month": 8, "name": "Sep." }, - { "month": 9, "name": "Oct." }, - { "month": 10, "name": "Nov." }, - { "month": 11, "name": "Dec." }, - { "month": 0, "name": "Jan." }, - { "month": 1, "name": "Feb." }, +const ECONOMY_MONTHS = [ + // Spring + "Mar.", "Apr.", "May", + // Summer + "Jun.", "Jul.", "Aug.", + // Autumn + "Sep.", "Oct.", "Nov.", + // Winter + "Dec.", "Jan.", "Feb." +] + +const PERIOD_NAMES = [ + "EARLY_SPRING", "MID_SPRING", "LATE_SPRING", + "EARLY_SUMMER", "MID_SUMMER", "LATE_SUMMER", + "EARLY_AUTUMN", "MID_AUTUMN", "LATE_AUTUMN", + "EARLY_WINTER", "MID_WINTER", "LATE_WINTER" ] module.exports.Economy = function (economy) { @@ -34,86 +36,62 @@ module.exports.Economy = function (economy) { this.calculateEconomy = function (difficulty, cb) { var prices = calcluatePrices(this.rawPrices, getPriceFactor(difficulty)) - var months = getOrderMonths(); - + var months = ECONOMY_MONTHS; cb({ prices: prices, months: months }) } } -var getOrderMonths = function () { - var months = new Array(); - delete ECONOMY_MONTHS[0]; - - ECONOMY_MONTHS.forEach((month, ix) => { - months.splice(month.month, 0, month.name) - }) - return months; -} - var calcluatePrices = function (fillTypes, factor) { - var results = [] - , resultPrices = Array(2).fill(null).map(() => Array()); - if (!Array.isArray(fillTypes)) { fillTypes = [fillTypes] } - fillTypes.some((fillType, i) => { - if (!lodash.isEmpty(fillType)) { - fillType.prices.forEach((price, ix) => { - if (price > 0) { - var calcPrice = (price * factor) - , calcPriceFormat = util.formatNumber(calcPrice, 2, ' €') - , monthIndex = ECONOMY_MONTHS[ix].month - - resultPrices[0].splice(monthIndex, 0, calcPrice) - resultPrices[1].splice(monthIndex, 0, calcPriceFormat) - } - }) - fillType.prices = resultPrices[0] - fillType.formattedPrices = resultPrices[1] - results.push(fillType) - resultPrices[0] = new Array() - resultPrices[1] = new Array() - } - }) - return results + return fillTypes.filter(ft => !lodash.isEmpty(ft)). + map((fillType) => { + const prices = fillType.prices.map(price => (price > 0) ? price * factor : 0); + const formattedPrices = fillType.prices.map(price => (price > 0) ? util.formatNumber(price, 0, ' €') : ''); + return new FillType(fillType.name, prices, formattedPrices) + }); } var mapPrices = function (fillTypes) { - var results = [] - if (!Array.isArray(fillTypes)) { fillTypes = [fillTypes]; } - fillTypes.forEach(type => { - if (!lodash.isEmpty(type) && !EXCLUDED_PRODUCTS.includes(type._attributes.fillType)) { - results.push(new FillType(type)) - } - }) - return results -} - -var FillType = function (type) { - this.name = type._attributes.fillType - this.prices = FillTypePrices(type.history.period) - this.formattedPrices = null + return fillTypes.filter( + type => !lodash.isEmpty(type) && !EXCLUDED_PRODUCTS.includes(type._attributes.fillType) + ).map( + type => FillType.fromEconomyFillType(type) + ); } -var FillTypePrices = function (prices) { - var results = Array() +class FillType { + constructor(name, prices, formattedPrices) { + this.name = name; + this.prices = prices; + this.formattedPrices = formattedPrices; + } - if (!Array.isArray(prices)) { - prices = [prices]; + static fromEconomyFillType(type) { + const name = type._attributes.fillType; + const prices = this.pricesFromHistory(type.history.period); + return new FillType(name, prices, []); } - prices.forEach(price => { - if (!lodash.isEmpty(price)) { - results[price._attributes.period] = Number(price._text) + static pricesFromHistory(historyPeriods) { + if (!Array.isArray(historyPeriods)) { + historyPeriods = [historyPeriods]; } - }) - return results + + return historyPeriods.sort((a, b) => { + const periodA = a._attributes.period; + const periodB = b._attributes.period; + const periodAnum = Number(periodA) ? Number(periodA) : PERIOD_NAMES.indexOf(periodA); + const periodBnum = Number(periodB) ? Number(periodB) : PERIOD_NAMES.indexOf(periodB); + return periodAnum - periodBnum; + }).map(p => Number(p._text)); + } } var getPriceFactor = function (difficulty) { diff --git a/server/model/game.js b/server/model/game.js index 31cb2e9..b876b59 100644 --- a/server/model/game.js +++ b/server/model/game.js @@ -10,7 +10,7 @@ module.exports.Game = function (game) { this.mapname = game.settings !== undefined ? game.settings.mapTitle._text : '-' this.timeScale = util.formatNumber(timeScale, 0, "x") this.saveInterval = game.settings !== undefined ? util.formatNumber(game.settings.autoSaveInterval._text, 0, '') : 0 - this.difficulty = game.settings !== undefined ? game.settings.difficulty._text : '-' + this.difficulty = game.settings !== undefined && game.settings.difficulty !== undefined ? game.settings.difficulty : '-' this.economicDifficulty = game.settings !== undefined ? game.settings.economicDifficulty._text : '-' this.isNewServer = game.settings === undefined || game.statistics === undefined ? true : false -} \ No newline at end of file +} diff --git a/server/model/server.js b/server/model/server.js index 167f1ce..6257ef7 100644 --- a/server/model/server.js +++ b/server/model/server.js @@ -2,6 +2,7 @@ var lodash = require('lodash') module.exports.Server = function(server){ this.name = server._attributes.name + this.game = server._attributes.game || "Farming Simulator 22" this.version = server._attributes.version this.mods = getMods((server.Mods !== undefined ? server.Mods.Mod : null)) }