Commit 00c822e4 authored by Romain DELEAU's avatar Romain DELEAU

fix: create final or repeat task before a task

parent 13d2dc2c
......@@ -72,9 +72,9 @@
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#b9dfe3'" mat-menu-item (click)="addTask(mission, role, i, j, 'normal')">Ajouter une Tâche</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#bccecc'" mat-menu-item (click)="addTask(mission, role, i, j, 'annexe')">Ajouter une Tâche annexe</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#e8e3b3'" mat-menu-item (click)="addTask(mission, role, i, j, 'optionnal')">Ajouter une Tâche optionnelle</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#b28386'" mat-menu-item (click)="addTask(mission, role, i, j, 'final')" *ngIf="dontContainFinalOrRepeatTask(tasks)">Ajouter une Tâche finale</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#b28386'" mat-menu-item (click)="addTask(mission, role, i, j, 'final')" *ngIf="canCreateFinalOrRepeatTask(tasks, j)">Ajouter une Tâche finale</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#bfdaa3'" mat-menu-item (click)="addTask(mission, role, i, j, 'event')">Ajouter un Événement aléatoire</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#abbcc6'" mat-menu-item (click)="addTask(mission, role, i, j, 'repeat')" *ngIf="dontContainFinalOrRepeatTask(tasks)">Recommencer le tour</button>
<button class="container-scenario-main-missions-mission-roles-role-tasks-menuButton" [style.background-color]="'#abbcc6'" mat-menu-item (click)="addTask(mission, role, i, j, 'repeat')" *ngIf="canCreateFinalOrRepeatTask(tasks, j)">Recommencer le tour</button>
</mat-menu>
</div>
</div>
......
......@@ -113,7 +113,6 @@ export class AppComponent {
task.symbol = Object.assign(new Symbol(), task.symbol);
task.characters = task.characters.map((characterData: any) => Object.assign(new Character(), characterData));
task.characters.forEach((character, index) => {
console.log(character instanceof Character);
let i: number | undefined = scenario.characters.findIndex(element => element.name == character.name && element.description == character.description && element.color == character.color);
if (typeof i !== 'undefined' && i !== -1) {
task.characters[i] = scenario.characters[index];
......@@ -154,4 +153,16 @@ export class AppComponent {
dontContainFinalOrRepeatTask(tasks: (Task|null)[]): boolean {
return !(tasks.some(task => task?.type == 'final') || tasks.some(task => task?.type == 'repeat'));
}
dontHaveTaskAfter(tasks: (Task|null)[], index: number): boolean {
return !tasks.slice(index, tasks.length).some(task => task instanceof Task);
}
canCreateFinalOrRepeatTask(tasks: (Task|null)[], index: number): boolean {
let res: boolean = false;
if (this.dontContainFinalOrRepeatTask(tasks) && this.dontHaveTaskAfter(tasks, index)) {
res = true;
}
return res;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment