File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -728,7 +728,7 @@ <h1>BACKPACK</h1>
728728
729729 < div class ="footer ">
730730 < button id ="item-use-btn "> Use (R)</ button >
731- < button id ="item-drop-btn "> Drop (X)</ button >
731+ < button id ="item-drop-btn "> Remove (X)</ button >
732732 < button id ="inventory-close-btn "> Close (I)</ button >
733733 </ div >
734734 </ div >
Original file line number Diff line number Diff line change @@ -119,7 +119,19 @@ export class Backpack {
119119 this . decreaseItemQty ( selectedItem ) ;
120120 }
121121
122- dropItem ( ) { }
122+ dropItem ( ) {
123+ if ( ! selectedItem ) return ;
124+ const ind = this . inventory . findIndex (
125+ ( item ) => item . itemName === selectedItem
126+ ) ;
127+
128+ if ( ind != - 1 ) {
129+ this . inventory . splice ( ind , 1 ) ;
130+ selectedItem = null ;
131+ this . saveInventoryState ( ) ;
132+ this . render ( ) ;
133+ }
134+ }
123135
124136 render ( ) {
125137 const backpack = document . getElementById ( 'backpack-content' ) ;
@@ -170,6 +182,8 @@ export class Backpack {
170182 }
171183 } else if ( e . key == 'r' ) {
172184 this . useItem ( ) ;
185+ } else if ( e . key == 'x' ) {
186+ this . dropItem ( )
173187 }
174188 }
175189
You can’t perform that action at this time.
0 commit comments