Jump to content

[Not a mod but...] Create image from a map file


Mat Fenric

Recommended Posts

Hello

I have loaded the source code of VintageStoryAPI, VSEssentialsMod, VSCreativeMod and VSSurvivalMod to find how load a map and generate images for a web site (so, not for a mod).

I know that the map is a .db file in the VintagestoryData\Maps directory

It's possible to read it with the method OpenOrCreate of a MapBD object, get a MapPieceDB object with GetMapPiece method and read the Pixels int array.

But I don't know how to initiate a ILogger object for the MapDB constructor.

MapDB mapdb = new MapDB(logger);

And I don't know yet how I will be able to read the Pixels int array to tranform the int in pixel data and generate the image.

My actual attempt :

string errorMessage = null;
string mapdbfilepath = @"[...]\VintagestoryData\Maps\[...].db";

//? api.World.Logger - ILogger Logger
MapDB mapdb = new MapDB(logger);
mapdb.OpenOrCreate(mapdbfilepath, ref errorMessage, false, true, false);

Vec2i coord = new Vec2i(0, 0);
MapPieceDB piece = mapdb.GetMapPiece(coord);

if (piece?.Pixels != null)
{
    lblIntsMap.Text = string.Empty;

    foreach (int pixel in piece.Pixels)
        lblIntsMap.Text += pixel.ToString();
}

I'm not sure how the coordinates of the Vec2i cord object work...

Can you help me ?

Link to comment
Share on other sites

20 minutes ago, Mat Fenric said:

I'm not sure how the coordinates of the Vec2i cord object work...

I think it takes a map for the chunk at these coordinates. Try 500_000 500_000 - this should give one of the chunks next to the spawn. The game uses absolute unsigned coordinates, which are translated into coordinates relative to the spawn for the player.

Or 500_000/api.WorldManager.ChunkSize

Link to comment
Share on other sites

7 minutes ago, DArkHekRoMaNT said:

I think it takes a map for the chunk at these coordinates. Try 500_000 500_000 - this should give one of the chunks next to the spawn. The game uses absolute unsigned coordinates, which are translated into coordinates relative to the spawn for the player.

Or 500_000/api.WorldManager.ChunkSize

Good tip, thank you.

Link to comment
Share on other sites

@DArkHekRoMaNTIt 's not block coordinates but chunk coordinates, so the middle is 15 625 x 15 625 (for 1 024 000 blocks by side map and 32 by side chunk).

For everyone, I found a way to read the file.

Now I need to know how to transform data like this into pixel color:

Quote

-15517387, -14515600, -14337470, -14996173, -15238566, -15574202, -15120567, -14657446, -15712449, -14915227, -15247020, -14595008, -15318210, -15909570, -15581383, -15644605, -14270390, -14858429, -15453650, -15579068, -12941203, -13470627, -13470627, -15381435, -14588327, -14785187, -15579064, -15247539, -15048360, -15445172, -14786472, -15049640

 

Link to comment
Share on other sites

  • 1 year later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.