Просмотр исходного кода

Spell and weapon table should be mostly implemented.

Christopher Giese 1 год назад
Родитель
Сommit
7d52316dde

+ 148 - 0
.nx/cache/d/daemon.log

@@ -458737,3 +458737,151 @@ To fix this, set a unique name for each project in a project.json inside the pro
 [NX Daemon Server] - 2023-11-04T12:20:23.198Z - Time taken for 'hash changed files from watcher' 148.9957000017166ms
 [NX Daemon Server] - 2023-11-04T12:20:23.198Z - [WATCHER]: Processing file changes in outputs
 [NX Daemon Server] - 2023-11-04T12:20:23.198Z - Done responding to the client null
+[NX Daemon Server] - 2023-11-05T10:39:11.255Z - Started listening on: \\.\pipe\nx\C:\Users\chris\AppData\Local\Temp\b99a3e5445b3962b8dd8\d.sock
+[NX Daemon Server] - 2023-11-05T10:39:11.261Z - [WATCHER]: Subscribed to changes within: c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools (native)
+[NX Daemon Server] - 2023-11-05T10:39:11.262Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T10:39:11.264Z - Closed a connection. Number of open connections: 0
+[NX Daemon Server] - 2023-11-05T10:39:11.264Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T10:39:11.265Z - [REQUEST]: Client Request for Project Graph Received
+[NX Daemon Server] - 2023-11-05T10:39:11.791Z - Error detected when recomputing project file map: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+[NX Daemon Server] - 2023-11-05T10:39:11.792Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+Error: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+    at readProjectConfigurationsFromRootMap (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:97:15)
+    at buildProjectsConfigurationsFromProjectPathsAndPlugins (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:70:19)
+    at createProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:131:129)
+    at WorkspaceContext.<anonymous> (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:82:39)
+    at getProjectConfigurationsFromContext (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\utils\workspace-context.js:26:29)
+    at _retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:81:72)
+    at retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:58:12)
+    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
+    at async processCollectedUpdatedAndDeletedFiles (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:102:34)
+    at async processFilesAndCreateAndSerializeProjectGraph (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:138:17)
+[NX Daemon Server] - 2023-11-05T10:39:11.793Z - Time taken for 'hash changed files from watcher' 72.75139999389648ms
+[NX Daemon Server] - 2023-11-05T10:39:11.793Z - [WATCHER]: Processing file changes in outputs
+[NX Daemon Server] - 2023-11-05T10:39:11.794Z - Done responding to the client null
+[NX Daemon Server] - 2023-11-05T13:48:02.838Z - Started listening on: \\.\pipe\nx\C:\Users\chris\AppData\Local\Temp\b99a3e5445b3962b8dd8\d.sock
+[NX Daemon Server] - 2023-11-05T13:48:02.840Z - [WATCHER]: Subscribed to changes within: c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools (native)
+[NX Daemon Server] - 2023-11-05T13:48:02.843Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T13:48:02.844Z - Established a connection. Number of open connections: 2
+[NX Daemon Server] - 2023-11-05T13:48:02.846Z - Closed a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T13:48:02.847Z - [REQUEST]: Client Request for Project Graph Received
+[NX Daemon Server] - 2023-11-05T13:48:03.297Z - Error detected when recomputing project file map: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+[NX Daemon Server] - 2023-11-05T13:48:03.297Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+Error: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+    at readProjectConfigurationsFromRootMap (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:97:15)
+    at buildProjectsConfigurationsFromProjectPathsAndPlugins (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:70:19)
+    at createProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:131:129)
+    at WorkspaceContext.<anonymous> (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:82:39)
+    at getProjectConfigurationsFromContext (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\utils\workspace-context.js:26:29)
+    at _retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:81:72)
+    at retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:58:12)
+    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
+    at async processCollectedUpdatedAndDeletedFiles (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:102:34)
+    at async processFilesAndCreateAndSerializeProjectGraph (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:138:17)
+[NX Daemon Server] - 2023-11-05T13:48:03.299Z - Time taken for 'hash changed files from watcher' 24.452500104904175ms
+[NX Daemon Server] - 2023-11-05T13:48:03.299Z - [WATCHER]: Processing file changes in outputs
+[NX Daemon Server] - 2023-11-05T13:48:03.299Z - Done responding to the client null
+[NX Daemon Server] - 2023-11-05T15:03:44.548Z - Started listening on: \\.\pipe\nx\C:\Users\chris\AppData\Local\Temp\b99a3e5445b3962b8dd8\d.sock
+[NX Daemon Server] - 2023-11-05T15:03:44.552Z - [WATCHER]: Subscribed to changes within: c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools (native)
+[NX Daemon Server] - 2023-11-05T15:03:44.564Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T15:03:44.566Z - Closed a connection. Number of open connections: 0
+[NX Daemon Server] - 2023-11-05T15:03:44.566Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T15:03:44.567Z - [REQUEST]: Client Request for Project Graph Received
+[NX Daemon Server] - 2023-11-05T15:03:44.733Z - Error detected when recomputing project file map: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+[NX Daemon Server] - 2023-11-05T15:03:44.734Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+Error: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+    at readProjectConfigurationsFromRootMap (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:97:15)
+    at buildProjectsConfigurationsFromProjectPathsAndPlugins (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:70:19)
+    at createProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:131:129)
+    at WorkspaceContext.<anonymous> (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:82:39)
+    at getProjectConfigurationsFromContext (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\utils\workspace-context.js:26:29)
+    at _retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:81:72)
+    at retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:58:12)
+    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
+    at async processCollectedUpdatedAndDeletedFiles (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:102:34)
+    at async processFilesAndCreateAndSerializeProjectGraph (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:138:17)
+[NX Daemon Server] - 2023-11-05T15:03:44.735Z - Time taken for 'hash changed files from watcher' 27.117199897766113ms
+[NX Daemon Server] - 2023-11-05T15:03:44.736Z - [WATCHER]: Processing file changes in outputs
+[NX Daemon Server] - 2023-11-05T15:03:44.736Z - Done responding to the client null
+[NX Daemon Server] - 2023-11-05T18:49:04.240Z - Started listening on: \\.\pipe\nx\C:\Users\chris\AppData\Local\Temp\b99a3e5445b3962b8dd8\d.sock
+[NX Daemon Server] - 2023-11-05T18:49:04.243Z - [WATCHER]: Subscribed to changes within: c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools (native)
+[NX Daemon Server] - 2023-11-05T18:49:04.249Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T18:49:04.251Z - Closed a connection. Number of open connections: 0
+[NX Daemon Server] - 2023-11-05T18:49:04.251Z - Established a connection. Number of open connections: 1
+[NX Daemon Server] - 2023-11-05T18:49:04.253Z - [REQUEST]: Client Request for Project Graph Received
+[NX Daemon Server] - 2023-11-05T18:49:04.363Z - Error detected when recomputing project file map: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+[NX Daemon Server] - 2023-11-05T18:49:04.363Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+Error: The following projects are defined in multiple locations:
+- DnDTools: 
+  - 
+  - .
+
+To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.
+    at readProjectConfigurationsFromRootMap (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:97:15)
+    at buildProjectsConfigurationsFromProjectPathsAndPlugins (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\project-configuration-utils.js:70:19)
+    at createProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:131:129)
+    at WorkspaceContext.<anonymous> (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:82:39)
+    at getProjectConfigurationsFromContext (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\utils\workspace-context.js:26:29)
+    at _retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:81:72)
+    at retrieveProjectConfigurations (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\project-graph\utils\retrieve-workspace-files.js:58:12)
+    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
+    at async processCollectedUpdatedAndDeletedFiles (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:102:34)
+    at async processFilesAndCreateAndSerializeProjectGraph (c:\Users\chris\Softwareprojekte\CharacterJournal\DnDTools\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:138:17)
+[NX Daemon Server] - 2023-11-05T18:49:04.365Z - Time taken for 'hash changed files from watcher' 42.78379988670349ms
+[NX Daemon Server] - 2023-11-05T18:49:04.366Z - [WATCHER]: Processing file changes in outputs
+[NX Daemon Server] - 2023-11-05T18:49:04.366Z - Done responding to the client null

+ 1 - 1
.nx/cache/d/server-process.json

@@ -1 +1 @@
-{"processId":6640}
+{"processId":20216}

+ 11 - 22
src/app/journal/journal-stats/weapons-container/spell-table/spell-table.component.html

@@ -8,7 +8,7 @@
     class="example-box"
     *ngFor="let spell of spells; let index = index"
     cdkDrag
-    (change)="updateSpells()"
+    (change)="updateSpellsInDatabase()"
   >
     <div class="spell-type">
       <icon
@@ -73,19 +73,6 @@
           *ngIf="spell.needsMaterial"
         ></icon>
       </div>
-      <!-- Add bar with costs, components and ritual concentration -->
-      <!-- <icon
-      *ngIf="spell.canRitual"
-      [size]="'s'"
-      [type]="'spell'"
-      [icon]="'ritual'"
-    ></icon>
-    <icon
-      *ngIf="spell.needsConcentration"
-      [size]="'s'"
-      [type]="'spell'"
-      [icon]="'concentration'"
-    ></icon> -->
     </div>
 
     <div class="vertical-line"></div>
@@ -97,19 +84,15 @@
     <!--  -->
 
     <div class="attack-container">
-      <!-- <div *ngIf="spell.needsSavingThrow" class="saving-throw">
-            <div class="saving-throw-attribute">{{ spell.savingThrowAttribute }}</div>
-            <div class="saving-throw-dc">{{ spell.savingThrowDC }}</div>
-        </div> -->
       <div *ngIf="spell.needsSavingThrow" class="saving-throw">
         <div class="saving-throw-attribute">
-          {{ spell.savingThrowAttribute }}
+          {{ attributes[spell.savingThrowAttribute!] }}
         </div>
-        <div class="saving-throw-dc">15</div>
+        <div class="saving-throw-dc">{{ spellSaveDC }}</div>
       </div>
 
       <div *ngIf="!spell.needsSavingThrow" class="attack-roll">
-        <div class="attack-roll-bonus">+7</div>
+        <div class="attack-roll-bonus">{{ spellAttackBonus }}</div>
       </div>
     </div>
 
@@ -144,7 +127,13 @@
     <!--  -->
 
     <div class="spell-edit">
-      <icon [size]="'s'" [type]="'UI'" [icon]="'edit'"></icon>
+      <icon
+        [size]="'s'"
+        [type]="'UI'"
+        [icon]="'edit'"
+        (click)="emitUpdateSpell(index)"
+        [class]="'pointer'"
+      ></icon>
     </div>
   </div>
   <div class="add-box">

+ 33 - 6
src/app/journal/journal-stats/weapons-container/spell-table/spell-table.component.ts

@@ -1,7 +1,5 @@
-import { Component, EventEmitter, Output } from '@angular/core';
+import { Component, EventEmitter, Output, Input } from '@angular/core';
 import { DataService } from 'src/services/data/data.service';
-import { Weapon } from 'src/interfaces/weapon';
-import { Damage } from 'src/interfaces/damage';
 import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
 import { Spell } from 'src/interfaces/spell';
 
@@ -15,19 +13,33 @@ export class SpellTableComponent {
 
   @Output() public createNewSpell: EventEmitter<void> =
     new EventEmitter<void>();
+  @Output() public updateSpellEvent: EventEmitter<any> =
+    new EventEmitter<any>();
+
+  @Input() public spellAttackBonus: string = '0';
+  @Input() public spellSaveDC: number = 0;
 
   public spells!: Spell[];
 
+  public attributes: any = {
+    strength: 'STR',
+    dexterity: 'DEX',
+    constitution: 'CON',
+    intelligence: 'INT',
+    wisdom: 'WIS',
+    charisma: 'CHA',
+  };
+
   public ngOnInit(): void {
     this.spells = this.dataAccessor.getSpells();
   }
 
   public dropSpells(event: CdkDragDrop<string[]>): void {
     moveItemInArray(this.spells, event.previousIndex, event.currentIndex);
-    this.updateSpells();
+    this.updateSpellsInDatabase();
   }
 
-  public updateSpells(): void {
+  public updateSpellsInDatabase(): void {
     this.dataAccessor.setSpells(this.spells);
   }
 
@@ -38,6 +50,21 @@ export class SpellTableComponent {
 
   public addSpell(spell: Spell) {
     this.spells.push(spell);
-    this.updateSpells();
+    this.updateSpellsInDatabase();
+  }
+
+  public emitUpdateSpell(index: number): void {
+    this.updateSpellEvent.emit({ spell: this.spells[index], index: index });
+    console.log('emitUpdateWeapon()');
+  }
+
+  public updateSpell(spell: Spell, index: number): void {
+    this.spells[index] = spell;
+    this.updateSpellsInDatabase();
+  }
+
+  public deleteSpell(index: number): void {
+    this.spells.splice(index, 1);
+    this.updateSpellsInDatabase();
   }
 }

+ 16 - 4
src/app/journal/journal-stats/weapons-container/weapon-table/weapon-table.component.html

@@ -8,7 +8,7 @@
     class="example-box"
     *ngFor="let weapon of weapons; let index = index"
     cdkDrag
-    (change)="updateWeapons()"
+    (change)="updateWeaponInDatabase()"
   >
     <div class="weapon-type">
       <icon
@@ -37,9 +37,15 @@
     <div class="damage-list">
       <div
         class="damage-row"
-        *ngFor="let damage of weapon.damage; let index = index"
+        *ngFor="let damage of weapon.damage; let damageIndex = index"
       >
-        <span>{{ damage.diceNumber }} {{ damage.diceType }} </span>
+        <span>{{ damage.diceNumber }} {{ damage.diceType }}</span>
+        <span *ngIf="weapon.isVersatile && damageIndex === 0"
+          >({{ weapon.versatileDamage }})</span
+        >
+        <span *ngIf="damageIndex === 0 && damageModifiers[index] !== '0'">
+          {{ damageModifiers[index] }}
+        </span>
         <span>
           <icon
             [size]="'xs'"
@@ -55,7 +61,13 @@
     <div class="vertical-line"></div>
 
     <div class="weapon-edit">
-      <icon [size]="'s'" [type]="'UI'" [icon]="'edit'"></icon>
+      <icon
+        [size]="'s'"
+        [type]="'UI'"
+        [icon]="'edit'"
+        (click)="emitUpdateWeapon(index)"
+        [class]="'pointer'"
+      ></icon>
     </div>
   </div>
   <div class="add-box">

+ 98 - 4
src/app/journal/journal-stats/weapons-container/weapon-table/weapon-table.component.ts

@@ -1,7 +1,9 @@
 import { Component, EventEmitter, Output } from '@angular/core';
+// import { Observable } from 'rxjs';
 import { DataService } from 'src/services/data/data.service';
+import { Attribute } from 'src/interfaces/attribute';
 import { Weapon } from 'src/interfaces/weapon';
-import { Damage } from 'src/interfaces/damage';
+// import { Damage } from 'src/interfaces/damage';
 import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
 
 @Component({
@@ -15,18 +17,81 @@ export class WeaponTableComponent {
   @Output() public createNewWeapon: EventEmitter<void> =
     new EventEmitter<void>();
 
+  @Output() public updateWeaponEvent: EventEmitter<any> =
+    new EventEmitter<any>();
+
   public weapons!: Weapon[];
+  public damageModifiers: string[] = [
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+    '0',
+  ];
+  public isMonk: boolean = false;
+  public strengthValue: number = 0;
+  public dexterityValue: number = 0;
 
   public ngOnInit(): void {
+    this.dataAccessor.strength$.subscribe((newValue: Attribute) => {
+      this.strengthValue = newValue.value;
+      if (this.weapons) {
+        this.calculateDamageModifierArray();
+      }
+    });
+    this.dataAccessor.dexterity$.subscribe((newValue: Attribute) => {
+      this.dexterityValue = newValue.value;
+      if (this.weapons) {
+        this.calculateDamageModifierArray();
+      }
+    });
     this.weapons = this.dataAccessor.getWeapons();
+    this.calculateDamageModifierArray();
+  }
+
+  /**
+   * Claculates the whole damage modifier array.
+   * Calls the single damage modifier calculation for each weapon.
+   */
+  private calculateDamageModifierArray(): void {
+    this.weapons.forEach((_, index) => {
+      this.calculateSingleDamageModifier(index);
+    });
+  }
+
+  private calculateSingleDamageModifier(index: number): void {
+    let value: number;
+    let bonus: number = 0;
+    const weapon: Weapon = this.weapons[index];
+    if (this.isMonk || weapon.isFinesse) {
+      value = Math.max(this.strengthValue, this.dexterityValue);
+    } else if (weapon.isRanged) {
+      value = this.dexterityValue;
+    } else {
+      value = this.strengthValue;
+    }
+    if (weapon.isMagical) {
+      bonus = weapon.magicBonus!;
+    }
+    this.damageModifiers[index] = this.calculateModifier(value, bonus);
   }
 
   public dropWeapons(event: CdkDragDrop<string[]>): void {
     moveItemInArray(this.weapons, event.previousIndex, event.currentIndex);
-    this.updateWeapons();
+    moveItemInArray(
+      this.damageModifiers,
+      event.previousIndex,
+      event.currentIndex
+    );
+    this.updateWeaponInDatabase();
   }
 
-  public updateWeapons(): void {
+  public updateWeaponInDatabase(): void {
     this.dataAccessor.setWeapons(this.weapons);
   }
 
@@ -37,6 +102,35 @@ export class WeaponTableComponent {
 
   public addWeapon(weapon: Weapon) {
     this.weapons.push(weapon);
-    this.updateWeapons();
+    this.calculateDamageModifierArray();
+    this.updateWeaponInDatabase();
+  }
+
+  public emitUpdateWeapon(index: number): void {
+    this.updateWeaponEvent.emit({ weapon: this.weapons[index], index: index });
+    console.log('emitUpdateWeapon()');
+  }
+
+  public updateWeapon(weapon: Weapon, index: number): void {
+    this.weapons[index] = weapon;
+    this.calculateSingleDamageModifier(index);
+    this.updateWeaponInDatabase();
+  }
+
+  public deleteWeapon(index: number): void {
+    this.weapons.splice(index, 1);
+    this.calculateDamageModifierArray();
+    this.updateWeaponInDatabase();
+  }
+
+  ////// Calculation Helpers
+
+  private calculateModifier(attributeValue: number, bonus: number): string {
+    let mod: number = Math.floor((attributeValue - 10) / 2) + bonus;
+    if (mod > 0) {
+      return '+' + mod;
+    } else {
+      return mod.toString();
+    }
   }
 }

+ 14 - 3
src/app/journal/journal-stats/weapons-container/weapons-container.component.html

@@ -3,13 +3,21 @@
     <li [ngbNavItem]="1">
       <button ngbNavLink>Waffen</button>
       <ng-template ngbNavContent>
-        <weapon-table (createNewWeapon)="openWeaponModal()"></weapon-table>
+        <weapon-table
+          (createNewWeapon)="openWeaponCreationModal()"
+          (updateWeaponEvent)="openWeaponUpdateModal($event)"
+        ></weapon-table>
       </ng-template>
     </li>
     <li [ngbNavItem]="2">
       <button ngbNavLink>Zauber</button>
       <ng-template ngbNavContent>
-        <spell-table (createNewSpell)="openSpellModal()"></spell-table>
+        <spell-table
+          [spellAttackBonus]="spellAttackBonus"
+          [spellSaveDC]="spellSaveDC"
+          (createNewSpell)="openSpellCreationModal()"
+          (updateSpellEvent)="openSpellUpdateModal($event)"
+        ></spell-table>
       </ng-template>
     </li>
   </ul>
@@ -21,11 +29,14 @@
   <weapon-modal
     #weaponTable
     (weaponCreated)="addNewlyCreatedWeapon($event)"
-    (onAnyCloseEvent)="log()"
+    (weaponUpdated)="updateWeaponInTable($event)"
+    (weaponDelete)="deleteWeaponInTable($event)"
   ></weapon-modal>
 
   <spell-modal
     #spellModal
     (spellCreated)="addNewlyCreatedSpell($event)"
+    (spellDeleted)="deleteSpellInTable($event)"
+    (spellUpdated)="updateSpellInTable($event)"
   ></spell-modal>
 </div>

+ 60 - 60
src/app/journal/journal-stats/weapons-container/weapons-container.component.ts

@@ -1,12 +1,10 @@
 import { Component, ViewChild } from '@angular/core';
-import { DataService } from 'src/services/data/data.service';
 import { Weapon } from 'src/interfaces/weapon';
 import { Spell } from 'src/interfaces/spell';
-import { Damage } from 'src/interfaces/damage';
-import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
-import { NgxSmartModalService, NgxSmartModalComponent } from 'ngx-smart-modal';
+import { NgxSmartModalService } from 'ngx-smart-modal';
 import { WeaponTableComponent } from './weapon-table/weapon-table.component';
 import { SpellTableComponent } from './spell-table/spell-table.component';
+import { DataService } from 'src/services/data/data.service';
 
 @Component({
   selector: 'app-weapons-container',
@@ -15,8 +13,8 @@ import { SpellTableComponent } from './spell-table/spell-table.component';
 })
 export class WeaponsContainerComponent {
   public constructor(
-    public dataAccessor: DataService,
-    public ngxSmartModalService: NgxSmartModalService
+    public ngxSmartModalService: NgxSmartModalService,
+    private dataAccessor: DataService
   ) {}
 
   @ViewChild(WeaponTableComponent) weaponTable!: WeaponTableComponent;
@@ -24,74 +22,67 @@ export class WeaponsContainerComponent {
 
   public active: number = 1;
 
-  public newWeaponName: string = '';
-  public newWeaponDamageType: string = '';
-  public newWeaponRange: string = '';
-  public newWeaponAttackBonus: string = '';
-
-  public newWeaponDamage: Damage[] = [
-    { diceNumber: '', diceType: '', damageType: '' },
-  ];
-
-  public newWeaponProficient: boolean = false;
-  public newWeaponAttribute: string = '';
-  public newWeaponIsVersatile: boolean = false;
-  public newWeaponIsTwoHanded: boolean = false;
-  public newWeaponIsFinesse: boolean = false;
-  public newWeaponIsRanged: boolean = false;
-  public newWeaponVersatileDamage: Damage[] = [
-    { diceNumber: '', diceType: '', damageType: '' },
-  ];
-
-  public newSpellName: string = '';
-  public newSpellAttackBonus: string = '';
-  public newSpellDamage: string = '';
-  public newSpellType: string = '';
-  public newSpellRange: string = '';
-  public newSpellProficient: boolean = false;
-  public newSpellAttribute: string = '';
-
-  public spells!: Spell[];
+  public spellAttackBonus: string = '0';
+  public spellSaveDC: number = 0;
+  private spellcastingAttribute: string | undefined;
+  private spellcastingAttributeModifier: number = 0;
+  private proficiencyBonus: number = 2;
 
   public ngOnInit(): void {
-    this.spells = this.dataAccessor.getSpells();
+    //this.dataAccessor.getSpellcastingAttribute() oder so
+    this.spellcastingAttribute = 'intelligence';
+
+    this.dataAccessor.proficiency$.subscribe((value) => {
+      this.proficiencyBonus = value.value;
+      if (this.spellcastingAttribute) {
+        this.computeSpellAttackBonusAndSaveDC();
+      }
+    });
+
+    this.dataAccessor.intelligence$.subscribe((value) => {
+      this.spellcastingAttributeModifier = Math.floor((value.value - 10) / 2);
+      this.computeSpellAttackBonusAndSaveDC();
+    });
   }
 
-  public dropSpells(event: CdkDragDrop<string[]>): void {
-    moveItemInArray(this.spells, event.previousIndex, event.currentIndex);
-    this.updateSpells();
+  // spells
+  public openSpellCreationModal(): void {
+    this.ngxSmartModalService.getModal('spellModal').open();
+    console.log('openSpellModal()');
   }
 
-  public updateSpells(): void {
-    this.dataAccessor.setSpells(this.spells);
+  public addNewlyCreatedSpell(spell: Spell): void {
+    this.spellTable.addSpell(spell);
   }
 
-  public addSpell(): void {
-    // this.spells.push({
-    //   name: this.newSpellName,
-    //   damage: this.newSpellDamage,
-    //   attackBonus: this.newSpellAttackBonus,
-    //   range: this.newSpellRange,
-    //   type: this.newSpellType,
-    //   level: 0,
-    //   attribute: this.newSpellAttribute,
-    // });
-    this.ngxSmartModalService.getModal('spellModal').close();
+  public openSpellUpdateModal(data: any): void {
+    this.ngxSmartModalService.getModal('spellModal').setData(data);
+    this.ngxSmartModalService.getModal('spellModal').open();
   }
 
-  // spells
+  public updateSpellInTable(data: any): void {
+    console.log('updateSpellInTable()', data);
+    this.spellTable.updateSpell(data.spell, data.index);
+  }
 
-  public openSpellModal(): void {
-    this.ngxSmartModalService.getModal('spellModal').open();
-    console.log('openSpellModal()');
+  public deleteSpellInTable(index: number): void {
+    console.log('deleteSpellInTable()', index);
+    this.spellTable.deleteSpell(index);
   }
 
-  public addNewlyCreatedSpell(spell: Spell): void {
-    this.spellTable.addSpell(spell);
+  private computeSpellAttackBonusAndSaveDC(): void {
+    let attackBonus =
+      this.spellcastingAttributeModifier + this.proficiencyBonus;
+    this.spellSaveDC = 8 + attackBonus;
+    if (attackBonus >= 0) {
+      this.spellAttackBonus = '+' + attackBonus;
+    } else {
+      this.spellAttackBonus = attackBonus.toString();
+    }
   }
 
   // weapons
-  public openWeaponModal(): void {
+  public openWeaponCreationModal(): void {
     console.log('openWeaponModal()');
     this.ngxSmartModalService.getModal('weaponModal').open();
   }
@@ -100,7 +91,16 @@ export class WeaponsContainerComponent {
     this.weaponTable.addWeapon(weapon);
   }
 
-  public log(): void {
-    console.log('log');
+  public openWeaponUpdateModal(data: any): void {
+    this.ngxSmartModalService.getModal('weaponModal').setData(data);
+    this.ngxSmartModalService.getModal('weaponModal').open();
+  }
+
+  public updateWeaponInTable(data: any): void {
+    this.weaponTable.updateWeapon(data.weapon, data.index);
+  }
+
+  public deleteWeaponInTable(index: number): void {
+    this.weaponTable.deleteWeapon(index);
   }
 }

+ 12 - 3
src/app/journal/spell-modal/spell-modal.component.html

@@ -2,6 +2,7 @@
   #spellModal
   identifier="spellModal"
   (onAnyCloseEventFinished)="removeData()"
+  (onOpenFinished)="checkIfUpdate()"
 >
   <div>
     <h2 style="text-align: center">Waffe hinzufügen</h2>
@@ -35,10 +36,16 @@
           <input type="checkbox" [(ngModel)]="newSpellNeedsConcentration" />
           <label>Konzentration</label>
         </div>
+
         <div class="checkbox-element">
-          <input type="checkbox" [(ngModel)]="newSpellCost" />
+          <select [(ngModel)]="newSpellCost">
+            <option *ngFor="let cost of costs" [value]="cost.value">
+              {{ cost.display }}
+            </option>
+          </select>
           <label>Kosten</label>
         </div>
+
         <div class="checkbox-element">
           <input type="checkbox" [(ngModel)]="newSpellCanRitual" />
           <label>Ritual möglich?</label>
@@ -94,7 +101,7 @@
         <label>Erfordert Rettungswurf</label>
       </div>
       <select
-        [(ngModel)]="newSpellAreaOfEffectType"
+        [(ngModel)]="newSpellSavingThrowAttribute"
         *ngIf="newSpellNeedsSavingThrow"
       >
         <option
@@ -157,7 +164,9 @@
         ></icon>
       </div>
 
-      <button (click)="createSpell()">Add</button>
+      <button *ngIf="!isUpdate" (click)="createSpell()">Add</button>
+      <button *ngIf="isUpdate" (click)="updateSpell()">Update</button>
+      <button *ngIf="isUpdate" (click)="deleteSpell()">Delete</button>
     </div>
   </div>
 </ngx-smart-modal>

+ 93 - 1
src/app/journal/spell-modal/spell-modal.component.ts

@@ -12,10 +12,14 @@ export class SpellModalComponent {
   public constructor(public ngxSmartModalService: NgxSmartModalService) {}
   @Output() public spellCreated: EventEmitter<Spell> =
     new EventEmitter<Spell>();
+  @Output() public spellUpdated: EventEmitter<any> = new EventEmitter<any>();
+
+  @Output() public spellDeleted: EventEmitter<number> =
+    new EventEmitter<number>();
 
   public newSpellName: string = '';
   public newSpellLevel: number = 0;
-  public newSpellCost: string = '';
+  public newSpellCost: string = 'action';
   public newSpellCanRitual: boolean = false;
   public newSpellNeedsConcentration: boolean = false;
   public newSpellNeedsVerbal: boolean = false;
@@ -35,6 +39,9 @@ export class SpellModalComponent {
   public newSpellRadius: string | undefined;
   public newSpellAreaOfEffectType: string | undefined;
 
+  public isUpdate: boolean = false;
+  public indexForUpdate: number | undefined;
+
   // Options for the select boxes
   public areaTypes: any[] = [
     { display: 'Kegel', value: 'cone' },
@@ -96,6 +103,12 @@ export class SpellModalComponent {
     '10',
   ];
 
+  public costs: any[] = [
+    { display: 'Aktion', value: 'action' },
+    { display: 'Bonusaktion', value: 'bonus action' },
+    { display: 'Reaktion', value: 'reaction' },
+  ];
+
   public createSpell(): void {
     let newspell: Spell = {
       name: this.newSpellName,
@@ -162,5 +175,84 @@ export class SpellModalComponent {
     this.newSpellHasAreaOfEffect = false;
     this.newSpellRadius = undefined;
     this.newSpellAreaOfEffectType = undefined;
+    this.isUpdate = false;
+    this.ngxSmartModalService.resetModalData('spellModal');
+  }
+
+  //  update
+
+  public checkIfUpdate(): void {
+    if (this.ngxSmartModalService.getModalData('spellModal')) {
+      this.isUpdate = true;
+      const data: any = this.ngxSmartModalService.getModalData('spellModal');
+      const spell = data.spell;
+      this.newSpellName = spell.name;
+      this.newSpellLevel = spell.level;
+      this.newSpellCost = spell.cost;
+      this.newSpellCanRitual = spell.canRitual;
+      this.newSpellNeedsConcentration = spell.needsConcentration;
+      this.newSpellNeedsVerbal = spell.needsVerbal;
+      this.newSpellNeedsSomatic = spell.needsSomatic;
+      this.newSpellNeedsMaterial = spell.needsMaterial;
+      this.newSpellSchool = spell.school;
+      this.newSpellDescription = spell.description;
+      this.newSpellNeedsSavingThrow = spell.needsSavingThrow;
+      this.newSpellSavingThrowAttribute = spell.savingThrowAttribute;
+      this.newSpellAttackBonus = spell.attackBonus;
+      this.newSpellDamage = spell.damage;
+      this.newSpellIsRanged = spell.isRanged;
+      this.newSpellRange = spell.range;
+      this.newSpellHasAreaOfEffect = spell.hasAreaOfEffect;
+      this.newSpellRadius = spell.radius;
+      this.newSpellAreaOfEffectType = spell.areaOfEffectType;
+
+      this.indexForUpdate = data.index;
+    }
+  }
+
+  public updateSpell(): void {
+    const newspell: Spell = {
+      name: this.newSpellName,
+      damage: this.newSpellDamage,
+      level: this.newSpellLevel,
+      cost: this.newSpellCost,
+      canRitual: this.newSpellCanRitual,
+      needsConcentration: this.newSpellNeedsConcentration,
+      needsVerbal: this.newSpellNeedsVerbal,
+      needsSomatic: this.newSpellNeedsSomatic,
+      needsMaterial: this.newSpellNeedsMaterial,
+      needsSavingThrow: this.newSpellNeedsSavingThrow,
+      isRanged: this.newSpellIsRanged,
+      range: this.newSpellRange,
+      hasAreaOfEffect: this.newSpellHasAreaOfEffect,
+    };
+    if (this.newSpellDescription) {
+      newspell.description = this.newSpellDescription;
+    }
+    if (this.newSpellSchool) {
+      newspell.school = this.newSpellSchool;
+    }
+    if (this.newSpellSavingThrowAttribute) {
+      newspell.savingThrowAttribute = this.newSpellSavingThrowAttribute;
+    }
+    if (this.newSpellAttackBonus) {
+      newspell.attackBonus = this.newSpellAttackBonus;
+    }
+    if (this.newSpellHasAreaOfEffect) {
+      newspell.radius = this.newSpellRadius;
+    }
+    if (this.newSpellHasAreaOfEffect) {
+      newspell.areaOfEffectType = this.newSpellAreaOfEffectType;
+    }
+    this.spellUpdated.emit({ spell: newspell, index: this.indexForUpdate });
+    this.ngxSmartModalService.closeLatestModal();
+    this.removeData();
+  }
+
+  public deleteSpell(): void {
+    this.spellDeleted.emit(this.indexForUpdate);
+    console.log('deleteSpell()', this.indexForUpdate);
+    this.ngxSmartModalService.closeLatestModal();
+    this.removeData();
   }
 }

+ 30 - 20
src/app/journal/weapon-modal/weapon-modal.component.html

@@ -3,6 +3,7 @@
   identifier="weaponModal"
   id="weaponModal"
   (onAnyCloseEventFinished)="removeData()"
+  (onOpenFinished)="checkIfUpdate()"
 >
   <div>
     <h2 style="text-align: center">Waffe hinzufügen</h2>
@@ -46,16 +47,34 @@
           </select>
           <label>Gewicht</label>
         </div>
+        <div class="checkbox-element">
+          <input type="checkbox" [(ngModel)]="newWeaponIsMagical" />
+          <label>Magisch</label>
+        </div>
       </div>
 
       <div class="input-element">
         <label for="weaponAttackBonus">Angriffsbonus</label>
-        <input
-          type="text"
-          class="add-input"
-          id="weaponAttackBonus"
-          [(ngModel)]="newWeaponAttackBonus"
-        />
+        <select [(ngModel)]="newWeaponAttackBonus">
+          <option
+            *ngFor="let attackBonus of attackBonuses"
+            [value]="attackBonus"
+          >
+            {{ attackBonus }}
+          </option>
+        </select>
+      </div>
+
+      <div class="input-element" *ngIf="newWeaponIsMagical">
+        <label>Magischer Modifikator</label>
+        <select [(ngModel)]="newWeaponMagicBonus">
+          <option
+            *ngFor="let magicBonus of magicBonuses"
+            [value]="magicBonus.value"
+          >
+            {{ magicBonus.display }}
+          </option>
+        </select>
       </div>
 
       <div class="input-element" *ngIf="newWeaponIsRanged">
@@ -95,23 +114,12 @@
             </div>
           </div>
 
-          <div *ngIf="newWeaponIsVersatile">
+          <div *ngIf="newWeaponIsVersatile && index === 0">
             Zweihändiger Schaden
             <div class="flex-row gap-10">
-              <div class="flex-column">
-                <label>Anzahl</label>
-                <select
-                  [(ngModel)]="newWeaponVersatileDamage[index].diceNumber"
-                >
-                  <option *ngFor="let number of numbers" [value]="number">
-                    {{ number }}
-                  </option>
-                </select>
-              </div>
-
               <div class="flex-column">
                 <label>Würfel</label>
-                <select [(ngModel)]="newWeaponVersatileDamage[index].diceType">
+                <select [(ngModel)]="newWeaponVersatileDamage">
                   <option *ngFor="let die of dice" [value]="die">
                     {{ die }}
                   </option>
@@ -146,7 +154,9 @@
         ></icon>
       </div>
 
-      <button (click)="createWeapon()">Add</button>
+      <button *ngIf="!isUpdate" (click)="createWeapon()">Erstellen</button>
+      <button *ngIf="isUpdate" (click)="updateWeapon()">Aktualisieren</button>
+      <button *ngIf="isUpdate" (click)="deleteWeapon()">Entfernen</button>
     </div>
   </div>
 </ngx-smart-modal>

+ 110 - 17
src/app/journal/weapon-modal/weapon-modal.component.ts

@@ -13,24 +13,30 @@ export class WeaponModalComponent {
 
   @Output() public weaponCreated: EventEmitter<Weapon> =
     new EventEmitter<Weapon>();
-  public active: number = 1;
+
+  @Output() public weaponUpdated: EventEmitter<any> = new EventEmitter<any>();
+
+  @Output() public weaponDelete: EventEmitter<number> =
+    new EventEmitter<number>();
 
   public newWeaponName: string = '';
   public newWeaponRange: string = '5 ft.';
-  public newWeaponAttackBonus: string = '';
+  public newWeaponAttackBonus: string = '+0';
   public newWeaponDamage: Damage[] = [
     { diceNumber: '', diceType: '', damageType: '' },
   ];
   public newWeaponProficient: boolean = false;
-  public newWeaponAttribute: string = '';
   public newWeaponIsVersatile: boolean = false;
   public newWeaponIsTwoHanded: boolean = false;
   public newWeaponIsFinesse: boolean = false;
   public newWeaponIsRanged: boolean = false;
-  public newWeaponVersatileDamage: Damage[] = [
-    { diceNumber: '', diceType: '', damageType: '' },
-  ];
+  public newWeaponVersatileDamage: string = '';
   public newWeaponWeight: string = 'normal';
+  public newWeaponIsMagical: boolean = false;
+  public newWeaponMagicBonus: number = 0;
+
+  public indexForUpdate: number | undefined;
+  public isUpdate: boolean = false;
 
   // Options for the select boxes
   public weights: string[] = ['leicht', 'normal', 'schwer'];
@@ -65,6 +71,43 @@ export class WeaponModalComponent {
     '9',
     '10',
   ];
+
+  public attackBonuses: string[] = [
+    '-5',
+    '-4',
+    '-3',
+    '-2',
+    '-1',
+    '+0',
+    '+1',
+    '+2',
+    '+3',
+    '+4',
+    '+5',
+    '+6',
+    '+7',
+    '+8',
+    '+9',
+    '+10',
+    '+11',
+    '+12',
+    '+13',
+    '+14',
+    '+15',
+    '+16',
+    '+17',
+    '+18',
+    '+19',
+    '+20',
+  ];
+
+  public magicBonuses: any[] = [
+    { display: '+1', value: 1 },
+    { display: '+2', value: 2 },
+    { display: '+3', value: 3 },
+    { display: '+4', value: 4 },
+    { display: '+5', value: 5 },
+  ];
   //
 
   public createWeapon(): void {
@@ -80,6 +123,8 @@ export class WeaponModalComponent {
       isRanged: this.newWeaponIsRanged,
       versatileDamage: this.newWeaponVersatileDamage,
       weight: this.newWeaponWeight,
+      isMagical: this.newWeaponIsMagical,
+      magicBonus: this.newWeaponMagicBonus,
     };
     this.weaponCreated.emit(newWeapon);
     this.ngxSmartModalService.closeLatestModal();
@@ -87,32 +132,80 @@ export class WeaponModalComponent {
 
   public addDamage(): void {
     this.newWeaponDamage.push({ diceNumber: '', diceType: '', damageType: '' });
-    this.newWeaponVersatileDamage.push({
-      diceNumber: '',
-      diceType: '',
-      damageType: '',
-    });
   }
 
   public removeDamage(index: number): void {
     this.newWeaponDamage.splice(index, 1);
-    this.newWeaponVersatileDamage.splice(index, 1);
   }
 
   public removeData(): void {
     this.newWeaponName = '';
     this.newWeaponRange = '5 ft.';
-    this.newWeaponAttackBonus = '';
+    this.newWeaponAttackBonus = '+0';
     this.newWeaponDamage = [{ diceNumber: '', diceType: '', damageType: '' }];
     this.newWeaponProficient = false;
-    this.newWeaponAttribute = '';
     this.newWeaponIsVersatile = false;
     this.newWeaponIsTwoHanded = false;
     this.newWeaponIsFinesse = false;
     this.newWeaponIsRanged = false;
-    this.newWeaponVersatileDamage = [
-      { diceNumber: '', diceType: '', damageType: '' },
-    ];
+    this.newWeaponVersatileDamage = '';
     this.newWeaponWeight = 'normal';
+    this.newWeaponIsMagical = false;
+    this.newWeaponMagicBonus = 0;
+    this.isUpdate = false;
+    this.ngxSmartModalService.resetModalData('weaponModal');
+  }
+
+  // update
+
+  public checkIfUpdate(): void {
+    console.log('checkIfUpdate()');
+    if (this.ngxSmartModalService.getModalData('weaponModal')) {
+      this.isUpdate = true;
+      const data: any = this.ngxSmartModalService.getModalData('weaponModal');
+      const weapon = data.weapon;
+      this.newWeaponName = weapon.name;
+      this.newWeaponRange = weapon.range;
+      this.newWeaponAttackBonus = weapon.attackBonus;
+      this.newWeaponDamage = weapon.damage;
+      this.newWeaponProficient = weapon.proficient;
+      this.newWeaponIsVersatile = weapon.isVersatile;
+      this.newWeaponIsTwoHanded = weapon.isTwoHanded;
+      this.newWeaponIsFinesse = weapon.isFinesse;
+      this.newWeaponIsRanged = weapon.isRanged;
+      this.newWeaponVersatileDamage = weapon.versatileDamage;
+      this.newWeaponWeight = weapon.weight;
+      this.newWeaponIsMagical = weapon.isMagical;
+      this.newWeaponMagicBonus = weapon.magicBonus;
+
+      this.indexForUpdate = data.index;
+    }
+  }
+
+  public updateWeapon(): void {
+    const newWeapon: Weapon = {
+      name: this.newWeaponName,
+      damage: this.newWeaponDamage,
+      attackBonus: this.newWeaponAttackBonus,
+      range: this.newWeaponRange,
+      isFinesse: this.newWeaponIsFinesse,
+      proficient: this.newWeaponProficient,
+      isTwoHanded: this.newWeaponIsTwoHanded,
+      isVersatile: this.newWeaponIsVersatile,
+      isRanged: this.newWeaponIsRanged,
+      versatileDamage: this.newWeaponVersatileDamage,
+      weight: this.newWeaponWeight,
+      isMagical: this.newWeaponIsMagical,
+      magicBonus: this.newWeaponMagicBonus,
+    };
+    this.weaponUpdated.emit({ weapon: newWeapon, index: this.indexForUpdate });
+    this.ngxSmartModalService.closeLatestModal();
+    this.removeData();
+  }
+
+  public deleteWeapon(): void {
+    this.weaponDelete.emit(this.indexForUpdate);
+    this.ngxSmartModalService.closeLatestModal();
+    this.removeData();
   }
 }

+ 3 - 1
src/interfaces/weapon.ts

@@ -9,7 +9,9 @@ export interface Weapon {
   isFinesse: boolean;
   isRanged: boolean;
   weight: string;
-  versatileDamage?: Damage[];
+  versatileDamage?: string;
+  isMagical: boolean;
+  magicBonus?: number;
 }
 
 interface Damage {

+ 14 - 11
src/services/data/data.service.ts

@@ -150,9 +150,10 @@ export class DataService {
       isTwoHanded: true,
       isRanged: false,
       weight: 'schwer',
+      isMagical: false,
     },
     {
-      name: 'Kurzbogen',
+      name: 'Kurzbogen +1',
       attackBonus: '+5',
       damage: [{ diceNumber: '1', diceType: 'd8', damageType: 'piercing' }],
       proficient: false,
@@ -162,6 +163,8 @@ export class DataService {
       isTwoHanded: true,
       isRanged: true,
       weight: 'leicht',
+      isMagical: true,
+      magicBonus: 1,
     },
     {
       name: 'Feuerstab',
@@ -170,10 +173,7 @@ export class DataService {
         { diceNumber: '1', diceType: 'd6', damageType: 'bludgeoning' },
         { diceNumber: '1', diceType: 'd4', damageType: 'fire' },
       ],
-      versatileDamage: [
-        { diceNumber: '1', diceType: 'd8', damageType: 'bludgeoning' },
-        { diceNumber: '1', diceType: 'd4', damageType: 'fire' },
-      ],
+      versatileDamage: 'd8',
       proficient: true,
       range: '5ft',
       isFinesse: false,
@@ -181,15 +181,17 @@ export class DataService {
       isTwoHanded: false,
       isRanged: false,
       weight: 'normal',
+      isMagical: false,
     },
   ];
 
   public getWeapons(): Weapon[] {
     return this.weapons;
   }
+
   public setWeapons(weapons: Weapon[]): void {
     this.weapons = weapons;
-    console.log('weapons updated: ', this.weapons);
+    console.log('weapons updated from data service: ', this.weapons);
   }
 
   private spells: Spell[] = [
@@ -203,7 +205,7 @@ export class DataService {
       needsMaterial: true,
       needsConcentration: false,
       needsSavingThrow: true,
-      savingThrowAttribute: 'DEX',
+      savingThrowAttribute: 'dexterity',
       school: 'Evocation',
       damage: [{ diceNumber: '8', diceType: 'd6', damageType: 'fire' }],
       isRanged: true,
@@ -252,6 +254,7 @@ export class DataService {
 
   public setSpells(spells: Spell[]): void {
     this.spells = spells;
+    console.log('spells updated from data service: ', this.spells);
   }
 
   // #region Character Data observables
@@ -321,7 +324,7 @@ export class DataService {
   });
   public inspiration$ = this.inspirationSubject.asObservable();
 
-  private proficiencySubject = new BehaviorSubject<object>({
+  private proficiencySubject = new BehaviorSubject<any>({
     name: 'proficiencyBonus',
     value: 2,
   });
@@ -369,7 +372,7 @@ export class DataService {
   }
 
   private strengthSubject = new BehaviorSubject<Attribute>(
-    { name: 'strength', value: 10, proficiency: true } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
+    { name: 'strength', value: 19, proficiency: true } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
   );
   public strength$ = this.strengthSubject.asObservable();
 
@@ -379,7 +382,7 @@ export class DataService {
   public dexterity$ = this.dexteritySubject.asObservable();
 
   private constitutionSubject = new BehaviorSubject<Attribute>(
-    { name: 'constitution', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
+    { name: 'constitution', value: 12, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
   );
   public constitution$ = this.constitutionSubject.asObservable();
 
@@ -389,7 +392,7 @@ export class DataService {
   public intelligence$ = this.intelligenceSubject.asObservable();
 
   private wisdomSubject = new BehaviorSubject<Attribute>(
-    { name: 'wisdom', value: 10, proficiency: true } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
+    { name: 'wisdom', value: 13, proficiency: true } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
   );
   public wisdom$ = this.wisdomSubject.asObservable();