From 91af4a80271ada2223110df932e60822a50aa4b7 Mon Sep 17 00:00:00 2001 From: Ayush Saini Date: Fri, 2 Apr 2021 14:00:25 +0530 Subject: [PATCH] added some hooks and user custom tag , effects --- dist/ba_data/python/ba/_activitytypes.py | 2 + dist/ba_data/python/ba/_app.py | 2 + dist/ba_data/python/ba/_hooks.py | 8 +-- dist/ba_data/python/bastd/actor/playerspaz.py | 2 + dist/ba_root/mods/custom_hooks.py | 16 ++++++ dist/ba_root/mods/playersData/custom.json | 10 ++++ dist/ba_root/mods/playersData/pdata.py | 51 ++++++++++++++++++- dist/ba_root/mods/spaz/modifyspaz.py | 5 ++ dist/ba_root/mods/stats/mystats.json | 0 .../data.json => stats/mystats.py} | 0 dist/ba_root/mods/tools/Log.py | 0 dist/ba_root/mods/tools/Logger.py | 39 ++++++++++++++ 12 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 dist/ba_root/mods/playersData/custom.json create mode 100644 dist/ba_root/mods/spaz/modifyspaz.py delete mode 100644 dist/ba_root/mods/stats/mystats.json rename dist/ba_root/mods/{playersData/data.json => stats/mystats.py} (100%) delete mode 100644 dist/ba_root/mods/tools/Log.py create mode 100644 dist/ba_root/mods/tools/Logger.py diff --git a/dist/ba_data/python/ba/_activitytypes.py b/dist/ba_data/python/ba/_activitytypes.py index c51655d..a68df53 100644 --- a/dist/ba_data/python/ba/_activitytypes.py +++ b/dist/ba_data/python/ba/_activitytypes.py @@ -168,6 +168,8 @@ class ScoreScreenActivity(Activity[EmptyPlayer, EmptyTeam]): from bastd.actor.text import Text from ba import _language super().on_begin() + import custom_hooks as chook + chook.score_screen_on_begin(self._stats) # Pop up a 'press any button to continue' statement after our # min-view-time show a 'press any button to continue..' diff --git a/dist/ba_data/python/ba/_app.py b/dist/ba_data/python/ba/_app.py index 47b19fd..cfefea7 100644 --- a/dist/ba_data/python/ba/_app.py +++ b/dist/ba_data/python/ba/_app.py @@ -279,6 +279,8 @@ class App: from bastd import maps as stdmaps from bastd.actor import spazappearance from ba._enums import TimeType + import custom_hooks + custom_hooks.on_app_launch() cfg = self.config diff --git a/dist/ba_data/python/ba/_hooks.py b/dist/ba_data/python/ba/_hooks.py index 85c60f7..3779a30 100644 --- a/dist/ba_data/python/ba/_hooks.py +++ b/dist/ba_data/python/ba/_hooks.py @@ -308,6 +308,7 @@ def party_invite_revoke(invite_id: str) -> None: transition='out_right') import privateserver as pvt +import custom_hooks as chooks def filter_chat_message(msg: str, client_id: int) -> Optional[str]: """Intercept/filter chat messages. @@ -316,9 +317,10 @@ def filter_chat_message(msg: str, client_id: int) -> Optional[str]: Should filter and return the string to be displayed, or return None to ignore the message. """ - pvt.handlechat(msg,client_id); - del client_id # Unused by default. - return msg + pvt.handlechat(msg,client_id) + return chooks.filter_chat_message(msg,client_id) + + def local_chat_message(msg: str) -> None: diff --git a/dist/ba_data/python/bastd/actor/playerspaz.py b/dist/ba_data/python/bastd/actor/playerspaz.py index b77aa8a..b7b3708 100644 --- a/dist/ba_data/python/bastd/actor/playerspaz.py +++ b/dist/ba_data/python/bastd/actor/playerspaz.py @@ -70,6 +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) # Overloads to tell the type system our return type based on doraise val. diff --git a/dist/ba_root/mods/custom_hooks.py b/dist/ba_root/mods/custom_hooks.py index e69de29..5dc17f1 100644 --- a/dist/ba_root/mods/custom_hooks.py +++ b/dist/ba_root/mods/custom_hooks.py @@ -0,0 +1,16 @@ + + + +def filter_chat_message(msg,client_id): + + return msg + +def on_app_launch(): + #something + +def score_screen_on_begin(_stats): + #stats + +def playerspaz_init(player): + #add tag,rank,effect + \ No newline at end of file diff --git a/dist/ba_root/mods/playersData/custom.json b/dist/ba_root/mods/playersData/custom.json new file mode 100644 index 0000000..1058441 --- /dev/null +++ b/dist/ba_root/mods/playersData/custom.json @@ -0,0 +1,10 @@ +{ + "customtag":{ + "pb-id":"smoothy", + "pb-45":"something" + }, + "customeffects":{ + "pb-id":"ice", + "pb-id":"scorch", + } +} \ No newline at end of file diff --git a/dist/ba_root/mods/playersData/pdata.py b/dist/ba_root/mods/playersData/pdata.py index fb54814..691a314 100644 --- a/dist/ba_root/mods/playersData/pdata.py +++ b/dist/ba_root/mods/playersData/pdata.py @@ -1,7 +1,7 @@ # Released under the MIT License. See LICENSE for details. roles={} data={} - +custom={} def roles(): global roles @@ -86,4 +86,53 @@ def commit(): f=open("roles.json",'w') json.dump(roles,f,indent=4) f.close() +#======================= CUSTOM EFFECTS/TAGS =============== + +def custom(): + global custom + if custom=={}: + f=open("custom.json","r") + dat=json.loads(f.read()) + custom=dat + f.close() + return custom + + + +def set_effect(effect,id): + global custom + _custom=custom() + _custom['customeffects'][id]=effect + custom=_custom + commit_c() + + +def set_tag(tag,id): + global custom + _custom=custom() + _custom['customtag'][id]=tag + custom=_custom + commit_c() + +def remove_effect(id): + global custom + _custom=custom() + _custom['customeffects'].pop(id) + custom=_custom + commit_c() + + +def remove_tag(id): + global custom + _custom=custom() + _custom['customtag'].pop(id) + custom=_custom + commit_c() + + +def commit_c(): + global custom + f=open("custom.json",'w') + json.dump(custom,f,indent=4) + f.close() diff --git a/dist/ba_root/mods/spaz/modifyspaz.py b/dist/ba_root/mods/spaz/modifyspaz.py new file mode 100644 index 0000000..3f2ff2d --- /dev/null +++ b/dist/ba_root/mods/spaz/modifyspaz.py @@ -0,0 +1,5 @@ + + + + + diff --git a/dist/ba_root/mods/stats/mystats.json b/dist/ba_root/mods/stats/mystats.json deleted file mode 100644 index e69de29..0000000 diff --git a/dist/ba_root/mods/playersData/data.json b/dist/ba_root/mods/stats/mystats.py similarity index 100% rename from dist/ba_root/mods/playersData/data.json rename to dist/ba_root/mods/stats/mystats.py diff --git a/dist/ba_root/mods/tools/Log.py b/dist/ba_root/mods/tools/Log.py deleted file mode 100644 index e69de29..0000000 diff --git a/dist/ba_root/mods/tools/Logger.py b/dist/ba_root/mods/tools/Logger.py new file mode 100644 index 0000000..38f26c9 --- /dev/null +++ b/dist/ba_root/mods/tools/Logger.py @@ -0,0 +1,39 @@ + +import ba,_ba +import datetime; +import os +# ct stores current time + + + +path=_ba.env()['python_directory_user'] +serverdata=os.path.join(path,"serverData" + os.sep) +class log(object): + def __init__(self,msg,type='sys'): + ct = datetime.datetime.now() + msg=ct+msg + + if type=='chat': + + f=open(serverdata+"Chat Logs.log","a+") + + + + elif type=='playerjoin': + f.open(serverdata+"joining.log","a+") + + + elif type=='chatcmnd': + f.open(serverdata+"cmndusage.log","a+") + + else: + f=open(serverdata+"logs.log","a+") + + f.write(msg) + f.close() + + + + + +