#Confused about separation of responsibility between scripts and scenes

3 messages · Page 1 of 1 (latest)

charred tusk
#

Ok, I am trying to build an inventory system for my RPG game. I think I have a good understanding of how resources are utilized, I have the following structure for my classes.

item_data.gd

extends Resource
class_name ItemData

## Enable debug output for item resource
@export var debug: bool = false

@export var id : int

@export var name : String

@export var weight : float

@export var max_stack_count : int = 1

@export var base_cost: int

@export var sprite : Texture2D

Then we have stack_data.gd

extends Resource
class_name StackData

# The stack represents a collection of items of the same type
@export var item_data : ItemData
@export var count : int = 1

And finally container_data.gd.

extends Resource
class_name ContainerData

# The container holds a list of stacks
@export var slots : Array[StackData] = []

This is all pretty standard and common from what I've seen. This framework provides the "data storage" so I can create items and defined "sets" of items with containers.

My confusion is how I implement this data in my game effectively.

Let's take the Container as our example. There are a few places we might need to access the data stored in a container resource

  • Something abstract like the player's inventory
  • Something interactable like a chest

My first thought is that I need some scripting logic for basic container operations, with functions like add_to_container(), remove_from_container(), etc. An entire script for this functionality makes sense.

But where does this code go? Does it live in a standalone utility script, like a ContainerManager that can simply take in a ContainerData object as input?

Should I be using a Container scene, where each instance of the scene is one logical container?

#

In my previous implementation, I had a ContainerComponent scene that could be dragged as a child of a 2D interactable scene/object (like a vase) and give it the "property" of being a container. I think this is good design

#

But how would I have something like that interact with the "underlying" container logic? What needs to be a scene and what just needs to be a script?