EmperorFool
Deity
As a result of a conversation with davidlallen in this thread, I've started working on a method to make CvGameUtils modular as part of BUG. I'd like to get some feedback on my initial design from the modders that will be using it.
First a little background. CvGameUtils defines several callback functions used by the SDK via CvGameInterface. As a modder, you have a few options when overriding how CvGameUtils behaves.
First a little background. CvGameUtils defines several callback functions used by the SDK via CvGameInterface. As a modder, you have a few options when overriding how CvGameUtils behaves.
Note: I have written a separate tutorial for those unfamiliar with the process. My design depends on method 1 from that tutorial, so it will help to read that post.[/quote]
My design is similar to BugEventManager which is based on CvCustomEventManager by Dr. Elmer Jiggles. I have written a replacement for CvGameUtils called BugGameUtils which can dispatch callbacks to multiple subordinate modules that get registered by XML configuration files during the BUG initialization phase. As with BugEventManager, modders would never modify BugGameUtils nor CvGameInterfaceFile which connects it to BTS.
Example: AcquireCityGoldGameUtils
This example will change BTS so that when a player captures a city they always gain 1000. This will be very similar to method 1 from my tutorial.
1. As in method 1, create a new module containing your game utils class and add your modified callback functions as above. It's okay to subclass CvGameUtils, but it's no longer necessary. It will make no difference to BUG which will make merging mods built this way even easier.
2. Register your module with BUG. In BUG you create an XML file containing your options, events, shortcuts, etc. This step will require one additional line:
Because the names of the callback functions are determined by CvGameInterface.py and cannot be changed by the modder, BUG is able to detect all of your callback functions automatically.
My design is similar to BugEventManager which is based on CvCustomEventManager by Dr. Elmer Jiggles. I have written a replacement for CvGameUtils called BugGameUtils which can dispatch callbacks to multiple subordinate modules that get registered by XML configuration files during the BUG initialization phase. As with BugEventManager, modders would never modify BugGameUtils nor CvGameInterfaceFile which connects it to BTS.
Example: AcquireCityGoldGameUtils
This example will change BTS so that when a player captures a city they always gain 1000. This will be very similar to method 1 from my tutorial.
1. As in method 1, create a new module containing your game utils class and add your modified callback functions as above. It's okay to subclass CvGameUtils, but it's no longer necessary. It will make no difference to BUG which will make merging mods built this way even easier.
Code:
## AcquireCityGoldGameUtils.py
class AcquireCityGoldGameUtils:
def doCityCaptureGold(self, argsList):
return 1000
2. Register your module with BUG. In BUG you create an XML file containing your options, events, shortcuts, etc. This step will require one additional line:
Code:
<mod id="AcquireCityGold">
[B]<game-utils module="AcquireCityGoldGameUtils"/>[/B]
</mod>
Because the names of the callback functions are determined by CvGameInterface.py and cannot be changed by the modder, BUG is able to detect all of your callback functions automatically.