Code Monkey home page Code Monkey logo

simple-inventory's People

Contributors

chapelr avatar lorenzoancora avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

simple-inventory's Issues

Access descriptions and create links outside inv

Hello!

it will be perfecto to add the description when using loops for inv.table. Also, the option to create links to popup, use or drop outside the defined interface (i think its not possible now).

Thank you!

Optionally run a function before each item/stack transfer and allow it to cancel the transfer

I may be over-complicating things and should just build my own UI to do this, but maybe it makes sense to have built in.

The reason I would like this feature is to use the inventory for a trading system.

The user-supplied function should be able to:

  • know where the transfer is from and to. Probably just a from and to argument that gets passed the inventory names.
  • know what is being transferred. The name of the item or the whole item, either works for me, I just want to have something I can look up in a list of item values.
  • if transferring stacks are supported, a way to know how many of an item is being transferred.
  • cancel the transfer. E.g. if the function determines that the owner of the receiving inventory doesn't have enough money to pay for the item.

Recipes/examples

Ideas for examples:

  • Crafting game inventory (basic stacks like wood, stone, etc).
  • Collectibles/currency (gems, mini medals, etc).
  • Key/adventure/puzzle inventory (like a point-and-click adventure game).
  • Consumables inventory (potions).
  • Shop
  • (Probably not for beta release.) Very basic equipment system (maybe, would require lots of extra code).

Item.extendPrototype() does not work as expected

Imagine the following sequence:

Item.extendPrototype({ image: "" });
Item.add("Book", { image: "book.png", description: "A book" });
Item.add("Dog", { image: "dog.png", description: "A dog" });
Item.add("Ring", { description: "A Ring" });

This should add an image property to an item, with a default value of an empty string. I would expect this to be set as given on both Book and Dog and blank on Ring.

However this is not the case:

Item.get("Book").image => "book.png"
Item.get("Dog").image => "dog.png"
Item.get("Ring").image => "dog.png"

It appears that the last value supplied for the image property applies to all subsequent Items, as if the default values had been modified.

I suspect the error is here:

Object.assign(this, Object.assign(defaultOpts, opts));

This should probably be:

Object.assign(this, Object.assign({}, defaultOpts, opts));

Compare method

Method that returns true if the inventory contains all the items in an itemset, + a relevant macro.

Simple Inventory: item metadata

Items should accept metadata, which will be assigned internally: the private array will be an array of objects rather than strings.

Each item will have:

  • name: the name of the item, as passed in.
  • stack: how many items are the same item, allowing inventories to optionally treat items as stackables (configured on a per inventory basis, probably via a new macro).
  • acquired: the name of the passage the item was acquired from. (should transfers track the giving inventory? I don't know if there's a good way to track that, since inventories are just stored in vars)

Users will also be able to define (non-statefully) items via a new API and macro set.

Items have:

  • name: a unique name. (required)
  • tags: meta data tags for the item.
  • label: a short description of the item. (optional)
  • description: a passage name or string description of the item. If the description is a passage name, that always wins out. (optional)
  • onUse: wiki code or function to run on usage. (optional)
  • onGet: wiki code or function to run when the item is received. (optional)
  • onDrop: wiki code or function to run when the item is dropped. (optional)
  • maxStack: the maximum number of items of this kind that can be carried at once. (optional)
  • metadata: object for any user data. Does not need to be serializable, so functions and weird classes are fine. Only available via JS API.

If an item is passed to an inventory that doesn't have an item def, it will be treated like a key item, per the current implementation of SI, plus the new automatic metadata properties.

Items will probably be a class, the metadata passed into the inventory will probably include the whole instance. Might be better as a straight up factory, though.

These additions shouldn't be breaking, if implemented properly, but the code will be heavier, so it may be worth adding the hooks for this system to Simple Inventory, but making the Item class and API / macros an optional extension.

Design goals.

  • No breaking changes, this shouldn't be a 3.0.0 update if at all possible.
  • I want to preserve the simple inventory as a place users can set flags or traits.
  • I do not want users to use this as a poor man's attribute system, eg using a stack of "strength" items as an attribute score. I can't stop that, but I want to encourage this being used for items.

Simple inventory version 3

New major version, will have many breaking changes.

Core new features (all optional):

  • stacking
  • item descriptions
  • usables (run code on use)
  • better API
  • simpler class structure
  • fewer but more robust macros

Export/Import issue?

Is there a known issue with exporting and importing? On my twine game the inventory systems works fine, but inventory content is not saved on export. I verified this with a button:

<<button "Serialize Game" >>
<<script>>
const myGameState = Save.serialize();
if (myGameState === null) {
/* Failure. You've disallowed saving. */
}
console.log(LZString.decompressFromBase64(myGameState));
Save.deserialize(myGameState);
<</script>>

Doing this will empty out my inventory. The output from the Save.serialize() is logged and shows there is nothing in the inventory array. perhaps a problem with marshalling?

*all commands for interface

The interface should have "take/give/drop all" options. Should be optional via an all flag.

Give/drop all optional confirmation?

Changing "Drop" name does not work

When this code defines the <> macro, it also a defines a list of options that includes a dropActionText property, which is assigned a value of 'Drop'.

The value of that dropActionText property is later passed as an argument to the addon's dropLink() function, that generates the "drop" related link for an inventory item.

And unfortunately that dropLink() function will use that argument value instead of the Inventory.strings.drop setting, if the argument is not an empty String.

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.