views:

46

answers:

2

I'm designing (and ultimately writing) a system in Django that consists of two major components:

  1. A Game Manager: this is essentially a data-entry piece. Trusted (non-public) users will enter information on a gaming system, such as options that a player may have. The interface for this is solely the Django admin console, and it doesn't "do" anything except hold the information.
  2. A Character Manager: this is the consumer of the above data. Public users will create characters in the role-playing systems defined above, pulling from the options entered by those trusted users. This is a separate app in the project from Django's standpoint.

There's one piece I'm not sure where to put, however, and that is the "rules" that are associated with each game. Essentially, for each game put into the first app, there are a sets of prerequisites, limitations, and other business logic specific to that game. (There's also similarly-structured logic that will be common to all games.) The logic is going to be coded in Python, rather than user-entered.

That logic is used in the process of validating a particular character, but is associated with a particular game and will need to be swapped out dynamically. Is it a separate app, or should it be validation tied to the forms of the Character Manager? Or can it be both?

This is the first Django app I've built from scratch (rather than chewing on someone else's code), and I'm new to the Python philosophy to boot, so I'm all ears on this.

Thanks in advance.

+1  A: 

I would create subdirectory named rules in the app with game logic and there create module named after each game, that you would like serve. Then create a common interface for those modules, that will be utilized by your games and import proper rules module by name (if your game is called adom, then simply __import__('rules.adom') inside the main game engine and call game specific methods.

If your games don't create own models and views, then there seems to be no reason to create specific app for each of them. This is a delicate matter, because code used is based on data stored in the database. Didn't you think about storing additional gaming scripts inside the database to and then exec them? This seems more natural: a game is set of data and additional scripts associated with that game.

gruszczy
The games component does have its own set of models, but not views (other than the admin console), and all game data is entered in a single app ("Game Manager"), not in separate apps per game. The character side will have separate models and views from the game side, but will pull some data from that side.I thought about the gaming scripts approach, but was concerned about potential speed issues with that many DB calls and execs. The character side will validate using AJAX calls for each change made. Is that a non-issue, in your opinion?
Melissa Avery
Well, from what I understand, those gaming scripts can and should be easily cached. You don't need to retrieve them every time from the database - you can just store required scripts and exec them when required. Only every so often you should update them. It simply doesn't feel right, that you have some code, that usage is really dependant on the data in the database. It's not part of your codebase, rather it's also game specific data.
gruszczy
Ahh, okay. That makes a lot of sense.
Melissa Avery
Glad, I could help. I was once RPG fan too :-)
gruszczy
+1  A: 

the "rules" that are associated with each game.

for each game put into the first app, there are a sets of prerequisites, limitations, and other business logic specific to that game.

That's part of the game app, then.

There's also similarly-structured logic that will be common to all games.

That's part of the game app, then.

That logic is used in the process of validating a particular character, but is associated with a particular game.

Correct. That's part of the game app, then. Characters are associated with one or more games.

should it be validation tied to the forms of the Character Manager?

The Character Forms can have data cleansing rules which depend on a Game.

S.Lott