Coder Social home page Coder Social logo

zcaliptium / gdinv Goto Github PK

View Code? Open in Web Editor NEW
75.0 3.0 10.0 66 KB

More or less universal inventory system plugin for Godot Engine (3.3+). Data-driven.

License: MIT License

GDScript 100.00%
godot-engine godot godot3 inventory-system inventory gdscript

gdinv's People

Contributors

kimabjorkede avatar kulkodar avatar zcaliptium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gdinv's Issues

Item Definition Sets/Batches

At current state the parser supports only single definition per JSON config.

  • weapons/
    • iron_sword.json -> iron_sword
    • bronze_sword.json -> bronze_sword
  • potions/
    • small_health_potion.json -> small_health_potion
    • large_health_potion.json -> large_health_potion
    • small_mana_potion.json -> small_mana_potion
    • large_mana_potion.json -> large_mana_potion

It could be useful to implement functionality to load multiple definitions from one file:

  • Weapons.json ->
    • iron_sword
    • bronze_sword
  • Potions.json ->
    • small_health_potion
    • large_health_potion
    • small_mana_potion
    • large_mana_potion

Crash with from_data()

This line crashes Godot.

for i in range (0, stacks_data):

i becomes a boolean value and can't be iterated upon.

Changing the function to this fixes the issue.
(Notice the added new_stack.stackSize = stacks_data[i].stackSize)

func from_data(json_data: Dictionary) -> void:
	var stacks_data = json_data.get("stacks", []);
	
	clear();
	
	if (typeof(stacks_data) == TYPE_ARRAY):
		# For finite inventory.
		if (RestrictStackSize):
			for i in range (0, stacks_data.size()):
				if (i >= STACKS.size()):
					break;

				# Skip invalid stacks (null elements in array).
				if (stacks_data[i] == null):
					continue;

				var new_stack = GDInv_ItemStack.new();
				new_stack.from_data(stacks_data[i]);
				STACKS[i] = new_stack;
		else:
			for i in range (0, stacks_data.size()):
				print(stacks_data[i])
				var new_stack = GDInv_ItemStack.new();
				new_stack.from_data(stacks_data[i]);
				new_stack.stackSize = stacks_data[i].stackSize
				print(new_stack.stackSize)
				STACKS.append(new_stack);

maxStackSize exceeded causes an item to just be added to a different slot. Is this intended?

Maybe I just don't correctly understand how slots and stacks should work.
I would expect that by setting maxStack: 1 I would be configuring the inventory to only accept 1 item of that type (identifier) and refuse to add beyond that amount.
However the way it currently works, it just "spills over" the new item to a new slot.
This appears somewhat counterintuitive to me.
Let me know what I am getting wrong.

GDInv_Inventory init() appends to STACKS withouth size - check

Multiple calls to init() in GDInv_Inventory increase the size of GDInv_Inventory.STACKS altough GDInv_Inventory.MaxStacks stays the same. A size - check before the call to STACKS.append could solve this problem of different STACKS.size() and MaxStacks.

This was an issue for me because I dynamically created the inventory (with call to init()) and on tree_enter GDInv_Inventory.init() gets called again via GDInv_Inventory._ready().

ObjectDB instances leaked at exit

After setting up everything following the Wiki, I added one .json file representing an item, which is successfully loaded through the Singleton GDInv_ItemDB, and everything seemed fine. However, upon closing the game, I stumbled across the console logging out that some Object instances were leaked.

Therefore, I run again with --verbose flag (in case you wonder how, from the editor go to Project settings => editor => run args and put --verbose in there). Here I show you an example of the output with the leaked instance:

image

As you can see, the GDInv_ItemDefinition class was leaked. Hence, I checked out in the codebase where it was generated, and found out that in the Singleton class GDInv_ItemDB inside the load_item function, a GDInv_ItemDefinition instance is created, which is a class that extends Object, which however is not freed when the game is closed, leading to the warning above.

So I just changed it to extend a Reference, which will be freed automatically when the game closes leading to no leaks, but I'm not sure whether this is right solution or not. Any thoughts?

It might even be that I have made a mistake along the way, and this is not supposed to happen usually. In case you think this is the reality, please let me know, thank you.

Unable to load the plugin

I added the plugin as submodule to my project, started godot, enabled plugin, and then -
изображение
In GDInv_ItemDB.gd and the same in ItemStack (only it says singleton instead of class)
Also this gets printed to console:

modules\gdscript\gdscript.cpp:1412 - Condition "!named_globals.has(p_name)" is true.
Script does not inherit a Node: res://addons/gdinv/GDInv_ItemDB.gd.
editor\editor_autoload_settings.cpp:460 - Condition "!info->node" is true. Continuing.

I use Godot 3.2

Inventory should extend Node

I think GDInv_Inventory needs to extend Node, because otherwise it can't work with static typing as all the get_node kind of functions expect Nodes.

For example all of these give errors:

onready var inventory: GDInv_Inventory = $inventory
onready var inventory: GDInv_Inventory = $inventory as GDInv_Inventory
onready var inventory := $inventory as GDInv_Inventory

_ready():
  var inv: GDInv_Inventory = $inventory

I believe this is because GDInv_Inventory extends Object and not Node.

Wrong installing

I'm thinking github project must repeat structure of "addons" directory("addons/gdinv"). It wrong installing by it...

Saving inventory

Is there any prefered or intendend way to save the inventory?

I tried saving it by doing file.store_val($GDInv_Inventory.STACKS, true). But the whole object doesn't get saved, and it gives off errors getting read back.

The only way I found was to keep track of the inventory in a seperate dictionary, but it seems very convoluted to have to keep track of the inventory in a dictionary.

Missing a method to remove items by id

It would be useful to be able to remove an item by id instead of having to find the slot index first.
Such method would just return false in case of failure.

GDInv_ItemStack.from_data sometimes don't handle 'stackSize' properly.

Sometimes 'stackSize' field could TYPE_INT rather than TYPE_REAL.

gdinv/GDInv_ItemStack.gd

Lines 25 to 37 in 8a08eea

func from_data(json_data: Dictionary):
var item_id = json_data.get("item", "null");
var size = json_data.get("stackSize", 0.0);
var caps = json_data.get("capabilities", {})
if (typeof(item_id) == TYPE_STRING and item_id != "null"):
item = GDInv_ItemDB.get_item_by_id(item_id);
if (typeof(caps) == TYPE_DICTIONARY):
capabilities = caps;
if (typeof(size) == TYPE_REAL):
stackSize = int(size);

GDInv_ItemDB and GDInv_ItemStack can't be fully loaded.

I'm getting an error saying The class "GDInv_ItemStack" couldn't be fully loaded (script error or cyclic dependency.) And it seems to be the cyclic dependency because DB and Stack do in fact call on each other. Is this a bug or have I set something up incorrectly?

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.