Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. Directory Structure
  2.  
  3.  
  4. o mtricks/mtricks.py
  5. o libs/players/__init__.py
  6. o libs/players/cache.py
  7. o libs/menus/popups.py
  8. o libs/menus/hudhints.py
  9. o libs/triggers/__init__.py
  10. o libs/triggers/file_handler.py
  11. o libs/tricks/__init__.py
  12. o libs/tricks/file_handler.py
  13. o libs/database/__init__.py
  14.  
  15. o mtricks.py
  16. o Functions:
  17. All events such as player_hurt, player_move go here etc. All imports will be done here e.g:
  18. from mtricks.libs.players import players # players is a dict containing Player objects
  19. from mtricks.libs.players.cache import PlayerCache
  20. from mtricks.libs.menus.popups import ACP
  21. from mtricks.libs.menus.hudhints import ACH
  22. ...
  23. Contain the basic load / unload of your mod
  24. This file should be one of the smallest files, it shouldn't be doing much really apart from responding to
  25. events. All this mod should do is something like this:
  26. def player_hurt(event_var):
  27. players[event_var['userid']].heal(50) # some function regarding the player
  28. This file is NOT for telling "How to heal" but rather telling the file that knows how to do it
  29. (in this case the players/__init__.py file) to do the heal. Rather than implement the code here,
  30. we are simply delegating the work to another library to do. This makes the main file easy and
  31. manageable to see what's happening. When you look back at it in the future you can get a generic
  32. idea of what the script is doing. If you need to see more in depth you can look in the libraries to
  33. see HOW the player is healed for example.
  34.  
  35. o libs/players/__init__.py
  36. o Imports:
  37. from mtricks.libs.players.cache import PlayerCache
  38. o Classes
  39. class PlayerObject(object):
  40. This class will be instanted for each connected player. This will store
  41. information about a player, such as their health, tricks performed and
  42. everything else. This object will also create another variable called
  43. cache:
  44.  
  45. self.cache = PlayerCache(self.userid)
  46.  
  47. The cache variable will be explained below and implemented in the
  48. libs/players/cache.py file.
  49.  
  50. class PlayerManager(object):
  51. This class is simply here to "act" like a dictionary. It will have a
  52. function called addPlayer which will add a player to the internal
  53. dictionary. The only reason we have this is to store the player's
  54. instances. We will only have 1 instance of this class called "players"
  55. which is implemented in the global scope as so:
  56.  
  57. players = PlayerManager()
  58.  
  59. Then what we can do is say: players.addPlayer(2). What this will do
  60. is append an item to the internal dictionary with the value of that
  61. from the PlayerObject instance like so:
  62.  
  63. def addPlayer(self, userid):
  64. self.playerDict[userid] = PlayerObject(userid)
  65.  
  66. This means we can make a "customized" dictionary to hold our player
  67. instances.
  68.  
  69. o libs/players/cache.py
  70. o Imports:
  71. from mtricks.libs.database import getDatabase
  72. o Classes:
  73. class PlayerCache(object):
  74. This class will be here to pull information about a player from the
  75. database. All this does is create a "cache" of the databases values,
  76. i.e how many times a trick is performed:
  77.  
  78. self.tricksPerformed = 0
  79.  
  80. This way, every time we want to know how many tricks this user has
  81. performed, we simply call the local variable rather than invoke
  82. the database. For each variable, we will have 2 values, an old value
  83. and a current value, for example:
  84.  
  85. self.oldTricksPerformed = 0
  86. self.tricksPerformed = 0
  87.  
  88. We will always read the tricksPerformed and update that value. The
  89. oldTricksPerformed will be the value that the database holds. This
  90. way, we can have a "commit" function which tests if any values have
  91. changed: for example:
  92.  
  93. def commit():
  94. if self.tricksPerformed != self.oldTricksPerformed:
  95. # The user has changed the amount of tricks they have performed,
  96. # commit it to the database to save the changes to disk.
  97.  
  98. The commit function will be executed for each player directly before
  99. a database is commited (i.e at round_end).
  100.  
  101. o libs/menus/popups.py
  102. o Imports:
  103. from mtricks.libs.database import getDatabase
  104. o Classes:
  105. class ACP(object):
  106. This class will be here for automatic popup creations such as
  107. top10, trick's triggers, records, and player's settings
  108.  
  109. o libs/menus/hudhints.py
  110. o Imports:
  111. None
  112. o Classes:
  113. class ACH(object):
  114. This class will be here for automatic hudhints management, such as
  115. a looped hudhint, auto server messages, and other things
  116.  
  117. o libs/triggers/__init__.py
  118. o Imports:
  119. from mtricks.libs.triggers import file_handler
  120. o Classes:
  121. class Trigger(object):
  122. This class will be an object for a particular trigger, it will contains
  123. coordinates and other informations such as Backwards, HalfSideways, etc
  124.  
  125. o libs/triggers/file_handler.py
  126. o Imports:
  127. None
  128. o Classes:
  129. class TriggersManager(object):
  130. This class will pull info from a text file and build actual Trigger objects.
  131. In sense, this will turn stored info such as "1.00 1.123123 0.21432" into an actual Trigger object.
  132. This will also save the files in this method.
  133.  
  134. o libs/tricks/__init__.py
  135. o Imports:
  136. from mtricks.libs.tricks import file_handler
  137. o Classes:
  138. class Trick(object):
  139. This class will denote how a trick is performed such as triggers, combo, endsOn, etc.
  140.  
  141. o libs/tricks/file_handler.py
  142. o Imports:
  143. None
  144. o Classes:
  145. class TricksManager(object)
  146. This class will pull info from a text file and build actual Trick objects.
  147. This will turn stored info such as triggers, combo, endsOn, etc into an actual Trigger object.
  148. This will also save the files in this method.
  149.  
  150. o libs/database/__init__.py
  151. o Imports:
  152. None
  153. o Classes:
  154. class SQLiteManager(object):
  155. Contain all database information and methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement