From c33e7d4ccc15aa92600da0f7a550dc7b91848e2f Mon Sep 17 00:00:00 2001 From: Hubert Walczak Date: Thu, 19 Oct 2023 11:55:43 +0200 Subject: [PATCH] Added option to replace avatars as team logos --- public/panel.json | 15 +++++++++++++++ src/HUD/Players/Avatar.tsx | 37 ++++++++++++++++++++++++++++++++---- src/HUD/Players/Observed.tsx | 2 +- src/HUD/Players/Player.tsx | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/public/panel.json b/public/panel.json index 0aa1428..813e344 100644 --- a/public/panel.json +++ b/public/panel.json @@ -63,6 +63,21 @@ "name":"right_image", "label":"Right box's image logo" }, + { + "type":"select", + "name":"replace_avatars", + "label":"Use team logos as player avatars", + "values": [ + { + "label": "Only if player has no avatar", + "name": "if_missing" + }, + { + "label": "Always", + "name": "always" + } + ] + }, { "type": "action", "name": "boxesState", diff --git a/src/HUD/Players/Avatar.tsx b/src/HUD/Players/Avatar.tsx index 96c25cb..c4be7d5 100644 --- a/src/HUD/Players/Avatar.tsx +++ b/src/HUD/Players/Avatar.tsx @@ -5,9 +5,12 @@ import PlayerCamera from "./../Camera/Camera"; import { avatars } from './../../api/avatars'; import { Skull } from './../../assets/Icons'; +import { configs } from '../../App'; +import { apiUrl } from '../../api/api'; interface IProps { steamid: string, + teamId?: string | null, slot?: number, height?: number, width?: number, @@ -15,13 +18,39 @@ interface IProps { showCam?: boolean, sidePlayer?: boolean } -export default class Avatar extends React.Component { +export default class Avatar extends React.Component { + constructor(props: IProps){ + super(props); + this.state = { + replaceAvatar: 'never' + } + } + componentDidMount() { + const onDataChange = (data:any) => { + if(!data) return; + const display = data.display_settings; + if(!display) return; + this.setState({ + replaceAvatar: display.replace_avatars || 'never' + }) + }; + configs.onChange(onDataChange); + onDataChange(configs.data); + } + getAvatarUrl = () => { + const avatarData = avatars[this.props.steamid] && avatars[this.props.steamid].url ? avatars[this.props.steamid].url : null; + if(this.state.replaceAvatar === 'always' || (this.state.replaceAvatar === 'if_missing' && !avatarData)){ + return this.props.teamId ? `${apiUrl}api/teams/logo/${this.props.teamId}` : avatarData || null; + } + return avatarData || null; + + } render() { const { showCam, steamid, width, height, showSkull, sidePlayer } = this.props; //const url = avatars.filter(avatar => avatar.steamid === this.props.steamid)[0]; - const avatarData = avatars[this.props.steamid]; - if (!avatarData || !avatarData.url) { + const avatarUrl = this.getAvatarUrl(); + if (!avatarUrl) { return null; } @@ -31,7 +60,7 @@ export default class Avatar extends React.Component { showCam ? ( sidePlayer ?
: ) : null } { - showSkull ? : {'Avatar'} + showSkull ? : {'Avatar'} } diff --git a/src/HUD/Players/Observed.tsx b/src/HUD/Players/Observed.tsx index e9595bb..1810d2a 100644 --- a/src/HUD/Players/Observed.tsx +++ b/src/HUD/Players/Observed.tsx @@ -58,7 +58,7 @@ export default class Observed extends React.Component<{ player: Player | null, v return (
- {} + {}
{player.name}
diff --git a/src/HUD/Players/Player.tsx b/src/HUD/Players/Player.tsx index 31edcc6..62903a9 100644 --- a/src/HUD/Players/Player.tsx +++ b/src/HUD/Players/Player.tsx @@ -76,7 +76,7 @@ const Player = ({ player, isObserved }: IProps) => { return (
- +
K