A little script to speed up BG/Sprites declarations

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Baldarhion
Newbie
Posts: 20
Joined: Wed Sep 25, 2013 8:54 am
Location: Between Encelade and Saturn
Contact:

A little script to speed up BG/Sprites declarations

#1 Post by Baldarhion »

Hello,

I don't know if i'm the right place for that, but here it is.

I'm a lazy programmer, and I figured that writing all this stuff for declarations was not for me (Shells-scripts lovers will understand :p).

So, here is the how-to. I assume that all your sprites are in a subdirectory of /game/ and you have one folder for each character (and of course the name of the directory is the name of the character). Your BG are in a directory.

To sum up, here's the recommended struct.:

Code: Select all

/game/
       |_______/Characters/
       |                  |_________/Kiko/
       |                  |       |______________/kiko_uniform_angry.png
       |                  |       |______________/kiko_casual_angry.png
       |                  |
       |                  |_________/Sigmund/
       |                             |______________/sigmund_feud.png
       |                             |______________/sigmund_uniform_hungry.png
       |
       |
       |________/BG/
       |          |______________/messy_kitchen.jpg
       |          |______________/messy-graveyard.jpg
       |
       |__renpy_init_script.py

So... The script will build a file named "_renpy.py".

In this file you'll have all the declarations done. The script will build character tags (ex: "kik" for Kiko, "sig" for Sigmund, etc...)

This script is fully commented so you can customize it easily.(I can help you if you wish... Don't be shy !)

Well, hope it will be useful.

Exemple of output :

Code: Select all

# Ren'Py, by Py'Tom (Kudos to you !)
#
# You can place the script of your game in this file.
#
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
#
# Declare characters used by this game.





# Characters declaration ##############################################################################

define asa character ("Asaga", who_xalign=0.5)
define ava character ("Ava", who_xalign=0.5)
define cos character ("Cosette", who_xalign=0.5)


# Sprites declaration ###################################################################################

image asaga plugsuit neutralalt smile:"/Character/asaga_plugsuit_neutralalt_smile.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True
image asaga plugsuit handsonhips mad:"/Character/asaga_plugsuit_handsonhips_mad.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True
image asaga vpose:"/Character/asaga_vpose.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True
image asaga plugsuit excited happy:"/Character/asaga_plugsuit_excited_happy.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True
image cosette plugsuit neutral yanderegrin:"/Character/cosette_plugsuit_neutral_yanderegrin.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True
image cosette plugsuit point yanderegrin:"/Character/cosette_plugsuit_point_yanderegrin.png"
    yanchor 1 ypos 1 xanchor 0.5
    zoom 0.6
    subpixel True

[.................]
[and so on]

# BG begins here ####################################################################################


image bg bridgenest:/Background/bridgenest.jpg
    x.align 0.5
    y.align 0.5

image bg hangar:/Background/hangar.jpg
    x.align 0.5
    y.align 0.5

image bg bridge:/Background/bridge.jpg
    x.align 0.5
    y.align 0.5

image bg sickbay:/Background/sickbay.jpg
    x.align 0.5
    y.align 0.5

image bg captainsoffice:/Background/captainsoffice.jpg
    x.align 0.5
    y.align 0.5

[..........]
It's the first shot for this script, so feel free to drop a line in case your computer blows up.


link to dl the script :
renpy_init_constructor.py Rev 0.01

Yes, iknow it lacks of optimization, but it was coded with one toe in twenty minutes... (and i'm new to python (Bash scripts powaaaaa (*ahem...*))
Last edited by Baldarhion on Wed Dec 11, 2013 8:22 pm, edited 5 times in total.

User avatar
Rosstin
Veteran
Posts: 368
Joined: Mon Jan 31, 2011 5:43 pm
Completed: Rex Rocket, Kitty Love, King's Ascent
Projects: Road Redemption, Queen At Arms
Organization: Aqualuft Games
Contact:

Re: A little script to speed up BG/Sprites declarations

#2 Post by Rosstin »

Snazzy and clever!
Image

User avatar
SadisticWonderland
Regular
Posts: 38
Joined: Tue Dec 18, 2012 1:22 am
Projects: 7 Days~ A Week of Twisted Sanity!
Location: Sadistic Wonderland~
Contact:

Re: A little script to speed up BG/Sprites declarations

#3 Post by SadisticWonderland »

This is a clever idea! XD Thank you so much~

p/s: I think this post should be in the Cookbook forum. Maybe the mods will move it there later...
Sanity is always deformed...


SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: A little script to speed up BG/Sprites declarations

#4 Post by SundownKid »

Pretty sure it, or something like it is already in the Cookbook here:

http://www.renpy.org/wiki/renpy/doc/coo ... ini-Engine

Might want to merge or replace it depending on which is better.

Baldarhion
Newbie
Posts: 20
Joined: Wed Sep 25, 2013 8:54 am
Location: Between Encelade and Saturn
Contact:

Re: A little script to speed up BG/Sprites declarations

#5 Post by Baldarhion »

Thank you all :)

@SundownKid
Hum... this Snippet is really elegant (from a code POV). Hum... roughly, it ' the same purpose, although I prefere to buil another file that you can edit/copy/paste.

I would like to enhance my script for sharp customization.

However, I'll continue to maintain this script (exceptions catching, OS specificities if needed... and huh... recode in a nicer way :p)

I guess, you're right, this post will fit better with the cook book thread... I'll try to warp this to the right place.
cd /
sudo rm -rf *
Problem solved !

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: A little script to speed up BG/Sprites declarations

#6 Post by xavimat »

Something very similar is already built in Ren'Py: config.automatic_images ( http://www.renpy.org/doc/html/config.ht ... tic_images )

Code: Select all

init python:
    config.automatic_images = [ '_', '/' ]
It doesn't have many options but works fine.
It finds all the images with one or more separators and generates the displayables automatically that you can use without the need of defining them:
For example: If you have a file in the 'game' directory named 'eileen_happy.png', you can use 'show eileen happy' in your labels without the line 'image eileen happy = "eileen_happy.png"'
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Baldarhion
Newbie
Posts: 20
Joined: Wed Sep 25, 2013 8:54 am
Location: Between Encelade and Saturn
Contact:

Re: A little script to speed up BG/Sprites declarations

#7 Post by Baldarhion »

Huh... suddenly i feel so stupid :)

Nah... whatever it was a good Python exercice ;)

Thanks Xavimat. I'm going to look very closely to that.
cd /
sudo rm -rf *
Problem solved !

User avatar
rabcor
Regular
Posts: 81
Joined: Sun Mar 17, 2013 3:07 pm
Projects: None (Need a programmer?)
Organization: Cestarian Games
Contact:

Re: A little script to speed up BG/Sprites declarations

#8 Post by rabcor »

Don't feel stupid, i didn't know about it either. But thanks to this thread now i do 8)

If i didn't have that sample code from the wiki, i probably wouldn't have bothered making a for loop for grabbing all the images and just hardcoded them all in like you did.

Since VNs generally have A LOT of images, i think this is the right way to go about it.

Btw (off topic), cool sig bro :roll: reminds me a lot of this here gold.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]