dependency version operators

а также сделал и вынес Version в ContentPackVersion ну и подправил луа скрипты.
требуются тесты
This commit is contained in:
KotIsOff
2025-08-26 01:52:26 +03:00
parent 5b18639d94
commit 7aa4c33721
7 changed files with 255 additions and 13 deletions
+51
View File
@@ -0,0 +1,51 @@
#include <string>
#include "content/ContentPack.hpp"
class Version {
public:
int major;
int minor;
int patch;
Version(const std::string& version);
bool operator==(const Version& other) const {
return major == other.major && minor == other.minor && patch == other.patch;
}
bool operator<(const Version& other) const {
if (major != other.major) return major < other.major;
if (minor != other.minor) return minor < other.minor;
return patch < other.patch;
}
bool operator>(const Version& other) const {
return other < *this;
}
bool operator>=(const Version& other) const {
return !(*this < other);
}
bool operator<=(const Version& other) const {
return !(*this > other);
}
bool process_operator(const std::string& op, const Version& other) const {
auto dep_op = Version::string_to_operator(op);
switch(dep_op) {
case DependencyVersionOperator::equal: return *this == other;
case DependencyVersionOperator::more: return *this > other;
case DependencyVersionOperator::less: return *this < other;
case DependencyVersionOperator::less_or_equal: return *this <= other;
case DependencyVersionOperator::more_or_equal: return *this >= other;
default: return false;
}
}
static DependencyVersionOperator string_to_operator(const std::string& op);
static bool matches_pattern(const std::string& version);
};