shipEmblemLicensesController.py (4377B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\shipEmblemLicensesController.py 2 import blue 3 import evetypes 4 from carbon.common.script.sys.serviceConst import ROLE_GML 5 from cosmetics.common.cosmeticsConst import NOTIFICATION_BY_TYPE 6 from shipcosmetics.client.factory import ShipCosmeticGatewayFactory 7 from shipcosmetics.client.licensegateway.licenseSignals import on_ship_cosmetics_license_change 8 from shipcosmetics.client.licensegateway.quasar import on_ship_license_changed_internal 9 from notifications.common.notification import Notification 10 from localization import GetByLabel 11 from publicGateway.grpc.exceptions import GenericException 12 13 class ShipEmblemLicensesController(object): 14 15 def __init__(self): 16 self._cache = None 17 self._ship_license_gateway = ShipCosmeticGatewayFactory().license_gateway 18 on_ship_license_changed_internal.connect(self._on_ship_license_changed) 19 20 def _refresh_cache(self): 21 self._cache = self._ship_license_gateway.listOwnedLicenses(session.charid) 22 23 def flush_cache(self): 24 self._cache = None 25 26 def is_ship_license_owned(self, license_id): 27 return any((license.licenseID == license_id for license in self.get_owned_ship_licenses())) 28 29 def get_all_ship_licenses(self): 30 return self._ship_license_gateway.listAll() 31 32 def get_all_licensed_ship_groups(self): 33 return self._ship_license_gateway.listAllShipGroups() 34 35 def get_owned_ship_licenses(self, force_refresh = False): 36 if force_refresh or self._cache is None: 37 self._refresh_cache() 38 return self._cache 39 40 def get_unowned_ship_licenses(self, force_refresh = False): 41 owned_licenses = set(self.get_owned_ship_licenses(force_refresh)) 42 all_licenses = set(self.get_all_ship_licenses()) 43 return all_licenses.difference(owned_licenses) 44 45 def get_owned_ship_licenses_for_ship(self, ship_id, force_refresh = False): 46 licenses = self.get_owned_ship_licenses(force_refresh) 47 ship_item = sm.GetService('godma').GetItem(ship_id) 48 if ship_item is not None: 49 return [ license for license in licenses if license.shipTypeID == ship_item.typeID ] 50 else: 51 return [] 52 53 def get_ship_licenses_for_ship_type(self, ship_type_id): 54 return self._ship_license_gateway.listByShipTypeId(ship_type_id) 55 56 def get_by_ship_license_type_id(self, license_id): 57 return self._ship_license_gateway.getByShipCosmeticLicenseTypeID(license_id) 58 59 def _on_ship_license_changed(self, license, granted): 60 self.flush_cache() 61 on_ship_cosmetics_license_change(license.licenseID, granted) 62 if granted: 63 self._trigger_ship_license_granted_notification(license) 64 65 def _trigger_ship_license_granted_notification(self, license): 66 license = self._ship_license_gateway.getByLicenseId(license.licenseID) 67 if license: 68 notification_type = NOTIFICATION_BY_TYPE.get(license.cosmeticType, None) 69 if notification_type is not None: 70 notification = Notification.MakeShipCosmeticLicenseAcquiredNotification(notificationType=notification_type, header=GetByLabel('UI/ShipCosmetics/ShipCosmeticsLicenseGrantedNotification', licenseName=evetypes.GetName(license.fsdTypeID)), body=GetByLabel('UI/ShipCosmetics/ShipCosmeticsLicenseGrantedNotificationBody', shipName=evetypes.GetName(license.shipTypeID)), createdTime=blue.os.GetWallclockTime(), callback=None) 71 sm.ScatterEvent('OnNewNotificationReceived', notification) 72 73 def debug_grant_ship_cosmetics_license(self, license_id): 74 if session.role & ROLE_GML: 75 channel = self._ship_license_gateway.grantLicense_admin(session.charid, license_id) 76 try: 77 channel.receive() 78 except GenericException: 79 pass 80 finally: 81 on_ship_cosmetics_license_change(license_id, True) 82 83 def debug_revoke_ship_cosmetics_license(self, license_id): 84 if session.role & ROLE_GML: 85 channel = self._ship_license_gateway.revokeLicense_admin(session.charid, license_id) 86 try: 87 channel.receive() 88 except GenericException: 89 pass 90 finally: 91 on_ship_cosmetics_license_change(license_id, False)