Advertisement
Guest User

BBot Template Example

a guest
Nov 28th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. from contextlib import contextmanager
  2. import sys
  3. import os
  4. sys.path.append(os.path.dirname(__file__))
  5.  
  6. from bbot_template_pb2 import BBotUI, BBotUIControl
  7.  
  8.  
  9. class BBotUIWizard:
  10.     def __init__(self, config):
  11.         self._config = config
  12.         self._ui = BBotUI()
  13.         self._parent_path = ''
  14.  
  15.     @contextmanager
  16.     def group(self, name):
  17.         ctrl = BBotUIControl()
  18.         ctrl.set_type(BBotUIControl.T_GROUP)
  19.         ctrl.set_caption(name)
  20.  
  21.         ui = self._ui
  22.         ui.add_controls(ctrl)
  23.         self._ui = ctrl
  24.  
  25.         try:
  26.             yield
  27.         finally:
  28.             self._ui = ui
  29.  
  30.     def textField(self, caption, defaultValue=None):
  31.         ctrl = BBotUIControl()
  32.         ctrl.set_type(BBotUIControl.T_STRING)
  33.         ctrl.set_caption(caption)
  34.         ctrl.set_str_value(defaultValue)
  35.         self._ui.add_controls(ctrl)
  36.  
  37.         # TODO: return current value from config
  38.         path = self._parent_path + '/' + caption
  39.         return self._config.get(path, defaultValue)       # 'Info/Build Mark'
  40.  
  41.     def comboBox(self, caption, options):
  42.         pass
  43.  
  44.     def comboBoxMulti(self, caption, options):
  45.         pass
  46.  
  47.  
  48. class Stage:
  49.     def __init__(self, name):
  50.         self._name = name
  51.         self._params = {}
  52.         self._stages = []
  53.         self.__setitem__ = self._params.__setitem__
  54.  
  55.  
  56. class BBotStagesWizard:
  57.     def __init__(self, config):
  58.         self._config = config
  59.         self._stages = []
  60.  
  61.     @contextmanager
  62.     def stage(self, name):
  63.         st = Stage(name)
  64.         lst = self._stages
  65.         lst.append(st)
  66.  
  67.         self._stages = st._stages
  68.         try:
  69.             yield st
  70.         finally:
  71.             self._stages = lst
  72.  
  73.  
  74.  
  75. # ------------------------------------------------------------------------------------------
  76.  
  77.  
  78. def applyTemplate(projInfo, config):
  79.     #
  80.     # Emit UI
  81.     #
  82.     ui = BBotUIWizard(config)
  83.  
  84.     with ui.group('Info'):
  85.         buildMark = ui.textField('Build Mark')
  86.  
  87.         if projInfo.workspace == 'HaloF2P':
  88.             defaultLevel = 'startup_lobby'
  89.         else:
  90.             defaultLevel = 'ui'
  91.         defaultLevel = ui.textField('Default Level', defaultLevel)
  92.  
  93.         scenes = ui.comboBoxMulti('Scenes List', projInfo.getSceneList())       # multiple selection
  94.  
  95.     with ui.group('Options'):
  96.         lightmapQuality = ui.comboBox('LM Quality', ['High', 'Medium', 'Low'])
  97.  
  98.     #
  99.     # Emit Stages
  100.     #
  101.     pr = BBotStagesWizard(config)
  102.  
  103.     with pr.stage('Perforce') as st:
  104.         st['workspace'] = projInfo.workspace
  105.  
  106.     with pr.stage('Build'):
  107.         for name in scenes:
  108.             with pr.stage('BuildLevel') as st:
  109.                 st['workspace'] = projInfo.workspace
  110.                 st['level_name'] = name
  111.                 st['lm_quality'] = lightmapQuality
  112.  
  113.     with pr.stage('Packer') as st:
  114.         st['levels'] = scenes
  115.         st['default_level'] = defaultLevel
  116.         st['build_mark'] = buildMark
  117.  
  118.     return ui, pr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement