Comments (2)
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:
- Implement a
can_hold_item(item: InventoryItem)
for theInventory
class that would always returntrue
. Again, the idea is to inherit from theInventory
class (or one of it's derivatives) and override this method. - Modify the
Inventory._can_add_item
method, so that always returnsfalse
whencan_hold_item
fails. This will makeInventory.add_item
andInventory.transfer
fail if the inventory can't hold the given item. - 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. - There's two ways you can implement categories that I can think of:
- 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)
- Via node properties: Inherit from
InventoryItem
, add an array of strings as a member andexport
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:
- Inventory constraints have been recently added and the code is not very polished/modification friendly :(
- 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 fromInventoryConstraint
, 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.
I opened a separate issue for adding Inventory.can_hold_item
. Will move this over to discussions.
from gloot.
Related Issues (20)
- Add a `can_hold_item` method for the `Inventory` class HOT 1
- Error message when no selected styles on CtrlInventoryGridEx HOT 2
- Increasing lag/slow down when using create_and_add_item with InventoryGridStacked HOT 3
- need more ex HOT 3
- Is there a way to use d-pad/arrows to control selection instead of mouse? HOT 1
- Auto-remove items when `stack_size == 0` HOT 1
- bad performance with big grid inventories HOT 2
- Multiple item slots can hold the same item HOT 1
- Dragging items from a `CtrItemSlot` to a `CtrlInventoryGrid` doesn't work HOT 1
- Add an optional `ItemSlot` feature that would take ownership of the equipped item HOT 1
- Add an option to resize `CtrlItemSlot` icons HOT 1
- No signal named `item_selected` in CtrlInventoryGrid HOT 4
- Item image will take up maximum height and width of image when used in a CtrlItemSlotEx HOT 2
- _get_prototype_size returning width x width not width x height HOT 2
- Changing inventory_grid for CtrlInventoryGridEx doesn't increase size of custom textures. HOT 4
- Rotatable Grid Based Items HOT 1
- Multi-select items in CtrlInventoryStacked HOT 2
- set_property changes the protoset instead of the properties HOT 8
- After clear() cant interact with inventoryGrid HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gloot.