luv

Workshop wiki

inventory.lisp

luvcraft/inventory.lisp

system luvcraft/core · 14 definitions · on GitHub

Player-owned block inventory state, independent of any presentation system.

in-package#:luvcraft
defclassblock-inventory-entry
block:initarg:block:readerblock-inventory-entry-block
quantity:initarg:quantity:initformnil:accessorblock-inventory-entry-quantity
:documentation

One material in an inventory. A NIL quantity means unlimited supply.

defclassblock-inventory
entries:initarg:entries:accessorblock-inventory-entries
:documentation

The ordered materials available to one player.

defunmake-block-inventory

Make an inventory containing blocks in display and number-key order.

quantity is the initial count of every material, or NIL for creative-mode unlimited supply.

whenquantity
check-typequantity
integer0
make-instance'block-inventory:entries
mapcar
lambda
block
check-typeblockblock-kind
make-instance'block-inventory-entry:blockblock:quantityquantity
blocks
defunblock-inventory-blocks
inventory

Return inventory's materials in stable display and selection order.

mapcar#'block-inventory-entry-block
block-inventory-entriesinventory
defunblock-inventory-quickbar-entries
inventory

Return the first ten entries addressable by number keys, 1-9 then 0.

let
entries
block-inventory-entriesinventory
defunblock-inventory-quickbar-blocks
inventory

Return inventory's number-key materials in stable order.

mapcar#'block-inventory-entry-block
defunblock-inventory-entry-for
inventoryblock

Return inventory's entry for block, or NIL when it is unavailable.

findblock
block-inventory-entriesinventory
:key#'block-inventory-entry-block:test#'eq
defunadd-block-to-inventory
inventoryblock&optional

Add quantity of block to finite inventory storage and return its entry.

Adding to an unlimited entry leaves it unlimited. A previously unavailable block is appended, preserving the stable order of existing number keys.

check-typequantity
integer0
let
entry
unlessentry
setfentry
make-instance'block-inventory-entry:blockblock:quantity0
block-inventory-entriesinventory
append
block-inventory-entriesinventory
listentry
when
block-inventory-entry-quantityentry
incf
block-inventory-entry-quantityentry
quantity
entry
defunremove-block-from-inventory
inventoryblock&optional

Consume quantity of block and report success.

Unlimited entries always succeed. Finite entries remain present at zero so the view and number-key ordering do not jump as blocks are used.

check-typequantity
integer0
let
entry
whenentry
let
available
block-inventory-entry-quantityentry
when
or
nullavailable
<=quantityavailable
whenavailable
decf
block-inventory-entry-quantityentry
quantity
t
defgenericblock-kind-carried-p
block
:documentation

Whether block is a thing a player picks up and carries, rather than a material the palette gives without limit. A film is; stone is not.

:method
block
declare
ignoreblock
nil
defunblock-inventory-carried-blocks
inventory

Return the carried blocks inventory actually holds, in order.

loopforentryin
block-inventory-entriesinventory
forblock=
block-inventory-entry-blockentry
forquantity=
block-inventory-entry-quantityentry
whencollectblock
defgenerictoggle-luvcraft-inventory
session
:documentation

Toggle session's inventory view, returning true when one is available.

LUVCRAFT/CORE has no UI dependency. LUVCRAFT/MCCLIM supplies the session method.

defmethodtoggle-luvcraft-inventory
sessiont
declare
ignoresession
nil