<commit_before>"""
Place items.

This module handles the placement of food and toys in the yard.
"""

from lib import printer

try:
    input = raw_input
except NameError:
    pass


def menu(data):
    """Display yard menu."""
    data["prefix"] = "[The Yard]".format(printer.PColors, printer.PColors)
    list_yard_items(data)
    data["in_yard"] = True
    #TODO add a picture taking option
    actions = {"list owned items": list_owned_items,
               "examine yard": list_yard_items,
               "cats": cats,
               "place toy": place,
               "place food": food,
               "leave yard": exit}
    while data["in_yard"]:
        data["completer"].set_actions(actions.keys())
        printer.prompt(data["prefix"], actions.keys())
        inp = input("{.YARD}{}{.ENDC} What do you want to do? ".format(
            printer.PColors, data["prefix"], printer.PColors))
        if inp in actions:
            actions[inp](data)
            continue
        else:
            printer.invalid(data["prefix"])


def compute_space(data):
    """Compute available yard space."""
    return data["space"] - sum([item["size"] for item in data["yard"]])


def exit(data):
    """Cancel item placement."""
    data["in_yard"] = False


def list_owned_items(data):
    """Display a list of owned items."""
    owned_items = [item["name"] for item in data["items"].values() if "owned" in item["attributes"]]
    if len(owned_items) == 0:
        printer.warn(data["prefix"], "You don't own any items, better go buy some in the shop~!")
    else:
        printer.yard(data["prefix"], "You currently own a {0}".format(", and a ".join(owned_items)))


def list_yard_items(data):
    """Display list of items placed in yard."""
    if len(data["yard"]) > 0:
        items = [item for item in data["yard"]]
        for item in items:
            cats = "no one"
            if item["occupied"]:
                cats = ", and ".join([cat for cat in item["occupant"]])
            printer.yard(data["prefix"], "Your yard currently has a {0} in it, occupied by {1}".format(item["name"], cats))
        cat_activities(data)
    # TODO: add cat descriptions
    else:
        printer.warn(data["prefix"], "You currently have nothing in your yard, how sad")
    check_food(data)


def cat_activities(data):
    """Display cat activities."""
    yard_items = [(obj, obj["occupant"]) for obj in data["yard"] if obj["occupied"]]
    for item in yard_items:
        cats = item[1]
        for cat in cats:
            printer.p(data["prefix"], "{0} is playing with a {1}".format(cat, item[0]['name']))

def cats(data):
    """Allow you to look at the cats in your yard"""
    cats_in_yard = []
    [cats_in_yard.extend(obj["occupant"]) for obj in data["yard"] if obj["occupied"]]
    cat_names = [cat for cat in cats_in_yard]
    data["completer"].set_actions(cat_names)
    printer.yard(data["prefix"], "These are the cats in your yard:")
    for cat in cat_names:
        printer.yard(data["prefix"],cat)
    inp = input("{.YARD}{}{.ENDC} Which cat would you like to look at? ".format(
        printer.PColors, data["prefix"], printer.PColors))
    if inp in cat_names:
        desc_cat(data, [cat for cat in cats_in_yard if cat["name"] == inp][0])
    else:
        printer.warn(data["prefix"], "I'm sorry that cat isn't in your yard!")

def desc_cat(data, cat):
    printer.yard(data["prefix"], cat["desc"])


def place(data):
    """Place item in yard."""
    items_list = [item for item in data["items"].values()
                  if "owned" in item["attributes"] and not item["in_yard"]]
    # TODO: this is ultra gross
    placable_items = {}
    for item in items_list:
        #deliniate placable items from things like food
        if item["size"] < 6:
            placable_items[item["name"]] = item
    data["completer"].set_actions(placable_items.keys())
    printer.yard(data["prefix"], "Here are the items that you can put in your yard: {0}".format(", ".join(placable_items.keys())))
    inp = input("{.YARD}{}{.ENDC} Which item would you like to place? ".format(
        printer.PColors, data["prefix"], printer.PColors))
    if inp in placable_items.keys():
        try_to_place(data, placable_items[inp])
    else:<commit_msg>bug fix<commit_after>"""
Place items.

This module handles the placement of food and toys in the yard.
"""

from lib import printer

try:
    input = raw_input
except NameError:
    pass


def menu(data):
    """Display yard menu."""
    data["prefix"] = "[The Yard]".format(printer.PColors, printer.PColors)
    list_yard_items(data)
    data["in_yard"] = True
    #TODO add a picture taking option
    actions = {"list owned items": list_owned_items,
               "examine yard": list_yard_items,
               "cats": cats,
               "place toy": place,
               "place food": food,
               "leave yard": exit}
    while data["in_yard"]:
        data["completer"].set_actions(actions.keys())
        printer.prompt(data["prefix"], actions.keys())
        inp = input("{.YARD}{}{.ENDC} What do you want to do? ".format(
            printer.PColors, data["prefix"], printer.PColors))
        if inp in actions:
            actions[inp](data)
            continue
        else:
            printer.invalid(data["prefix"])


def compute_space(data):
    """Compute available yard space."""
    return data["space"] - sum([item["size"] for item in data["yard"]])


def exit(data):
    """Cancel item placement."""
    data["in_yard"] = False


def list_owned_items(data):
    """Display a list of owned items."""
    owned_items = [item["name"] for item in data["items"].values() if "owned" in item["attributes"]]
    if len(owned_items) == 0:
        printer.warn(data["prefix"], "You don't own any items, better go buy some in the shop~!")
    else:
        printer.yard(data["prefix"], "You currently own a {0}".format(", and a ".join(owned_items)))


def list_yard_items(data):
    """Display list of items placed in yard."""
    if len(data["yard"]) > 0:
        items = [item for item in data["yard"]]
        for item in items:
            cats = "no one"
            if item["occupied"]:
                cats = ", and ".join([cat for cat in item["occupant"]])
            printer.yard(data["prefix"], "Your yard currently has a {0} in it, occupied by {1}".format(item["name"], cats))
        cat_activities(data)
    # TODO: add cat descriptions
    else:
        printer.warn(data["prefix"], "You currently have nothing in your yard, how sad")
    check_food(data)


def cat_activities(data):
    """Display cat activities."""
    yard_items = [(obj, obj["occupant"]) for obj in data["yard"] if obj["occupied"]]
    for item in yard_items:
        cats = item[1]
        for cat in cats:
            printer.yard(data["prefix"], "{0} is playing with a {1}".format(cat, item[0]['name']))

def cats(data):
    """Allow you to look at the cats in your yard"""
    cats_in_yard = []
    [cats_in_yard.extend(obj["occupant"]) for obj in data["yard"] if obj["occupied"]]
    cat_names = [cat for cat in cats_in_yard]
    data["completer"].set_actions(cat_names)
    printer.yard(data["prefix"], "These are the cats in your yard:")
    for cat in cat_names:
        printer.yard(data["prefix"],cat)
    inp = input("{.YARD}{}{.ENDC} Which cat would you like to look at? ".format(
        printer.PColors, data["prefix"], printer.PColors))
    if inp in cat_names:
        desc_cat(data, [cat for cat in data["cats"] if cat == inp][0])
    else:
        printer.warn(data["prefix"], "I'm sorry that cat isn't in your yard!")

def desc_cat(data, cat):
    printer.yard(data["prefix"], data["cats"][cat]["desc"])


def place(data):
    """Place item in yard."""
    items_list = [item for item in data["items"].values()
                  if "owned" in item["attributes"] and not item["in_yard"]]
    # TODO: this is ultra gross
    placable_items = {}
    for item in items_list:
        #deliniate placable items from things like food
        if item["size"] < 6:
            placable_items[item["name"]] = item
    data["completer"].set_actions(placable_items.keys())
    printer.yard(data["prefix"], "Here are the items that you can put in your yard: {0}".format(", ".join(placable_items.keys())))
    inp = input("{.YARD}{}{.ENDC} Which item would you like to place? ".format(
        printer.PColors, data["prefix"], printer.PColors))
    if inp in placable_items.keys():
        try_to_place(data, placable_items[inp])
    else:
{'fraction_non_alphanumeric': 0.15198211975061757, 'fraction_numerical': 0.002823197270909305, 'mean_word_length': 2.9324699352451433, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6381641', 'n_tokens_mistral': 2624, 'n_tokens_neox': 2613, 'n_words': 810}