def __init__(self, machine_type): # this short circuits the generation of 'extra' DMD events if the virtual/color DMD is used use_virtual_dmd_only = config.value_for_key_path('use_virtual_dmd_only', False) if(use_virtual_dmd_only==True): self.get_events = self.get_events_noDMD else: self.frames_per_second = config.value_for_key_path('dmd_framerate', 30) # Instantiate 256 drivers. for i in range(0, 256): name = 'driver' + str(i) self.drivers.add(name, gameitems.VirtualDriver(None, name, i, True))
def create_pinproc(self): """Instantiates and returns the class to use as the P-ROC device. This method is called by :class:`GameController`'s init method to populate :attr:`proc`. Checks :mod:`~procgame.config` for the key path ``pinproc_class``. If that key path exists the string is used as the fully qualified class name to instantiate. The class is then instantiated with one initializer argument, :attr:`machine_type`. If that key path does not exist then this method returns an instance of :class:`pinproc.PinPROC`. """ self.frames_per_second = config.value_for_key_path('dmd_framerate', 30) klass_name = config.value_for_key_path('pinproc_class', 'pinproc.PinPROC') klass = util.get_class(klass_name) return klass(self.machine_type)
def __init__(self, machine_type): # this short circuits the generation of 'extra' DMD events if the virtual/color DMD is used use_virtual_dmd_only = config.value_for_key_path( 'use_virtual_dmd_only', False) if (use_virtual_dmd_only == True): self.get_events = self.get_events_noDMD else: self.frames_per_second = config.value_for_key_path( 'dmd_framerate', 60) # Instantiate 256 drivers. for i in range(0, 256): name = 'driver' + str(i) self.drivers.add(name, gameitems.VirtualDriver(None, name, i, True))
def config_named(name): if not os.path.isfile(name): # If we cannot find this file easily, try searching the config_path: config_paths = config.value_for_key_path('config_path', ['.']) if issubclass(type(config_paths), str): config_paths = [config_paths] found_path = util.find_file_in_path(name, config_paths) if found_path: name = found_path else: return None return yaml.load(open(name, 'r'))
def shared_manager(): """Returns a reference to the global, shared manager, if configured by the ``dmd_cache_path`` in :mod:`procgame.config`.""" global shared_cache_manager if not shared_cache_manager: path = config.value_for_key_path('dmd_cache_path') if path: shared_cache_manager = AnimationCacheManager(path) else: shared_cache_manager = None return shared_cache_manager
def load_config(self, path): super(Game,self).load_config(path) # Setup the key mappings from the config.json. # We used to do this in __init__, but at that time the # configuration isn't loaded so we can't peek into self.switches. key_map_config = config.value_for_key_path(keypath='keyboard_switch_map', default={}) if self.desktop: for k, v in key_map_config.items(): switch_name = str(v) if self.switches.has_key(switch_name): switch_number = self.switches[switch_name].number else: switch_number = pinproc.decode(self.machine_type, switch_name) self.desktop.add_key_map(ord(str(k)), switch_number)
def init_font_path(): global font_path try: value = config.value_for_key_path('font_path') if issubclass(type(value), list): font_path.extend(map(os.path.expanduser, value)) elif issubclass(type(value), str): font_path.append(os.path.expanduser(value)) elif value == None: print('WARNING no font_path set in %s!' % (config.path)) else: print('ERROR loading font_path from %s; type is %s but should be list or str.' % (config.path, type(value))) sys.exit(1) except ValueError, e: #print e pass
def init_hdfont_path(): global hdfont_path try: value = config.value_for_key_path('hdfont_path') if issubclass(type(value), list): hdfont_path.extend(map(os.path.expanduser, value)) elif issubclass(type(value), str): hdfont_path.append(os.path.expanduser(value)) elif value == None: print('WARNING no font_path set in %s!' % (config.path)) else: print('ERROR loading font_path from %s; type is %s but should be list or str.' % (config.path, type(value))) sys.exit(1) except ValueError, e: #print e pass
import os try: import sdl2.ext except Exception, e: if (os.getenv("PYSDL2_DLL_PATH") is None): from procgame import config p = config.value_for_key_path('PYSDL2_DLL_PATH', None) if (p is None): print( "Tried to load SDL2 but failed. Please set PYSDL2_DLL_PATH in your system environment variables or in your config.yaml" ) import sys sys.exit() else: os.environ["PYSDL2_DLL_PATH"] = p try: import sdl2.ext except Exception, e2: print( "Tried to load SDL2 but failed. \nThe PYSDL2_DLL_PATH in your config.yaml ['%s'] does contain a valid SDL2 DLL (or SDL2 is not properly installed on your system)" % p) print(e2) import sys sys.exit() from sdl2.ext.draw import prepare_color from sdl2.ext.color import convert_to_color import ctypes import random from sdl2 import endian, hints import time
import os if (os.getenv("PYSDL2_DLL_PATH") is None): from procgame import config os.environ["PYSDL2_DLL_PATH"] = config.value_for_key_path('PYSDL2_DLL_PATH', None) import sdl2.ext from sdl2.ext.draw import prepare_color from sdl2.ext.color import convert_to_color import ctypes import random from sdl2 import endian import time from ctypes import byref, cast, POINTER, c_int, c_float, sizeof, c_uint32, c_double # An SDL2 Display Helper ; Somewhat PyGame like # class DisplayObject(sdl2.ext.TextureSprite): SDL2_DM = None class FontManagerExtended(sdl2.ext.FontManager): """ this clas serves to add a few useful features to the default (py)SDL2 FontManager """ def get_font_pointer(self, alias, size): """ returns the pointer to the TTF_Font object """ if alias not in self.aliases: raise KeyError("Font %s not loaded" % font) elif size not in self.fonts[alias]: self._change_font_size(alias, size)
#from procgame import * # import dmd from procgame import config from layers import * import transitions import sys DMD_WIDTH = config.value_for_key_path('dmd_dots_w', 480) DMD_HEIGHT = config.value_for_key_path('dmd_dots_h', 240) LENGTH_IN_FRAMES = config.value_for_key_path('dmd_framerate', 30) class moveLayer(Layer): def __init__(self,layer=None, start_x=0,start_y=0, target_x=0,target_y=0, lengthInFrames=LENGTH_IN_FRAMES, callback=None, param=None, loop=False, composite_op = 'blacksrc' ): super(moveLayer,self).__init__(False) self.step_number=0 self.object_layer = layer self.callback = callback self.param = param self.start_x = start_x self.start_y = start_y self.lengthInFrames = lengthInFrames self.move_target_x = target_x self.move_target_y = target_y self.finished = False self.composite_op = composite_op self.loop = loop def next_frame(self): if not self.finished:
import os try: import sdl2.ext except Exception, e: if (os.getenv("PYSDL2_DLL_PATH") is None): from procgame import config p = config.value_for_key_path('PYSDL2_DLL_PATH', None) if(p is None): print("Tried to load SDL2 but failed. Please set PYSDL2_DLL_PATH in your system environment variables or in your config.yaml") import sys sys.exit() else: os.environ["PYSDL2_DLL_PATH"] = p try: import sdl2.ext except Exception, e2: print("Tried to load SDL2 but failed. \nThe PYSDL2_DLL_PATH in your config.yaml ['%s'] does contain a valid SDL2 DLL (or SDL2 is not properly installed on your system)" % p) print(e2) import sys sys.exit() from sdl2.ext.draw import prepare_color from sdl2.ext.color import convert_to_color from sdl2 import SDL_Init, SDL_INIT_VIDEO _HASSDLIMAGE = True try: from sdl2 import sdlimage except ImportError: _HASSDLIMAGE = False