Code organization

Yo!


First, I'm not sure if this is the correct place to post this.


I've been working on a few scripts for a roguelike, and until now I organized my code by plugin functionality. This is the same way we usualy do when using third party plugins for specific purposes, like:

  • Lets say I want a mini map on the map scene, I'll add a plugin for that.
  • Then I want to have fog of war on my map, I'll add a fog of war plugin.
  • Then I want random map generation and will add a plugin for that aswell.
  • And in the end, I want a HUD to be shown on the map scene... yes, another plugin



Note that all the plugins are related to the map, and they probably overrides a few functions that are common for each other. And also, the HUD plugin is related to the mini map plugin.


In this particular case, I'm woking on all the plugins myself and so I thought that I'm probably able to put it all together in an organized way so that all the engine works together as a whole.


But the thing is RPG Maker has already its design pattern to be easy to import plugins, and with that in mind I want to ask you: how do you think that would be a good way to organize your code when working with lots of related modifications? How do you do that if you do?
I think you're doing it the right way @Lantiz; the organization of each feature should be a plugin of it's own design. 
You could possibly lump them all into one giant plugin, but if they're seperate, a person can use each feature on it's own if you ever decided to share em. 


Also, it's a lot less reading with multiple than going through one single source file with lots of different working parts. Long story short, you're on the right track.
Oh I see your point.


Actually I din't mean to make it one file only, I meant to organize the project as a whole but not limiting to one file. It's just a way to put it tho.


Thanks for your words, sometimes I feel like using a bunch of plugins is kind of messy. Just me?
Nah it can be, when you have a lot in one game, looking at the PluginManager can be scary. Lol
Here is what I do for plugin manager organization :

Spoiler

plugin-manager-project.png



Sometimes I want to make a modification to an object, scene, or window but I do not want or need to create a full-fledged plugin. So I make miniature edits. Underneath the minor edits are the remainder of the plugins. I believe that creating one plugin per feature is best (although grouping similar features is also a good idea). I do not think that adding a bunch of plugins in is messy as long as you have some semblance of organization.
@Exhydra now that's exactly what I was looking for.


Sometimes a plugin file gets too big and I have to scroll it up and down to find something, and this can be a pain...


Looks like going back to the old RPGM style would fit nicelly (like the engine was organized in Ace I mean).
Well for someone wondering... latelly I found out that the plugin approach is still better.


The reason is simple: you can disable features on the editor. This is really useful when you are trying to find the reason for a bug sometimes.
Well for someone wondering... latelly I found out that the plugin approach is still better.


The reason is simple: you can disable features on the editor. This is really useful when you are trying to find the reason for a bug sometimes.



Exactly right, it's also always nice to have things organized in modular groups. 


4414f0a6c1.png
Yep.


Still bothers me to override the same classes in different files tho.


Also overriding the same function many times.


Anyway, looks like you got some neat plugins there.
Yep.


Still bothers me to override the same classes in different files tho.


Also overriding the same function many times.


Anyway, looks like you got some neat plugins there.



Ya well overriding functions is weird but it does allow for some easy overrides or inheritance. 


Also thanks, I'm glad you think they look cool. 
 
It sounds like you want to do inheritance.  I'm brand new to RPG Maker so I'm not sure if the way the javascript files are set up that it would prevent you from doing that?  Javascript is pretty flexible so it seems like you could refactor the files in a way that they could inherit from a base map object and thus would have access to the common functions you mentioned.
@Abrasive


Hi! Welcome!


It's not about inheritance, actually. RM makes good use of inheritance already, and so we do use it a lot.


The "problem" here (which is not a problem) is about the fact that it loads plugins by files so the developer can turn on/off the features of a given plugin anytime he want.


And by "problem" I mean it's when we are working on many aspects of the engine, making changes is many parts. By doing that we end up with code from the same class in different files, and overriding the same functions in many places.


Talking about organization, I find it to be troublesome, but in the end, being able to turn on/off plugins comes in hand when debugging.


Maybe we just need another way to handle the enabling/disabling. Or not at all...
@Lantiz
Thank you for the welcome 🙂


Now that you have elaborated some more it possibly sounds like a separation of concerns problem where things end up being tied to too many places.  Once I get rolling with RPG development I'm sure to run into the same issues.


To me, this is a red flag that I need to organize things differently, especially the latter portion of the sentence:

By doing that we end up with code from the same class in different files, and overriding the same functions in many places.



Sometimes callbacks can mitigate this so instead of overriding the same functions you tell the code to call back to a single place for the function.  Every project is different though, which is why architecture is a difficult problem to come up with solutions everyone can use.
@Abrasive


Yeah.


They did an awesome job tho.


RPG Maker has "it's own way" of doing that, and it was translated nicelly so the people can be confortable with updates... it's comming from ruby (RGSS) to Javascript.


Also end users who does not code can keep using the engine the way they learned back when they started using scripts in their games.

Original thread: https://forums.rpgmakerweb.com/threads/code-organization.68873/