ship_skin_state.py (5291B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\ships\skins\live_data\ship_skin_state.py 2 from cosmetics.client.ships.skins.live_data.slot_layout import SlotLayout 3 from cosmetics.common.ships.skins.static_data.skin_type import ShipSkinType 4 from eveProto.generated.eve_public.cosmetic.ship.ship_pb2 import State 5 from eveProto.generated.eve_public.character.character_pb2 import Identifier as CharacterIdentifier 6 from eveProto.generated.eve_public.ship.ship_pb2 import Identifier as ShipIdentifier 7 from eveProto.generated.eve_public.cosmetic.ship.skin.firstparty.firstparty_pb2 import Identifier as FirstPartyIdentifier 8 9 class ShipSkinState(object): 10 11 def __init__(self, ship_instance_id, character_id): 12 self._ship_instance_id = ship_instance_id 13 self._character_id = character_id 14 self._skin_data = None 15 16 @property 17 def skin_type(self): 18 if self._skin_data is not None: 19 return self._skin_data.get_type() 20 return ShipSkinType.NO_SKIN 21 22 @property 23 def ship_instance_id(self): 24 return self._ship_instance_id 25 26 @property 27 def character_id(self): 28 return self._character_id 29 30 @property 31 def skin_data(self): 32 return self._skin_data 33 34 @skin_data.setter 35 def skin_data(self, value): 36 self._skin_data = value 37 38 def __eq__(self, other): 39 if other is None: 40 return False 41 if self.skin_type != other.skin_type: 42 return False 43 return self.ship_instance_id == other.ship_instance_id and self.character_id == other.character_id and self.skin_data == other.skin_data 44 45 def __ne__(self, other): 46 return not self.__eq__(other) 47 48 def __str__(self): 49 return 'char_id %s, ship_id %s, skin_type %s, skin_data %s' % (self.character_id, 50 self.ship_instance_id, 51 self.skin_type, 52 self.skin_data) 53 54 @staticmethod 55 def build_from_proto(payload): 56 skin_state = ShipSkinState(payload.ship.sequential, payload.character.sequential) 57 skin_state.skin_data = build_skin_data_from_proto(payload.skin) 58 return skin_state 59 60 61 class ShipSkinData(object): 62 63 def __init__(self): 64 pass 65 66 def get_data(self): 67 raise NotImplementedError 68 69 def set_data(self, value): 70 raise NotImplementedError 71 72 def get_type(self): 73 raise NotImplementedError 74 75 def build_data_from_proto(self, payload): 76 raise NotImplementedError 77 78 def __eq__(self, other): 79 if other is None: 80 return False 81 return self.get_data() == other.get_data() 82 83 def __ne__(self, other): 84 return not self.__eq__(other) 85 86 87 class FirstPartySkinData(ShipSkinData): 88 89 def __init__(self): 90 self._skin_id = None 91 92 @property 93 def skin_id(self): 94 return self._skin_id 95 96 def get_data(self): 97 return self._skin_id 98 99 def set_data(self, value): 100 self._skin_id = value 101 102 def get_type(self): 103 return ShipSkinType.FIRST_PARTY_SKIN 104 105 def build_data_from_proto(self, payload): 106 self._skin_id = payload.identifier.sequential 107 108 def __str__(self): 109 return '%s' % self._skin_id 110 111 112 class ThirdPartySkinData(ShipSkinData): 113 114 def __init__(self): 115 self._slot_layout = None 116 self._skin_id = None 117 118 @property 119 def slot_layout(self): 120 return self._slot_layout 121 122 @property 123 def skin_id(self): 124 return self._skin_id 125 126 def get_data(self): 127 return self._slot_layout 128 129 def set_data(self, value): 130 self._slot_layout = value 131 132 def get_type(self): 133 return ShipSkinType.THIRD_PARTY_SKIN 134 135 def build_data_from_proto(self, payload): 136 self._skin_id = payload.identifier.hex if payload.identifier.hex else None 137 self._slot_layout = SlotLayout.build_from_proto(payload.layout) 138 139 def __eq__(self, other): 140 if other is None: 141 return False 142 return self.skin_id == other.skin_id and self.get_data() == other.get_data() 143 144 def __ne__(self, other): 145 return not self.__eq__(other) 146 147 def __str__(self): 148 return 'skin_id %s, slot layout %s' % (self._skin_id, self._slot_layout) 149 150 151 def build_skin_data_from_proto(payload): 152 skin_data = None 153 if payload.HasField('firstparty'): 154 skin_data = FirstPartySkinData() 155 skin_data.build_data_from_proto(payload.firstparty) 156 elif payload.HasField('thirdparty'): 157 skin_data = ThirdPartySkinData() 158 skin_data.build_data_from_proto(payload.thirdparty) 159 return skin_data 160 161 162 def build_proto_from_skin_state(ship_type_id, skin_state): 163 state = State() 164 state.character.CopyFrom(CharacterIdentifier(sequential=skin_state.character_id)) 165 state.ship.CopyFrom(ShipIdentifier(sequential=skin_state.ship_instance_id)) 166 if skin_state.skin_type == ShipSkinType.FIRST_PARTY_SKIN: 167 state.skin.firstparty.identifier.CopyFrom(FirstPartyIdentifier(sequential=skin_state.skin_data.get_data())) 168 elif skin_state.skin_type == ShipSkinType.THIRD_PARTY_SKIN: 169 skin_data = skin_state.skin_data.get_data() 170 state.skin.thirdparty.layout.CopyFrom(SlotLayout.build_proto_from_layout(ship_type_id, skin_data)) 171 else: 172 state.skin.no_skin = True 173 return state