happyleavesaoc/aoc-mgz

Can there be an example of how to use the Embedded struct in body to extract the action being performed

Closed this issue · 4 comments

cjds commented

I'm trying to understand how to use the struct to extract the action but am having trouble since Construct moved to 2.10 there are no docs there and the docs here parse_stream but do not show how to use the data

Construct 2.10 is not compatible with aoc-mgz. Use the version specified in setup.py. Embedded is not available in construct 2.10, and this module makes extensive use of that feature so we're stuck in 2.8.16 for now.

Does this answer your question?

cjds commented

Not really. I was saying that I can't figure out how to make use of the body because I can't find any docs on how to use Embedded struct anywhere.

If you could provide an example of how to access the data after parsing the stream, it would be very useful

Should not have to worry about the specific construct types -- they all offer easy access properties. For example, if you're using parse_stream to get the next body operation, you can do print(op) and get something like this:

Container:
    type = action (total 6)
    start = 148916
    op = 1
    length = 32
    action = Container:
        type_int = 3
        type = move (total 4)
        player_id = 1
        selected = 3
        x = 70.44791412353516
        y = 101.28125
        next = }\x07\x00\x00\x7f\x07\x00\x00 (total 8)
        flags = None
        unit_ids = ListContainer:
            1917
            1919
            1923
    end = 148960

This shows you what fields are available for the operation. If you wanted to access the unit_ids list, it would be like this: op.action.unit_ids and you would get a list.

cjds commented

That's perfect. I was doing dir(op) for ages trying to figure out what was avaialable.. Appreciate it :-)