role.component.ts 13 KB
Newer Older
Romain DELEAU's avatar
Romain DELEAU committed
1
import { Component, Input, OnInit } from '@angular/core';
2
import { MatDialog } from '@angular/material/dialog';
3
import { Mission } from 'src/app/class/mission/mission';
Romain DELEAU's avatar
Romain DELEAU committed
4 5 6 7 8 9 10 11 12
import { Ressource } from 'src/app/class/ressource/ressource';
import { CharacterReward } from 'src/app/class/rewards/character-reward/character-reward';
import { ObjectiveReward } from 'src/app/class/rewards/objective-reward/objective-reward';
import { ObjectsReward } from 'src/app/class/rewards/objects-reward/objects-reward';
import { OtherReward } from 'src/app/class/rewards/other-reward/other-reward';
import { QuestReward } from 'src/app/class/rewards/quest-reward/quest-reward';
import { SkillReward } from 'src/app/class/rewards/skill-reward/skill-reward';
import { RoleEducationnalObjective } from 'src/app/class/role-educationnal-objective/role-educationnal-objective';
import { Role } from 'src/app/class/role/role';
Romain DELEAU's avatar
Romain DELEAU committed
13
import { Scenario } from 'src/app/class/scenario/scenario';
Romain DELEAU's avatar
Romain DELEAU committed
14
import { SupplementaryRole } from 'src/app/class/supplementary-role/supplementary-role';
Romain DELEAU's avatar
Romain DELEAU committed
15
import { PieceDetailsService } from 'src/app/services/piece-details/piece-details.service';
16
import { TooltipService } from 'src/app/services/tooltip/tooltip.service';
17 18 19
import { SuppressDialogComponent } from 'src/app/components/dialogs/suppress-dialog/suppress-dialog.component';
import { CleanDialogComponent } from 'src/app/components/dialogs/clean-dialog/clean-dialog.component';
import { CreateDialogComponent } from 'src/app/components/dialogs/create-dialog/create-dialog.component';
20
import { Trace } from 'src/app/class/trace/trace';
Romain DELEAU's avatar
Romain DELEAU committed
21 22 23 24 25 26 27 28

@Component({
  selector: 'app-role',
  templateUrl: './role.component.html',
  styleUrls: ['./role.component.scss']
})
export class RoleComponent implements OnInit {

Romain DELEAU's avatar
Romain DELEAU committed
29
  @Input() scenario: Scenario = new Scenario();
Romain DELEAU's avatar
Romain DELEAU committed
30
  @Input() role: Role = new Role();
31 32
  @Input() mission: Mission = new Mission();
  @Input() i: number = 0;
33
  @Input() missionIndex: number = 0;
Romain DELEAU's avatar
Romain DELEAU committed
34

35
  constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog) { }
Romain DELEAU's avatar
Romain DELEAU committed
36 37

  ngOnInit(): void {
38
    this.mission.equalizeLengths();
Romain DELEAU's avatar
Romain DELEAU committed
39 40
  }

Romain DELEAU's avatar
Romain DELEAU committed
41
  displayMenu: string = 'hide';
Romain DELEAU's avatar
Romain DELEAU committed
42
  rewardType: number = 0;
Romain DELEAU's avatar
Romain DELEAU committed
43

44
  onClickPiece(): void {
Romain DELEAU's avatar
Romain DELEAU committed
45
    this.pieceDetailsService.piece = this.role;
Romain DELEAU's avatar
Romain DELEAU committed
46 47 48
    this.pieceDetailsService.missionIndex = this.missionIndex;
    this.pieceDetailsService.roleIndex = this.i;
    this.pieceDetailsService.pieceIndex = this.i;
Romain DELEAU's avatar
Romain DELEAU committed
49 50 51
  }

  onClickAdd(): void {
52
    const dialogRef = this.dialog.open(CreateDialogComponent, { data: 'un nouveau Rôle pour la Mission '+(this.missionIndex+1) });
53 54
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
55 56 57
        this.mission.roles.push(new Role());
        let missionIndex: number = this.scenario.missions.findIndex(mission => mission == this.mission);
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',missionIndex,this.i,'all','Role_['+(this.mission.roles.length-1)+']','#9AD5EC'));
58 59
      }
    });
Romain DELEAU's avatar
Romain DELEAU committed
60 61 62
  }

  onClickErase(): void {
63 64 65 66 67 68 69 70 71
    const dialogRef = this.dialog.open(CleanDialogComponent, { data: 'Role '+(this.role.intitule ? '<'+this.role.intitule+'>' : (this.i+1)) });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
        this.role.intitule = '';
        this.role.questName = '';
        this.role.description = '';
        this.role.educationnalObjectives = [new RoleEducationnalObjective()];
        this.role.rewards = [];
        this.role.stuff = '';
72 73 74 75 76 77 78 79 80 81 82
        this.role.supplementaryRoles = []; 
        this.role.tasks.forEach(inlineTasks => {
          inlineTasks.forEach(task => {
            this.role.ressources.forEach(ressource => {
              if (task?.prerequireRessources.some(element => element.ressource == ressource)) {
                let index: number = task.prerequireRessources.findIndex(element => element.ressource == ressource);
                task.prerequireRessources.splice(index, 1);
              }
            });
          });
        });
83 84
        this.role.ressources = [];
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'erase',this.missionIndex,this.i,'all','Role_['+(this.i)+']','#9AD5EC'));      
85 86
      }
    });
87 88 89
  }

  onClickDelete(): void {
90 91 92
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'ce Rôle '+(this.role.intitule ? '<'+this.role.intitule+'>' : this.i+1) });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
93 94 95
        this.mission.roles.splice(this.i, 1);
        let missionIndex: number = this.scenario.missions.findIndex(mission => mission == this.mission);
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',missionIndex,this.i,'all','Role_['+(this.i)+']','#9AD5EC'));     
96 97
      }
    });
98 99 100 101 102 103 104 105
  }

  canDelete(): boolean {
    let res: boolean = true;
    if (this.mission.roles.length <= 2) {
      res = false;
    }
    return res;
106
  }
Romain DELEAU's avatar
Romain DELEAU committed
107

Romain DELEAU's avatar
Romain DELEAU committed
108 109
  addEducationnalObjective(): void {
    this.role.educationnalObjectives.push(new RoleEducationnalObjective());
110
    this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.i,'Obj_['+(this.role.educationnalObjectives.length-1)+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
Romain DELEAU's avatar
Romain DELEAU committed
111 112 113
  }

  removeEducationnalObjective(index: number): void {
114 115 116 117
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'cette Objectif Pédagogique' });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
        this.role.educationnalObjectives.splice(index, 1);
118 119 120
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.i,'Obj_['+(index)+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
      } else {
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'cancel_delete',this.missionIndex,this.i,'Obj_['+(index)+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
121 122
      }
    });
Romain DELEAU's avatar
Romain DELEAU committed
123 124 125 126
  }

  addRessource(): void {
    this.role.ressources.push(new Ressource());
127
    this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.i,'skill/ressource_['+this.role.ressources.length+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
Romain DELEAU's avatar
Romain DELEAU committed
128 129 130
  }

  removeRessource(index: number): void {
131 132 133 134 135 136 137 138 139 140 141
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'cette Ressource' });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
        this.role.tasks.forEach(inlineTasks => {
          inlineTasks.forEach(task => {
            task?.prerequireRessources.forEach((prerequire, j) => {
              if (prerequire.ressource == this.role.ressources[index]) {
                task.prerequireRessources.splice(j, 1);
              }
            });
          });
Romain DELEAU's avatar
Romain DELEAU committed
142
        });
143 144 145 146
        this.role.ressources.splice(index, 1);
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.i,'Skill/Ressource_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));        
      } else {
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'cancel_delete',this.missionIndex,this.i,'Skill/Ressource_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
147
      }
Romain DELEAU's avatar
Romain DELEAU committed
148
    });
Romain DELEAU's avatar
Romain DELEAU committed
149 150 151 152
  }
  
  addSupplementaryRole(): void {
    this.role.supplementaryRoles.push(new SupplementaryRole());
153
    this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.i,'Secondary_role_['+this.role.supplementaryRoles.length+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
Romain DELEAU's avatar
Romain DELEAU committed
154 155 156
  }

  removeSupplementaryRole(index: number) {
157 158 159 160
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'ce Rôle Supplémentaire'+(this.role.supplementaryRoles[index].name ? ' <'+this.role.supplementaryRoles[index].name+'>' : '') });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
        this.role.supplementaryRoles.splice(index, 1);
161 162 163
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.i,'Secondary_role_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
      } else {
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'cancel_delete',this.missionIndex,this.i,'Secondary_role_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
164 165
      }
    });
Romain DELEAU's avatar
Romain DELEAU committed
166 167 168 169
  }

  addReward(): void {
    this.role.rewards.push(new QuestReward());
170
    this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.i,'Reward_['+this.role.rewards.length+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
Romain DELEAU's avatar
Romain DELEAU committed
171 172 173 174
  }

  changeRewardType(index: number, type: string): void {
    switch(type) {
175 176 177 178 179 180 181 182 183 184 185 186
      case 'objects': this.role.rewards[index] = new ObjectsReward();
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[ObjectsReward]', 'Role_['+this.i+']', '#9AD5EC', '*')); break;
      case 'quest': this.role.rewards[index] = new QuestReward(); 
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[QuestReward]', 'Role_['+this.i+']', '#9AD5EC', '*'));break;
      case 'skill': this.role.rewards[index] = new SkillReward();
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[SkillReward]', 'Role_['+this.i+']', '#9AD5EC', '*'));break;
      case 'objective': this.role.rewards[index] = new ObjectiveReward();
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[ObjectiveReward]', 'Role_['+this.i+']', '#9AD5EC', '*'));break;
      case 'character': this.role.rewards[index] = new CharacterReward();
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[CharacterReward]', 'Role_['+this.i+']', '#9AD5EC', '*')); break;
      case 'other': this.role.rewards[index] = new OtherReward();
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[OtherReward]', 'Role_['+this.i+']', '#9AD5EC', '*'));break;
Romain DELEAU's avatar
Romain DELEAU committed
187 188 189 190
    }
  }

  removeReward(index: number): void {
191 192 193
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'cette Récompense' });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
194 195 196 197
        this.role.rewards.splice(index, 1);
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.i,'Reward_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));        
      } else {
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'cancel_delete',this.missionIndex,this.i,'Reward_['+index+']', 'Role_['+this.i+']', '#9AD5EC', '*'));        
198 199
      }
    });
Romain DELEAU's avatar
Romain DELEAU committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
  }

  getObjectiveReward(index: number): ObjectiveReward {
    return this.role.rewards[index] as ObjectiveReward;
  }

  getQuestReward(index: number): QuestReward {
    return this.role.rewards[index] as QuestReward;
  }

  getCharacterReward(index: number): CharacterReward {
    return this.role.rewards[index] as CharacterReward;
  }

  getSkillReward(index: number): SkillReward {
    return this.role.rewards[index] as SkillReward;
  }

  getOtherReward(index: number): OtherReward {
    return this.role.rewards[index] as OtherReward;
  }

  getObjectsReward(index: number): ObjectsReward {
    return this.role.rewards[index] as ObjectsReward;
  }

  addObject(index: number): void {
    this.getObjectsReward(index).objects.push(new Ressource);
228
    this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.i,'Reward_['+index+']_object_['+this.getObjectsReward(index).objects.length+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
Romain DELEAU's avatar
Romain DELEAU committed
229 230 231
  }

  removeObject(i: number, j: number): void {
232 233 234 235
    const dialogRef = this.dialog.open(SuppressDialogComponent, { data: 'cet Objet de la Récompense' });
    dialogRef.afterClosed().subscribe(result => {
      if (result == true) {
        this.getObjectsReward(i).objects.splice(j, 1);
236 237 238
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.i,'Reward_['+i+']_object_['+j+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
      } else {
        this.scenario.traces.push(new Trace(this.scenario.traces.length,'cancel_delete',this.missionIndex,this.i,'Reward_['+i+']_object_['+j+']', 'Role_['+this.i+']', '#9AD5EC', '*'));
239 240
      }
    });
Romain DELEAU's avatar
Romain DELEAU committed
241
  }
242 243 244 245 246 247 248

  changeQuestReward(index: number, event: any) {
    let value: string = event.target.value;
    let reward = new QuestReward();
    reward.intitule = this.role.intitule;
    reward.questName = value;
    this.role.rewards[index] = reward;
249 250 251 252 253 254 255 256 257
    this.editTrace(event, 'Reward_['+index+']_quest');
  }

  editTrace(event: any, source: string): void {
    if (event.target.value != '') {
      this.scenario.traces.push(new Trace(this.scenario.traces.length,'write',this.missionIndex,this.i,source,'Role_['+(this.i)+']', '#9AD5EC','*'));
    } else {
      this.scenario.traces.push(new Trace(this.scenario.traces.length,'erase',this.missionIndex,this.i,source,'Role_['+(this.i)+']', '#9AD5EC','*'));
    }
258
  }
Romain DELEAU's avatar
Romain DELEAU committed
259
}