cleanup
This commit is contained in:
parent
f02e6c65d8
commit
64b94a3e1b
@ -1,3 +1,4 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "ContentPack.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@ -146,7 +147,7 @@ ContentPack ContentPack::read(const io::path& folder) {
|
||||
std::uint8_t op_size = 0;
|
||||
|
||||
// Two symbol operators
|
||||
if (op == ">=" || op == "=>" || op == "<=" || op == "=<") {
|
||||
if (op == ">=" || op == "<=") {
|
||||
op_size = 2;
|
||||
depVerOperator = op;
|
||||
}
|
||||
@ -169,7 +170,16 @@ ContentPack ContentPack::read(const io::path& folder) {
|
||||
}
|
||||
}
|
||||
|
||||
pack.dependencies.push_back({level, depName, depVer, depVerOperator});
|
||||
VersionOperator versionOperator;
|
||||
if (VersionOperatorMeta.getItem(depVerOperator, versionOperator)) {
|
||||
pack.dependencies.push_back(
|
||||
{level, depName, depVer, versionOperator}
|
||||
);
|
||||
} else {
|
||||
throw contentpack_error(
|
||||
pack.id, folder, "invalid version operator"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "content_fwd.hpp"
|
||||
#include "io/io.hpp"
|
||||
#include "util/EnumMetadata.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "content_fwd.hpp"
|
||||
#include "io/io.hpp"
|
||||
|
||||
class EnginePaths;
|
||||
|
||||
class contentpack_error : public std::runtime_error {
|
||||
@ -25,11 +26,19 @@ public:
|
||||
io::path getFolder() const;
|
||||
};
|
||||
|
||||
enum class DependencyVersionOperator {
|
||||
enum class VersionOperator {
|
||||
EQUAL, GREATHER, LESS,
|
||||
GREATHER_OR_EQUAL, LESS_OR_EQUAL
|
||||
};
|
||||
|
||||
VC_ENUM_METADATA(VersionOperator)
|
||||
{"=", VersionOperator::EQUAL},
|
||||
{">", VersionOperator::GREATHER},
|
||||
{"<", VersionOperator::LESS},
|
||||
{">=", VersionOperator::GREATHER_OR_EQUAL},
|
||||
{"<=", VersionOperator::LESS_OR_EQUAL},
|
||||
VC_ENUM_END
|
||||
|
||||
enum class DependencyLevel {
|
||||
REQUIRED, // dependency must be installed
|
||||
OPTIONAL, // dependency will be installed if found
|
||||
@ -41,7 +50,7 @@ struct DependencyPack {
|
||||
DependencyLevel level;
|
||||
std::string id;
|
||||
std::string version;
|
||||
std::string op;
|
||||
VersionOperator op;
|
||||
};
|
||||
|
||||
struct ContentPackStats {
|
||||
|
||||
@ -26,26 +26,11 @@ Version::Version(const std::string& version) {
|
||||
if (parts.size() > 2) patch = parts[2];
|
||||
}
|
||||
|
||||
DependencyVersionOperator Version::string_to_operator(const std::string& op) {
|
||||
if (op == "=")
|
||||
return DependencyVersionOperator::EQUAL;
|
||||
else if (op == ">")
|
||||
return DependencyVersionOperator::GREATHER;
|
||||
else if (op == "<")
|
||||
return DependencyVersionOperator::LESS;
|
||||
else if (op == ">=" || op == "=>")
|
||||
return DependencyVersionOperator::GREATHER_OR_EQUAL;
|
||||
else if (op == "<=" || op == "=<")
|
||||
return DependencyVersionOperator::LESS_OR_EQUAL;
|
||||
else
|
||||
return DependencyVersionOperator::EQUAL;
|
||||
}
|
||||
|
||||
bool isNumber(const std::string& s) {
|
||||
return !s.empty() && std::all_of(s.begin(), s.end(), ::is_digit);
|
||||
}
|
||||
|
||||
bool Version::matches_pattern(const std::string& version) {
|
||||
bool Version::matchesPattern(const std::string& version) {
|
||||
for (char c : version) {
|
||||
if (!isdigit(c) && c != '.') {
|
||||
return false;
|
||||
|
||||
@ -33,25 +33,22 @@ public:
|
||||
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:
|
||||
bool processOperator(VersionOperator op, const Version& other) const {
|
||||
switch (op) {
|
||||
case VersionOperator::EQUAL:
|
||||
return *this == other;
|
||||
case DependencyVersionOperator::GREATHER:
|
||||
case VersionOperator::GREATHER:
|
||||
return *this > other;
|
||||
case DependencyVersionOperator::LESS:
|
||||
case VersionOperator::LESS:
|
||||
return *this < other;
|
||||
case DependencyVersionOperator::LESS_OR_EQUAL:
|
||||
case VersionOperator::LESS_OR_EQUAL:
|
||||
return *this <= other;
|
||||
case DependencyVersionOperator::GREATHER_OR_EQUAL:
|
||||
case VersionOperator::GREATHER_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);
|
||||
static bool matchesPattern(const std::string& version);
|
||||
};
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "PacksManager.hpp"
|
||||
|
||||
#include <queue>
|
||||
@ -109,9 +110,9 @@ static bool resolve_dependencies(
|
||||
|
||||
auto dep_pack = found -> second;
|
||||
|
||||
if (Version::matches_pattern(dep.version) && Version::matches_pattern(dep_pack.version)
|
||||
if (Version::matchesPattern(dep.version) && Version::matchesPattern(dep_pack.version)
|
||||
&& Version(dep_pack.version)
|
||||
.process_operator(dep.op, Version(dep.version))
|
||||
.processOperator(dep.op, Version(dep.version))
|
||||
) {
|
||||
// dependency pack version meets the required one
|
||||
continue;
|
||||
@ -120,7 +121,11 @@ static bool resolve_dependencies(
|
||||
continue;
|
||||
} else {
|
||||
throw contentpack_error(
|
||||
dep.id, io::path(), "does not meet required version '" + dep.op + dep.version +"' of '" + pack->id + "'"
|
||||
dep.id,
|
||||
io::path(),
|
||||
"does not meet required version '" +
|
||||
VersionOperatorMeta.getNameString(dep.op) + dep.version +
|
||||
"' of '" + pack->id + "'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#define VC_ENABLE_REFLECTION
|
||||
|
||||
#include "assets/AssetsLoader.hpp"
|
||||
#include "content/Content.hpp"
|
||||
@ -19,6 +15,12 @@
|
||||
#include "world/World.hpp"
|
||||
#include "api_lua.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_pack_get_folder(lua::State* L) {
|
||||
@ -114,13 +116,14 @@ static int l_pack_get_info(
|
||||
default:
|
||||
throw std::runtime_error("");
|
||||
}
|
||||
auto opString = VersionOperatorMeta.getNameString(dpack.op);
|
||||
|
||||
lua::pushfstring(
|
||||
L,
|
||||
"%s%s@%s%s",
|
||||
prefix.c_str(),
|
||||
dpack.id.c_str(),
|
||||
dpack.op != "=" ? dpack.op.c_str() : "",
|
||||
(dpack.op == VersionOperator::EQUAL ? "" : opString).c_str(),
|
||||
dpack.version.c_str()
|
||||
);
|
||||
lua::rawseti(L, i + 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user