<commit_before>#
# Los Cocos: An extension for Pyglet
# http://code.google.com/p/los-cocos/
#

"""
Scene class and subclasses
"""

import bisect

from director import director

class Scene(object):
    """
    """
    
    def __init__(self, *layers):
        """
        Creates a Scene with layers, from bottom to top, giving a 
        z-value from 1.0 to len(layers)
        """
        self.layers = []
        self.layers_name = {}
        
        for i,l in enumerate(layers):
            self.add( i, l )

    def add( self, zvalue, layer, layer_name = None ):
        """
        add(zvalue, layer, layer_name) -> None
        
        Adds a layer at z-value depth, naming it 'name' if given.
        (name can be used later to remove the layer)
        """
        elem = zvalue, layer
        self.layers.insert( bisect.bisect( elem, self.layers ), elem )
        
    def remove( self, layer_name ):
        """
        remove(layer_name or layer_reference) -> None
        
        Removes a layer from the scene given the layer_name or the layer.
        If the layer can't be removed, and exception will be risen
        """
        if layer_name in self.layers_name:
            layer = self.layers_name[ layer_name ]
            self.remove_layer( layer )
            del self.layers_name[ layer_name ]<commit_msg>fix z-index bug<commit_after>#
# Los Cocos: An extension for Pyglet
# http://code.google.com/p/los-cocos/
#

"""
Scene class and subclasses
"""

import bisect

from director import director

class Scene(object):
    """
    """
    
    def __init__(self, *layers):
        """
        Creates a Scene with layers, from bottom to top, giving a 
        z-value from 1.0 to len(layers)
        """
        self.layers = []
        self.layers_name = {}
        
        for i,l in enumerate(layers):
            self.add( i, l )

    def add( self, zvalue, layer, layer_name = None ):
        """
        add(zvalue, layer, layer_name) -> None
        
        Adds a layer at z-value depth, naming it 'name' if given.
        (name can be used later to remove the layer)
        """
        elem = zvalue, layer
        bisect.insort( self.layers,  elem )
        
    def remove( self, layer_name ):
        """
        remove(layer_name or layer_reference) -> None
        
        Removes a layer from the scene given the layer_name or the layer.
        If the layer can't be removed, and exception will be risen
        """
        if layer_name in self.layers_name:
            layer = self.layers_name[ layer_name ]
            self.remove_layer( layer )
            del self.layers_name[ layer_name ]
{'fraction_non_alphanumeric': 0.09844755774327905, 'fraction_numerical': 0.0015145778114350624, 'mean_word_length': 1.8717391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6292397', 'n_tokens_mistral': 788, 'n_tokens_neox': 767, 'n_words': 260}