valks-games / inventory Goto Github PK
View Code? Open in Web Editor NEWA inventory system being made in Godot 4 C# for future games
License: MIT License
A inventory system being made in Godot 4 C# for future games
License: MIT License
The following code makes use of the Newtonsoft.Json namespace and should be converted to make use of the newer System.Text.Json namespace. This way a 3rd party nuget package is no longer being used. Newtonsoft was used in the first place because Godot 3 had no support for newer .Net features but since Godot supports .Net 7 now, this has since been possible.
Inventory/Scripts/Utils/Extensions/ExtensionsObject.cs
Lines 17 to 27 in bfcdb58
Inventory/Scripts/Utils/Extensions/ExtensionsObject.cs
Lines 39 to 68 in bfcdb58
Tests should be performed after the code has been converted. For example GD.Print(someNode.PrintFull());
should only print the custom user defined props and not crash the game.
The new code should look something like this
using System.Text.Json;
using System.Text.Json.Serialization;
public static string PrintFull(this object v) =>
JsonSerializer.Serialize(v, new JsonSerializerOptions
{
WriteIndented = true,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
TypeInfoResolver = ???
})
The ??? is what I don't understand on what to do next.
Left Click
or Right Click
) and 1
2
constantly while hovering the mouse over hotbar slot 1I have come to a point on my project where I need to make InventorySlot.cs and ItemCursor.cs share some kind of abstract class or interface. They both share the common function SetItem(Item item) as seen below.
InventorySlot.cs:
Inventory/Scripts/Inventory/InventorySlot.cs
Line 165 in 1d9a342
Inventory/Scripts/Inventory/ItemCursor.cs
Line 37 in 1d9a342
The problem is ItemCursor extends from Godot.Control and all the functions in ItemCursor are static while all the functions in InventorySlot are not static and InventorySlot extends from nothing. I need to figure out how to make ItemCursor ?not be static I think and not extend from Control. So I can get them extending from the same class and have public abstract void SetItem(Item item);
.
Not really sure how to make ItemCursor not extend from Control though. Maybe make a ItemCursorManager.cs script that handles a ItemCursor? But there will only ever be one mouse cursor in the game? So it feels like a waste to not make everything in it static but making it not static prevents me from making them share a same abstract class.
These two functions are very similar in nature (HotbarInvSlot(...)
and HotbarCursor(...)
). The only difference is one is handling for if there is a item currently being held in the cursor and the other handles the inventory slot item under where the cursor is hovering.
I want to combine these functions into 1 function and just call that function 2 times with different params but because ItemCursor
and InventorySlot
are 2 different things, this proves to be difficult. Perhaps they could extend from some kind of abstract class?
Inventory/Scripts/Utils/UtilsInventory.cs
Lines 59 to 70 in 14fd440
Inventory/Scripts/Utils/UtilsInventory.cs
Lines 72 to 115 in 14fd440
Inventory/Scripts/Utils/UtilsInventory.cs
Lines 117 to 173 in 14fd440
As mentioned in #4 this seems hard to implement because a Slot could either be a InventorySlot or be from the ItemCursor. But if this does get implemented I think it could really clean up a lot of the code.
I am trying to animate the hotbar to move downwards out of view, however resizing the window while this animation is in play has a unwanted consequence. (see attached video below)
Inventory/Scripts/Utils/UtilsInventory.cs
Line 24 in 501aaf9
with the following code.
var tween = node.GetTree().CreateTween();
var windowHeight = DisplayServer.WindowGetSize().Y;
tween.TweenProperty(Player.Inventory.PanelContainer, "position:y", windowHeight, 0.5);
I
Constantly set the position with Position = DisplayServer.GetWindowHeight() - Y
in _PhysicsProcess(double delta)
The previous implementation and this one should be kept and made defined so it is easy to switch between them depending on what kind of game you are making.
The code should be made to easily switch between the 2 depending on what kind of game you want to make.
If the player inventory is defined to be at the top then...
Currently item animations are only implemented for when Shift + Clicking
to transfer items from one inventory to another. This should eventually be abstracted to all inventory manipulations.
Item animations done so far
Shift + Click
Double Click
Left Click
Right Click
Hold + Left Click
Hold + Right Click
1
2
3
...
7
8
9
Shift + R
Shift + T
For reference here is the code for transferring a item.
Inventory/Scripts/Inventory/InventorySlot.cs
Lines 224 to 325 in 14fd440
And here is the code a chest calls when it is closed. (relevant because the chest cancels all the animations on closing the chest -- perhaps this code should be moved else where)
Lines 31 to 50 in 14fd440
As seen in the video in #7 the item panel description popups keep appearing on top of each other. This is unwanted. There should only be one panel description popup present at any time and it should be displaying the info for the item you are hovering over.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.