mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-11-16 15:25:12 +01:00
Fix errors in implementation of MapPacket. Add __str__ and __repr__ impls to the latter.
This commit is contained in:
parent
b9ac3a3356
commit
626b765094
@ -415,6 +415,11 @@ class MapPacket(Packet):
|
|||||||
self.type = type
|
self.type = type
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
self.location = (x, z)
|
self.location = (x, z)
|
||||||
|
def __repr__(self):
|
||||||
|
return ('MapIcon(type=%s, direction=%s, location=%s)'
|
||||||
|
% (self.type, self.direction, self.location))
|
||||||
|
def __str__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
class Map(object):
|
class Map(object):
|
||||||
__slots__ = 'id', 'scale', 'icons', 'pixels', 'width', 'height'
|
__slots__ = 'id', 'scale', 'icons', 'pixels', 'width', 'height'
|
||||||
@ -425,11 +430,20 @@ class MapPacket(Packet):
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.pixels = bytearray(0 for i in range(width*height))
|
self.pixels = bytearray(0 for i in range(width*height))
|
||||||
|
def __repr__(self):
|
||||||
|
return ('Map(id=%s, scale=%s, icons=%s, width=%s, height=%s)'
|
||||||
|
% (self.id, self.scale, self.icons, self.width, self.height))
|
||||||
|
def __str__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
class MapSet(object):
|
class MapSet(object):
|
||||||
__slots__ = 'maps_by_id'
|
__slots__ = 'maps_by_id'
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.maps_by_id = dict()
|
self.maps_by_id = dict()
|
||||||
|
def __repr__(self):
|
||||||
|
return 'MapSet(%s)' % ', '.join(self.maps_by_id.itervalues())
|
||||||
|
def __str__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
def read(self, file_object):
|
def read(self, file_object):
|
||||||
self.map_id = VarInt.read(file_object)
|
self.map_id = VarInt.read(file_object)
|
||||||
@ -437,16 +451,16 @@ class MapPacket(Packet):
|
|||||||
icon_count = VarInt.read(file_object)
|
icon_count = VarInt.read(file_object)
|
||||||
self.icons = []
|
self.icons = []
|
||||||
for i in range(icon_count):
|
for i in range(icon_count):
|
||||||
direction, type = divmod(UnsignedByte.read(file_object), 16)
|
type, direction = divmod(UnsignedByte.read(file_object), 16)
|
||||||
x = UnsignedByte.read(file_object)
|
x = Byte.read(file_object)
|
||||||
z = UnsignedByte.read(file_object)
|
z = Byte.read(file_object)
|
||||||
icon = MapPacket.MapIcon(type, direction, (x, z))
|
icon = MapPacket.MapIcon(type, direction, (x, z))
|
||||||
self.icons.append(icon)
|
self.icons.append(icon)
|
||||||
self.width = UnsignedByte.read(file_object)
|
self.width = UnsignedByte.read(file_object)
|
||||||
if self.width:
|
if self.width:
|
||||||
self.height = UnsignedByte.read(file_object)
|
self.height = UnsignedByte.read(file_object)
|
||||||
x = UnsignedByte.read(file_object)
|
x = Byte.read(file_object)
|
||||||
z = UnsignedByte.read(file_object)
|
z = Byte.read(file_object)
|
||||||
self.offset = (x, z)
|
self.offset = (x, z)
|
||||||
self.pixels = VarIntPrefixedByteArray.read(file_object)
|
self.pixels = VarIntPrefixedByteArray.read(file_object)
|
||||||
else:
|
else:
|
||||||
@ -474,6 +488,14 @@ class MapPacket(Packet):
|
|||||||
def write(self, socket, compression_threshold=None):
|
def write(self, socket, compression_threshold=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return 'MapPacket(%s)' % ', '.join(
|
||||||
|
'%s=%r' % (k, v)
|
||||||
|
for (k,v) in self.__dict__.iteritems()
|
||||||
|
if k != 'pixels')
|
||||||
|
def __str__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
STATE_PLAYING_CLIENTBOUND = {
|
STATE_PLAYING_CLIENTBOUND = {
|
||||||
0x00: KeepAlivePacket,
|
0x00: KeepAlivePacket,
|
||||||
0x01: JoinGamePacket,
|
0x01: JoinGamePacket,
|
||||||
|
Loading…
Reference in New Issue
Block a user