I am writing a function to calculate the total size of a "player appearance".
There are various "item slots" the player has, and if they are empty then 1 byte will be sent, otherwise there will be 2.
const getAppearanceBlockSize = (appearance: PlayerAppearance) => {
const headObscured = isCoveringHead(appearance.outfit.head);
return (
40
+ (appearance.outfit.head ? 2 : 1)
+ (appearance.outfit.cape ? 2 : 1)
+ (appearance.outfit.amulet ? 2 : 1)
+ (appearance.outfit.weapon ? 2 : 1)
+ (appearance.outfit.shield ? 2 : 1)
+ (appearance.outfit.head ? 2 : 1)
+ (headObscured ? 2 : 4)
);
};
The code seems fairly clear to me, but Code Climate has given it a high "cognitive complexity" score - indicating that the code is complex and should be broken up.
I can't think of any ways to break the code up, however, that wouldn't result in it being more complex than it currently is.