Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin system in python #306

Open
wants to merge 3 commits into
base: 2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@ Thumbs.db
/MSVC/HoldTheFlag_Win32_Debug/*.ib_pdb_index
*.ib_pdb_index

# Python things
__pycache__

# vi files
*~
*.swp
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ MP_WITH_CURSES
# build the server?
AC_ARG_ENABLE(server, AS_HELP_STRING([--disable-server],[do not compile server]))

# check whether python plugins are desired
AC_ARG_ENABLE(python, AS_HELP_STRING([--disable-python],[do not compile python support]))
if test "x$enable_python" != xno ; then
if test "x$enable_server" != xno ; then
AM_PATH_PYTHON([3.8])
AC_DEFINE(BZ_PYTHON, 1, [Enable python])
fi
fi
AM_CONDITIONAL(BUILD_PLUGINS, test "x$enable_plugins" != "xno")

# check whether plugins are desired
AC_ARG_ENABLE(plugins, AS_HELP_STRING([--disable-plugins],[do not compile plugins]))
if test "x$enable_plugins" != xno ; then
Expand Down
16 changes: 16 additions & 0 deletions python/bzBasic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from enum import IntEnum

class bz_PlayerUpdateState():
pass

class bz_eTeamType(IntEnum):
eNoTeam = -1
eRogueTeam = 0
eRedTeam = 1
eGreenTeam = 2
eBlueTeam = 3
ePurpleTeam = 4
eRabbitTeam = 5
eHunterTeam = 6
eObservers = 7
eAdministrators = 8
109 changes: 109 additions & 0 deletions python/bzEvents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from bzBasic import *

bz_eGetPlayerSpawnPosEvent = 1
bz_eTickEvent = 2
bz_eRawChatMessageEvent = 3
bz_eFlagTransferredEvent = 4
bz_eFlagGrabbedEvent = 5
bz_eFlagDroppedEvent = 6
bz_eShotFiredEvent = 7
bz_ePlayerDieEvent = 8
bz_ePlayerUpdateEvent = 9
bz_eAllowFlagGrab = 10
bz_ePlayerJoinEvent = 11
bz_ePlayerPartEvent = 12

class bz_EventData():
def __init__(self, eventType):
self.eventType = eventType

class bz_TickEventData_V1 (bz_EventData):
def __init__(self):
super().__init__(bz_eTickEvent)

class bz_GetPlayerSpawnPosEventData_V1 (bz_EventData):
def __init__(self, pos):
super().__init__(bz_eGetPlayerSpawnPosEvent)
self.pos = pos

class bz_ChatEventData_V1 (bz_EventData):
def __init__(self, fromPlayer, message):
super().__init__(bz_eRawChatMessageEvent)
self.fromPlayer = fromPlayer
self.message = message

class bz_FlagTransferredEventData_V1 (bz_EventData):
def __init__(self, flagType):
super().__init__(bz_eFlagTransferredEvent)
self.flagType = flagType

class bz_FlagGrabbedEventData_V1 (bz_EventData):
def __init__(self, flagType):
super().__init__(bz_eFlagGrabbedEvent)
self.flagType = flagType

class bz_FlagDroppedEventData_V1 (bz_EventData):
def __init__(self, flagType):
super().__init__(bz_eFlagDroppedEvent)
self.flagType = flagType

class bz_ShotFiredEventData_V1 (bz_EventData):
def __init__(self, playerID):
super().__init__(bz_eShotFiredEvent)
self.playerID = playerID

class bz_PlayerDieEventData_V2 (bz_EventData):
def __init__(self, playerID, flagKilledWith):
super().__init__(bz_ePlayerDieEvent)
self.playerID = playerID
self.flagKilledWith = flagKilledWith

class bz_PlayerUpdateEventData_V1 (bz_EventData):
def __init__(self, playerID, pos):
super().__init__(bz_ePlayerUpdateEvent)
self.playerID = playerID
self.state = bz_PlayerUpdateState()
self.state.pos = pos

class bz_AllowFlagGrabData_V1 (bz_EventData):
allow = True

def __init__(self, flagID, playerID):
super().__init__(bz_eAllowFlagGrab)
self.flagID = flagID
self.playerID = playerID

class bz_BasePlayerRecord():
def __init__(self, team):
self.team = team

class bz_PlayerJoinPartEventData_V1 (bz_EventData):
def __init__(self, part, team):
if part:
super().__init__(bz_ePlayerPartEvent)
else:
super().__init__(bz_ePlayerJoinEvent)
self.record = bz_BasePlayerRecord(bz_eTeamType(team))

# events handling

eventHandler = []
def RegisterEvent (eventType, plugin):
eventHandler.append((eventType, plugin))

def RemoveEvent (eventType, plugin):
eventHandler.remove((eventType, plugin))

def FlushEvents(plugin):
for couple in eventHandler:
if couple[1] == plugin:
eventHandler.remove(couple)

def callEvents(event):
for couple in eventHandler:
if not isinstance(event, bz_EventData):
break
if couple[0] != event.eventType:
continue
event = couple[1].Event(event)
return event
Loading
Loading