mirror of
https://github.com/solero/houdini.git
synced 2024-11-22 21:47:20 +00:00
Tidy up player settings handlers
This commit is contained in:
parent
0f574b8efd
commit
cd34c3dbb7
@ -1,93 +1,67 @@
|
|||||||
from houdini import handlers
|
from houdini import handlers
|
||||||
from houdini.handlers import XTPacket
|
from houdini.handlers import XTPacket
|
||||||
|
|
||||||
from houdini.converters import ItemConverter
|
from houdini.data.item import Item
|
||||||
|
|
||||||
# TODO: handle if the object item is None check better?
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upc'))
|
@handlers.handler(XTPacket('s', 'upc'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_colour(p, item: ItemConverter):
|
async def handle_send_update_player_colour(p, item: Item):
|
||||||
if item.id in p.data.inventory and item.is_color():
|
if item.id in p.data.inventory and item.is_color():
|
||||||
await p.data.update(color=item.id).apply()
|
await p.set_color(item)
|
||||||
await p.room.send_xt('upc', p.data.id, item.id)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'uph'))
|
@handlers.handler(XTPacket('s', 'uph'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_head(p, item: ItemConverter):
|
async def handle_send_update_player_head(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_head():
|
if item is None or (item.id in p.data.inventory and item.is_head()):
|
||||||
await p.data.update(head=item.id).apply()
|
await p.set_head(item)
|
||||||
await p.room.send_xt('uph', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(head=None).apply()
|
|
||||||
await p.room.send_xt('uph', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upf'))
|
@handlers.handler(XTPacket('s', 'upf'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_face(p, item: ItemConverter):
|
async def handle_send_update_player_face(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_face():
|
if item is None or (item.id in p.data.inventory and item.is_face()):
|
||||||
await p.data.update(face=item.id).apply()
|
await p.set_face(item)
|
||||||
await p.room.send_xt('upf', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(face=None).apply()
|
|
||||||
await p.room.send_xt('upf', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upn'))
|
@handlers.handler(XTPacket('s', 'upn'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_neck(p, item: ItemConverter):
|
async def handle_send_update_player_neck(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_neck():
|
if item is None or (item.id in p.data.inventory and item.is_neck()):
|
||||||
await p.data.update(neck=item.id).apply()
|
await p.set_neck(item)
|
||||||
await p.room.send_xt('upn', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(neck=None).apply()
|
|
||||||
await p.room.send_xt('upn', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upb'))
|
@handlers.handler(XTPacket('s', 'upb'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_body(p, item: ItemConverter):
|
async def handle_send_update_player_body(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_body():
|
if item is None or (item.id in p.data.inventory and item.is_body()):
|
||||||
await p.data.update(body=item.id).apply()
|
await p.set_body(item)
|
||||||
await p.room.send_xt('upb', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(body=None).apply()
|
|
||||||
await p.room.send_xt('upb', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upa'))
|
@handlers.handler(XTPacket('s', 'upa'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_hand(p, item: ItemConverter):
|
async def handle_send_update_player_hand(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_hand():
|
if item is None or (item.id in p.data.inventory and item.is_hand()):
|
||||||
await p.data.update(hand=item.id).apply()
|
await p.set_hand(item)
|
||||||
await p.room.send_xt('upa', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(hand=None).apply()
|
|
||||||
await p.room.send_xt('upa', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upe'))
|
@handlers.handler(XTPacket('s', 'upe'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_feet(p, item: ItemConverter):
|
async def handle_send_update_player_feet(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_feet():
|
if item is None or (item.id in p.data.inventory and item.is_feet()):
|
||||||
await p.data.update(feet=item.id).apply()
|
await p.set_feet(item)
|
||||||
await p.room.send_xt('upe', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(feet=None).apply()
|
|
||||||
await p.room.send_xt('upe', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upl'))
|
@handlers.handler(XTPacket('s', 'upl'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_flag(p, item: ItemConverter):
|
async def handle_send_update_player_flag(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_flag():
|
if item is None or (item.id in p.data.inventory and item.is_flag()):
|
||||||
await p.data.update(flag=item.id).apply()
|
await p.set_flag(item)
|
||||||
await p.room.send_xt('upl', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(flag=None).apply()
|
|
||||||
await p.room.send_xt('upl', p.data.id, 0)
|
|
||||||
|
|
||||||
@handlers.handler(XTPacket('s', 'upp'))
|
@handlers.handler(XTPacket('s', 'upp'))
|
||||||
@handlers.cooldown(1)
|
@handlers.cooldown(1)
|
||||||
async def handle_send_update_player_photo(p, item: ItemConverter):
|
async def handle_send_update_player_photo(p, item: Item):
|
||||||
if item is not None and item.id in p.data.inventory and item.is_photo():
|
if item is None or (item.id in p.data.inventory and item.is_photo()):
|
||||||
await p.data.update(photo=item.id).apply()
|
await p.set_photo(item)
|
||||||
await p.room.send_xt('upp', p.data.id, item.id)
|
|
||||||
else:
|
|
||||||
await p.data.update(photo=None).apply()
|
|
||||||
await p.room.send_xt('upp', p.data.id, 0)
|
|
||||||
|
@ -183,63 +183,92 @@ class Penguin(Spheniscidae):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def _client_connected(self):
|
async def set_color(self, item):
|
||||||
await super()._client_connected()
|
await self.data.update(color=item.id).apply()
|
||||||
|
await self.room.send_xt('upc', self.data.id, item.id)
|
||||||
|
self.logger.info('{} updated their color to \'{}\' '.format(
|
||||||
|
self.data.username, item.name))
|
||||||
|
|
||||||
|
async def set_head(self, item):
|
||||||
async def update_color(self, item):
|
|
||||||
item_id = None if item is None else item.id
|
|
||||||
await self.data.update(color=item_id).apply()
|
|
||||||
await self.room.send_xt('upc', self.data.id, item_id or 0)
|
|
||||||
self.logger.info('{} updated their color to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_head(self, item):
|
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(head=item_id).apply()
|
await self.data.update(head=item_id).apply()
|
||||||
await self.room.send_xt('uph', self.data.id, item_id or 0)
|
await self.room.send_xt('uph', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their head to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_face(self, item):
|
self.logger.info('{} updated their head item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their head item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_face(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(face=item_id).apply()
|
await self.data.update(face=item_id).apply()
|
||||||
await self.room.send_xt('upf', self.data.id, item_id or 0)
|
await self.room.send_xt('upf', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their face to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_neck(self, item):
|
self.logger.info('{} updated their face item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their face item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_neck(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(neck=item_id).apply()
|
await self.data.update(neck=item_id).apply()
|
||||||
await self.room.send_xt('upn', self.data.id, item_id or 0)
|
await self.room.send_xt('upn', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their neck to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_body(self, item):
|
self.logger.info('{} updated their neck item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their neck item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_body(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(body=item_id).apply()
|
await self.data.update(body=item_id).apply()
|
||||||
await self.room.send_xt('upb', self.data.id, item_id or 0)
|
await self.room.send_xt('upb', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their body to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_hand(self, item):
|
self.logger.info('{} updated their body item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their body item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_hand(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(hand=item_id).apply()
|
await self.data.update(hand=item_id).apply()
|
||||||
await self.room.send_xt('upa', self.data.id, item_id or 0)
|
await self.room.send_xt('upa', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their hand to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_feet(self, item):
|
self.logger.info('{} updated their hand item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their hand item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_feet(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(feet=item_id).apply()
|
await self.data.update(feet=item_id).apply()
|
||||||
await self.room.send_xt('upe', self.data.id, item_id or 0)
|
await self.room.send_xt('upe', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their feet to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_flag(self, item):
|
self.logger.info('{} updated their feet item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their feet item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_flag(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(flag=item_id).apply()
|
await self.data.update(flag=item_id).apply()
|
||||||
await self.room.send_xt('upl', self.data.id, item_id or 0)
|
await self.room.send_xt('upl', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their flag to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
|
||||||
async def update_photo(self, item):
|
self.logger.info('{} updated their flag item to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their flag item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
async def set_photo(self, item):
|
||||||
item_id = None if item is None else item.id
|
item_id = None if item is None else item.id
|
||||||
await self.data.update(photo=item_id).apply()
|
await self.data.update(photo=item_id).apply()
|
||||||
await self.room.send_xt('upp', self.data.id, item_id or 0)
|
await self.room.send_xt('upp', self.data.id, item_id or 0)
|
||||||
self.logger.info('{} updated their photo to \'{}\' '.format(self.data.username, item_id or 0))
|
|
||||||
|
self.logger.info('{} updated their background to \'{}\' '.format(
|
||||||
|
self.data.username, item.name) if item else
|
||||||
|
'{} removed their background item'.format(
|
||||||
|
self.data.username))
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.data is not None:
|
if self.data is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user