from struct import pack

LOG					= 1
SET_SPEED			= 2
SIM_ADDED			= 3
SIM_REMOVED			= 4
SIM_OUTFIT_CHANGED	= 5
CAMERA_POSITION		= 6

def serializeSimID(id):
	return id.to_bytes(length = 8,byteorder = "little")

class Log(object):
	def __init__(self,message):
		self.message = message
		
	def __bytes__(self):
		return (pack("<B",LOG)+self.message.encode("ascii"))

class SetSpeed(object):
	def __init__(self,speed):
		self.speed = int(speed)
		
	def __bytes__(self):
		return pack("<BB",SET_SPEED,self.speed)
	
class SimAdded(object):
	def __init__(self,id,name,translation,rotation):
		self.id				= id
		self.name			= name
		self.translation	= translation
		self.rotation		= rotation
		
	def __bytes__(self):
		return (pack("<B",SIM_ADDED)+serializeSimID(self.id)+pack("<B",len(self.name))+
			self.name.encode("utf-8")+pack("fff",*self.translation)+pack("<ffff",*self.rotation))
		
class SimRemoved(object):
	def __init__(self,id):
		self.id = id
		
	def __bytes__(self):
		return (pack("<B",SIM_REMOVED)+serializeSimID(self.id))
	
class SimOutfitChanged(object):
	def __init__(self,id):
		self.id = id
		
	def __bytes__(self):
		return (pack("<B",SIM_OUTFIT_CHANGED)+serializeSimID(self.id))
		
class CameraPosition(object):
	def __init__(self,position):
		self.position = position
		
	def __bytes__(self):
		return pack("<Bfff",CAMERA_POSITION,self.position[0],self.position[1],self.position[2])
	
