Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Repos_PosX Repos_PosY in PC inventory #3

Open
findell666 opened this issue Mar 30, 2022 · 7 comments
Open

Repos_PosX Repos_PosY in PC inventory #3

findell666 opened this issue Mar 30, 2022 · 7 comments

Comments

@findell666
Copy link

Hello,

I working with the old python version that is now called "master-obsolete".

I'm trying to get the position of the items in the inventory of the PC but I cannot find how. Can you help me please ?

PS : I used your lib to make this tool : https://threetowns-py.web.app/ (https://github.com/findell666/nwn-3t-items)

@jd28
Copy link
Owner

jd28 commented Mar 30, 2022

Hi,

I honestly didn't think anyone was using this anymore. Your project looks really cool!

I pushed a commit to master-obsolete that adds items function to player character. d50d3cb. Generally speaking it's probably safe to copy and paste missing things from CreatureInstance

So you can use the above like so:

from pynwn.resource import DirectoryContainer
from pynwn.player_character import PlayerCharacter

d = DirectoryContainer("adirectorywithbics")
p = PlayerCharacter("player.bic", d)

for pos, item in p.items:
    print("position:", pos, "resref:", item.resref)

@findell666
Copy link
Author

Thank you very much for your super fast update !

Now I can get the position of the items like I wanted :)

Your lib is awesome, it is very useful ! In terms of feature what is the difference with the new one ?

@jd28
Copy link
Owner

jd28 commented Apr 1, 2022

Happy to help and thank you for the kind words. If you need any further assistance just let me know, like I'm super curious if you could use PIL to render out the item-in-inventory textures. Maybe over here could be some inspiration, if it's something you're interested in doing.

The new version is going to be a wrapper around a C++ library, same style and spirit only more comprehensive and complete and useable in GUI projects like over here, a more humane JSON format, and actually be on pypi. But I've been a bit delayed on doing the bindings.. so not many features yet.

@findell666
Copy link
Author

findell666 commented Apr 1, 2022

I'm not that far (yet). But yes my ultimate goal would be to make a webapp that would allow you to manage your characters and items like the game Path of Exile does.

It started testing the minimap.py but for now I encounter errors. I had to comment out open(custom, 'rb') in resource.py, some error in minimap.py, sys.maxint line 24 and now I have an exception line 25 :
"startswith first arg must be bytes or a tuple of bytes, not str"
->EDIT : fixed by replacing readfp() by read()
->but now I have another exception : No section: 'TILE184' (line 28)

I keep going, thank again for your support !

@jd28
Copy link
Owner

jd28 commented Apr 2, 2022

I see I just assumed everyone would have a custom tlk, oops. 3t is still on 1.69?

I see xrange in there so there are probably some old Python 2 things about this. Running it through py2to3 gives the below. Does config have anything in it?

#!/usr/bin/env python

# Minimap Generator similar to the one in pspeed's nwn java tools
# NOTE: THIS EXAMPLE REQUIRES the Python Imaging Library!

from pynwn.resource import ResourceManager
from pynwn.util import chunks
import configparser, sys
import Image

if __name__ == '__main__':
    mgr      = ResourceManager.from_module('test.mod')
    scale    = 1
    minimum  = 32
    tga_dict = {}

    for area in mgr.module.areas:
        print(("Generating minimap for %s" % area.get_name(0)))

        config = configparser.ConfigParser()

        try:
            tile_tgas = []
            tga_size  = sys.maxsize
            config.readfp(mgr[area.tileset + '.set'].to_io())

            for tile in area.tiles:
                tga = config.get('TILE%d' % tile.id, 'ImageMap2D').lower()
                tga_fname = tga+'.tga'
                if not tga_fname in tga_dict:
                    tga_dict[tga_fname] = Image.open(mgr[tga_fname].to_io())

                tga = tga_dict[tga_fname]

                # I chose here to scale all the minimap images to the
                # smallest size so if one is 8x8 they will all be scaled
                # to 8x8.
                tga_size = min(tga_size, tga.size[0])
                tile_tgas.append((tga, tile.orientation))

            # Note: The tile list begins in the bottom left corner
            # so I'm going to reverse so that it starts in the top
            # left and draw down rather than up.
            tile_tgas = chunks(tile_tgas, area.width)[::-1]

            # minimum minimap tile size 16x16, just so some of the
            # smaller 8x8s are a little larger.
            tga_size = max(minimum, tga_size * scale)

            new_im = Image.new('RGBA', (area.width * tga_size,
                                        area.height * tga_size))

            for h in range(area.height):
                for w in range(area.width):

                    im, rot = tile_tgas[h][w]
                    new_loc = (w * tga_size, h * tga_size)

                    if im.size[0] != tga_size:
                        im = im.resize((tga_size, tga_size))

                    new_im.paste(im.rotate(rot*90), new_loc)

            new_im.save(area.resref + '.png')

        except Exception as e:
            print(e)
            continue

@findell666
Copy link
Author

I don't have the 3T mod (and its nwn dir) . I'm using my own vanilla nwn install for the tests. Yes it's 1.69 or maybe I installed 1.71 I don't remember. I will be able to check only next week-end.
Thank you :)

@findell666
Copy link
Author

findell666 commented Apr 10, 2022

Hello, I tested your code. Same exception.

Here is a screenshot of the debug of config variable.

image

I am using v1.69

Do you have discord ? It would be easier to chat there :) Findell#1884

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants