Shiggs713
Immortal
Hi all, I'm having some troubles merging these two files, and actually making it work. Its two event managers, one from the mongol camp mod, and another from a "barebones" north america mod, which has dynamic winter. Kevinman made it especially for the ACW mod, and I'd really like to keep both dynamic winter and the camp unit.
the two files in question are the eventmanagers for both "mods".
I've already merged the import calls but thats it.
here's WinterModEventManager.py, its the one I want to keep;
and here's the one I want to merge with winterModEventManager, its just regular old CvCustomEventManager.py;
thanks anyone for your help,
Shiggs
the two files in question are the eventmanagers for both "mods".
I've already merged the import calls but thats it.
here's WinterModEventManager.py, its the one I want to keep;
Code:
##-------------------------------------------------------------------
## Tests winter freeze global map change
##-------------------------------------------------------------------
from CvPythonExtensions import *
import CvUtil
import CvEventManager
import WinterMod
import IceMod
import MongolCamp
gc = CyGlobalContext()
class WinterEventManager(CvEventManager.CvEventManager):
def __init__(self):
CvEventManager.CvEventManager.__init__(self)
self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")
self.TERRAIN_PLAINS = gc.getInfoTypeForString("TERRAIN_PLAINS")
self.TERRAIN_SNOW = gc.getInfoTypeForString("TERRAIN_SNOW")
self.TERRAIN_TUNDRA = gc.getInfoTypeForString("TERRAIN_TUNDRA")
self.TERRAIN_GRASSTHINSOIL = gc.getInfoTypeForString("TERRAIN_GRASSTHINSOIL")
self.TERRAIN_PLAINSARID = gc.getInfoTypeForString("TERRAIN_PLAINSARID")
self.TERRAIN_WASTELAND = gc.getInfoTypeForString("TERRAIN_WASTELAND")
def onBeginGameTurn(self, argsList):
CvEventManager.CvEventManager.onBeginGameTurn(self, argsList)
iGameTurn = argsList[0]
map = CyMap()
for x in range(map.getGridWidth()):
for y in range(map.getGridHeight()):
plot = map.plot(x, y)
IceMod.IceCover(plot)
WinterMod.SnowCover(plot)
WinterMod.SnowGraphics(plot)
WinterMod.TreeGraphics(plot)
and here's the one I want to merge with winterModEventManager, its just regular old CvCustomEventManager.py;
Code:
from CvPythonExtensions import *
import CvUtil
import CvEventManager
## Below are Sub-Eventmanagers
import MongolCamp
gc = CyGlobalContext()
class CvCustomEventManager(CvEventManager.CvEventManager, object):
CustomEvents = {}
def __init__(self, *args, **kwargs):
super(CvCustomEventManager, self).__init__(*args, **kwargs)
# map the initial EventHandlerMap values into the new data structure
for eventType, eventHandler in self.EventHandlerMap.iteritems():
self.setEventHandler(eventType, eventHandler)
# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
MongolCamp.MongolCamp(self)
def beginEvent( self, context, argsList=-1 ):
"Begin Event"
if(self.CustomEvents.has_key(context)):
return self.CustomEvents[context][2](argsList)
else:
return CvEventManager.CvEventManager.beginEvent(self, context, argsList)
def applyEvent( self, argsList ):
'Apply the effects of an event '
context, playerID, netUserData, popupReturn = argsList
if(self.CustomEvents.has_key(context)):
entry = self.CustomEvents[context]
# the apply function
return entry[1]( playerID, netUserData, popupReturn )
else:
return CvEventManager.CvEventManager.applyEvent(self, argsList)
def addCustomEventDefinition(self, eventType, eventDefinition):
self.CustomEvents[eventType] = eventDefinition
def removeCustomEventDefinition(self, eventType):
del self.CustomEvents[eventType]
def setCustomEventDefinition(self, eventType, eventDefinition):
self.CustomEvents[eventType] = eventDefinition
def addEventHandler(self, eventType, eventHandler):
"""Adds a handler for the given event type.
A list of supported event types can be found in the initialization
of EventHandlerMap in the CvEventManager class.
"""
self.EventHandlerMap[eventType].append(eventHandler)
def removeEventHandler(self, eventType, eventHandler):
"""Removes a handler for the given event type.
A list of supported event types can be found in the initialization
of EventHandlerMap in the CvEventManager class. It is an error if
the given handler is not found in the list of installed handlers.
"""
self.EventHandlerMap[eventType].remove(eventHandler)
def setEventHandler(self, eventType, eventHandler):
"""Removes all previously installed event handlers for the given
event type and installs a new handler .
A list of supported event types can be found in the initialization
of EventHandlerMap in the CvEventManager class. This method is
primarily useful for overriding, rather than extending, the default
event handler functionality.
"""
self.EventHandlerMap[eventType] = [eventHandler]
def setPopupHandler(self, eventType, popupHandler):
"""Removes all previously installed popup handlers for the given
event type and installs a new handler.
The eventType should be an integer. It must be unique with respect
to the integers assigned to built in events. The popupHandler should
be a list made up of (name, beginFunction, applyFunction). The name
is used in debugging output. The begin and apply functions are invoked
by beginEvent and applyEvent, respectively, to manage a popup dialog
in response to the event.
"""
self.Events[eventType] = popupHandler
def handleEvent(self, argsList):
"""Handles events by calling all installed handlers."""
self.origArgsList = argsList
flagsIndex = len(argsList) - 6
self.bDbg, self.bMultiPlayer, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[flagsIndex:]
eventType = argsList[0]
return {
"kbdEvent": self._handleConsumableEvent,
"mouseEvent": self._handleConsumableEvent,
"OnSave": self._handleOnSaveEvent,
"OnLoad": self._handleOnLoadEvent
}.get(eventType, self._handleDefaultEvent)(eventType, argsList[1:])
def _handleDefaultEvent(self, eventType, argsList):
if self.EventHandlerMap.has_key(eventType):
for eventHandler in self.EventHandlerMap[eventType]:
# the last 6 arguments are for internal use by handleEvent
eventHandler(argsList[:len(argsList) - 6])
def _handleConsumableEvent(self, eventType, argsList):
"""Handles events that can be consumed by the handlers, such as
keyboard or mouse events.
If a handler returns non-zero, processing is terminated, and no
subsequent handlers are invoked.
"""
if self.EventHandlerMap.has_key(eventType):
for eventHandler in self.EventHandlerMap[eventType]:
# the last 6 arguments are for internal use by handleEvent
result = eventHandler(argsList[:len(argsList) - 6])
if (result > 0):
return result
return 0
# TODO: this probably needs to be more complex
def _handleOnSaveEvent(self, eventType, argsList):
"""Handles OnSave events by concatenating the results obtained
from each handler to form an overall consolidated save string.
"""
result = ""
if self.EventHandlerMap.has_key(eventType):
for eventHandler in self.EventHandlerMap[eventType]:
# the last 6 arguments are for internal use by handleEvent
result = result + eventHandler(argsList[:len(argsList) - 6])
return result
# TODO: this probably needs to be more complex
def _handleOnLoadEvent(self, eventType, argsList):
"""Handles OnLoad events."""
return self._handleDefaultEvent(eventType, argsList)
thanks anyone for your help,
Shiggs