diff options
| author | El-BG-1970 <elouan.gros.fr@gmail.com> | 2022-08-27 17:36:05 +0200 |
|---|---|---|
| committer | El-BG-1970 <elouan.gros.fr@gmail.com> | 2022-08-27 17:36:05 +0200 |
| commit | e056ac5d58e44a76a4185c37fce6948044b83c66 (patch) | |
| tree | b9f186a10f347822c30f64addf4126ce50a3bd1e | |
| parent | c7dbdf46a0ae76c15621fb4c4c320db1422b1e9b (diff) | |
| download | transacc-e056ac5d58e44a76a4185c37fce6948044b83c66.tar.gz | |
smart redisplay for panel and zone-prices panes
| -rw-r--r-- | src/main.lisp | 45 | ||||
| -rw-r--r-- | src/player.lisp | 3 | ||||
| -rw-r--r-- | tests/test-inventory.lisp | 8 | ||||
| -rw-r--r-- | tests/test-player.lisp | 4 |
4 files changed, 42 insertions, 18 deletions
diff --git a/src/main.lisp b/src/main.lisp index 5713a65..0153da4 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -17,11 +17,11 @@ :display-time t :display-function 'display-title) (zone-price :application - :display-time :command-loop + :display-time t :scroll-bar nil :display-function 'display-zone-price) (panel :application - :display-time :command-loop + :display-time t :scroll-bar nil :display-function 'display-panel) (int :interactor)) @@ -39,6 +39,11 @@ (defmethod frame-standard-output ((frame superapp)) (clim:get-frame-pane frame 'int)) +(defun redisplay (panel) + (clim:with-application-frame (frame) + (setf (clim:pane-needs-redisplay + (clim:get-frame-pane frame panel)) + t))) (defun format-zone-price (panel stream) (loop for it in panel do (format stream "~a :~T ~$$ [~@$$] owned: ~a~%" @@ -83,33 +88,50 @@ (game:get-zone g (cdr (cur-panel frame)))) stream))))) - - ;; Panel command + + ;; Prices command -> changes the panel to prices for zone (define-superapp-command (com-prices :name t) ((zone 'string)) (clim:with-application-frame (frame) (if (game:get-zone g zone) - (setf (cur-panel frame) (cons 'prices zone)) + (progn + (setf (cur-panel frame) (cons 'prices zone)) + (redisplay 'panel)) (format (frame-standard-output frame) "Zone ~A does not exist~%" zone)))) - ;; Stats command + ;; Stats command -> changes the panel to player stats (define-superapp-command (com-stats :name t) () (clim:with-application-frame (frame) - (setf (cur-panel frame) '(stats)))) - + (setf (cur-panel frame) '(stats)) + (redisplay 'panel))) + ;; Buy command (define-superapp-command (com-buy :name t) ((item 'string) (quantity 'integer)) (clim:with-application-frame (frame) (let ((out (frame-standard-output frame))) (if (game:buy-item g item quantity) - (format out "Bought ~a ~a~%" quantity item) + (progn + (when (eq 'stats (car (cur-panel frame))) + (redisplay 'panel)) + (redisplay 'zone-price) + (format out "Bought ~a ~a~%" quantity item)) (format out "Could not buy ~a ~a~%" quantity item))))) ;; Sell command (define-superapp-command (com-sell :name t) ((item 'string) (quantity 'integer)) - (game:sell-item g item quantity)) + (clim:with-application-frame (frame) + (let ((out (frame-standard-output frame)) + (sold (game:sell-item g item quantity))) + (if sold + (progn + (when (eq 'stats (car (cur-panel frame))) + (redisplay 'panel)) + (redisplay 'zone-price) + (format out "Sold ~a ~a~%" sold item)) + (format out "Could not sell any ~a" item))))) + ;; Goto command (define-superapp-command (com-goto :name t) ((dest 'string)) @@ -118,7 +140,8 @@ (if (game:change-zone g dest) (progn (setf (cur-zone frame) (zone:name (game:get-cur-zone g))) - (setf (clim:pane-needs-redisplay (clim:get-frame-pane frame 'title)) t) + (redisplay 'title) + (redisplay 'zone-price) (format out "Arrived in ~a" (zone:name (game:get-cur-zone g)))) (format out "Zone ~a does not exist!" dest))))) diff --git a/src/player.lisp b/src/player.lisp index c9033ac..992c951 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -54,7 +54,8 @@ (when stocked-item (setq cash (+ cash (* (cdr stocked-item) - (commodities:price item)))))))) + (commodities:price item)))) + (cdr stocked-item))))) (defmethod find-item ((p player) name) (with-slots (stock) p diff --git a/tests/test-inventory.lisp b/tests/test-inventory.lisp index ab732f5..61bfd19 100644 --- a/tests/test-inventory.lisp +++ b/tests/test-inventory.lisp @@ -20,7 +20,7 @@ (test inventory-init-values (let ((i (inventory:new-inventory 100))) (is (= (inventory::size i) 100)) - (is (= (inventory:filled i) 0)) + (is (= (car (inventory:how-filled i)) 0)) (is (eq (inventory::items i) nil)))) ;; test add and substract @@ -30,18 +30,18 @@ (c2 (commodities:new-commodity "apple" 99))) ;; add 10 (is (= (inventory:add-item i c 10) 10)) - (is (= (inventory:filled i) 10)) + (is (= (car (inventory:how-filled i)) 10)) ;; remove 4 (is (equal (inventory:remove-item i "apple" 4) (cons c 4))) - (is (= (inventory:filled i) 6)) + (is (= (car (inventory:how-filled i)) 6)) (is (equal (inventory::find-item i "apple") (cons c 6))) ;; adding 90 (is (= (inventory:add-item i c 90) 96)) ;; adding one too many (is (not (inventory:add-item i c 5))) - (is (= (inventory::filled i) 96)) + (is (= (car (inventory:how-filled i)) 96)) (is (and (commodities:commodity-eq c diff --git a/tests/test-player.lisp b/tests/test-player.lisp index a74ecd7..82cabcf 100644 --- a/tests/test-player.lisp +++ b/tests/test-player.lisp @@ -34,11 +34,11 @@ (is (= 1950 (player:get-cash p))) (is (not (player:buy-item p truck 1))) (is (= 10 - (inventory:filled (player::stock p)))) + (car (inventory:how-filled (player::stock p))))) (is (player:buy-item p c2 10)) (is (= 1840 (player:get-cash p))) (is (= 20 - (inventory:filled (player::stock p)))))) + (car (inventory:how-filled (player::stock p))))))) (test sell-item (let ((p (player:init-player "Joze")) |
