diff options
author | Mattes D <github@xoft.cz> | 2019-12-02 16:45:55 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-12-28 22:43:35 +0100 |
commit | 7453a9fbe120f345625a24bbea18c35cd3c26a6a (patch) | |
tree | e97cc9c90fedcad6e44f4011f0fdc4d2f6a284bf /src/BlockTypePalette.h | |
parent | BlockTypePalette: Refactored for usage in both directions. (diff) | |
download | cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar.gz cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar.bz2 cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar.lz cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar.xz cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.tar.zst cuberite-7453a9fbe120f345625a24bbea18c35cd3c26a6a.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockTypePalette.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/BlockTypePalette.h b/src/BlockTypePalette.h index adb156ff1..2d0985f08 100644 --- a/src/BlockTypePalette.h +++ b/src/BlockTypePalette.h @@ -34,6 +34,20 @@ public: }; + /** Exception that is thrown when loading the palette fails hard (bad format). */ + class LoadFailedException: + public std::runtime_error + { + using Super = std::runtime_error; + + public: + LoadFailedException(const AString & aReason): + Super(aReason) + { + } + }; + + /** Create a new empty instance. */ BlockTypePalette(); @@ -63,6 +77,13 @@ public: Used for protocol block type mapping. */ std::map<UInt32, UInt32> createTransformMapWithFallback(const BlockTypePalette & aFrom, UInt32 aFallbackIndex) const; + /** Loads the palette from the string representation. + Throws a LoadFailedException if the loading fails hard (bad string format). + If the string specifies duplicate entries (either to already existing entries, or to itself), + the duplicates replace the current values silently (this allows us to chain multiple files as "overrides". + Currently handles only JSON representation, expected to handle also Lua representation in the future. */ + void loadFromString(const AString & aString); + protected: @@ -77,4 +98,11 @@ protected: /** The maximum index ever used in the maps. Used when adding new entries through the index() call. */ UInt32 mMaxIndex; + + + /** Loads the palette from the JSON representation. + Throws a LoadFailedException if the loading fails hard (bad string format). + If the string specifies duplicate entries (either to already existing entries, or to itself), + the duplicates replace the current values silently (this allows us to chain multiple files as "overrides". */ + void loadFromJsonString(const AString & aJsonPalette); }; |