Page 1 of 2

Dynamic Dress Up Framework

Posted: Mon Feb 23, 2015 1:10 pm
by Pippin123
Here's a bit of code I made to handle character customisation and "dress up" minigames with the minimum of art assets and flexibiliy

Basic Structure:

A character class to handle "body specific" information like skin color, haircut, hair color etc, and an "inventory" that contains every clothing item the char is wearing.

Code: Select all

class PCstats(renpy.store.object):
        def __init__(self, name):
            self.name=name
            self.haircut="short"
            self.haircolor="white"
            self.skin="pale"
            self.lipstick="nude"
            self.wearing=[]
            
        def remove(self,clothes):
            if clothes in self.wearing:
                self.wearing.remove(clothes)
            return
        
        def wear(self,clothes):
            self.wearing.append(clothes)
            return
        
        def remove_all(self):
            list = [item for item in self.wearing if item.can_strip]
            if list!=[]:
                for item in list:
                    self.wearing.remove(item)
            return


A "clothing" class, that contains the name of the object, the path to the .png file, and it's drawing priority in compositing, so that you can add clothing in any order, and the vest will still draw over the t-shirt, etc...

Code: Select all

 class clothing(renpy.store.object):
        def __init__(self, name,pic,priority=10,can_strip=True):
            self.name=name
            self.pic=pic
            self.priority=priority
            self.can_strip=can_strip 
You can also create some "SFX" clothing items that cannot be removed normally ("can_strip=False"): e.g. scars, tatoos, wounds, blood...

For facial expression, eyes and mouth are stored separetly in transparent layers :
e.g. " eyes_angry_look right" or "mouth_smile" etc...

We can now define char image with associated tags:

Code: Select all

 $ seraphim = PCstats("Seraphim")
    
    image seraphim normal = DynamicDisplayable(draw_clothing,character=seraphim,art_path="seraphim/seraphim",mouth="normal",eyes="normal_straight")
    image seraphim angry = DynamicDisplayable(draw_clothing,character=seraphim,art_path="seraphim/seraphim",mouth="grit",eyes="angry_straight")
    image seraphim angry blushing = DynamicDisplayable(draw_clothing,character=seraphim,art_path="seraphim/seraphim",mouth="grit",eyes="angry_straight",blushing="light")

    image side seraphim normal = LiveCrop((102,41,150,150),"seraphim normal")
    image side seraphim angry = LiveCrop((102,41,150,150),"seraphim angry")
    image side seraphim angry blushing = LiveCrop((102,41,150,150),"seraphim angry blushing")

    define ser = Character(seraphim.name, color="#c8ffc8",image="seraphim",window_left_padding=150)
It's probably overkill if you don't plan to have a lot of different clothings options, facial expressions, but otherwise it allows a lot of flexibility:

- During your story, player and NPCs can "get a tan" , dye their hair, by simply changing a property
- Defining clothes as independent items allows for layering and transparency effects
- You can make some clothing items unlockable/buyable by mixing this system with a classic shop/inventory
- Face expressions are not tied to clothing.

Here's a full code with some art assets and exemple of use:
Dress Up - Cookbook.rar
(997.57 KiB) Downloaded 860 times
Hope it can be useful to someone

PS: The art assets are on the "skimpy" side, sorry...

edit: some people had trouble with the RAR archive, here's a zip.
Dress Up - Cookbook.zip
(1.1 MiB) Downloaded 492 times

Re: Dynamic Dress Up Framework

Posted: Mon Feb 23, 2015 5:46 pm
by Ryuushiro
I just tested it and it works WONDERFULLY, Pippin123! :o

Thank you for your hard work~

Re: Dynamic Dress Up Framework

Posted: Sun Apr 05, 2015 6:16 pm
by qilin
Thanks for sharing!! I love that powerarmor, awesome:)

By the way, do you have any use of terms on this recipe?

Re: Dynamic Dress Up Framework

Posted: Wed Apr 08, 2015 3:17 pm
by qirien
Hey, this is really cool! We want to do something similar for our upcoming game, so we may adapt your code for it. :-)

I was thinking it would be even cooler if hair/skin color could be applied with filters...? It would allow the player a lot more choices, but maybe that would look funny. Might try it out!

Re: Dynamic Dress Up Framework

Posted: Thu Apr 09, 2015 7:24 am
by Pippin123
Yes, the color swap can apparently be done with functions through Hue and the like (im.Matrix I believe).
But then it's more a problem of me not being enough of a photoshop/Gimp artist to use it properly.

That would probably means separating the image layers between "base color" , "highlights" and "shadows" ...

Re: Dynamic Dress Up Framework

Posted: Thu Apr 09, 2015 7:31 am
by Pippin123
qilin wrote:Thanks for sharing!! I love that powerarmor, awesome:)

By the way, do you have any use of terms on this recipe?
Feel free to use it.

The Adeptas Sororitas power armor is part of a Warhammer40K game I have in mind.

Re: Dynamic Dress Up Framework

Posted: Wed Apr 15, 2015 6:17 am
by Brother O'Fart
Perhaps this is an unnecessary, even stupid question, but my curiosity is going to win this anyway: is it possible to have the kind of dress, etc. have any influence on the story line? For example: you're wearing a summer dress during the winter. As a result you get sick.

Re: Dynamic Dress Up Framework

Posted: Wed Apr 15, 2015 11:13 am
by Pippin123
Brother O'Fart wrote:Perhaps this is an unnecessary, even stupid question, but my curiosity is going to win this anyway: is it possible to have the kind of dress, etc. have any influence on the story line? For example: you're wearing a summer dress during the winter. As a result you get sick.
That would be easy, it just require a bit of advance planning.

You could :
-add a property to the clothes class (including a default value, to speed things up):

Code: Select all

class clothing(renpy.store.object):
        def __init__(self, name,pic,priority=10,can_strip=True,warm=True):
            self.name=name
            self.pic=pic
            self.priority=priority
            self.can_strip=can_strip 
            self.warm=warm
you would then define:

Code: Select all

$ winter_coat=clothing("Warm Coat","winter_coat.png")
$ summer_dress=clothing("Summer Dress","dress.png",10,True,False)
then you test if the item that char is wearing have the property warm.

Code: Select all

label winter_is_coming:
   python: 
       freezing=False
       for item in char.wearing:
            if not item.warm:
                 freezing=True
   if freezing:
        jump label_cold
   else:
        jump label_warm
There's probably some other way, with lists of "suitable clothings". The basic idea is that you test what's in the char.wearing list.

Re: Dynamic Dress Up Framework

Posted: Thu Apr 16, 2015 11:38 am
by Brother O'Fart
Thank you! I can only look with awe to your wisdom.

*Bows.*

:wink:

Re: Dynamic Dress Up Framework

Posted: Thu Apr 16, 2015 1:42 pm
by stwkun
Thanks for sharing :D

Re: Dynamic Dress Up Framework

Posted: Thu Aug 06, 2015 6:02 pm
by Katta
Sorry, I'm a noob, but what would the code be if I don't have a base and clothing/hair, but three different sprite images with their own sets of emotions and I want to choose between the three based on the choice?
(solved by ConditionSwitch)

Re: Dynamic Dress Up Framework

Posted: Wed Aug 12, 2015 10:05 am
by Pippin123
I'm not sure I understand fully what you want

You have a char that can be 3 possible sprites ?

Something like char1, char 2 char 3 and associated jpg char1_happy.jpg, char1_sad.jpg etc ?

In that case, defining your images with condition switch sounds indeed the simplest solution.

Code: Select all

$ char_choice=1
image char happy = ConditionSwitch(char_choice==1,"char1_happy.jpg",char_choice==2,"char2_happy.jpg",char_choice==3,"char3_happy.jpg")
Or were you asking for something else?

Re: Dynamic Dress Up Framework

Posted: Wed Jun 22, 2016 3:07 am
by Pippin123
I added a .zip version of the file due to request.
The .rar SHOULD work for everyone, but you never know

Re: Dynamic Dress Up Framework

Posted: Sun Feb 24, 2019 6:24 am
by screamingpenguin
Hey! I'm sorry to bump an old thread, but this code is perfect for what I need!
However, one major problem;
When saving and exiting the game the character always resets to the defaults.. I've spent three very long days trying to figure out a workaround, but I'm not super experienced with coding so I've met countless dead ends..
Any advice on what to do to? ^^;

Re: Dynamic Dress Up Framework

Posted: Sun Feb 24, 2019 7:41 am
by Alex
screamingpenguin wrote: Sun Feb 24, 2019 6:24 am ...When saving and exiting the game the character always resets to the defaults.. ...
The problem might be in a way you store your variables and all.
Check this links if not yet:
https://www.renpy.org/doc/html/save_load_rollback.html
https://www.renpy.org/doc/html/python.h ... -statement