Automap (client) [VS plugin mod]
Rev. | 1c8849af29a916822885541c010ffc4b7bb90d5a |
---|---|
Tamanho | 1,764 bytes |
Hora | 2022-05-02 03:22:25 |
Autor | melchior |
Mensagem de Log | 2nd Entity processing fix attempt
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using ProtoBuf;
using Vintagestory.API.Common;
using Vintagestory.GameContent;
using Vintagestory.API.Util;
using Vintagestory.API.MathTools;
namespace ShardProcessor
{
public class WalkableMapDB : MapDB
{
private SQLiteCommand walkMapPieceCmd;
public WalkableMapDB(ILogger logger) : base(logger)
{
}
public override void OnOpened( )
{
base.OnOpened( );
walkMapPieceCmd = sqliteConn.CreateCommand( );
walkMapPieceCmd.CommandText = @"SELECT position, data FROM mappiece";
walkMapPieceCmd.Prepare( );
}
public IEnumerable<LocalizedMapPiece> WalkMapTiles( )
{
using (SQLiteDataReader sqlite_datareader = walkMapPieceCmd.ExecuteReader( ))
{
int numForPos = sqlite_datareader.GetOrdinal(@"position");
int numForData = sqlite_datareader.GetOrdinal(@"data");
while (sqlite_datareader.Read( ))
{
var posInteger = sqlite_datareader.GetInt64(numForPos);//[];//Integer KEY
object data = sqlite_datareader[numForData];
if (data == null) yield return null;
var rawMapP = SerializerUtil.Deserialize<MapPieceDB>(data as byte[ ]);
var nextPiece = new LocalizedMapPiece( ) {
ChunkPos = posInteger.Convert(),
Pixels = rawMapP.Pixels,
};
yield return nextPiece;
}
}
}
}
public class LocalizedMapPiece : MapPieceDB
{
public Vec2i ChunkPos;
}
public static class MapDB_Assist
{
public static Vec2i Convert(this long input)
{
var vector = new Vec2i( );
vector.X = ( int )(0x7FFFFFF & input); //Passthru only last 27 bits
vector.Y = ( int )(input >> 27 );//Shift 27 right
return vector;
}
}
}