Skip to content

Advice Request: Correct area of code to add a "blacklist categories" and "required categories" set of flags? #111

@Polatrite

Description

@Polatrite

I am working on a project that utilizes many different inventory grids with different purposes - a normal inventory, as well as individual slots for equipment, a furnace grid for smelting, a workbench grid for milling, a combining grid for synthesizing, etc.

TL;DR: I'm wondering where I should integrate these new constraints to Gloot to support this functionality for all inventory types in the cleanest way possible. This could also be a feature request, but I'm keen on having it somewhat quickly so I can just add it myself and submit a PR!


Each grid is allowed to accept certain categories of items, but not accept others. I plan to implement this with a blacklist and a required list.

Items will contain a "flags" property which is an array of all the categories they belong to.

A sword might be [item, equippable, weapon, sword]. A piece of raw meat might be [item, food, raw], whereas cooked meat might be [item, food, cooked, consumable].

Blacklist: Array[Enum.ITEM_CATEGORIES]
A list of item categories that cannot be inserted into this inventory. If an item contains any of the blacklisted categories, the item transfer will fail.

Required list: Array[Enum.ITEM_CATEGORIES]
A list of item categories that are required to be inserted into this inventory. If an item does not contain all of the required categories, the item transfer will fail.

Examples of how this is used:

  • The main player inventory might have a required list of ['item'].
  • A cooking station might have a required list of ['food'] but a blacklist of ['cooked'].
  • A smelting furnace might have a required list of ['smeltable'].
  • A helmet equipment slot on a paperdoll might have a required list of ['equipment', 'helmet'] but a blacklist of ['broken']

The goal here being to encode lots of gameplay rules into the required/blacklist system and drastically cut down on bespoke validation logic all over the place - let the inventory system manage all of this for us.


I was looking through the codebase (which I am admittedly not super familiar with) and originally implemented a hacky version of this at the control level. However after digging a bit more, it seems like the ConstraintManager and specifically adding a new constraint (or two) for the required vs. blacklist logic might seem like the best course of action. Do you have any advice on how to tackle this problem?

Thanks for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions