npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rpgjs-inventory

v1.0.6

Published

It's a plugin of [RPG JS](https://rpgjs.dev/) engine that gives possibility to manage inventory.\ Example implementation: [inventory](https://github.com/dominx99/rpgjs-plugins/blob/master/examples/inventory)

Downloads

7

Readme

RPG JS Plugin

Description

It's a plugin of RPG JS engine that gives possibility to manage inventory.
Example implementation: inventory

Features

✅Move, stack, replace item in inventory
✅Filling existing stacks while adding to inventory
⬜Configurable max stack size, currently max stack size is hardcoded to 200

Watch the video

Installation

You can easily install the RPG JS Plugin using npm. Open your terminal and run the following command:

npx rpgjs add rpgjs-inventory

Usage

First you have to add ivnentory to the initialization of player process:

main/player.ts

import { Inventory, Backpack, Equipment } from 'rpgjs-inventory';

const player: RpgPlayerHooks {}

const originalInitializeMethod = RpgPlayer.prototype.initialize;
RpgPlayer.prototype.initialize = function() {
    originalInitializeMethod.apply(this);

    this.inventory = new Inventory([new Backpack('main', 30) ], new Equipment());
}

export default player

Backpack arguments are:

  • id: string - it is id of the backpack to interact with
  • size: string - quantity of slots in the backpack

[!IMPORTANT] You can add multiple backpacks to the inventory, but it's not well tested yet

Next you should use extended decorators which allows to set icon for an Item:

import { Item } from 'rpgjs-inventory';

/** @ts-ignore */
@Item({
    id: 'hp-potion-1',
    name: 'Healing Potion',
    description: 'Gives 100 HP',
    icon: 'hp-potion-1'
    /* other params */
})
export default class Potion {
}

Add item

  • Example
player.addItem('potion', 300)
player.inventory.addItem({
    itemId: 'potion',
    type: 'item',
    nb: 300,
})
  • Usage

It adds item to the inventory.

[!IMPORTANT] Note that you have to also use native player.addItem method because this plugin does not overwrite the main items system but it's only next layer on top of it.

Next you can use player.inventory.addItem which will take into account stack size.
If there are already potions in inventory it will fill already existing stacks and then add the rest to the empty one.

Replace item

  • Example
const from: Slot = { backpack: 'main', slot: 5 };
const from: Slot = { backpack: 'main', slot: 25 };

player.inventory.replaceItems(from: Slot, to: Slot);
  • Usage

It replaces items in inventory.
In case when there is no item in from or to slot then it does nothing.

Stack items

  • Example
const from: Slot = { backpack: 'main', slot: 5 };
const from: Slot = { backpack: 'main', slot: 25 };

player.inventory.replaceItems(from: Slot, to: Slot);
  • Usage

it stacks two items with the same id in the inventory.

Move item to empty slot

  • Example
const from: Slot = { backpack: 'main', slot: 5 };
const from: Slot = { backpack: 'main', slot: 25 };
const quantityToMove = 50;

moveItemToEmptySlot(from, to, quantityToMove);
  • Usage

It moves an item to the other empty slot in inventory.
In case when target slot is not empty then it will trigger an error.

Move item

  • Example
const from: Slot = { backpack: 'main', slot: 5 };
const from: Slot = { backpack: 'main', slot: 25 };
const quantityToMove = 50;
player.inventory.moveItem(from, to, quantityToMove);
  • Usage:

It is facade of the 3 methods: replaceItems, stackItems and moveItemToEmptySlot.
If target slot is empty then it will just move an item.
If the first and target slot items are the same (id) then it will stack these items.
If the first and target slot items are different then it will replace these items.

Move item

  • Example
const from: Slot = { backpack: 'main', slot: 5 };
const quantity = 50;

player.inventory.decreaseQuantityOfSlot(slot, quantity): void {
  • Usage:

  • It decreases item quantity by slot

  • Remember to also decrease item quantity of native inventory system, eg.

player.useItem('potion');
player.inventory.decreaseQuantityOfSlot({ backpack: 'main', slot: 0 }, 1);