Giter Site home page Giter Site logo

Comments (2)

peter-kish avatar peter-kish commented on June 12, 2024

Hi,

The idea makes a lot of sense and ItemSlot already has something similar implemented in the form of an overridable can_hold_item method. It almost always returns true, but the idea is to inherit ItemSlot and override can_hold_item it with custom checks.

Speaking off the top of my head, this is the approach I would take to implement something like that:

  1. Implement a can_hold_item(item: InventoryItem) for the Inventory class that would always return true. Again, the idea is to inherit from the Inventory class (or one of it's derivatives) and override this method.
  2. Modify the Inventory._can_add_item method, so that always returns false when can_hold_item fails. This will make Inventory.add_item and Inventory.transfer fail if the inventory can't hold the given item.
  3. Once Inventory.can_hold_item is properly implemented you can override it in your derived inventory class with custom checks, where you would check the item categories and blacklist/required list of the inventory.
  4. There's two ways you can implement categories that I can think of:
    1. Via item properties in the protoset: Unfortunately, protosets don't support arrays, but it's still doable as a single string that contains space-separated list of categories (would have to be parsed though)
    2. Via node properties: Inherit from InventoryItem, add an array of strings as a member and export it to be editable from the inspector (this one may be easier to implement at first but you may miss out on some useful features of the protosets)

Anyways, right now, I would suggest against taking the constraints approach for a few reasons:

  1. Inventory constraints have been recently added and the code is not very polished/modification friendly :(
  2. While my idea for constraints was a component based approach: allowing the user to come up with new constraints to modify inventory behavior (same as you described), they are still not on that level. The constraints are not totally independent and the ConstraintManager is aware of their potential presence. Adding new constraints will definitely mess up some of the logic. Ideally, we will be able to just inherit from InventoryConstraint, add some custom logic and add that constraint to the inventory with no additional changes, but we're not quite there yet.

Hope this helped.

from gloot.

peter-kish avatar peter-kish commented on June 12, 2024

I opened a separate issue for adding Inventory.can_hold_item. Will move this over to discussions.

from gloot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.