فهرست منبع

added a quick use button for food

Warafear 6 ماه پیش
والد
کامیت
6692628eb8

+ 12 - 3
src/app/journal/journal-inventory/journal-inventory.component.html

@@ -84,9 +84,18 @@
       }
 
       <div class="footer">
-        <ui-button [width]="'w22'" (click)="addItem('consumables')"
-          >{{ "buttons.addEntry" | translate }}
-        </ui-button>
+        @if (foodActive === 1) {
+          <ui-button [width]="'w12'" (click)="addItem('consumables')"
+            >{{ "buttons.addEntry" | translate }}
+          </ui-button>
+          <ui-button [width]="'w12'" (click)="consumeFood()"
+            >{{ "buttons.consume" | translate }}
+          </ui-button>
+        } @else {
+          <ui-button [width]="'w22'" (click)="addItem('consumables')"
+            >{{ "buttons.addEntry" | translate }}
+          </ui-button>
+        }
       </div>
     </div>
 

+ 1 - 0
src/app/journal/journal-inventory/journal-inventory.component.scss

@@ -237,6 +237,7 @@
   button {
     padding: 1rem 0;
   }
+  justify-content: space-around;
 }
 
 // Drag and Drop

+ 15 - 6
src/app/journal/journal-inventory/journal-inventory.component.ts

@@ -49,12 +49,6 @@ export class JournalInventoryComponent {
   private data = inject(DataService);
   private modal = inject(ModalService);
 
-  // constructor(
-  //   private detailsAccessor: DetailsService,
-  //   private dataAccessor: DataService,
-  //   private modalAccessor: ModalService,
-  // ) {}
-
   public ngOnInit(): void {
     this.weaponsAndArmor = this.data.weaponsAndArmor;
     this.consumables = this.data.consumables;
@@ -166,6 +160,21 @@ export class JournalInventoryComponent {
     }
   }
 
+  /**
+   * Consumes one unit of food from the inventory.
+   * It always uses the first entry in the list.
+   * If the food item is empty, it will be removed from the list.
+   */
+  public consumeFood(): void {
+    if (this.food.length > 0) {
+      this.food[0].quantity--;
+      if (this.food[0].quantity === 0) {
+        this.food.splice(0, 1);
+      }
+      this.updateFood();
+    }
+  }
+
   // Updates
 
   public updateDatabase(listname: string): void {