summaryrefslogtreecommitdiffstats
path: root/src/inventory.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/inventory.lisp')
-rw-r--r--src/inventory.lisp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/inventory.lisp b/src/inventory.lisp
index 8aa590f..a8b7c59 100644
--- a/src/inventory.lisp
+++ b/src/inventory.lisp
@@ -1,7 +1,7 @@
(defpackage inventory
(:use :cl)
(:export :new-inventory
- :filled
+ :how-filled
:add-item
:remove-item
:find-item))
@@ -21,6 +21,10 @@
(when (> size 0)
(make-instance 'inventory :size size)))
+(defmethod how-filled ((inv inventory))
+ (with-slots (size filled) inv
+ (cons filled size)))
+
(defmethod find-item ((inv inventory) name)
(with-slots (items) inv
(find-if
@@ -36,15 +40,16 @@
(setq filled (- filled (cdr item)))))
(defmethod update-item ((inv inventory) item qty old-item)
+ (delete-item inv old-item)
(with-slots (filled items) inv
- (delete-item inv old-item)
(let ((total-quantity (+ qty (cdr old-item)))
(item-name (commodities:name item))
(item-price (commodities:price item))
(old-qty (cdr old-item))
(old-item-price (commodities:price (car old-item))))
(let ((new-item (commodities:new-commodity item-name
- (/ (+ (* qty item-price) (* old-qty old-item-price))
+ (/ (+ (* qty item-price)
+ (* old-qty old-item-price))
total-quantity))))
(push (cons
new-item