MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / update_stats

Method update_stats

shared.py:1960–2015  ·  view source on GitHub ↗

Update gamification stats using lifetime achievements and SQLite database statistics.

(self, persist=True)

Source from the content-addressed store, hash-verified

1958 self.x_center1 = self.width // 2 # Center horizontally
1959 self.y_bottom1 = self.height - 20 # Default bottom position
1960
1961 # Female (shieldmaiden) character frames for mesh units named after
1962 # a woman. Loaded here so they share the same scale as the standard
1963 # frames and are ready before the first randomizer tick.
1964 try:
1965 self.load_female_images(img_scale)
1966 except Exception as e:
1967 logger.error(f"Error loading female (woman) images: {e}")
1968
1969 except Exception as e:
1970 logger.error(f"Error loading images: {e}")
1971 raise
1972
1973 # Which woman/*.png stands in for each scan status. With no entry, a status
1974 # draws a random frame from the plain portraits, and IDLE draws from those
1975 # plus the idle_*.png expression variants (see load_female_images). Add a
1976 # status entry here to pin specific art to a specific status.
1977 WOMAN_STATUS_IMAGES = {}
1978
1979 def _prepare_female_image(self, img, img_scale):
1980 """Turn a status/woman/*.png into a 1-bit character frame the same
1981 height as the default animation frames.
1982
1983 The frames are shipped ready-made: 78x78, 1-bit, already dithered and
1984 outlined by scripts/gen_female_frames.py. So this only flattens any
1985 transparency onto white, converts to 1-bit with a plain threshold (no
1986 second dither), and scales with NEAREST on large displays — the same
1987 way the default .bmp frames are scaled — so the dither pattern stays
1988 crisp instead of being smeared."""
1989 if img is None or Image is None:
1990 return None
1991 # Match the height of the standard animation frames as loaded (78px,
1992 # already scaled up on large displays). Note self.IDLE is the small
1993 # 28px status icon, not an animation frame, so it is not a reference.
1994 target_h = max(1, int(78 * (img_scale if img_scale and img_scale > 1.05 else 1.0)))
1995 for frames in (getattr(self, 'image_series', None) or {}).values():
1996 if frames:
1997 target_h = frames[0].height
1998 break
1999 if img.mode in ('RGBA', 'LA', 'P'):
2000 img = img.convert('RGBA')
2001 bg = Image.new('RGB', img.size, (255, 255, 255))
2002 bg.paste(img, mask=img.split()[-1])
2003 img = bg
2004 if img.mode != '1':
2005 img = img.convert('L').point(lambda p: 255 if p > 127 else 0, mode='1')
2006 if img.height != target_h:
2007 ratio = target_h / float(img.height)
2008 resample = getattr(Image, 'Resampling', Image).NEAREST
2009 img = img.resize((max(1, int(round(img.width * ratio))), target_h), resample)
2010 return img
2011
2012 def load_female_images(self, img_scale):
2013 """Build the per-status female frame pool from status/woman/*.png.
2014
2015 Each PNG is loaded and prepared once; the status map then references the
2016 prepared copies, so a status with several images shares them rather than
2017 re-decoding. Runs whether or not the unit is currently female — cheap,

Callers 6

sync_all_countsFunction · 0.80
get_current_statusFunction · 0.80
execute_actionMethod · 0.80
update_shared_dataMethod · 0.80
update_shared_dataMethod · 0.80

Calls 7

errorMethod · 0.80
infoMethod · 0.80
get_statsMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected