Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Hozer |
Hello!
I’m building a RPG game where my Items are all resources, for example (pseudocode):
class Item(cost: int, equipped_scene_path: Path, icon: Path)
class MeleeWeapon(damage: int) extends Item
class Shield(defense: int) extends Item
class Consumable(use_count: int) extends Item
class Potion(hp_healed: int) extends Consumable
Now I’m using a .tres file (Right click → New → Resource → Choose class) to create “instances” of these items, which are later parsed and added to an item DB.
Now, as the project is getting more items, I want to use JSON/CSV/SpreadSheet to organize the items, so now I’m testing a JSON similiar to this one:
[
{
"CODE": "MACE",
"NAME": "Mace",
"CLASS": "MeleeWeapon",
"COST": 10,
"ICON_PATH": "res://assets/items/generic_mace/icon.png",
"BASE_DAMAGE": 20
},
{
"CODE": "SAMPLESWORD",
"NAME": "Sample Sword",
"CLASS": "MeleeWeapon",
"COST": 5,
"ICON_PATH": "res://assets/items/generic_sword/icon.png",
"BASE_DAMAGE": 15
},
{
"CODE": "TORCH",
"NAME": "Torch",
"CLASS": "Item",
"COST": 0,
"ICON_PATH": "res://assets/items/torch/icon.png"
},
{
"CODE": "WOODEN_SHIELD",
"NAME": "Wooden Shield",
"CLASS": "Shield",
"COST": 10,
"ICON_PATH": "res://assets/items/generic_shield/icon.png",
"DEFENSE": 15
}
]
However, I cannot find a way to tell Godot to instance the class in parsed_item[“CLASS”] as the .tres usually does. Do you have any idea of how I should approach this? Or maybe I am making it too complicated for no reason.