Jeckel
Great Reverend
JDataKit Modding Utility
This mod component is not ment for stand alone use. If you simply add this mod in by itself
there will be no ingame changes.
This comp is intended as a wrapper to Stone-D's SdToolKit. Instead of importing the methods from SdToolKit, you would instead import this mod's methods. Its main function is that the mod adds another level of storage to SdToolKit. It also automaticly stores the given data under a given unit. The code is pretty well documented and explained in the files so check it out for your self.
One final note. I had to put a new function in the SdToolKit file. It is surounded by
## JDataKit Start ##
and
## JDataKit End ##
and is also been added to the SdToolKit's readme file.
This modcomp comes with Dr Elmer Jiggle's CustomEventManager and a CvJDataKitEventManager.py file which sets the onUnitCreated and onUnitLost events. These two events set and remove Types dictionaries on all units so that types and stats can mearly be set and gotten.
The meat of the modcomp and the only file that is nessesary, besides SdToolKit.py, is CvJDataStorageUtils.py.
There are three important terms that are used in this code. They are Type, Stat, and Value. A Type is made up of a Python Dictionary. Each Type dictionary contains 0 or more Stats and each Stat has a Value. Throughout the code and the info below, TypesDict and similar referres to the primary dictionary for each unit that contains the individual sub dictionarys of Stat/Value pairs.
For example take the TypesDict
{ "Physical" : { "Strength" : 4, "Dexterity" : 2, "Stamina" : 3 }, "Social" : { "Appearance" : 3, "Manipulation" : 1, "Charisma" : 4 } }
In that example the entire dictionary would be the primary dictionary that is stored on a specific pUnit object. Each key of the primary dictionary, the "Physical" and "Social" keys, is termed a Type. The value of each Type has set as its value a dictionary, this sub dictionary is termed a StatsDict or a dictionary of Stat/Value pairs. Both Types and Stats should be strings as other kinds of data may have unforseen results. The python dictionary value of each Stat is termed Value and is being referred to when the capitallized version of the word is used. Though I origionally wrote this with the intention of storing only integars and maybe strings as Values, I don't forsee any problems storing any kind of data that would be normally exceptable by SdToolKit.
Also important to note. While I use pUnit in my examples, any Civ obj that has the methods pObj.getOwner() and pObj.getID() can be used to store data in a data pool unique to that object. If at anypoint the owner or ID of the object changes, neither SdToolKit nor my wrapper code transfers stored data, all this must be done by the modder.
This files methods are listed and explained below.
####################################################
The reason I wrote this utility to wrap around SdToolKit is the problem of transfering the stored data from one unit object to another, say when its allegiance changes in the UnitAllegiance Mod. In game terms the unit didn't die, it is the same unit, just owned by someone else, but in code terms the old unit (and all the stored data for it) are gone. For example, that units religions from the JUnitReligion would be gone and lost forever unless I planned for allegiance change in the religion mod or religion in the allegiance mod. Neither of wich is exceptable.
Hense I wrote this. Now if the religion mod sets the religions with JDataKit, then the allegiance mod, or any mod that uses different unit objects for the same ingame unit, can use JDataKit to get that units intire data and put it on the new unit obj.
I will be going over my previous mods as I get time and transfering them to use this storage structure. I also am finishing up some addons for this that will provide more specific options and functions for CyUnits and auto setting of data on them. Don't know if anyone else will find use of this, but its out there none the less and will make my life easyer. Use as you will.
File: JDataKit_v0.11.zip
Compatible: Civ4 v1.61 and Warlords
Mod Folder: Mods\JDataKit
Released: October 10, 2006
Size: 20.4 kb
CivFanatics: JDataKit Modcomp v0.11 File Now Available
This mod component is not ment for stand alone use. If you simply add this mod in by itself
there will be no ingame changes.
This comp is intended as a wrapper to Stone-D's SdToolKit. Instead of importing the methods from SdToolKit, you would instead import this mod's methods. Its main function is that the mod adds another level of storage to SdToolKit. It also automaticly stores the given data under a given unit. The code is pretty well documented and explained in the files so check it out for your self.

One final note. I had to put a new function in the SdToolKit file. It is surounded by
## JDataKit Start ##
and
## JDataKit End ##
and is also been added to the SdToolKit's readme file.
This modcomp comes with Dr Elmer Jiggle's CustomEventManager and a CvJDataKitEventManager.py file which sets the onUnitCreated and onUnitLost events. These two events set and remove Types dictionaries on all units so that types and stats can mearly be set and gotten.
The meat of the modcomp and the only file that is nessesary, besides SdToolKit.py, is CvJDataStorageUtils.py.
There are three important terms that are used in this code. They are Type, Stat, and Value. A Type is made up of a Python Dictionary. Each Type dictionary contains 0 or more Stats and each Stat has a Value. Throughout the code and the info below, TypesDict and similar referres to the primary dictionary for each unit that contains the individual sub dictionarys of Stat/Value pairs.
For example take the TypesDict
{ "Physical" : { "Strength" : 4, "Dexterity" : 2, "Stamina" : 3 }, "Social" : { "Appearance" : 3, "Manipulation" : 1, "Charisma" : 4 } }
In that example the entire dictionary would be the primary dictionary that is stored on a specific pUnit object. Each key of the primary dictionary, the "Physical" and "Social" keys, is termed a Type. The value of each Type has set as its value a dictionary, this sub dictionary is termed a StatsDict or a dictionary of Stat/Value pairs. Both Types and Stats should be strings as other kinds of data may have unforseen results. The python dictionary value of each Stat is termed Value and is being referred to when the capitallized version of the word is used. Though I origionally wrote this with the intention of storing only integars and maybe strings as Values, I don't forsee any problems storing any kind of data that would be normally exceptable by SdToolKit.
Also important to note. While I use pUnit in my examples, any Civ obj that has the methods pObj.getOwner() and pObj.getID() can be used to store data in a data pool unique to that object. If at anypoint the owner or ID of the object changes, neither SdToolKit nor my wrapper code transfers stored data, all this must be done by the modder.
This files methods are listed and explained below.
####################################################
Spoiler :
CvJDataStorageUtils.py
initTypesDict(pUnit, dictInit=None)
Returns True on success, False on failure.
This method sets the initial types dictionary on the unit. You can give an optional dictionary that will be used instead of the default one.
initTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This will initiate a blank StatsDict under the key xType. This StatsDict can then have Stat/Value pairs written to it with the set methods below.
########################
# Verification methods #
########################
hasTypesDict(pUnit)
Returns True on success, False on failure.
Tells you if the unit has the primary dictionary of Types set on it.
hasTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This takes a Type and tells you if the offered unit has a dictionary of Stats listed under that Type.
hasTypeStat(pUnit, xType, xStat):
Returns True on success, False on failure.
This takes both a Type and a Stat and tells if the unit has that Stat.
###################
# The set methods #
###################
setTypeStatsDict(pUnit, xType, dictStats=None)
Returns True on success, False on failure.
This takes a Type and an optional python dictionary containing Stat/Value pairs. If the optional dictionary is not provided then the Type's StatsDict will be set blank. If the optional dictionary is provided then it will replace the current Type's StatsDict. Note if the Type does not exist, this method will auto initTypeStatsDict() for you and then set the value as normal.
setTypeStat(pUnit, xType, xStat, xStatValue=None)
Returns True on success, False on failure.
This works much like the other set, but it requires a valid Type and will NOT auto create one. Stat does not have to exist yet, and if it does the current value will be overwritten by xStatValue. If xStatvalue is left blank or set to None then the Value of Stat will be set to the integar 0.
######################
# The delete methods #
######################
Note: All the delete methods return True if given nonexistant Types or Stats.
delTypesDict(pUnit)
Returns True on success, False on failure.
This will remove all JDataKit stored data. It will NOT effect in any way other data stored by SdToolKit.
delTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This will remove a Type and all the Stat/Value pairs in its dictionary.
delTypeStat(pUnit, xType, xStat)
Returns True on success, False on failure.
This will remove a single Stat/Value pair from a Type's StatsDict.
###################
# The get methods #
###################
getDataIDStr(pObj=None)
This is intended for internal use and merely returns a unique ID string for a given CyObject.
getUnitStatsStrType_StrStatList(pUnit, strDelim="_", bStatsTypeFirst=True)
I wrote this just for fun and to test some things for a non Civ project.
What it does is returns a list of deliminated TYpe/Stat pairs. So using the example above, this function would return a python list object, ["Physical"_"Strength", "Physical"_"Dexterity", "Physical"_"Stamina", "Social"_"Appearance", "Social"_"Manipulation", "Social"_"Charisma"].
getTypesDict(pUnit)
Returns a dictionary obj on success, False on failure.
This will return the entire TypesDict of the given unit.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
getTypeStatsDict(pUnit, xType)
Returns a dictionary obj on success, False on failure.
This will return the StatsDict for a given Type.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
getTypeStat(pUnit, xType, xStat)
Returns None on Failure.
This will give you the Value of the given Stat.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
initTypesDict(pUnit, dictInit=None)
Returns True on success, False on failure.
This method sets the initial types dictionary on the unit. You can give an optional dictionary that will be used instead of the default one.
initTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This will initiate a blank StatsDict under the key xType. This StatsDict can then have Stat/Value pairs written to it with the set methods below.
########################
# Verification methods #
########################
hasTypesDict(pUnit)
Returns True on success, False on failure.
Tells you if the unit has the primary dictionary of Types set on it.
hasTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This takes a Type and tells you if the offered unit has a dictionary of Stats listed under that Type.
hasTypeStat(pUnit, xType, xStat):
Returns True on success, False on failure.
This takes both a Type and a Stat and tells if the unit has that Stat.
###################
# The set methods #
###################
setTypeStatsDict(pUnit, xType, dictStats=None)
Returns True on success, False on failure.
This takes a Type and an optional python dictionary containing Stat/Value pairs. If the optional dictionary is not provided then the Type's StatsDict will be set blank. If the optional dictionary is provided then it will replace the current Type's StatsDict. Note if the Type does not exist, this method will auto initTypeStatsDict() for you and then set the value as normal.
setTypeStat(pUnit, xType, xStat, xStatValue=None)
Returns True on success, False on failure.
This works much like the other set, but it requires a valid Type and will NOT auto create one. Stat does not have to exist yet, and if it does the current value will be overwritten by xStatValue. If xStatvalue is left blank or set to None then the Value of Stat will be set to the integar 0.
######################
# The delete methods #
######################
Note: All the delete methods return True if given nonexistant Types or Stats.
delTypesDict(pUnit)
Returns True on success, False on failure.
This will remove all JDataKit stored data. It will NOT effect in any way other data stored by SdToolKit.
delTypeStatsDict(pUnit, xType)
Returns True on success, False on failure.
This will remove a Type and all the Stat/Value pairs in its dictionary.
delTypeStat(pUnit, xType, xStat)
Returns True on success, False on failure.
This will remove a single Stat/Value pair from a Type's StatsDict.
###################
# The get methods #
###################
getDataIDStr(pObj=None)
This is intended for internal use and merely returns a unique ID string for a given CyObject.
getUnitStatsStrType_StrStatList(pUnit, strDelim="_", bStatsTypeFirst=True)
I wrote this just for fun and to test some things for a non Civ project.
What it does is returns a list of deliminated TYpe/Stat pairs. So using the example above, this function would return a python list object, ["Physical"_"Strength", "Physical"_"Dexterity", "Physical"_"Stamina", "Social"_"Appearance", "Social"_"Manipulation", "Social"_"Charisma"].
getTypesDict(pUnit)
Returns a dictionary obj on success, False on failure.
This will return the entire TypesDict of the given unit.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
getTypeStatsDict(pUnit, xType)
Returns a dictionary obj on success, False on failure.
This will return the StatsDict for a given Type.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
getTypeStat(pUnit, xType, xStat)
Returns None on Failure.
This will give you the Value of the given Stat.
Note: This method requires the sdGetEntity method added to the SdToolKit file and will not function without it.
The reason I wrote this utility to wrap around SdToolKit is the problem of transfering the stored data from one unit object to another, say when its allegiance changes in the UnitAllegiance Mod. In game terms the unit didn't die, it is the same unit, just owned by someone else, but in code terms the old unit (and all the stored data for it) are gone. For example, that units religions from the JUnitReligion would be gone and lost forever unless I planned for allegiance change in the religion mod or religion in the allegiance mod. Neither of wich is exceptable.
Hense I wrote this. Now if the religion mod sets the religions with JDataKit, then the allegiance mod, or any mod that uses different unit objects for the same ingame unit, can use JDataKit to get that units intire data and put it on the new unit obj.
I will be going over my previous mods as I get time and transfering them to use this storage structure. I also am finishing up some addons for this that will provide more specific options and functions for CyUnits and auto setting of data on them. Don't know if anyone else will find use of this, but its out there none the less and will make my life easyer. Use as you will.

File: JDataKit_v0.11.zip
Compatible: Civ4 v1.61 and Warlords
Mod Folder: Mods\JDataKit
Released: October 10, 2006
Size: 20.4 kb
CivFanatics: JDataKit Modcomp v0.11 File Now Available