[Server] Reorder world map script functions

0.6.3
David Cernat 7 years ago
parent b81ca18316
commit 84af9d9999

@ -43,39 +43,6 @@ int WorldstateFunctions::GetMapTileCellY(unsigned int index) noexcept
return readWorldstate->mapChanges.mapTiles.at(index).y;
}
void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept
{
if (index >= readWorldstate->mapChanges.mapTiles.size())
return;
const std::vector<char>& imageData = readWorldstate->mapChanges.mapTiles.at(index).imageData;
std::ofstream outputFile(filePath, std::ios::binary);
std::ostream_iterator<char> outputIterator(outputFile);
std::copy(imageData.begin(), imageData.end(), outputIterator);
}
void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept
{
mwmp::MapTile mapTile;
mapTile.x = cellX;
mapTile.y = cellY;
std::ifstream inputFile(filePath, std::ios::binary);
mapTile.imageData = std::vector<char>(std::istreambuf_iterator<char>(inputFile), std::istreambuf_iterator<char>());
if (mapTile.imageData.size() > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Error loading image file for map tile: "
"%s has a size of %i, which is over the maximum allowed of %i!",
filePath, mapTile.imageData.size(), mwmp::maxImageDataSize);
}
else
{
writeWorldstate.mapChanges.mapTiles.push_back(mapTile);
}
}
void WorldstateFunctions::SetHour(double hour) noexcept
{
writeWorldstate.hour = hour;
@ -126,6 +93,39 @@ void WorldstateFunctions::UseActorCollisionForPlacedObjects(bool useActorCollisi
writeWorldstate.useActorCollisionForPlacedObjects = useActorCollision;
}
void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept
{
if (index >= readWorldstate->mapChanges.mapTiles.size())
return;
const std::vector<char>& imageData = readWorldstate->mapChanges.mapTiles.at(index).imageData;
std::ofstream outputFile(filePath, std::ios::binary);
std::ostream_iterator<char> outputIterator(outputFile);
std::copy(imageData.begin(), imageData.end(), outputIterator);
}
void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept
{
mwmp::MapTile mapTile;
mapTile.x = cellX;
mapTile.y = cellY;
std::ifstream inputFile(filePath, std::ios::binary);
mapTile.imageData = std::vector<char>(std::istreambuf_iterator<char>(inputFile), std::istreambuf_iterator<char>());
if (mapTile.imageData.size() > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Error loading image file for map tile: "
"%s has a size of %i, which is over the maximum allowed of %i!",
filePath, mapTile.imageData.size(), mwmp::maxImageDataSize);
}
else
{
writeWorldstate.mapChanges.mapTiles.push_back(mapTile);
}
}
void WorldstateFunctions::SendWorldMap(unsigned short pid, bool broadcast) noexcept
{
Player *player;

@ -15,9 +15,6 @@
{"GetMapTileCellX", WorldstateFunctions::GetMapTileCellX},\
{"GetMapTileCellY", WorldstateFunctions::GetMapTileCellY},\
\
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
{"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\
\
{"SetHour", WorldstateFunctions::SetHour},\
{"SetDay", WorldstateFunctions::SetDay},\
{"SetMonth", WorldstateFunctions::SetMonth},\
@ -30,6 +27,9 @@
{"SetPlacedObjectCollisionState", WorldstateFunctions::SetPlacedObjectCollisionState},\
{"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\
\
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
{"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\
\
{"SendWorldMap", WorldstateFunctions::SendWorldMap},\
{"SendWorldTime", WorldstateFunctions::SendWorldTime},\
{"SendWorldCollisionOverride", WorldstateFunctions::SendWorldCollisionOverride}
@ -88,27 +88,6 @@ public:
*/
static int GetMapTileCellY(unsigned int index) noexcept;
/**
* \brief Save the .png image data of the map tile at a certain index in the read worldstate's
* map changes.
*
* \param i The index of the map tile.
* \param filePath The file path of the resulting file.
* \return void
*/
static void SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept;
/**
* \brief Load a .png file as the image data for a map tile and add it to the write-only worldstate
* stored on the server.
*
* \param cellX The X coordinate of the cell corresponding to the map tile.
* \param cellY The Y coordinate of the cell corresponding to the map tile.
* \param filePath The file path of the loaded file.
* \return void
*/
static void LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept;
/**
* \brief Set the world's hour in the write-only worldstate stored on the server.
*
@ -194,6 +173,27 @@ public:
*/
static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept;
/**
* \brief Save the .png image data of the map tile at a certain index in the read worldstate's
* map changes.
*
* \param i The index of the map tile.
* \param filePath The file path of the resulting file.
* \return void
*/
static void SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept;
/**
* \brief Load a .png file as the image data for a map tile and add it to the write-only worldstate
* stored on the server.
*
* \param cellX The X coordinate of the cell corresponding to the map tile.
* \param cellY The Y coordinate of the cell corresponding to the map tile.
* \param filePath The file path of the loaded file.
* \return void
*/
static void LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept;
/**
* \brief Send a WorldMap packet with the current set of map changes in the write-only
* worldstate.

Loading…
Cancel
Save