o
    -PFj                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ dZdZ	dZ
G dd	 d	eZd ddZd!ddZd"ddZd#ddZd$ddZdS )%    )annotationsN)Path)Any)idlesleepwalklooksittail_wagz0.1.0   c                   @  s   e Zd ZdS )PetPackageErrorN)__name__
__module____qualname__ r   r   D/opt/sixxie/releases/current/packages/pet_package_schema/__init__.pyr      s    r   package_dir
str | Pathreturndict[str, Any]c              
   C  sn   t | }|d }| stdzt|jdd}W n tjy1 } z	td|j |d }~ww t||S )Nzpet.jsonzpet.json is missingzutf-8)encodingzpet.json is invalid JSON: )	r   existsr   jsonloads	read_textJSONDecodeErrormsgvalidate_pet_package)r   package_pathmanifest_pathmanifestexcr   r   r   load_pet_package   s   
r"   r    c           
      C  s   t | }t|d}t|d}t|d}t|d}t | s%dt |jv r)td|| }| s5tdt|d}t	|
  }	|||t|d	pOt|d
|	t|d|t|ddddddS )NiddisplayNamedescriptionspritesheetPathz..z0spritesheet path must be a package-relative filezspritesheet file is missing
animationsruntimeVersionsha256)r&   checksumAlgorithmchecksummimeTypeuserApprovedFpublic)fixtureKindsensitiveContentStored)r#   r$   r%   r(   assetr'   r-   source)r   _required_textis_absolutepartsr   r   _normalize_animationsgethashlibr)   
read_bytes	hexdigeststrDEFAULT_RUNTIME_VERSION_guess_mime_typebool)
r   r    r   pet_iddisplay_namer%   spritesheet_pathspritesheet_filer'   r+   r   r   r   r   (   s6   



r   keyr;   c                 C  s2   |  |}t|tr| st| d| S )Nz is required)r7   
isinstancer;   stripr   )r    rC   valuer   r   r   r3   M   s   
r3   rawr   dict[str, dict[str, int | str]]c                 C  s   | d u rdd t tD S t| tstdi }|  D ]D\}}|tvr+td| t|ts8td| dt|dd}|dk rLtd	| d
t|dd|t|ddd||< qt	tt	| }|D ]}t
|tdd||< qk|S )Nc                 S  s   i | ]\}}||t d dqS )low_disturbancerowframesmode)DEFAULT_FRAMES_PER_ACTION).0indexactionr   r   r   
<dictcomp>V   s    z)_normalize_animations.<locals>.<dictcomp>zanimations must be an objectz!animation action is not allowed: zanimation spec for z must be an objectrL      zanimation frames for z must be positiverK   r   rM   rI   rJ   )	enumerateALLOWED_ACTIONSrD   dictr   itemsintr7   r;   setrP   rN   )rG   
normalizedrQ   specrL   missingr   r   r   r6   T   s4   

r6   pathr   c                 C  s(   | j  dkr	dS | j  dkrdS dS )Nz.webpz
image/webpz.pngz	image/pngzapplication/octet-stream)suffixlower)r]   r   r   r   r=   v   s
   r=   )r   r   r   r   )r   r   r    r   r   r   )r    r   rC   r;   r   r;   )rG   r   r   rH   )r]   r   r   r;   )
__future__r   r8   r   pathlibr   typingr   rU   r<   rN   
ValueErrorr   r"   r   r3   r6   r=   r   r   r   r   <module>   s    	


%
"