Dr Elmer Jiggle
King
- Joined
- Feb 25, 2003
- Messages
- 811
While developing my alerts mod, I had occasion to implement several Python modules that I think will be useful to a wider audience. The modules attached here are also available within that mod, but I've packaged them separately here to keep out the code that's unique to the alerts mod. This thread will also serve as a more appropriate place for questions about these modules.
I've included a brief description of each module below, but the code is extensively documented, so I'm not going to duplicate that here.
CvPath.py
Exposes variables that point to various interesting directories within the Civilziation 4 hierarchy. For example, there are variables for the install directory, the user directory, and the complete Python search path.
CvConfigParser.py
Provides convenient INI file handling. Usage is as simple as
Advantages of INI files over other approaches such as embedding the settings directly in Python or using an XML file include
CvCustomEventManager.py
Implements an extensible event manager. If multiple mods exist that all override the default event manager, you can simply register their needs with calls such as
Enjoy.
Changes:
DrEJlib.zip
I've included a brief description of each module below, but the code is extensively documented, so I'm not going to duplicate that here.
CvPath.py
Exposes variables that point to various interesting directories within the Civilziation 4 hierarchy. For example, there are variables for the install directory, the user directory, and the complete Python search path.
CvConfigParser.py
Provides convenient INI file handling. Usage is as simple as
Code:
config = CvConfigParser.CvConfigParser("Foo.ini")
# default to 5 if not specified in the .INI file
myInt = config.getint("My Section", "My Int Option", 5)
Advantages of INI files over other approaches such as embedding the settings directly in Python or using an XML file include
- Users tend to be less intimidated by INI files
- Users tend to be less likely to completely mess up an INI file
- The game's anti-cheating mechanism prevents editing of mod source files but not INI files, so this method is compatible with Game of the Month
CvCustomEventManager.py
Implements an extensible event manager. If multiple mods exist that all override the default event manager, you can simply register their needs with calls such as
Code:
em1.addEventHandler("cityGrowth", em1.onCityGrowth)
em1.addEventHandler("cityDoTurn", em1.onCityDoTurn)
em2.addEventHandler("cityGrowth", em2.onCityGrowth)
Enjoy.
Changes:
- 2006-Aug-11
- Updated for Warlords compatibility.
- 2006-May-1, v1.4
- Added validity checking for event types in the add, remove, and setEventHandler functions. An exception is thrown if the event type string is incorrect.
- Added a setPopupHandler function for defining new popup dialog handlers.
- 2006-Mar-12, v1.3
- Fixed a bug with determining the user directory when the installation directory has been renamed. Thanks to 12monkeys
- 2006-Feb-28, v1.2
- Fixed the search path for .INI files. The parser was searching the Assets directories instead of their respective parent directories. Thanks to jray
- Restored the 6 Boolean state flags to the event handler front end. Thanks to jray
- 2006-Feb-2, v1.1
- Added the CvModName feature to CvConfigParser to allow discovery of the active mod name under certain circumstances.
- Fixed exception handling in INI file reader.
DrEJlib.zip