Guest User

Untitled

a guest
Jun 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. # ..PremiumMod/libs/baseclass.py
  2.  
  3. import es
  4. import cfglib
  5. from PremiumMod.libs.constant import CFG_PATH, INI_PATH
  6. from PremiumMod.libs.database import setup_dict
  7.  
  8.  
  9.  
  10. #These shouldn't be here, but imported from PremiumMod or somewhere you keep constants
  11.  
  12.  
  13. if not CFG_PATH.isdir():
  14.     CFG_PATH.mkdir()
  15. if not INI_PATH.isdir():
  16.     INI_PATH.mkdir()
  17. ##
  18.  
  19. class FeatureBase:
  20.     def __init__(self):
  21.         self.name = self.__class__.__module__.split('.')[~0] #This is the name of the file
  22.  
  23.         self.module = __import__(self.__class__.__module__).features.__dict__[self.name] #This gets the module (eg. for registering events)
  24.  
  25.         self._featurename = {'en':self.name}
  26.         self._featuredescription = {'en':self.name}
  27.  
  28.     def __getattr__(self, attr):
  29.         if attr == 'cvar':
  30.             return lambda name, default, description='': self.cfg.cvar('pm_'+(self.name.lower())+'_'+name, default, description)
  31.  
  32.         elif attr in ('addGroup', 'addValueToGroup'):
  33.             return getattr(self.ini, attr)
  34.  
  35.         raise AttributeError, attr
  36.  
  37.     def __load__(self, late): #Do player specific stuff
  38.         pass
  39.  
  40.     def __unload__(self): #Do player specific stuff/cleanup
  41.         pass
  42.  
  43.     def setName(self, name=None):
  44.         if name is None:
  45.             self._featurename = self.ini['name']
  46.             return
  47.  
  48.         self._featurename['en'] = name
  49.  
  50.     def setDescription(self, description=None):
  51.         if name is None:
  52.             self._featuredescription = self.ini['description']
  53.             return
  54.         self._featuredescription['en'] = name
  55.  
  56.     def iniConfig(self):
  57.         v = CFG_PATH.joinpath('features')
  58.         if not v.isdir():
  59.             v.mkdir()
  60.         self.cfg = cfglib.AddonCFG(v.joinpath(self.name+'.cfg'))
  61.  
  62.     def exeConfig(self):
  63.         self.cfg.write()
  64.         self.cfg.execute()
  65.  
  66.     def iniLanguage(self):
  67.         v = INI_PATH.joinpath('features')
  68.         if not v.isdir():
  69.             v.mkdir()
  70.         self.ini = cfglib.AddonINI(v.joinpath(self.name+'.ini'))
  71.  
  72.     def exeLanguage(self):
  73.         self.ini.write()
  74.  
  75.     def hasFeature(self, steamid):
  76.         #if setup_dict[steamid].get(self.name, False):
  77.         #return True
  78.         return setup_dict[steamid].get(self.name, False) #You're gonna have to replace this (my_dict-thing)
  79.  
  80.  
  81.     def registerEvent(self, event, callback):
  82.         es.addons.registerForEvent(self.module, event, callback)
  83.  
  84.     def unregisterEvent(self, event):
  85.         es.addons.unregisterForEvent(self.module, event)
  86.  
  87.     def onFeatureEnabled(self, userid): #Gets called when <userid> enabled the feature
  88.         pass
  89.  
  90.     def onFeatureDisabled(self, userid): #Gets called when <userid> disabled the feature
  91.         pass
Add Comment
Please, Sign In to add comment