diff options
author | worktycho <work.tycho@gmail.com> | 2015-06-19 20:41:28 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2015-06-19 20:41:28 +0200 |
commit | 33d68572a61fa1c2201278b8bf4f77c73371930e (patch) | |
tree | 44a986bb7f90beee57a5bdc842c720fd657618bb /src/Generating/PrefabPiecePool.h | |
parent | Check the return value of InflateString (diff) | |
parent | Added cubeset file format docs. (diff) | |
download | cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar.gz cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar.bz2 cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar.lz cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar.xz cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.tar.zst cuberite-33d68572a61fa1c2201278b8bf4f77c73371930e.zip |
Diffstat (limited to 'src/Generating/PrefabPiecePool.h')
-rw-r--r-- | src/Generating/PrefabPiecePool.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h index b9c1f0483..a22c6abd4 100644 --- a/src/Generating/PrefabPiecePool.h +++ b/src/Generating/PrefabPiecePool.h @@ -16,6 +16,13 @@ +// fwd: +class cLuaState; + + + + + class cPrefabPiecePool : public cPiecePool { @@ -34,6 +41,10 @@ public: const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs ); + /** Creates a pool and loads the contents of the specified file into it. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + cPrefabPiecePool(const AString & a_FileName, bool a_LogWarnings); + /** Destroys the pool, freeing all pieces. */ ~cPrefabPiecePool(); @@ -50,6 +61,20 @@ public: May be called multiple times with different PieceDefs, will add all such pieces. */ void AddStartingPieceDefs(const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs); + /** Loads the pieces from the specified file. Returns true if successful, false on error. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool LoadFromFile(const AString & a_FileName, bool a_LogWarnings); + + /** Loads the pieces from the specified Cubeset file. Returns true if successful, false on error. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool LoadFromCubesetFile(const AString & a_FileName, bool a_LogWarnings); + + /** Returns the number of regular (non-starting) pieces. */ + size_t GetAllPiecesCount(void) const { return m_AllPieces.size(); } + + /** Returns the number of starting pieces. */ + size_t GetStartingPiecesCount(void) const { return m_StartingPieces.size(); } + protected: /** The type used to map a connector type to the list of pieces with that connector */ @@ -70,7 +95,61 @@ protected: /** Adds the prefab to the m_PiecesByConnector map for all its connectors. */ void AddToPerConnectorMap(cPrefab * a_Prefab); + + /** Loads the pieces from the cubeset file parsed into the specified Lua state. + Returns true on success, false on error. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool LoadFromCubesetFileVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings); + + /** Loads a single piece from the cubeset file parsed into the specified Lua state. + The piece's definition table is expected to be at the top of the Lua stack. + Returns true on success, false on error. + a_PieceIndex is the index of the piece, in the Pieces table. It is used for logging only. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool LoadCubesetPieceVer1(const AString & a_FileName, cLuaState & a_LuaState, int a_PieceIndex, bool a_LogWarnings); + + /** Loads a single piece's prefab from the cubeset file parsed into the specified Lua state. + The piece's definition table is expected to be at the top of the Lua stack. + Returns the prefab on success, nullptr on failure. + a_PieceName is the identification of the piece, used for logging only. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + UniquePtr<cPrefab> LoadPrefabFromCubesetVer1( + const AString & a_FileName, + cLuaState & a_LuaState, + const AString & a_PieceName, + bool a_LogWarnings + ); + /** Reads a single piece's connectors from the cubeset file parsed into the specified Lua state. + The piece's definition table is expected to be at the top of the Lua stack. + Returns true on success, false on failure. + The connectors are added into the a_Prefab object. + No Connectors table is considered a failure, empty Connectors table is considered a success. + If any of the connectors are malformed, it is considered a failure, although the rest of the connectors will still load. + a_PieceName is the identification of the piece, used for logging only. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool ReadConnectorsCubesetVer1( + const AString & a_FileName, + cLuaState & a_LuaState, + const AString & a_PieceName, + cPrefab * a_Prefab, + bool a_LogWarnings + ); + + /** Reads a single piece's metadata from the cubeset file parsed into the specified Lua state. + The piece's definition table is expected to be at the top of the Lua stack. + Returns true on success, false on failure. + The metadata is applied into the a_Prefab object. + a_PieceName is the identification of the piece, used for logging only. + If a_LogWarnings is true, logs a warning to console when loading fails. */ + bool ApplyMetadataCubesetVer1( + const AString & a_FileName, + cLuaState & a_LuaState, + const AString & a_PieceName, + cPrefab * a_Prefab, + bool a_LogWarnings + ); + // cPiecePool overrides: virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetStartingPieces(void) override; |