from pathlib import Path import math,json,hashlib,copy import numpy as np from PIL import Image,ImageDraw from room_art364 import RoomArt from easy88_clues import render_clue,draw_symbol from font_utils import load_font from easy88_native_devices import build_device,sync_device NUMERIC={'read_code','weigh','net_weigh','measure','liquid_read','clock','mirror','transfer','half_code','page_code','count','index_code','label_index'} ADJUST={'adjust','support_align','window_align','colour_windows','block_faces','cup_orient','slide_align'} ROTATE={'rotate_picture','rotate_pipes','rotate_rails'} def icon(name,size=320): im=Image.new('RGB',(size,size),(224,216,192));d=ImageDraw.Draw(im) try:draw_symbol(d,str(name),(40,40,size-40,size-40),fill=(36,62,66),outline=(25,40,43)) except Exception:d.text((20,120),str(name).replace('_',' '),font=load_font(30),fill=(30,40,40)) return im class EasyScene(RoomArt): def __init__(self,og,run,spec): self.spec=spec;super().__init__(og,run) self.centres={};self.stage_centres=[];self.stage_views=[];self.roots=[];self.bases=[];self.covers=[];self.clues=[];self.clue_mats=[];self.clue_sigs={};self.nodes_by_stage=[];self.controls=[];self.choice_nodes=[];self.buffers=[];self.items=[];self.slots=[];self.tools=[];self.setups=[];self.special={};self.active_flash={};self.status_nodes=[];self.physical_hooks={};self.physical_hidden=[] def palette(self): super().palette();theme=self.spec.get('theme','') colors={'sewing':(.25,.34,.28),'gardening':(.24,.34,.21),'tea':(.36,.26,.17),'signal':(.24,.31,.33),'painting':(.32,.33,.29),'archive':(.31,.27,.20),'pantry':(.42,.39,.31),'packing':(.35,.30,.23),'laundry':(.55,.59,.56),'music':(.32,.23,.17),'toys':(.30,.40,.47),'sports':(.22,.31,.40),'camping':(.27,.32,.22),'bath':(.44,.53,.51),'linen':(.47,.45,.38),'books':(.30,.23,.17),'pottery':(.47,.36,.28),'shoes':(.30,.24,.19),'coffee':(.35,.28,.21),'lost_property':(.36,.39,.35)} self.mats['paint']=self.mat('theme_paint',colors.get(theme,(.30,.35,.35)),rough=.9) for n,c in [('cream',(.70,.68,.60)),('dark_panel',(.035,.05,.06)),('leaf_green',(.15,.37,.17)),('blue',(.08,.20,.42)),('purple',(.31,.12,.36)),('yellow',(.75,.61,.08))]:self.mat(n,c,rough=.95) self.mat('red_led',(.32,.045,.02),rough=.8,emission=(.2,.015,.005));self.mat('water',(.04,.27,.34),rough=.15,opacity=.65) def label_image(self,key,text,width=1000,height=200): im=Image.new('RGB',(width,height),(220,214,192));d=ImageDraw.Draw(im);lines=str(text).split('\n');size=max(10,int(height*.60/max(1,len(lines)))) while size>9: f=load_font(size) if max(d.textbbox((0,0),v,font=f)[2] for v in lines)