# generated by scripts/generate_messages.py

from typing import Any, Dict

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import pack_int

class ObjPlayerInput(PrettyPrint):
    def __init__(
            self,
            direction: int = 0,
            target_x: int = 0,
            target_y: int = 0,
            jump: int = 0,
            fire: int = 0,
            hook: int = 0,
            player_flags: int = 0,
            wanted_weapon: int = 0,
            next_weapon: int = 0,
            prev_weapon: int = 0
    ) -> None:
        self.item_name: str = 'item.player_input'
        self.type_id: int = 1
        self.id: int = 0
        self.size: int = 10

        self.direction: int = direction
        self.target_x: int = target_x
        self.target_y: int = target_y
        self.jump: int = jump
        self.fire: int = fire
        self.hook: int = hook
        self.player_flags: int = player_flags
        self.wanted_weapon: int = wanted_weapon
        self.next_weapon: int = next_weapon
        self.prev_weapon: int = prev_weapon

    def __iter__(self):
        yield 'item_name', self.item_name
        yield 'type_id', self.type_id
        yield 'id', self.id
        yield 'size', self.size

        yield 'direction', self.direction
        yield 'target_x', self.target_x
        yield 'target_y', self.target_y
        yield 'jump', self.jump
        yield 'fire', self.fire
        yield 'hook', self.hook
        yield 'player_flags', self.player_flags
        yield 'wanted_weapon', self.wanted_weapon
        yield 'next_weapon', self.next_weapon
        yield 'prev_weapon', self.prev_weapon

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'direction': self.direction,
            'target_x': self.target_x,
            'target_y': self.target_y,
            'jump': self.jump,
            'fire': self.fire,
            'hook': self.hook,
            'player_flags': self.player_flags,
            'wanted_weapon': self.wanted_weapon,
            'next_weapon': self.next_weapon,
            'prev_weapon': self.prev_weapon
        }

    # first byte of data
    # has to be the first byte of the message payload
    # NOT the chunk header and NOT the message id
    def unpack(self, unpacker: Unpacker) -> bool:
        self.direction = unpacker.get_int()
        self.target_x = unpacker.get_int()
        self.target_y = unpacker.get_int()
        self.jump = unpacker.get_int()
        self.fire = unpacker.get_int()
        self.hook = unpacker.get_int()
        self.player_flags = unpacker.get_int()
        self.wanted_weapon = unpacker.get_int()
        self.next_weapon = unpacker.get_int()
        self.prev_weapon = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.direction) + \
            pack_int(self.target_x) + \
            pack_int(self.target_y) + \
            pack_int(self.jump) + \
            pack_int(self.fire) + \
            pack_int(self.hook) + \
            pack_int(self.player_flags) + \
            pack_int(self.wanted_weapon) + \
            pack_int(self.next_weapon) + \
            pack_int(self.prev_weapon)