.:: Alex Erne :: PHP/MySQL & Unity3D/C# projects ::.
Recent news
* advertisement *
  19 June 2016 - Rewriting/optimizing parts of the code :: Posted in d20 project

With the d20 project growing more and more, I've also been thinking about some of the userfriendlyness that the plugin needs. As programmer of the project, I know all the ins & outs of the code and know why I've done some of the things that are in place. But I can imagine that a user of the plugin would have some questionmarks at some of the (current) code and choices I've made.

One of the examples of the (current) choices I've made is the way you add feats, classes and other stuff to your character. At this moment I'm simply calling a method to add one of these things from the code. Much like the following:
          d20Classes.AddClass(myChar, (int)d20Class.StrongHero, true);
While the first two parameters are pretty clear, the third one is not. Why add a boolean value there to tell if I want to add the class yes or no, while the method is called AddClass()? Well, that has to do with the internal workings of the method. I'm also using it to determine if a class is available to take, and then I should not add it to myChar
It's exactly that why I've taken an other look at how the code of the plugin shoudl behave. I want it to be 100% lear for the user of the plugin what's going on in the code without too much dabbling with the mechanics I'm using to let the code function flawlessly.

My first thought was to include these methods as part of the d20Character class, but looking at the number of methods that are already used to Add and Check data within the d20Character class is huge, and I'm only at about 75% of coding the d20 Modern RPG basic rules, with FX and Psionics to be added later as well. This would mean that the d20Character class would become one massive (memmory hogging:!:) class. And while one such class used would not matter a lot, in a RPG you need this class dozens (if not 100s) of times, because not only your main character is using it, but also most (all?) of the NPC characters that are out there.

As an alternative I figured to make these methods an extension (or rather someone on reddit reminded me of that ). And with the code of the method already there, all I have to do is add a very small extension for it, and the above example looks like:
          public static void AddClass(this d20Character myChar, int myClass) {
            d20Classes.AddClass(myChar, myClass, true);

This small extension makes it possible for me to make the same call now like:
A call that's a lot smaller and makes more sense. Afterall, you're now just simply telling to add the Strong Hero to myChar with one clear instruction without any odd stuff around it (like that boolean value). More importantly, for not being part of the d20Character class, the size of the class stays the same as it already is (which is already pretty big I must add )

Now I have to 'translate' all the methods that I've written in the past into these clear extensions. Though it's not a ot of work, I do need to go through most of my demo code again to see which methods I'm calling, make the extension code and then rewrite that demo code.

And while at it, you might have noticed that I'm also using a cast to int for the character class ((int)d20Classes.StrongHero). I'm using this because I have 3 different enums that are linked to the d20CharacterClass class. These enums hold the hero's occupation, the basic class and advanced class, and I'm musing to merge these 3 different enums into a big one so that this cast won't be required anymore either. I just have to take a close look at the code on how to implement it in the best and most efficient way...

Post A Comment!
* advertisement *
* advertisement *

This website is Copyright © 2009 - 2018 Alex Erné
PHP/MySQL coding by Alex Erné Copyright © 2009 - 2016 Alex Erné
...all rights reserved...

AE games™ and the AE games logo are Trademarks owned by Alex Erné
TetraGems™, Burst-a-Bubble™ and the Burst-a-Bubble logo are Trademarks owned by Alex Erné