{"id":"frexsim/grid-pack","name":"grid-pack","scope":"frexsim","platform":"roblox","description":"An easy way to create grid-type inventories.","version":"0.2.3","latest":"0.2.3","versions":["0.2.0","0.2.2","0.2.3"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"sleitnick/signal":{"version":"^2.0.1","alias":"signal"},"sleitnick/trove":{"version":"^1.1.0","alias":"trove"}},"integrity":"a8ee3abd81af6c74d4bdec00c903dbbe7703eb29b70353e536f80615fa740444","likes":0,"downloads":0,"install":"forest install frexsim/grid-pack","url":"https://forest.dev/p/roblox/frexsim/grid-pack","files":"https://api.forest.dev/ai/package/roblox/frexsim/grid-pack/files","readme":"# GridPack\r\nAn easy way to create grid-style inventories on Roblox.\r\n\r\n## How to Install\r\nHead to the releases page and download the latest gridpack.rbxm file.\r\nThen insert the downloaded file in Roblox Studio by right clicking on ReplicatedStorage and choosing \"Insert from File...\".\r\n\r\n![InsertFromFile](./readme/InsertFromFile.png)\r\n\r\n## Getting Started\r\nHere are some small guides to help you get started!\r\nStart by creating a LocalScript and follow along:\r\n\r\n### Creating Your First Grid\r\nTo create a grid your first grid item manager you will need to use the `.createGrid()` method in GridPack.\r\nHere is an example:\r\n\r\n```lua\r\nlocal GridPack = require(game:GetService(\"ReplicatedStorage\").Packages.GridPack)\r\n\r\nlocal screenGui = Instance.new(\"ScreenGui\")\r\nscreenGui.Name = \"GridPack\"\r\nscreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling -- ZIndexBehavior has to be set to Sibling since CanvasGroups don't work with Global and GridPack heavily relies on CanvasGroups.\r\nscreenGui.ResetOnSpawn = false\r\nscreenGui.Parent = game:GetService(\"Players\").LocalPlayer.PlayerGui\r\n\r\nlocal grid = GridPack.createGrid({\r\n    Parent = screenGui, -- Parent of the grid container\r\n\r\n    Visible = true -- If the grid is visible, changes the containers visible property. Also disables item interaction on all items inside.\r\n\r\n    Assets = {\r\n        Slot = nil -- Add your own GuiObject here to customize the slots in the grid.\r\n    }\r\n\r\n    GridSize = Vector2.new(8, 15), -- How many slots the grid has on the X and Y axes.\r\n    SlotAspectRatio = 1, -- Aspect ratio of one slot in the grid, helps with different resolutions if you're using scale instead of offset.\r\n\r\n    AnchorPoint = Vector2.new(0, 0.5), -- Anchor point of the grid container\r\n    Position = UDim2.new(0, 20, 0.5, 0), -- Position of the grid container\r\n    Size = UDim2.fromScale(0.25, 0.5), -- Size of the grid container\r\n\t\r\n    Metadata = {\r\n        -- Here you are free to store any values you want.\r\n    }\r\n})\r\n```\r\n\r\nYou should now have a grid on your screen once you join the game!\r\n\r\n### Adding Items\r\nAdding items to grids is really easy. But before adding you will have to create a new item. This is done in a simmilar way as creating a grid, but instead you use the `.createItem()` method.\r\nHere is an example showing an item being created and added to the grid we just created:\r\n\r\n```lua\r\n-- Continuing from last example.\r\n\r\nlocal item = GridPack.createItem({\r\n    Position = Vector2.new(0, 0), -- Position in a grid.\r\n    Size = Vector.new(2, 3), -- Size in a grid.\r\n\r\n    Assets = {\r\n        Item = nil, -- Add a custom GuiObject here to change the item's gui element.\r\n    },\r\n\t\r\n    Metadata = {\r\n        -- Here you are free to store any values you want.\r\n    },\r\n})\r\n\r\ngrid:AddItem(item) -- Add the item to the grid.\r\n```\r\n\r\nThe item should now be added to the grid and should also be draggable!\r\n\r\n### Connecting Item Managers\r\nTo connect two item managers together you use a TransferLink. Both Grids and SingleSlots can be connected to eachother and Grid to SingleSlot.\r\nThis is done like:\r\n\r\n```lua\r\n-- Continuing from last example.\r\n\r\nlocal transferGrid = GridPack.createGrid({\r\n    Parent = screenGui,\r\n\r\n    Visible = true\r\n\r\n    GridSize = Vector2.new(8, 15),\r\n    SlotAspectRatio = 1,\r\n\r\n    AnchorPoint = Vector2.new(1, 0.5),\r\n    Position = UDim2.new(1, -20, 0.5, 0),\r\n    Size = UDim2.fromScale(0.25, 0.5),\r\n})\r\n\r\nlocal transferLink = GridPack.createTransferLink({}) -- Create TransferLink\r\ngrid:ConnectTransferLink(transferLink) -- Connect TransferLink to our first grid.\r\ntransferGrid:ConnectTransferLink(transferLink) -- Connect the TransferLink to our new grid.\r\n```\r\n\r\nYou will now be able to drag an item over to the other inventory and it should adjust to the new inventory.\r\n\r\n### Single Slots\r\nWith SingleSlots you are able to drag any item into it, disreguarding the size and position of the item. This can be used as an equip slot where you have your primary weapon, tool or armor stored.\r\n\r\nThe SingleSlot setup is a little different than the Grid setup.\r\nHere is and example:\r\n\r\n```lua\r\nlocal GridPack = require(game:GetService(\"ReplicatedStorage\").Packages.GridPack)\r\n\r\nlocal screenGui = Instance.new(\"ScreenGui\")\r\nscreenGui.Name = \"GridPack\"\r\nscreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling\r\nscreenGui.ResetOnSpawn = false\r\nscreenGui.Parent = game:GetService(\"Players\").LocalPlayer.PlayerGui\r\n\r\nlocal singleSlot = GridPack.createSingleSlot({\r\n    Parent = screenGui, -- Parent of the slot container\r\n\r\n    Visible = true -- If the slot is visible, changes the containers visible property. Also disables item interaction on the item inside.\r\n\r\n    Assets = {\r\n        Slot = nil -- Add your own GuiObject here to customize the slot.\r\n    }\r\n\r\n    AnchorPoint = Vector2.new(0, 0.5), -- Anchor point of the slot container\r\n    Position = UDim2.new(0, 20, 0.5, 0), -- Position of the slot container\r\n    Size = UDim2.fromScale(0.25, 0.5), -- Size of the slot container\r\n\t\r\n    Metadata = {\r\n        -- Here you are free to store any values you want.\r\n    }\r\n})\r\n```\r\n\r\n## Item Communication with Server\r\nSince GridPack doesn't handle the serverside for you, items come with the `.MoveMiddleware` property which is run before the item actually gets moved on the client.\r\nAnd you can use this property to validate your item movements by return true or false is the movement is valid.\r\nItem collision is still checked before `.MoveMiddleware` but it's also good to check for collision on the server to prevent cheating or client desync.\r\nHere's and example of how client to server communication would work:\r\n\r\n```lua\r\nlocal item = GridPack.createItem({\r\n    -- Other Item properties\r\n\r\n    MoveMiddleware = function(movedItem, newGridPosition, lastItemManager, newItemManager)\r\n        --[[\r\n            movedItem: This Item\r\n            newGridPosition: This Item's new position in a Grid. (Doesn't apply with SingleSlots)\r\n            lastItemManager: The ItemManager that the Item was in before it got moved.\r\n            newItemManager: The new ItemManager the item was moved to. (If there is one)\r\n        ]]\r\n\r\n        if newItemManager then\r\n            -- Ask server to validate the Item movement between ItemManagers and return the result to the Item\r\n            return ReplicatedStorage.Remotes.MoveItemAcrossItemManager:InvokeServer()\r\n        else\r\n            -- Ask server to validate the Item movement between positions and return the result to the Item\r\n            return ReplicatedStorage.Remotes.MoveItem:InvokeServer()\r\n        end\r\n\r\n        -- If the result if false then the Item will move back to it's last position.\r\n    end,\r\n\r\n    Metadata = {\r\n        -- Tip: Here you can any values you need for MoveMiddleware!\r\n    }\r\n\r\n    -- Other Item properties\r\n})\r\n```","readmeTruncated":false}