diff options
Diffstat (limited to 'src/Protocol')
-rw-r--r-- | src/Protocol/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Protocol/ProtocolPalettes.cpp | 107 | ||||
-rw-r--r-- | src/Protocol/ProtocolPalettes.h | 63 |
3 files changed, 0 insertions, 172 deletions
diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index cc96f1878..f3d0e1901 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -12,7 +12,6 @@ target_sources( Protocol_1_11.cpp Protocol_1_12.cpp Protocol_1_13.cpp - ProtocolPalettes.cpp ProtocolRecognizer.cpp RecipeMapper.cpp @@ -28,7 +27,6 @@ target_sources( Protocol_1_11.h Protocol_1_12.h Protocol_1_13.h - ProtocolPalettes.h ProtocolRecognizer.h RecipeMapper.h ) diff --git a/src/Protocol/ProtocolPalettes.cpp b/src/Protocol/ProtocolPalettes.cpp deleted file mode 100644 index 2dc0857a9..000000000 --- a/src/Protocol/ProtocolPalettes.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "Globals.h" -#include "ProtocolPalettes.h" -#include "../BlockTypePalette.h" - - - - - -void ProtocolPalettes::load(const AString & aProtocolFolder) -{ - auto contents = cFile::GetFolderContents(aProtocolFolder); - for (const auto & c: contents) - { - auto fullName = aProtocolFolder + cFile::PathSeparator() + c; - if (cFile::IsFolder(fullName)) - { - loadSingleVersion(c, fullName); - } - } -} - - - - - -std::shared_ptr<const BlockTypePalette> ProtocolPalettes::blockTypePalette(const AString & aProtocolVersion) const -{ - cCSLock lock(mCS); - auto itr = mPalettes.find(aProtocolVersion); - if (itr == mPalettes.end()) - { - return nullptr; - } - return itr->second.mBlockTypePalette; -} - - - - - -std::vector<AString> ProtocolPalettes::protocolVersions() const -{ - cCSLock lock(mCS); - - std::vector<AString> res; - for (const auto & p: mPalettes) - { - res.push_back(p.first); - } - return res; -} - - - - - -void ProtocolPalettes::loadSingleVersion(const AString & aProtocolVersion, const AString & aFolder) -{ - // Get the file list, sort by name - auto contents = cFile::GetFolderContents(aFolder); - std::sort(contents.begin(), contents.end()); - - // Load files into the palettes: - cCSLock lock(mCS); - auto & pal = mPalettes[aProtocolVersion]; - for (const auto & c: contents) - { - if (c.length() < 8) - { - // Name too short, can't have the ".btp.txt" etc. suffix - continue; - } - auto fnam = aFolder + cFile::PathSeparator() + c; - if (!cFile::IsFile(fnam)) - { - continue; - } - auto fileType = c.substr(c.length() - 8); - if ((fileType == ".btp.txt") || (c == "blocks.json")) - { - try - { - pal.mBlockTypePalette->loadFromString(cFile::ReadWholeFile(fnam)); - } - catch (...) - { - // Ignore silently - } - } - else if ((fileType == ".itp.txt") || (c == "items.json")) - { - // TODO: Load item type palette - } - } -} - - - - - -//////////////////////////////////////////////////////////////////////////////// -// ProtocolPalettes::Palettes: - -ProtocolPalettes::Palettes::Palettes(): - mBlockTypePalette(new BlockTypePalette) -{ -} diff --git a/src/Protocol/ProtocolPalettes.h b/src/Protocol/ProtocolPalettes.h deleted file mode 100644 index fad093a04..000000000 --- a/src/Protocol/ProtocolPalettes.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "../OSSupport/CriticalSection.h" - - - - - -// fwd: -class BlockTypePalette; - - - - - -/** Loads the protocol-specific palettes on startup and provides them to the individual protocol -instances when they are created. -Uses the data in the $/Server/Protocol folder. Each protocol version has a subfolder there, -containing possibly multiple palette files. All the files are loaded in sequence (alpha-sorted), -into the palette corresponding to the file's extension (*.btp.txt -> BlockTypePalette). -Provides thread safety for the data properly. */ -class ProtocolPalettes -{ -public: - - /** Loads all the per-protocol palettes. - aProtocolFolder is the folder that contains a subfolder for each protocol version; - each subfolder contains the protocol-specific palettes (as in $/Server/Protocol) - If a protocol version is already loaded, yet present in the folder, the newly loaded data is merged - into the current data. - Always succeeds (even when there are no palettes). */ - void load(const AString & aProtocolFolder); - - /** Returns the BlockTypePalette for the specified protocol. - Returns nullptr if no such palette has been loaded. */ - std::shared_ptr<const BlockTypePalette> blockTypePalette(const AString & aProtocolVersion) const; - - /** Returns the version names of all protocols that have been loaded. */ - std::vector<AString> protocolVersions() const; - - -protected: - - /** Container for all palettes for a single protocol. */ - struct Palettes - { - std::shared_ptr<BlockTypePalette> mBlockTypePalette; - // TODO: ItemTypePalette - - Palettes(); - }; - - - /** The CS protecting all members against multithreaded access. */ - mutable cCriticalSection mCS; - - /** The map of protocol version -> all its palettes. */ - std::map<AString, Palettes> mPalettes; - - - /** Loads all the palettes from the specified folder into mPalettes under the aProtocolVersion key. */ - void loadSingleVersion(const AString & aProtocolVersion, const AString & aFolder); -}; |