daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jun 21st, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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__).skills.__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('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.AddonCFG(v.joinpath(self.name+'.ini'))
  71.  
  72.     def exeLanguage(self):
  73.         self.ini.write()
  74.  
  75.     def hasFeature(self, steamid):
  76.         return setup_dict[steamid].get(self.name, False) #You're gonna have to replace this (my_dict-thing)
  77.  
  78.     def registerEvent(self, event, callback):
  79.         es.addons.registerForEvent(self.module, event, callback)
  80.  
  81.     def unregisterEvent(self, event):
  82.         es.addons.unregisterForEvent(self.module, event)
  83.  
  84.     def onFeatureEnabled(self, userid): #Gets called when <userid> enabled the feature
  85.         pass
  86.  
  87.     def onFeatureDisabled(self, userid): #Gets called when <userid> disabled the feature
  88.         pass
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top