|
@@ -2,6 +2,9 @@ import { Injectable } from '@angular/core';
|
|
|
import Localbase from 'localbase';
|
|
|
import { Character } from 'src/interfaces/character';
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { BehaviorSubject } from 'rxjs';
|
|
|
+import { Attribute } from 'src/interfaces/attribute';
|
|
|
+import { Skill } from 'src/interfaces/skill';
|
|
|
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
@@ -11,9 +14,279 @@ export class DataService {
|
|
|
|
|
|
constructor(private Router: Router) {
|
|
|
this.db = new Localbase('myDatabase');
|
|
|
+ // this.test();
|
|
|
}
|
|
|
|
|
|
- public character: any;
|
|
|
+ // public test(): void {
|
|
|
+ // let char: Character = {
|
|
|
+ // characterData: {
|
|
|
+ // name: 'Eliane',
|
|
|
+ // class: '',
|
|
|
+ // race: '',
|
|
|
+ // level: '',
|
|
|
+ // subclass: '',
|
|
|
+ // background: '',
|
|
|
+ // experience: '',
|
|
|
+ // inspiration: '',
|
|
|
+ // proficiencyBonus: '2',
|
|
|
+ // },
|
|
|
+ // attributes: {
|
|
|
+ // strength: ['12', false],
|
|
|
+ // dexterity: ['14', false],
|
|
|
+ // constitution: ['16', false],
|
|
|
+ // intelligence: ['10', false],
|
|
|
+ // wisdom: ['16', false],
|
|
|
+ // charisma: ['10', false],
|
|
|
+ // },
|
|
|
+ // skills: {
|
|
|
+ // acrobatics: ['12', false],
|
|
|
+ // animalHandling: ['11', false],
|
|
|
+ // arcana: ['11', false],
|
|
|
+ // athletics: ['11', false],
|
|
|
+ // deception: ['11', false],
|
|
|
+ // history: ['12', false],
|
|
|
+ // insight: ['13', false],
|
|
|
+ // intimidation: ['14', false],
|
|
|
+ // investigation: ['16', false],
|
|
|
+ // medicine: ['15', false],
|
|
|
+ // nature: ['17', false],
|
|
|
+ // perception: ['18', false],
|
|
|
+ // performance: ['19', false],
|
|
|
+ // persuasion: ['20', false],
|
|
|
+ // religion: ['9', false],
|
|
|
+ // sleightOfHand: ['8', false],
|
|
|
+ // stealth: ['7', false],
|
|
|
+ // survival: ['6', false],
|
|
|
+ // },
|
|
|
+ // combatStats: {
|
|
|
+ // armorClass: '18',
|
|
|
+ // initiative: '+2',
|
|
|
+ // speed: '30',
|
|
|
+ // hitPointMaximum: '12',
|
|
|
+ // currentHitPoints: '12',
|
|
|
+ // temporaryHitPoints: '0',
|
|
|
+ // hitDice: '',
|
|
|
+ // deathSaveSuccesses: '0',
|
|
|
+ // deathSaveFailures: '0',
|
|
|
+ // },
|
|
|
+ // appearance: {
|
|
|
+ // age: '',
|
|
|
+ // height: '',
|
|
|
+ // weight: '',
|
|
|
+ // eyes: '',
|
|
|
+ // skin: '',
|
|
|
+ // hair: '',
|
|
|
+ // },
|
|
|
+ // personality: {
|
|
|
+ // personalityTraits: '',
|
|
|
+ // ideals: '',
|
|
|
+ // bonds: '',
|
|
|
+ // flaws: '',
|
|
|
+ // },
|
|
|
+ // weapons: {
|
|
|
+ // name: '',
|
|
|
+ // attackBonus: '',
|
|
|
+ // damage: '',
|
|
|
+ // damageType: '',
|
|
|
+ // range: '',
|
|
|
+ // description: '',
|
|
|
+ // },
|
|
|
+ // };
|
|
|
+ // this.character = char;
|
|
|
+ // // console.log('character: ', this.character);
|
|
|
+ // }
|
|
|
+
|
|
|
+ public character: any = {};
|
|
|
+
|
|
|
+ // #region character data retrieval
|
|
|
+
|
|
|
+ public getCompleteCharacter(): Character {
|
|
|
+ return this.character;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getCharacterData(): any {
|
|
|
+ return this.character.characterData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getAppearance(): any {
|
|
|
+ return this.character.appearance;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getAttributes(): any {
|
|
|
+ return this.character.attributes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getSkills(): any {
|
|
|
+ return this.character.skills;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getCombatStats(): any {
|
|
|
+ return this.character.combatStats;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getPersonality(): any {
|
|
|
+ return this.character.personality;
|
|
|
+ }
|
|
|
+
|
|
|
+ public getWeapons(): any {
|
|
|
+ return this.character.weapons;
|
|
|
+ }
|
|
|
+
|
|
|
+ // #endregion
|
|
|
+
|
|
|
+ // #region Attribute observables
|
|
|
+
|
|
|
+ // Atrributes
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param newValue The new value of the Attribute
|
|
|
+ */
|
|
|
+ updateAttribute(newValue: Attribute) {
|
|
|
+ const functionCall: string = newValue.name + 'Subject.next(newValue)';
|
|
|
+ eval(`this.${functionCall}`);
|
|
|
+ console.log('updateAttribute: ', newValue.name);
|
|
|
+ // Datenbank updaten
|
|
|
+ }
|
|
|
+
|
|
|
+ private strengthSubject = new BehaviorSubject<Attribute>(
|
|
|
+ { name: 'strengt', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public strength$ = this.strengthSubject.asObservable();
|
|
|
+
|
|
|
+ private dexteritySubject = new BehaviorSubject<Attribute>(
|
|
|
+ { name: 'dexterity', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ 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
|
|
|
+ );
|
|
|
+ public constitution$ = this.constitutionSubject.asObservable();
|
|
|
+
|
|
|
+ private intelligenceSubject = new BehaviorSubject<Attribute>(
|
|
|
+ { name: 'intelligence', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public intelligence$ = this.intelligenceSubject.asObservable();
|
|
|
+
|
|
|
+ private wisdomSubject = new BehaviorSubject<Attribute>(
|
|
|
+ { name: 'wisdom', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public wisdom$ = this.wisdomSubject.asObservable();
|
|
|
+
|
|
|
+ private charismaSubject = new BehaviorSubject<Attribute>(
|
|
|
+ { name: 'charisma', value: 10, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public charisma$ = this.charismaSubject.asObservable();
|
|
|
+
|
|
|
+ // #endregion
|
|
|
+
|
|
|
+ // #region Skill observables
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param newValue The new value of the skill
|
|
|
+ */
|
|
|
+ updateSkills(newValue: Skill) {
|
|
|
+ const functionCall: string = newValue.name + 'Subject.next(newValue)';
|
|
|
+ eval(`this.${functionCall}`);
|
|
|
+ console.log('updateSkill: ', newValue.name);
|
|
|
+ // Datenbank updaten
|
|
|
+ }
|
|
|
+
|
|
|
+ private acrobaticsSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'acrobatics', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public acrobatics$ = this.acrobaticsSubject.asObservable();
|
|
|
+
|
|
|
+ private animalHandlingSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'animalHandling', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public animalHandling$ = this.animalHandlingSubject.asObservable();
|
|
|
+
|
|
|
+ private arcanaSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'arcana', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public arcana$ = this.arcanaSubject.asObservable();
|
|
|
+
|
|
|
+ private athleticsSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'athletics', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public athletics$ = this.athleticsSubject.asObservable();
|
|
|
+
|
|
|
+ private deceptionSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'deception', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public deception$ = this.deceptionSubject.asObservable();
|
|
|
+
|
|
|
+ private historySubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'history', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public history$ = this.historySubject.asObservable();
|
|
|
+
|
|
|
+ private insightSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'insight', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public insight$ = this.insightSubject.asObservable();
|
|
|
+
|
|
|
+ private intimidationSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'intimidation', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public intimidation$ = this.intimidationSubject.asObservable();
|
|
|
+
|
|
|
+ private investigationSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'investigation', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public investigation$ = this.investigationSubject.asObservable();
|
|
|
+
|
|
|
+ private medicineSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'medicine', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public medicine$ = this.medicineSubject.asObservable();
|
|
|
+
|
|
|
+ private natureSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'nature', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public nature$ = this.natureSubject.asObservable();
|
|
|
+
|
|
|
+ private perceptionSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'perception', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public perception$ = this.perceptionSubject.asObservable();
|
|
|
+
|
|
|
+ private performanceSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'performance', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public performance$ = this.performanceSubject.asObservable();
|
|
|
+
|
|
|
+ private persuasionSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'persuasion', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public persuasion$ = this.persuasionSubject.asObservable();
|
|
|
+
|
|
|
+ private religionSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'religion', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public religion$ = this.religionSubject.asObservable();
|
|
|
+
|
|
|
+ private sleightOfHandSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'sleightOfHand', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public sleightOfHand$ = this.sleightOfHandSubject.asObservable();
|
|
|
+
|
|
|
+ private stealthSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'stealth', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public stealth$ = this.stealthSubject.asObservable();
|
|
|
+
|
|
|
+ private survivalSubject = new BehaviorSubject<Skill>(
|
|
|
+ { name: 'survival', value: 1, proficiency: false } //erstmal nur gemockt, später muss der Wert aus der Datenbank kommen
|
|
|
+ );
|
|
|
+ public survival$ = this.survivalSubject.asObservable();
|
|
|
+
|
|
|
+ // #endregion
|
|
|
+
|
|
|
+ // #region database calls
|
|
|
|
|
|
public async addData(
|
|
|
collection: string,
|
|
@@ -49,15 +322,23 @@ export class DataService {
|
|
|
this.db.collection(collection).delete();
|
|
|
}
|
|
|
|
|
|
+ // #endregion
|
|
|
+
|
|
|
+ // #region character selection and construction
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param character The name of the character that was selected
|
|
|
+ */
|
|
|
public async selectCharacter(character: string) {
|
|
|
console.log('selectCharacter ausgewählt');
|
|
|
const characterData = await this.getCollectionWithKeys(character);
|
|
|
- this.character = this.getcurrentCharacterData(characterData);
|
|
|
+ this.character = this.buildCurrentCharacter(characterData);
|
|
|
+ console.log('character: ', this.character);
|
|
|
this.Router.navigate(['journal']);
|
|
|
}
|
|
|
|
|
|
- private getcurrentCharacterData(currentCharacterData: any) {
|
|
|
- console.log(currentCharacterData);
|
|
|
+ private buildCurrentCharacter(currentCharacterData: any): Character {
|
|
|
const [
|
|
|
appearanceData,
|
|
|
attributesData,
|
|
@@ -68,7 +349,6 @@ export class DataService {
|
|
|
weaponsData,
|
|
|
] = currentCharacterData.map((entry: any) => entry.data);
|
|
|
|
|
|
- console.log(appearanceData);
|
|
|
const appearance = {
|
|
|
age: appearanceData.age,
|
|
|
height: appearanceData.height,
|
|
@@ -155,6 +435,8 @@ export class DataService {
|
|
|
skills: skills,
|
|
|
weapons: weapons,
|
|
|
};
|
|
|
- this.character = newCharacter;
|
|
|
+ console.log('newCharacter: ', newCharacter);
|
|
|
+ return newCharacter;
|
|
|
}
|
|
|
+ // #endregion
|
|
|
}
|