Update tag.py

This commit is contained in:
Sarasayed0118 2024-04-07 05:42:55 +05:30 committed by GitHub
parent ca5fe94e92
commit eeeb0b9caf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,11 +1,13 @@
from playersData import pdata from playersData import pdata
import ba, setting, _ba import ba, setting, _ba
from stats import mystats from stats import mystats
sett = setting.get_settings_data() sett = setting.get_settings_data()
def addtag(node,player): def addtag(node,player):
profiles=[]
app = _ba.app
session_player=player.sessionplayer session_player=player.sessionplayer
account_id=session_player.get_v1_account_id() account_id=session_player.get_v1_account_id()
profiles=session_player.inputdevice.get_player_profiles()
customtag_=pdata.get_custom() customtag_=pdata.get_custom()
customtag=customtag_['customtag'] customtag=customtag_['customtag']
paidtag=customtag_['paidtags'] paidtag=customtag_['paidtags']
@ -24,8 +26,10 @@ def addtag(node,player):
tag=roles[role]['tag'] tag=roles[role]['tag']
col=roles[role]['tagcolor'] col=roles[role]['tagcolor']
break; break;
if not profiles:
profiles = app.config.get('Player Profiles', {})
if tag: if tag:
Tag(node,tag,col) Tag(node,tag,col,player,profiles)
def addrank(node,player): def addrank(node,player):
@ -47,56 +51,107 @@ def addhp(node, spaz):
spaz.hptimer = ba.Timer(100,ba.Call(showHP),repeat = True, timetype=ba.TimeType.SIM, timeformat=ba.TimeFormat.MILLISECONDS) spaz.hptimer = ba.Timer(100,ba.Call(showHP),repeat = True, timetype=ba.TimeType.SIM, timeformat=ba.TimeFormat.MILLISECONDS)
class Tag(object): class Tag(object):
def __init__(self,owner=None,tag="somthing",col=(1,1,1)): def __init__(self, owner=None, tag="something", col=(1, 1, 1), player=None, profiles=None):
self.node=owner self.node = owner
self.player = player
self.profiles = profiles
self.tag = tag
mnode = ba.newnode('math', mnode = ba.newnode('math',
owner=self.node, owner=self.node,
attrs={ attrs={
'input1': (0, 1.5, 0), 'input1': (0, 1.5, 0),
'operation': 'add' 'operation': 'add'
}) })
self.node.connectattr('torso_position', mnode, 'input2') self.node.connectattr('torso_position', mnode, 'input2')
##
# Check permission for all roles
if self.check_permissions():
custom_tag = self.parse_custom_tag()
tag_text = custom_tag if custom_tag else tag
self.create_tag_text(tag_text, col, mnode)
else:
custom_tag = self.parse_custom_tag()
tag_text = custom_tag if custom_tag else tag
self.create_tag_text(tag_text, col, mnode)
##
def check_permissions(self):
session_player = self.player.sessionplayer
account_id = session_player.get_v1_account_id()
roles = pdata.get_roles()
for role in roles:
if account_id in roles[role]["ids"]:
return True
return False
##
def parse_custom_tag(self):
session_player = self.player.sessionplayer
account_id = session_player.get_v1_account_id()
customtag_ = pdata.get_custom()
customtag = customtag_['customtag']
tags = customtag.get(account_id)
# Check if tag is available in customtag
if tags is not None:
return self.process_escape_sequences(tags)
# If EnableProfilesTag is True, check profiles for /tag
if sett["EnablePlayerProfilesTag"]:
for p in self.profiles:
if '/tag' in p:
try:
# Split the profile string by '/tag' and get the second part (after the '/tag' command)
tagg = p.split('/tag', 1)[1].strip()
return self.process_escape_sequences(tagg)
except IndexError:
pass # Continue to the next profile if tag is invalid
# If no tag is found in customtag or profiles, return the default tag
return self.process_escape_sequences(self.tag)
##
def process_escape_sequences(self, tag):
# Process escape sequences in the tag text
if '\\' in tag: if '\\' in tag:
tag = tag.replace('\\d', ('\ue048')) \
tag = tag.replace('\\d', ('\ue048')) .replace('\\c', ('\ue043')) \
tag = tag.replace('\\c', ('\ue043')) .replace('\\h', ('\ue049')) \
tag = tag.replace('\\h', ('\ue049')) .replace('\\s', ('\ue046')) \
tag = tag.replace('\\s', ('\ue046')) .replace('\\n', ('\ue04b')) \
tag = tag.replace('\\n', ('\ue04b')) .replace('\\f', ('\ue04f')) \
tag = tag.replace('\\f', ('\ue04f')) .replace('\\g', ('\ue027')) \
tag = tag.replace('\\g', ('\ue027')) .replace('\\i', ('\ue03a')) \
tag = tag.replace('\\i', ('\ue03a')) .replace('\\m', ('\ue04d')) \
tag = tag.replace('\\m', ('\ue04d')) .replace('\\t', ('\ue01f')) \
tag = tag.replace('\\t', ('\ue01f')) .replace('\\bs', ('\ue01e')) \
tag = tag.replace('\\bs', ('\ue01e')) .replace('\\j', ('\ue010')) \
tag = tag.replace('\\j', ('\ue010')) .replace('\\e', ('\ue045')) \
tag = tag.replace('\\e', ('\ue045')) .replace('\\l', ('\ue047')) \
tag = tag.replace('\\l', ('\ue047')) .replace('\\a', ('\ue020')) \
tag = tag.replace('\\a', ('\ue020')) .replace('\\b', ('\ue00c'))
tag = tag.replace('\\b', ('\ue00c')) return tag
##
def create_tag_text(self, tag_text, col, mnode):
self.tag_text = ba.newnode('text', self.tag_text = ba.newnode('text',
owner=self.node, owner=self.node,
attrs={ attrs={
'text': tag, 'text': tag_text,
'in_world': True, 'in_world': True,
'shadow': 1.0, 'shadow': 1.0,
'flatness': 1.0, 'flatness': 1.0,
'color': tuple(col), 'color': tuple(col),
'scale': 0.01, 'scale': 0.01,
'h_align': 'center' 'h_align': 'center'
}) })
mnode.connectattr('output', self.tag_text, 'position') mnode.connectattr('output', self.tag_text, 'position')
# Animate the color of the text node if animation is enabled
if sett["enableTagAnimation"]: if sett["enableTagAnimation"]:
ba.animate_array(node=self.tag_text, attr='color', size=3, keys={ ba.animate_array(node=self.tag_text, attr='color', size=3, keys={
0.2: (2,0,2), 0.2: (2, 0, 2),
0.4: (2,2,0), 0.4: (2, 2, 0),
0.6: (0,2,2), 0.6: (0, 2, 2),
0.8: (2,0,2), 0.8: (2, 0, 2),
1.0: (1,1,0), 1.0: (1, 1, 0),
1.2: (0,1,1), 1.2: (0, 1, 1),
1.4: (1,0,1) 1.4: (1, 0, 1)
}, loop=True) }, loop=True)
class Rank(object): class Rank(object):
def __init__(self,owner=None,rank=99): def __init__(self,owner=None,rank=99):