This commit is contained in:
Ayush Saini 2021-04-07 03:58:40 +05:30
parent 14007f0b0e
commit e9f6da8a2e
13 changed files with 76 additions and 70 deletions

View file

@ -70,8 +70,8 @@ class PlayerSpaz(Spaz):
self.last_player_held_by: Optional[ba.Player] = None
self._player = player
self._drive_player_position()
import custom_hooks
custom_hooks.playerspaz_init(self._player)
from spazmod import modifyspaz
modifyspaz.main(self.node,self._player)
# Overloads to tell the type system our return type based on doraise val.

View file

@ -1,6 +1,6 @@
# Released under the MIT License. See LICENSE for details.
from playersData import pdata
from chatCMDS import chatcmd
from chatHandle.chatCMDS import chatcmd
from chatFilter import chatfilter
import ba,_ba

View file

@ -1,17 +1,17 @@
def filter_chat_message(msg,client_id):
from chatHandle import handlechat
return handlechat.filter_chat_message(msg,client_id)
def on_app_launch():
pass
#something
def score_screen_on_begin(_stats):
pass
#stats
def playerspaz_init(player):
pass
#add tag,rank,effect

View file

@ -1,12 +1,14 @@
# Released under the MIT License. See LICENSE for details.
import os,_ba,json
roles={}
data={}
custom={}
data_path = os.path.join(_ba.env()['python_directory_user'],"playersData" + os.sep)
def roles():
def get_roles():
global roles
if roles=={}:
f=open("roles.json","r")
f=open(data_path+"roles.json","r")
dat=json.loads(f.read())
roles=dat
f.close()
@ -14,7 +16,7 @@ def roles():
def create_role(role):
global roles
_roles=roles()
_roles=get_roles()
if role not in _roles:
_roles[role]={
"tag":role,
@ -31,7 +33,7 @@ def create_role(role):
def add_player_role(role,id):
global roles
_roles=roles()
_roles=get_roles()
if role in _roles:
_roles[role].ids.append(id)
roles=_roles
@ -41,7 +43,7 @@ def add_player_role(role,id):
def add_command_role(role,command):
global roles
_roles=roles()
_roles=get_roles()
if role in _roles:
_roles[role].commands.append(command)
roles=_roles
@ -52,7 +54,7 @@ def add_command_role(role,command):
def remove_player_role(role,id):
global roles
_roles=roles()
_roles=get_roles()
if role in _roles:
_roles[role].ids.remove(id)
roles=_roles
@ -62,7 +64,7 @@ def remove_player_role(role,id):
def remove_command_role():
global roles
_roles=roles()
_roles=get_roles()
if role in _roles:
_roles[role].commands.remove(command)
roles=_roles
@ -72,7 +74,7 @@ def remove_command_role():
def change_role_tag(role,tag):
global roles
_roles=roles()
_roles=get_roles()
if role in _roles:
_roles[role].tag=tag
roles=_roles
@ -85,14 +87,14 @@ def commit(_roles):
global roles
if _roles=={}:
return
f=open("roles.json",'w')
f=open(data_path+"roles.json",'w')
json.dump(_roles,f,indent=4)
f.close()
roles=_roles
def get_role(acc_id):
global roles
_roles =roles()
_roles =get_roles()
for role in _roles:
if acc_id in role["ids"]:
return role
@ -100,10 +102,10 @@ def get_role(acc_id):
#======================= CUSTOM EFFECTS/TAGS ===============
def custom():
def get_custom():
global custom
if custom=={}:
f=open("custom.json","r")
f=open(data_path+"custom.json","r")
dat=json.loads(f.read())
custom=dat
f.close()
@ -113,7 +115,7 @@ def custom():
def set_effect(effect,id):
global custom
_custom=custom()
_custom=get_custom()
_custom['customeffects'][id]=effect
custom=_custom
commit_c()
@ -121,14 +123,14 @@ def set_effect(effect,id):
def set_tag(tag,id):
global custom
_custom=custom()
_custom=get_custom()
_custom['customtag'][id]=tag
custom=_custom
commit_c()
def remove_effect(id):
global custom
_custom=custom()
_custom=get_custom()
_custom['customeffects'].pop(id)
custom=_custom
commit_c()
@ -136,7 +138,7 @@ def remove_effect(id):
def remove_tag(id):
global custom
_custom=custom()
_custom=get_custom()
_custom['customtag'].pop(id)
custom=_custom
commit_c()
@ -144,6 +146,6 @@ def remove_tag(id):
def commit_c():
global custom
f=open("custom.json",'w')
f=open(data_path+"custom.json",'w')
json.dump(custom,f,indent=4)
f.close()

View file

@ -18,7 +18,7 @@
"commands":[],
"ids":[]
},
"donor":{
"toppers":{
"tag":"DONOR",
"tagcolor":(2,2,2),
"commands":[],

View file

@ -5,5 +5,7 @@
"bottom left watermark":"join discord for fun",
"center highlights":["message 1","message 2","message 3"]
},
"enabletags":true
"enabletags":true,
"enablerank":true,
"enableeffects":false
}

View file

@ -1,20 +1,19 @@
# Released under the MIT License. See LICENSE for details.
import ba,_ba,json,os
from stats import mystats
statsFile = mystats.statsfile
settingjson = os.path.join(_ba.env()['python_directory_user'],"setting.json")
def get_setting():
s = {}
f=open("setting.json","r")
s = {}
f=open(settingjson,"r")
d = json.loads(f.read())
f.close()
return d
def commit(updated_settings: dict):
if updated_settings == {}: return
f=open("setting.json",'w')
json.dump(updated_settings,f,indent=4)
f.close()
f=open(settingjson,'w')
json.dump(updated_settings,f,indent=4)
f.close()
def sendError(msg: str, ID: int = None):
if ID is not None:

View file

@ -1,7 +0,0 @@
# Released under the MIT License. See LICENSE for details.
#
"""Common bits of functionality shared between all efro projects.
Things in here should be hardened, highly type-safe, and well-covered by unit
tests since they are widely used in live client and server code.
"""

View file

@ -1,11 +1,11 @@
import tag
import effects
from spazmod import tag
from spazmod import effects
import setting
# all activites related to modify spaz by any how will be here
def main(node,player):
_setting=setting.get_setting()
if _setting['enabletags']:
tag.addtag(node,player)
if _setting['enablerank']:

View file

@ -1,11 +1,12 @@
import pdata
from playersData import pdata
import ba
def addtag(node,player):
session_player=player.sessionplayer
account_id=session_player.get_account_id()
customtag=pdata.custom()['customtag']
roles=pdata.roles()
customtag_=pdata.get_custom()
customtag=customtag_['customtag']
roles=pdata.get_roles()
role=pdata.get_role(account_id)
tag=None
if account_id in customtag:
@ -13,12 +14,19 @@ def addtag(node,player):
elif role:
tag=roles[role]['tag']
tag(node,tag)
Tag(node,tag)
from stats import mystats
def addrank(node,player):
session_player=player.sessionplayer
account_id=session_player.get_account_id()
rank=mystats.getRank(account_id)
class tag(object):
def __init__(owner=None,tag="somthing"):
if rank:
Rank(node,rank)
class Tag(object):
def __init__(self,owner=None,tag="somthing"):
self.node=owner
mnode = ba.newnode('math',
owner=self.node,
attrs={
@ -34,17 +42,18 @@ class tag(object):
'shadow': 1.0,
'flatness': 1.0,
'color': (1,1,1),
'scale': 0.02,
'scale': 0.01,
'h_align': 'center'
})
mnode.connectattr('output', self.tag_text, 'position')
class rank(object):
def __init__(owner=None,rank=1):
class Rank(object):
def __init__(self,owner=None,rank=99):
self.node=owner
mnode = ba.newnode('math',
owner=self.node,
attrs={
'input1': (0, 1.4, 0),
'input1': (0, 1.2, 0),
'operation': 'add'
})
self.node.connectattr('torso_position', mnode, 'input2')
@ -56,7 +65,7 @@ class rank(object):
'shadow': 1.0,
'flatness': 1.0,
'color': (1,1,1),
'scale': 0.02,
'scale': 0.01,
'h_align': 'center'
})
mnode.connectattr('output', self.rank_text, 'position')

View file

@ -1,7 +0,0 @@
# Released under the MIT License. See LICENSE for details.
#
"""Common bits of functionality shared between all efro projects.
Things in here should be hardened, highly type-safe, and well-covered by unit
tests since they are widely used in live client and server code.
"""

View file

@ -31,7 +31,7 @@ html_start = f'''<!DOCTYPE html>
<style>table{table_style} th{heading_style}</style>
</head>
<body>
<h3 style="text-align:center">Top 200 Players of {our_settings['server_name']}</h3>
<h3 style="text-align:center">Top 200 Players </h3>
<table border=1>
<tr>
<th><b>Rank</b></th>
@ -46,7 +46,9 @@ html_start = f'''<!DOCTYPE html>
def refreshStats():
# lastly, write a pretty html version.
# our stats url could point at something like this...
stats = setting.getStats()
f=open(statsfile)
stats = json.loads(f.read())
f=open(htmlfile, 'w')
f.write(html_start)
entries = [(a['scores'], a['kills'], a['deaths'], a['games'], a['name_html'], a['aid']) for a in stats.values()]
@ -116,12 +118,13 @@ def refreshStats():
f.close()
global ranks
ranks=_ranks
f2 = open(statsfile, "w")
f2.write(json.dumps(pStats, indent=4))
f2.close()
from playersData import pdata
pdata.update_toppers(toppersIDS)
pdata.update_toppers(toppersIDs)
def update(score_set):
"""
@ -149,7 +152,10 @@ def update(score_set):
# from disk, do display-string lookups for accounts that need them,
# and write everything back to disk (along with a pretty html version)
# We use a background thread so our server doesn't hitch while doing this.
if account_scores: UpdateThread(account_kills, account_deaths, account_scores).start()
print(account_kills)
print(account_scores)
if account_scores:
UpdateThread(account_kills, account_deaths, account_scores).start()
class UpdateThread(threading.Thread):
def __init__(self, account_kills, account_deaths, account_scores):
@ -157,14 +163,16 @@ class UpdateThread(threading.Thread):
self._account_kills = account_kills
self.account_deaths = account_deaths
self.account_scores = account_scores
print("init thread")
def run(self):
# pull our existing stats from disk
print("run thead")
try:
if os.path.exists(statsfile):
with open(statsfile) as f:
stats = json.loads(f.read())
except:
return
stats={}
# now add this batch of kills to our persistant stats
for account_id, kill_count in self._account_kills.items():
@ -213,4 +221,4 @@ def getRank(acc_id):
if ranks==[]:
refreshStats()
if acc_id in ranks:
return ranks.index(acc_id)
return ranks.index(acc_id)+1

View file

@ -2,7 +2,7 @@
#TODO need to set coordinates of text node , move timer values to settings.json
from ba._enums import TimeType
import ba
import ba,_ba
import setting
class textonmap:
def __init__(self):
@ -12,7 +12,7 @@ class textonmap:
left=_textonmap['bottom left watermark']
top=_textonmap['top watermark']
self.timerr=ba.Timer(8,self.highlights,repeat=True)
self.timerr=ba.Timer(8,ba.Call(self.highlights),repeat=True)
self.left_watermark(left)
self.top_message(top)