diff --git a/game/scripts/doll/main.rpy b/game/scripts/doll/main.rpy index ab30e88c..c12a8bd3 100644 --- a/game/scripts/doll/main.rpy +++ b/game/scripts/doll/main.rpy @@ -1,4 +1,6 @@ init python: + import asyncio + class Doll(DollMethods): def __init__(self, name, clothes, face, body): self.wardrobe = {} @@ -60,37 +62,66 @@ init python: def hide(self): renpy.hide(name=self.tag, layer=self.layer) - def build_image(self): + def make_image(self): + asyncio.run(self.build_image()) + + async def build_image(self): # Add body, face, cum, clothes, masks - masks = [] + + async def build_clothes(clothes): + sprites = [] + masks = [] + + for i in clothes.values(): + obj, _, is_worn = i + + if not obj is None and is_worn: + zorder = obj.zorder + + sprites.extend([ + (obj.get_image(), zorder), + obj.get_back(), + obj.get_front(), + obj.get_armfix(), + ]) + + if obj.mask: + masks.append((obj.mask, zorder-1)) + return (sprites, masks) + + async def build_face(): + return (self.face.get_image(), 1) + + async def build_body(): + return (self.body.get_image(), 0) + + async def build_cum(zorder): + return (self.face.get_image(), zorder) + + face, body, cum, (clothes, masks) = await asyncio.gather( + build_cum(self.cum.zorder_cum), + build_body(), + build_face(), + build_clothes(self.clothes), + ) + sprites = [ - (self.body.get_image(), 0), - (self.face.get_image(), 1), - (self.cum.get_image(), self.cum.zorder_cum), - (self.emote, 1000), + face, + body, + cum, + *clothes, + (self.emote, 1000) ] - for i in self.clothes.values(): - clothing, _, is_worn = i - - if not clothing is None and is_worn: - zorder = clothing.zorder - - sprites.extend([ - (clothing.get_image(), zorder), - clothing.get_back(), - clothing.get_front(), - clothing.get_armfix(), - ]) - - if clothing.mask: - masks.append((clothing.mask, zorder-1)) + # Filter out Nulls + sprites = [x for x in sprites if not isinstance(x[0], Null)] sprites.sort(key=itemgetter(1)) masks.sort(key=itemgetter(1)) - back_sprites = [x for x in sprites if x[1] < 0] - sprites = [x for x in sprites if x[1] >= 0] + # Filter out sprites with zorder less than zero, there's no need to iterate over them. + back_sprites = [x[0] for x in sprites if x[1] < 0] + sprites = [x for x in sprites if x[1] > -1] # Apply alpha mask for m in masks: @@ -108,8 +139,9 @@ init python: sprites.insert(0, (masked, mask_zorder)) break - sprites = back_sprites + sprites - return tuple(x[0] for x in sprites if not isinstance(x[0], Null)) + sprites = back_sprites + [x[0] for x in sprites] + self.sprite = DollDisplayable(Fixed(*sprites, fit_first=True)) + return def equip(self, obj, remove_old=True): """Takes DollCloth or DollOutfit object to equip.""" diff --git a/game/scripts/doll/outfits.rpy b/game/scripts/doll/outfits.rpy index dd57f75f..5086980a 100644 --- a/game/scripts/doll/outfits.rpy +++ b/game/scripts/doll/outfits.rpy @@ -43,30 +43,53 @@ init python: if self in self.char.outfits: self.char.outfits.remove(self) - def build_image(self): - masks = [] + def make_image(self): + asyncio.run(self.build_image()) + + async def build_image(self): + # Add body, face, cum, clothes, masks + + async def build_clothes(group): + sprites = [] + masks = [] + + for i in group: + sprites.append([i.get_image(), i.zorder]) + + sprites.extend([ + (i.get_image(), i.zorder), + i.get_back(), + i.get_front(), + i.get_armfix(mannequin=True), + ]) + + if i.mask: + masks.append((i.mask, i.zorder-1)) + + return (sprites, masks) + + async def build_mannequin(group): + return (self.char.body.get_mannequin(group), 0) + + mannequin, (clothes, masks) = await asyncio.gather( + build_mannequin(self.group), + build_clothes(self.group), + ) + sprites = [ - (self.char.body.get_mannequin(self.group), 0) + mannequin, + *clothes, ] - for i in self.group: - sprites.append([i.get_image(), i.zorder]) - - sprites.extend([ - (i.get_image(), i.zorder), - i.get_back(), - i.get_front(), - i.get_armfix(mannequin=True), - ]) - - if i.mask: - masks.append((i.mask, i.zorder-1)) + # Filter out Nulls + sprites = [x for x in sprites if not isinstance(x[0], Null)] sprites.sort(key=itemgetter(1)) masks.sort(key=itemgetter(1)) - back_sprites = [x for x in sprites if x[1] < 0] - sprites = [x for x in sprites if x[1] >= 0] + # Filter out sprites with zorder less than zero, there's no need to iterate over them. + back_sprites = [x[0] for x in sprites if x[1] < 0] + sprites = [x for x in sprites if x[1] > -1] # Apply alpha mask for m in masks: @@ -84,8 +107,9 @@ init python: sprites.insert(0, (masked, mask_zorder)) break - sprites = back_sprites + sprites - return tuple(x[0] for x in sprites) + sprites = back_sprites + [x[0] for x in sprites] + self.sprite = DollDisplayable(Fixed(*sprites, fit_first=True)) + return def exists(self): return (self in self.char.outfits)