Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Directory Structure
- o mtricks/mtricks.py
- o libs/players/__init__.py
- o libs/players/cache.py
- o libs/menus/popups.py
- o libs/menus/hudhints.py
- o libs/triggers/__init__.py
- o libs/triggers/file_handler.py
- o libs/tricks/__init__.py
- o libs/tricks/file_handler.py
- o libs/database/__init__.py
- o mtricks.py
- o Functions:
- All events such as player_hurt, player_move go here etc. All imports will be done here e.g:
- from mtricks.libs.players import players # players is a dict containing Player objects
- from mtricks.libs.players.cache import PlayerCache
- from mtricks.libs.menus.popups import ACP
- from mtricks.libs.menus.hudhints import ACH
- ...
- Contain the basic load / unload of your mod
- This file should be one of the smallest files, it shouldn't be doing much really apart from responding to
- events. All this mod should do is something like this:
- def player_hurt(event_var):
- players[event_var['userid']].heal(50) # some function regarding the player
- This file is NOT for telling "How to heal" but rather telling the file that knows how to do it
- (in this case the players/__init__.py file) to do the heal. Rather than implement the code here,
- we are simply delegating the work to another library to do. This makes the main file easy and
- manageable to see what's happening. When you look back at it in the future you can get a generic
- idea of what the script is doing. If you need to see more in depth you can look in the libraries to
- see HOW the player is healed for example.
- o libs/players/__init__.py
- o Imports:
- from mtricks.libs.players.cache import PlayerCache
- o Classes
- class PlayerObject(object):
- This class will be instanted for each connected player. This will store
- information about a player, such as their health, tricks performed and
- everything else. This object will also create another variable called
- cache:
- self.cache = PlayerCache(self.userid)
- The cache variable will be explained below and implemented in the
- libs/players/cache.py file.
- class PlayerManager(object):
- This class is simply here to "act" like a dictionary. It will have a
- function called addPlayer which will add a player to the internal
- dictionary. The only reason we have this is to store the player's
- instances. We will only have 1 instance of this class called "players"
- which is implemented in the global scope as so:
- players = PlayerManager()
- Then what we can do is say: players.addPlayer(2). What this will do
- is append an item to the internal dictionary with the value of that
- from the PlayerObject instance like so:
- def addPlayer(self, userid):
- self.playerDict[userid] = PlayerObject(userid)
- This means we can make a "customized" dictionary to hold our player
- instances.
- o libs/players/cache.py
- o Imports:
- from mtricks.libs.database import getDatabase
- o Classes:
- class PlayerCache(object):
- This class will be here to pull information about a player from the
- database. All this does is create a "cache" of the databases values,
- i.e how many times a trick is performed:
- self.tricksPerformed = 0
- This way, every time we want to know how many tricks this user has
- performed, we simply call the local variable rather than invoke
- the database. For each variable, we will have 2 values, an old value
- and a current value, for example:
- self.oldTricksPerformed = 0
- self.tricksPerformed = 0
- We will always read the tricksPerformed and update that value. The
- oldTricksPerformed will be the value that the database holds. This
- way, we can have a "commit" function which tests if any values have
- changed: for example:
- def commit():
- if self.tricksPerformed != self.oldTricksPerformed:
- # The user has changed the amount of tricks they have performed,
- # commit it to the database to save the changes to disk.
- The commit function will be executed for each player directly before
- a database is commited (i.e at round_end).
- o libs/menus/popups.py
- o Imports:
- from mtricks.libs.database import getDatabase
- o Classes:
- class ACP(object):
- This class will be here for automatic popup creations such as
- top10, trick's triggers, records, and player's settings
- o libs/menus/hudhints.py
- o Imports:
- None
- o Classes:
- class ACH(object):
- This class will be here for automatic hudhints management, such as
- a looped hudhint, auto server messages, and other things
- o libs/triggers/__init__.py
- o Imports:
- from mtricks.libs.triggers import file_handler
- o Classes:
- class Trigger(object):
- This class will be an object for a particular trigger, it will contains
- coordinates and other informations such as Backwards, HalfSideways, etc
- o libs/triggers/file_handler.py
- o Imports:
- None
- o Classes:
- class TriggersManager(object):
- This class will pull info from a text file and build actual Trigger objects.
- In sense, this will turn stored info such as "1.00 1.123123 0.21432" into an actual Trigger object.
- This will also save the files in this method.
- o libs/tricks/__init__.py
- o Imports:
- from mtricks.libs.tricks import file_handler
- o Classes:
- class Trick(object):
- This class will denote how a trick is performed such as triggers, combo, endsOn, etc.
- o libs/tricks/file_handler.py
- o Imports:
- None
- o Classes:
- class TricksManager(object)
- This class will pull info from a text file and build actual Trick objects.
- This will turn stored info such as triggers, combo, endsOn, etc into an actual Trigger object.
- This will also save the files in this method.
- o libs/database/__init__.py
- o Imports:
- None
- o Classes:
- class SQLiteManager(object):
- Contain all database information and methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement