mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Added plugin hashset, metadata lists to Game class.
This commit is contained in:
+20
-2
@@ -25,6 +25,7 @@
|
||||
#ifndef __LOOT_GAME__
|
||||
#define __LOOT_GAME__
|
||||
|
||||
#include "metadata.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -40,10 +41,19 @@
|
||||
|
||||
namespace loot {
|
||||
|
||||
class Plugin;
|
||||
/* Each Game object should store the config details specific to that game.
|
||||
It should also store the plugin and masterlist data for that game.
|
||||
Plugin data should be stored as an unordered hashset, the elements of which are
|
||||
referenced by ordered lists and other structures.
|
||||
Masterlist / userlist data should be stored as structures which hold plugin and
|
||||
global message lists.
|
||||
Each game should have functions to load this plugin and masterlist / userlist
|
||||
data. Plugin data should be loaded as header-only and as full data.
|
||||
*/
|
||||
|
||||
class Game {
|
||||
public:
|
||||
//Game functions.
|
||||
Game(); //Sets game to LOOT_Game::autodetect, with all other vars being empty.
|
||||
Game(const unsigned int baseGameCode, const std::string& lootFolder = "");
|
||||
|
||||
@@ -71,18 +81,25 @@ namespace loot {
|
||||
boost::filesystem::path UserlistPath() const;
|
||||
boost::filesystem::path ReportPath() const;
|
||||
|
||||
//Game plugin functions.
|
||||
|
||||
bool IsActive(const std::string& plugin) const;
|
||||
|
||||
void GetLoadOrder(std::list<Plugin>& loadOrder) const;
|
||||
void SetLoadOrder(const std::list<Plugin>& loadOrder) const; //Modifies game load order, even though const.
|
||||
|
||||
void RefreshActivePluginsList();
|
||||
void RedatePlugins();
|
||||
void RedatePlugins(); //Change timestamps to match load order (Skyrim only).
|
||||
|
||||
//Caches for condition results, active plugins and CRCs.
|
||||
boost::unordered_map<std::string, bool> conditionCache; //Holds lowercased strings.
|
||||
boost::unordered_map<std::string, uint32_t> crcCache; //Holds lowercased strings.
|
||||
|
||||
//Plugin data and metadata lists.
|
||||
MetadataList masterlist;
|
||||
MetadataList userlist;
|
||||
boost::unordered_set<Plugin, plugin_hash> plugins;
|
||||
|
||||
espm::Settings espm_settings;
|
||||
|
||||
static const unsigned int autodetect = 0;
|
||||
@@ -102,6 +119,7 @@ namespace loot {
|
||||
std::string _repositoryBranch;
|
||||
|
||||
boost::filesystem::path gamePath; //Path to the game's folder.
|
||||
|
||||
boost::unordered_set<std::string> activePlugins; //Holds lowercased strings.
|
||||
|
||||
//Creates directory in LOOT folder for LOOT's game-specific files.
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "helpers.h"
|
||||
#include "metadata.h"
|
||||
#include "parsers.h"
|
||||
#include "streams.h"
|
||||
|
||||
#include <src/libespm.h>
|
||||
|
||||
@@ -754,6 +755,30 @@ namespace loot {
|
||||
return boost::filesystem::exists(game.DataPath() / (name.substr(0, name.length() - 3) + "bsa"));
|
||||
}
|
||||
|
||||
void MetadataList::Load(boost::filesystem::path& filepath) {
|
||||
plugins.clear();
|
||||
messages.clear();
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "Loading file: " << filepath;
|
||||
|
||||
loot::ifstream in(filepath);
|
||||
YAML::Node metadataList = YAML::Load(in);
|
||||
in.close();
|
||||
|
||||
if (metadataList["plugins"])
|
||||
plugins = metadataList["plugins"].as< list<Plugin> >();
|
||||
if (metadataList["globals"])
|
||||
messages = metadataList["globals"].as< list<Message> >();
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "File loaded successfully.";
|
||||
}
|
||||
|
||||
size_t plugin_hash::operator () (const Plugin& p) const {
|
||||
size_t seed = 0;
|
||||
boost::hash_combine(seed, p.Name());
|
||||
return seed;
|
||||
}
|
||||
|
||||
bool operator == (const File& lhs, const Plugin& rhs) {
|
||||
return boost::iequals(lhs.Name(), rhs.Name());
|
||||
}
|
||||
|
||||
+14
-2
@@ -24,10 +24,8 @@
|
||||
#ifndef __LOOT_METADATA__
|
||||
#define __LOOT_METADATA__
|
||||
|
||||
#include "game.h"
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -36,6 +34,7 @@
|
||||
|
||||
namespace loot {
|
||||
|
||||
class Game;
|
||||
|
||||
//A FormID is a 32 bit unsigned integer of the form xxYYYYYY in hex. The xx is the position in the masters list of the plugin that the FormID is from, and the YYYYYY is the rest of the FormID. Here the xx bit is stored as the corresponding filename to allow comparison between FormIDs from different plugins.
|
||||
class FormID {
|
||||
@@ -242,6 +241,19 @@ namespace loot {
|
||||
size_t numOverrideRecords;
|
||||
};
|
||||
|
||||
class MetadataList {
|
||||
public:
|
||||
void Load(boost::filesystem::path& filepath);
|
||||
|
||||
std::list<Plugin> plugins;
|
||||
std::list<Message> messages;
|
||||
};
|
||||
|
||||
struct plugin_hash : std::unary_function<Plugin, size_t> {
|
||||
size_t operator () (const Plugin& p) const;
|
||||
};
|
||||
|
||||
|
||||
bool operator == (const File& lhs, const Plugin& rhs);
|
||||
|
||||
bool operator == (const Plugin& lhs, const File& rhs);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define BOOST_SPIRIT_USE_PHOENIX_V3 1
|
||||
#endif
|
||||
|
||||
#include "game.h"
|
||||
#include "metadata.h"
|
||||
#include "helpers.h"
|
||||
#include "error.h"
|
||||
|
||||
Reference in New Issue
Block a user