Page 2 of 3

Re: Automatic character, background, etc. image defining scr

Posted: Sun Mar 08, 2015 11:32 pm
by cuttlefish
Ah! You’re right!

In the end, I ended up with this code and using show_side_image=ShowingSwitch() with the path_lists and paths the function collected.

Thanks for all of your help!

Re: Automatic character, background, etc. image defining scr

Posted: Mon Mar 09, 2015 12:36 am
by Zetsubou
Glad you got it working. Looking at the number of different layers you're using, I can see why you wanted to use this script :lol:

ps.

Code: Select all

if side_image:
    sidedict[' '.join(shortname)] = LiveComposite(image_size, *layers)
Brevity ftw.

Re: Automatic character, background, etc. image defining scr

Posted: Tue Jul 28, 2015 6:21 pm
by Ladycardboard
I'm having trouble getting your script to work right. I copy and pasted the script into my renpy script but get these errors:

Code: Select all

File "game/script.rpy", line 27: expected statement.
    def define_image(size, side, path_tuple, argList):
                    ^

File "game/script.rpy", line 48: expected statement.
    def get_character_indexes():
                             ^

File "game/script.rpy", line 51: expected statement.
    def define_chars (characterImageFolder, size=(370, 512), flip=True, side=False):
                     ^

File "game/script.rpy", line 113: expected statement.
    def define_extra (size, side, character, pose, outfit, cKey, oKey, pKey):
                     ^
Can you help me out?

Re: Automatic character, background, etc. image defining scr

Posted: Tue Jul 28, 2015 6:44 pm
by Zetsubou
I'd need to see your scripy.rpy file to be sure, but my guess is that you didn't put the code in an init python block.
ie. rather than

Code: Select all

def define_image(size, side, path_tuple, argList):
    #...
it should be

Code: Select all

init python:
    def define_image(size, side, path_tuple, argList):
        #...

Re: Automatic character, background, etc. image defining scr

Posted: Tue Jul 28, 2015 10:40 pm
by Ladycardboard
That error is solved but now all I'm getting is a grey placeholder picture with the text written in the middle of it. Here's the script:

Code: Select all

[spoiler]init python:
    
  def define_image(size, side, path_tuple, argList):
      path_tuple = tuple(entry for entry in path_tuple if entry is not None)
      if side:
          path_tuple = ('side', ) + path_tuple
      args = []
      for i in xrange(1, len(argList), 2):
          if argList[i] is not None:
              args.extend([(0, 0), argList[i]])
      renpy.image(path_tuple, LiveComposite(size, *args))
      if 'valerie' in path_tuple:
          print path_tuple

      if not side:

          flipArr = args
          for i in xrange(1, len(args), 2):
              flipArr[i] = im.Flip(args[i], horizontal=True)
          plist = list(path_tuple)
          plist.insert(1, 'flip') #flip after char name. eg. sara flip arms_crossed etc.
          renpy.image(tuple(plist), LiveComposite(size, *flipArr))

  def get_character_indexes():
      return {'expressions': {}, 'poses': {}, 'ears': {}, 'freya': {}, 'freya2': {}, 'arms': {}}

  def define_chars(characterImageFolder, size=(370, 512), flip=True, side=False):
      chars = {}

      for path in renpy.list_files():
          if path.startswith(characterImageFolder):
            pList = path.split("/")

            if len(pList) >= 4 and path.startswith(characterImageFolder + pList[-4] + "/poses/"):
                  if pList[-4] not in chars:
                    chars[pList[-4]] = get_character_indexes() #New character
                  if pList[-2] not in chars[pList[-4]]['poses']:
                    chars[pList[-4]]['poses'][pList[-2]] = {} #New pose
                  splitVal = os.path.splitext(pList[-1])[0]
                  if splitVal not in chars[pList[-4]]['poses'][pList[-2]] and splitVal != 'pose':
                    chars[pList[-4]]['poses'][pList[-2]][splitVal] = path #New outfit
            elif len(pList) >= 4 and path.startswith(characterImageFolder + pList[-4] + "/outfits_extra/"):
                  if pList[-4] not in chars:
                    chars[pList[-4]] = get_character_indexes() #New character
                  if pList[-2] not in chars[pList[-4]]['outfits_extra']:
                    chars[pList[-4]]['outfits_extra'][pList[-2]] = {} #New outfit extra
                  splitVal = os.path.splitext(pList[-1])[0]
                  if splitVal not in chars[pList[-4]]['outfits_extra'][pList[-2]]:
                    chars[pList[-4]]['outfits_extra'][pList[-2]][splitVal] = path #New pose
            elif path == characterImageFolder + pList[-2] + '/base.png':
              if pList[-2] not in chars:
                chars[pList[-2]] = get_character_indexes() #New character
              chars[pList[-2]]['base'] = path
            elif len(pList) >= 3:
              for val in ['outfits', 'poses', 'expressions', 'outfits_extra']:
                if path.startswith(characterImageFolder + pList[-3] + "/" + val + "/") and pList[-2] == val:
                  if pList[-3] not in chars:
                    chars[pList[-3]] = get_character_indexes()
                  splitVal = os.path.splitext(pList[-1])[0]
                  if splitVal not in chars[pList[-3]][pList[-2]]:
                    chars[pList[-3]][pList[-2]][splitVal] = path
                  break

      for cKey in chars:
          character = chars[cKey]
          if len(character['outfits']) > 0: #Standard directory structure
            for oKey in character['outfits']:
              outfit = character['outfits'][oKey]
              if len(character['poses']) > 0:
                  for pKey in character['poses']:
                      pose = character['poses'][pKey]
                      define_extra(size, side, character, pose, outfit, cKey, oKey, pKey)
              else:
                  define_extra(size, side, character, None, outfit, cKey, oKey, None)
          if len(character['poses']) > 0: #Pose-specific outfits
            for pKey in character['poses']:
              pose = character['poses'][pKey]
              if isinstance(pose, dict):
                posePath = characterImageFolder + cKey + '/poses/' + pKey + '/' + 'pose.png'
                for oKey in pose:
                  outfit = pose[oKey]
                  define_extra(size, side, character, posePath, outfit, cKey, oKey, pKey)
              else:
                  define_extra(size, side, character, pose, None, cKey, None, pKey)
          elif len(character['outfits']) == 0 and len(character['expressions']) > 0:
              #Base sprite contains pose and outfit
              define_extra(size, side, character, None, None, cKey, None, None)

  def define_extra(size, side, character, pose, outfit, cKey, oKey, pKey):
      for eKey in character['expressions']:
          expression = character['expressions'][eKey]
          nameList = tuple([cKey, oKey, pKey, eKey])
          args = [(0, 0), pose, (0, 0), outfit, (0, 0), expression]

          if 'base' in character:
              args = [(0, 0), character['base']] + args
          define_image(size, side, nameList, args)
          for oeKey in character['outfits_extra']:
              outfit_extra = character['outfits_extra'][oeKey]
              if isinstance(outfit_extra, dict):
                if pKey in outfit_extra: #For each pose
                  nameList = tuple([cKey, oKey, oeKey, pKey, eKey])
                  define_image(size, side, nameList, args + [(0, 0), outfit_extra[pKey]])
              else:
                  nameList = tuple([cKey, oKey, oeKey, pKey, eKey])
                  define_image(size, side, nameList, args + [(0, 0), outfit_extra])
[/spoiler]

Re: Automatic character, background, etc. image defining scr

Posted: Wed Jul 29, 2015 7:19 am
by Zetsubou
Ladycardboard wrote:That error is solved but now all I'm getting is a grey placeholder picture with the text written in the middle of it. Here's the script:
That grey placeholder with text means the image you tried to call hasn't been defined.
Given that you've added fields to the get_character_indexes function, I'm guessing the issue is that your folder/image structure doesn't match the rest of the script.
ie. The script as it is only looks for 'outfits', 'poses', 'expressions' and 'outfits_extra' directories, in addition to the base.png image.

So to add your extra fields (ears, freya, freya2, arms) you would need to adjust the define_chars and define_extra methods. The exact modifications will depend on the order you want the images to be stacked, and which, if any, should be optional.

I might have a go at making this script cleaner and more generic tomorrow. As it is, you certainly can add extra fields, but it isn't a very simple thing to do.

Re: Automatic character, background, etc. image defining scr

Posted: Wed Jul 29, 2015 2:33 pm
by Ladycardboard
that would be so helpful and nice! ;-; Thank you so much.

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 5:27 pm
by Ladycardboard
Okay, while waiting for you to update the script I tried renaming my folders and organizing them into the method used in the script but came up with an error when i tried to call it like in your read-me.

Code: Select all

File "game/script.rpy", line 110: invalid syntax
    define_characters("sprites/")
I tried adding "def" before the "define_characters" but that didn't fix the error. :(

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 6:13 pm
by Zetsubou
Still working on a more generic version of the script. Difficult stuff.

That particular error is because the documentation (wrongly) lists the method as "define_characters" while the function is actually called "define_chars". So change either the function name or the call so they both match.

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 6:43 pm
by Ladycardboard
Alright. I'll give it a try. I'll keep my eye on the thread to see what you come up with on the updated version. You're a miracle worker. :>

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 6:50 pm
by Ladycardboard
Tried it and got this error:

Image

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 6:51 pm
by Zetsubou
Remove the "def".

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 9:00 pm
by Ladycardboard
i'm gonna stop playing around with the old script and wait for the new one.

Re: Automatic character, background, etc. image defining scr

Posted: Thu Jul 30, 2015 9:07 pm
by Zetsubou
If you're only doing basic layers, it'll probably work as-is: http://pastebin.com/3q88xWUi
I haven't finished nested directories or tested optional layers yet.
I also haven't actually tested the script in a game yet, so it might not even work :lol:
I'll try to finish it off a bit later today and test it at home this evening.

Re: Automatic character, background, etc. image defining scr

Posted: Fri Jul 31, 2015 3:30 am
by Zetsubou
Okay, this should do it: https://github.com/koroshiya/renpy-imag ... posite.rpy
I haven't tried using it in an actual game though.
Documentation in the file. Let me know if I missed anything.
Basically you just edit the dictionary variable in the get_character_indexes function.