At the moment it's in a proof-of-concept state. The idea of this project is to extend module system in a way that makes scripts easier to understand, comfortable to write but still maintain compability with the original python code.
So the first thing that I made was to define a wrapper around Troop "class". We don't actually have classes in module system since it is procedure-oriented, but we now that troop instances exist, right? It might be somewhat difficult to explain the point, let's see an example instead.
Suppose we want to give some falchions to a looter. We would write such statement in our code:
But with our wrapper we can express the same statement this way:
Now it looks more "object oriented". T is our troop wrapper class. The trick is that this statement actually evaluates to the same touple from previous case so process_* scripts can't see the difference.
There are 2 main advantages of wrappers:
1) The code becomes easier to read and understand.
2) It gives us a way to exploit advanced code assist features of python script editors. I use pydev(http://www.pydev.org/) myself, for example.
I've already created definitions for most troop related operations. To use them you can download and import this python file: http://warband-sugar.googlecode.com/files/sugar_extras.py
If the idea is accepted by the community, I'll continue with defining wrappers for other classes of instances and may introduce more syntax sugar.
If you would like to contribute, join project at http://code.google.com/p/warband-sugar/
Feedback is required anyway
P.S. I haven't been modding M&B for a while so have no idea if there were any similiar things here. I'd appreciate if you pointed them out in case there were.
So the first thing that I made was to define a wrapper around Troop "class". We don't actually have classes in module system since it is procedure-oriented, but we now that troop instances exist, right? It might be somewhat difficult to explain the point, let's see an example instead.
Suppose we want to give some falchions to a looter. We would write such statement in our code:
Code:
(troop_add_items, "trp_looter", "itm_falchion", 10),
Code:
T("looter").add_items("itm_falchion", 10),
There are 2 main advantages of wrappers:
1) The code becomes easier to read and understand.
2) It gives us a way to exploit advanced code assist features of python script editors. I use pydev(http://www.pydev.org/) myself, for example.
Code:
class T:
def __init__(self, ID):
if (ID[0] == ":") or (ID[0] == "$"):
self.ID = ID
else:
self.ID = "trp_" + ID
def add_items(self, item, number):
return(troop_add_items, self.id, item, number)
I've already created definitions for most troop related operations. To use them you can download and import this python file: http://warband-sugar.googlecode.com/files/sugar_extras.py
If the idea is accepted by the community, I'll continue with defining wrappers for other classes of instances and may introduce more syntax sugar.
If you would like to contribute, join project at http://code.google.com/p/warband-sugar/
Feedback is required anyway
P.S. I haven't been modding M&B for a while so have no idea if there were any similiar things here. I'd appreciate if you pointed them out in case there were.