a
    V$c~                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZdae Zdag Zdd Zdd Zd	d
 Zdd ZdS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeNFc                 C   s0   | du rdS | t vr,t |  | dd  dS )zC
    Called to predict that the displayable `d` will be shown.
    Nc                 S   s   |   S N)predict_onei r   renpy/display\predict.py<lambda>9       zdisplayable.<locals>.<lambda>)	predictedadd	visit_all)dr   r   r   displayable/   s
    
r   c                 O   s   t | ||f dS )zd
    Called to predict that the named screen is about to be shown
    with the given arguments.
    N)screensappend)_screen_nameargskwargsr   r   r   screen<   s    r%   c                   C   s"   t jjjjat  td d = d S r   )	renpydisplayimcacheget_textureimager   clearr    r   r   r   r   resetE   s    r-   c              
   c   sT  t jjj  dV  t jjjjadat jj	D ]}t
| dadV  daq,t j  D ]}dadV  daqVtt jjdkrt jjd j}|j D ]0}|D ]&}zt
|j
 W q ty   Y q0 qqnt jjD ]
}|  qdadV sqqdat jjD ](}d}|s| sd}dadV  daqqg }tt jj D ]L\}	}
|
\}}||	||f t jjj|	g|R i | dadV  daq2daz| dd  W n< ty   t jjrddl}t d	 |!  t   Y n0 dat"D ]l}dV sqq||v rq|| |\}	}}|	#d
r"qdat jjj|	g|R i | daqdV  dS )a  
    The image prediction co-routine. This predicts the images that can
    be loaded in the near future, and passes them to the image cache's
    preload_image method to be queued up for loading.

    The .send should be called with True to do a expensive prediction,
    and with False to either do an inexpensive prediction or no
    prediction at all.

    Returns True if there's more predicting to be done, or False
    if there's no more predicting worth doing.
    TF   c                 S   s   |   S r   )predict_one_actionr   r   r   r   r      r   z&prediction_coroutine.<locals>.<lambda>r   NzWhile predicting actions._)$r&   r'   r(   r)   start_predictionpreload_imager+   
predictingstore_predict_setr   gamecontextpredictlencontextsscene_listslayersvalues	Exceptionconfigpredict_callbacksexpensive_predict_callbackslist_predict_screenitemsr!   r%   predict_screenr   debug_prediction	tracebackprint	print_excr    
startswith)root_widgetr   _islslsler   donepredicted_screensnamevaluer#   r$   rH   tr   r   r   prediction_coroutineL   s    



rV   )
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r&   r+   setr   r4   r    r   r%   r-   rV   r   r   r   r   <module>   s   8	