mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Break out version to integer functions
Move the multiple implementation of version to integers calculation to dedicated functions in one place.
This commit is contained in:
1 parent
af79e2abbd
commit
7d34c60dd1
3 files changed
+41
-6
No files matched your search
@@ -7,6 +7,8 @@ const libHash = require("../hash");
|
||||
const libSchema = require("../schema");
|
||||
const { findRoot } = require("../zip_ops");
|
||||
|
||||
const { integerModVersion, integerFactorioVersion } = require("./version");
|
||||
|
||||
|
||||
/**
|
||||
* Info about a mod available on the master server.
|
||||
@@ -36,8 +38,7 @@ class ModInfo {
|
||||
* @type {number}
|
||||
*/
|
||||
get integerVersion() {
|
||||
const [major, minor, sub] = this.version.split(".").map(n => Number.parseInt(n, 10));
|
||||
return major * 0x100000000 + minor * 0x10000 + sub; // Can't use bitwise here because this is 48-bits.
|
||||
return integerModVersion(this.version);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +88,7 @@ class ModInfo {
|
||||
* @type {number}
|
||||
*/
|
||||
get integerFactorioVersion() {
|
||||
const [major, minor] = this.factorioVersion.split(".").map(n => Number.parseInt(n, 10));
|
||||
return major * 0x100000000 + minor * 0x10000; // Can't use bitwise here because this is 48-bits.
|
||||
return integerFactorioVersion(this.factorioVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,8 @@ const zlib = require("zlib");
|
||||
|
||||
const libSchema = require("../schema");
|
||||
|
||||
const { integerFactorioVersion } = require("./version");
|
||||
|
||||
|
||||
/**
|
||||
* A setting for a mod.
|
||||
@@ -77,8 +79,7 @@ class ModPack {
|
||||
* @type {number}
|
||||
*/
|
||||
get integerFactorioVersion() {
|
||||
const [major, minor, sub] = this.factorioVersion.split(".").map(n => Number.parseInt(n, 10));
|
||||
return major * 0x100000000 + minor * 0x10000 + (sub || 0); // Can't use bitwise here because this is 48-bits.
|
||||
return integerFactorioVersion(this.factorioVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Helper functions for dealing with factorio version numbers
|
||||
"use strict";
|
||||
|
||||
|
||||
/**
|
||||
* Integer representation of a mod version
|
||||
*
|
||||
* Suitable for sorting and comparing version numbers which may have different
|
||||
* number of leading zeros in them.
|
||||
* @param {string} version - string representation of version.
|
||||
* @returns {number} numeric representation.
|
||||
*/
|
||||
function integerModVersion(version) {
|
||||
const [major, minor, sub] = version.split(".").map(n => Number.parseInt(n, 10));
|
||||
return major * 0x100000000 + minor * 0x10000 + sub; // Can't use bitwise here because this is 48-bits.
|
||||
}
|
||||
|
||||
/**
|
||||
* Integer representation of a factorio version
|
||||
*
|
||||
* Suitable for sorting and comparing version numbers which may have different
|
||||
* number of leading zeros in them.
|
||||
* @param {string} version - string representation of version.
|
||||
* @returns {number} numeric representation.
|
||||
*/
|
||||
function integerFactorioVersion(version) {
|
||||
const [major, minor, sub] = version.split(".").map(n => Number.parseInt(n, 10));
|
||||
return major * 0x100000000 + minor * 0x10000 + (sub || 0); // Can't use bitwise here because this is 48-bits.
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
integerModVersion,
|
||||
integerFactorioVersion,
|
||||
};
|
||||
Reference in new issue
Block a user