ó
ÔŒ\c           @  s¶   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z e j j Z e j j Z d „  Z	 d e d „ Z d d „ Z d d d d „ Z d „  Z e j d „  ƒ Z d	 „  Z d S(
   iÿÿÿÿ(   t   print_functionNc         C  sZ   |  j  d ƒ \ } } } | s" d St j j j | d ƒ } | d k rJ d St | | ƒ ƒ S(   sŒ   
    Given `d`, a string given a displayable, returns the displayale it
    corresponds to or None if it it does not correspond to one.
    t   :N(   t	   partitiont   Nonet   renpyt   configt   displayable_prefixt   gett   displayable(   t   dt   prefixt   colont   argt   fn(    (    s   renpy/easy.pyt   lookup_displayable_prefix"   s    c         C  s‹  t  |  t j j j ƒ r |  S|  d  k r, |  St  |  t ƒ rþ |  sP t d ƒ ‚ n7 d |  k r‡ t j j	 r‡ | r‡ t j j
 j |  d | ƒSt |  ƒ } | d  k	 r£ | S|  d d k rÃ t j j |  ƒ Sd |  k rß t j j |  ƒ St j j t |  j ƒ  ƒ ƒ Sn  t  |  t ƒ rt j j |  ƒ St  |  t ƒ rEt j j
 j |  d | ƒSt |  d ƒ rX|  S|  t k sp|  t k rt|  St d |  f ƒ ‚ d  S(	   Ns0   An empty string cannot be used as a displayable.t   [t   scopei    t   #t   .t
   _duplicates   Not a displayable: %r(   t
   isinstanceR   t   displayt   coret   DisplayableR   t
   basestringt	   ExceptionR   t   dynamic_imagest   imaget   DynamicImageR   t   storet   Solidt   Imaget   ImageReferencet   tuplet   splitt   Colort   listt   hasattrt   Truet   False(   R	   R   t   dynamict   rv(    (    s   renpy/easy.pyt   displayable_or_none4   s4    c         C  su  t  |  t j j j ƒ r |  St  |  t ƒ rè |  s@ t d ƒ ‚ n1 d |  k rq t j j rq t j j	 j
 |  d | ƒSt |  ƒ } | d	 k	 r | S|  d d k r­ t j j |  ƒ Sd |  k rÉ t j j |  ƒ St j j t |  j ƒ  ƒ ƒ Sn  t  |  t ƒ rt j j |  ƒ St  |  t ƒ r/t j j	 j
 |  d | ƒSt |  d ƒ rB|  S|  t k sZ|  t k r^|  St d |  f ƒ ‚ d	 S(
   sØ   
    :doc: udd_utility
    :name: renpy.displayable

    This takes `d`, which may be a displayable object or a string. If it's
    a string, it converts that string into a displayable using the usual
    rules.
    s0   An empty string cannot be used as a displayable.R   R   i    R   R   R   s   Not a displayable: %rN(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   (   R	   R   R)   (    (    s   renpy/easy.pyR   ]   s0    
c      
     s  t  ˆ  t ƒ s ˆ  g ‰  n  ‡  f d †  } x_ˆ  D]-} t  | t ƒ sL q1 n  | d
 k	 rd | k r| ry t | ƒ } n i  } xÜ t j j j | D]j } | | d <t j	 j
 | d | d t d t ƒd } | | ƒ rá t | ƒ S| d
 k	 r“ | j | ƒ q“ q“ Wq1 t j	 j
 | d | d t d t ƒd } | | ƒ rBt | ƒ S| d
 k	 r1 | j | ƒ q1 q1 Wˆ  d } | | ƒ rˆt | d	 t ƒSd
 Sd
 S(   sÚ   
    Substitutes a scope into `d`, then returns a displayable.

    If `prefix` is given, and a prefix has been given a prefix search is
    performed until a file is found. (Only a file can be used in this case.)
    c           s}   t  j j |  ƒ r t St  j j |  ƒ r, t St |  ƒ r< t St ˆ  ƒ d k ry t  j j	 d  k	 ry t  j j	 |  ƒ ry t Sn  d  S(   Ni   (   R   t   loadert   loadableR&   t   exportst   image_existsR   t   lenR   t   missing_image_callbackR   (   t   name(   R	   (    s   renpy/easy.pyt   find–   s    $s   [prefix_t   prefix_R   t   forcet	   translatei    iÿÿÿÿR(   N(   R   R$   R   R   t   dictR   t	   styledatat	   stylesetst   prefix_searcht   substitutionst
   substituteR&   R'   R*   t   append(   R	   R   R
   t   searchR2   t   it   pR)   (    (   R	   s   renpy/easy.pyt   dynamic_image‹   s4    
(
(

c         C  s8   t  j j |  ƒ }  |  d  k	 r4 t  j j j |  ƒ n  d  S(   N(   R   t   easyR*   R   R   t   predictR   (   R	   (    (    s   renpy/easy.pyRB   Ð   s    c         c  s9   t  j  ƒ  } d  Vt d j |  t  j  ƒ  | d ƒ ƒ d  S(   Ns   {0}: {1:.2f} msg     @@(   t   timet   printt   format(   R1   t   start(    (    s   renpy/easy.pyt   timed×   s    c   	      G  s·   g  } x | D] } | j  i  ƒ q W|  s. | St t | | ƒ ƒ } xm |  j ƒ  D]_ \ } } xP | D]3 \ } } | j | ƒ rc | | | t | ƒ <Pqc qc Wt d j | ƒ ƒ ‚ qP W| S(   s‡  
    :doc: other

    Splits up `properties` into multiple dictionaries, one per `prefix`. This
    function checks each key in properties against each prefix, in turn.
    When a prefix matches, the prefix is stripped from the key, and the
    resulting key is mapped to the value in the corresponding dictionary.

    If no prefix matches, an exception is thrown. (The empty string, "",
    can be used as the last prefix to create a catch-all dictionary.)

    For example, this splits properties beginning with text from
    those that do not::

        text_properties, button_properties = renpy.split_properties(properties, "text_", "")
    s*   Property {} begins with an unknown prefix.(   R<   R$   t   zipt	   iteritemst
   startswithR/   R   RE   (	   t
   propertiest   prefixesR)   t   _it   prefix_dt   kt   vR
   R	   (    (    s   renpy/easy.pyt   split_propertiesÞ   s    (   t
   __future__R    t   renpy.displayR   t   renpy.styledatat
   contextlibRC   t   colorR#   R   R   R&   R*   R   R@   RB   t   contextmanagerRG   RQ   (    (    (    s   renpy/easy.pyt   <module>   s   	).E	