use namedtuple for position type and use it as subclass for ClientExplosion.Record
This commit is contained in:
1 parent
8552c6efe5
commit
4a508f935b
2 files changed
+7
-16
No files matched your search
@@ -172,20 +172,8 @@ class ExplosionPacket(Packet):
|
|||||||
|
|
||||||
packet_name = 'explosion'
|
packet_name = 'explosion'
|
||||||
|
|
||||||
class Record(object):
|
class Record(Position):
|
||||||
__slots__ = 'x', 'y', 'z'
|
pass
|
||||||
|
|
||||||
def __init__(self, x, y, z):
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.z = z
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return ('Record(x=%s, y=%s, z=%s)'
|
|
||||||
% (self.x, self.y, self.z))
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.__repr__()
|
|
||||||
|
|
||||||
def read(self, file_object):
|
def read(self, file_object):
|
||||||
self.x = Float.read(file_object)
|
self.x = Float.read(file_object)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ These definitions and methods are used by the packet definitions
|
|||||||
"""
|
"""
|
||||||
import struct
|
import struct
|
||||||
import uuid
|
import uuid
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
class Type(object):
|
class Type(object):
|
||||||
@@ -225,7 +226,9 @@ class UUID(Type):
|
|||||||
socket.send(uuid.UUID(value).bytes)
|
socket.send(uuid.UUID(value).bytes)
|
||||||
|
|
||||||
|
|
||||||
class Position(Type):
|
class Position(Type, namedtuple('Position', ('x', 'y', 'z'))):
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read(file_object):
|
def read(file_object):
|
||||||
location = UnsignedLong.read(file_object)
|
location = UnsignedLong.read(file_object)
|
||||||
@@ -242,7 +245,7 @@ class Position(Type):
|
|||||||
if z >= pow(2, 25):
|
if z >= pow(2, 25):
|
||||||
z -= pow(2, 26)
|
z -= pow(2, 26)
|
||||||
|
|
||||||
return {'x': x, 'y': y, 'z': z}
|
return Position(x=x, y=y, z=z)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def send(x, y, z, socket):
|
def send(x, y, z, socket):
|
||||||
|
|||||||
Reference in new issue
Block a user