Commit 88e5cb61 authored by Romain DELEAU's avatar Romain DELEAU

change object reward system in role, disable the possibility to create a new...

change object reward system in role, disable the possibility to create a new old object reward but it stay usable if existing in an import file / fix a bug in copied role save where he wasn't save
parent 4a5801b0
...@@ -276,6 +276,9 @@ export class AppComponent { ...@@ -276,6 +276,9 @@ export class AppComponent {
if (rewardData.type == 'other') { if (rewardData.type == 'other') {
return Object.assign(new OtherReward(), rewardData); return Object.assign(new OtherReward(), rewardData);
} }
if (rewardData.type == 'object') {
return Object.assign(new ObjectReward(), rewardData);
}
}); });
role.rewards.forEach((reward: Reward, index: number) => { role.rewards.forEach((reward: Reward, index: number) => {
if (reward instanceof SkillReward) { if (reward instanceof SkillReward) {
...@@ -290,7 +293,15 @@ export class AppComponent { ...@@ -290,7 +293,15 @@ export class AppComponent {
let i: number = role.educationnalObjectives.findIndex(element => element.objective == reward.objective.objective); let i: number = role.educationnalObjectives.findIndex(element => element.objective == reward.objective.objective);
reward.objective = role.educationnalObjectives[i]; reward.objective = role.educationnalObjectives[i];
} }
if (reward instanceof ObjectReward) {
if (scenario.ressources.some(element => element.name == reward.object.name && element.type == 'ressource' && element.number == reward.object.number)) {
let i: number = scenario.ressources.findIndex(element => element.name == reward.object.name && element.type == 'ressource' && element.number == reward.object.number);
reward.object = scenario.ressources[i];
} else {
let i: number = role.ressources.findIndex(element => element.name == reward.object.name && element.type == 'ressource' && element.number == reward.object.number);
reward.object = role.ressources[i];
}
}
}); });
role.discussions = role.discussions.map((discussionData: any) => { role.discussions = role.discussions.map((discussionData: any) => {
let character: Character | undefined = scenario.characters.find(char => char.color == discussionData.character.color let character: Character | undefined = scenario.characters.find(char => char.color == discussionData.character.color
......
...@@ -12,6 +12,7 @@ import { MinimapService } from 'src/app/services/minimap/minimap.service'; ...@@ -12,6 +12,7 @@ import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { UnityService } from 'src/app/services/unity/unity.service'; import { UnityService } from 'src/app/services/unity/unity.service';
import { CharacterReward } from 'src/app/class/rewards/character-reward/character-reward'; import { CharacterReward } from 'src/app/class/rewards/character-reward/character-reward';
import { Reward } from 'src/app/class/rewards/reward';
@Component({ @Component({
selector: 'app-game-characters', selector: 'app-game-characters',
...@@ -45,6 +46,13 @@ export class GameCharactersComponent implements OnInit { ...@@ -45,6 +46,13 @@ export class GameCharactersComponent implements OnInit {
this.scenario.characters = []; this.scenario.characters = [];
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
mission.roles.forEach(role => { mission.roles.forEach(role => {
for (let i = 0; i < role.rewards.length; i++) {
let reward: Reward = role.rewards[i];
if (reward.type == 'character') {
role.rewards.splice(i,1);
i--;
}
}
role.tasks.forEach(inlineTasks => { role.tasks.forEach(inlineTasks => {
inlineTasks.forEach(task => { inlineTasks.forEach(task => {
if (task instanceof Task) { if (task instanceof Task) {
...@@ -86,6 +94,15 @@ export class GameCharactersComponent implements OnInit { ...@@ -86,6 +94,15 @@ export class GameCharactersComponent implements OnInit {
if (result == true) { if (result == true) {
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
mission.roles.forEach(role => { mission.roles.forEach(role => {
for (let i = 0; i < role.rewards.length; i++) {
let reward: Reward = role.rewards[i];
if (reward.type == 'character') {
if ((reward as CharacterReward).character == this.scenario.characters[index]) {
role.rewards.splice(i,1);
i--;
}
}
}
role.tasks.forEach(inlineTask => { role.tasks.forEach(inlineTask => {
inlineTask.forEach(task => { inlineTask.forEach(task => {
if (task instanceof Task) { if (task instanceof Task) {
......
...@@ -69,7 +69,8 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip ...@@ -69,7 +69,8 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip
<option value="skill">{{'role_reward_type_skill' | translate}}</option> <option value="skill">{{'role_reward_type_skill' | translate}}</option>
<option value="character">{{'role_reward_type_character' | translate}}</option> <option value="character">{{'role_reward_type_character' | translate}}</option>
<option value="objective">{{'role_reward_type_objective' | translate}}</option> <option value="objective">{{'role_reward_type_objective' | translate}}</option>
<option value="objects">{{'role_reward_type_object' | translate}}</option> <option value="objects" hidden>{{'role_reward_type_object' | translate}}</option>
<option value="object">{{'role_reward_type_object' | translate}}</option>
<!--<option value="discuss">Changer de discussion</option>--> <!--<option value="discuss">Changer de discussion</option>-->
<option value="other">{{'role_reward_type_other' | translate}}</option> <option value="other">{{'role_reward_type_other' | translate}}</option>
</select> </select>
...@@ -99,6 +100,22 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip ...@@ -99,6 +100,22 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip
<button mat-button><mat-icon fontIcon="remove"></mat-icon></button> <button mat-button><mat-icon fontIcon="remove"></mat-icon></button>
</div> </div>
--> -->
<div class="piece-form-rewards-reward-object" *ngIf="reward.type == 'object'">
<input type="number" [(ngModel)]="getObjectReward(i).quantity" (change)="editTrace($event, 'Reward_['+i+']_quantity')"/>
<select [(ngModel)]="getObjectReward(i).object" (change)="editTrace($event, 'Reward_['+i+']_object')"
[matTooltip]="translate.instant('role_reward_type_object_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips">
<ng-container *ngFor="let ressource of scenario.ressources">
<option [ngValue]="ressource" *ngIf="ressource.type == 'ressource'">{{ressource.name}}</option>
</ng-container>
<ng-container *ngFor="let ressource of role.ressources">
<option [ngValue]="ressource" *ngIf="ressource.type == 'ressource'">{{ressource.name}}</option>
</ng-container>
</select>
<button mat-button (click)="removeReward(i)"><mat-icon fontIcon="remove"></mat-icon></button>
</div>
<div class="piece-form-rewards-reward-skill" *ngIf="reward.type == 'skill'"> <div class="piece-form-rewards-reward-skill" *ngIf="reward.type == 'skill'">
<input type="number" [(ngModel)]="getSkillReward(i).quantity" (change)="editTrace($event, 'Reward_['+i+']_quantity')"/> <input type="number" [(ngModel)]="getSkillReward(i).quantity" (change)="editTrace($event, 'Reward_['+i+']_quantity')"/>
<select [(ngModel)]="getSkillReward(i).skill" (change)="editTrace($event, 'Reward_['+i+']_skill')" <select [(ngModel)]="getSkillReward(i).skill" (change)="editTrace($event, 'Reward_['+i+']_skill')"
......
...@@ -324,7 +324,7 @@ ...@@ -324,7 +324,7 @@
} }
} }
&-skill { &-skill, &-object {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
......
...@@ -28,6 +28,7 @@ import { Task } from 'src/app/class/task/task'; ...@@ -28,6 +28,7 @@ import { Task } from 'src/app/class/task/task';
import { CopyRoleSuccessComponent } from 'src/app/components/snackbars/copy-role-success/copy-role-success.component'; import { CopyRoleSuccessComponent } from 'src/app/components/snackbars/copy-role-success/copy-role-success.component';
import { RoleOccurrence } from 'src/app/class/role-occurrence/role-occurrence'; import { RoleOccurrence } from 'src/app/class/role-occurrence/role-occurrence';
import { ObjectReward } from 'src/app/class/rewards/object-reward/object-reward'; import { ObjectReward } from 'src/app/class/rewards/object-reward/object-reward';
import { Reward } from 'src/app/class/rewards/reward';
@Component({ @Component({
selector: 'app-role', selector: 'app-role',
...@@ -110,6 +111,19 @@ export class RoleComponent implements OnInit { ...@@ -110,6 +111,19 @@ export class RoleComponent implements OnInit {
newReward.character = (reward as CharacterReward).character; newReward.character = (reward as CharacterReward).character;
this.copyRoleService.role?.rewards.push(newReward); this.copyRoleService.role?.rewards.push(newReward);
} }
if (reward.type == 'object') {
let newReward: ObjectReward = new ObjectReward();
newReward.type = reward.type;
newReward.quantity = (reward as ObjectReward).quantity;
if (this.scenario.ressources.some(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type)) {
let i: number = this.scenario.ressources.findIndex(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type);
newReward.object = this.scenario.ressources[i];
} else {
let i: number = this.role.ressources.findIndex(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type);
newReward.object = this.role.ressources[i];
}
this.copyRoleService.role?.rewards.push(newReward);
}
if (reward.type == 'other') { if (reward.type == 'other') {
let newReward: OtherReward = new OtherReward(); let newReward: OtherReward = new OtherReward();
newReward.type = reward.type; newReward.type = reward.type;
...@@ -128,7 +142,11 @@ export class RoleComponent implements OnInit { ...@@ -128,7 +142,11 @@ export class RoleComponent implements OnInit {
} }
onClickPaste(): void { onClickPaste(): void {
this.role = Object.assign(new Role(), this.copyRoleService.role); //this.role = Object.assign(new Role(), this.copyRoleService.role);
this.role.intitule = (this.copyRoleService.role as Role).intitule;
this.role.questName = (this.copyRoleService.role as Role).questName;
this.role.description = (this.copyRoleService.role as Role).description;
this.role.stuff = (this.copyRoleService.role as Role).stuff;
this.role.ressources = (this.copyRoleService.role as Role).ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData)); this.role.ressources = (this.copyRoleService.role as Role).ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData));
this.role.educationnalObjectives = (this.copyRoleService.role as Role).educationnalObjectives.map((educationnalObjectiveData: any) => Object.assign(new RoleEducationnalObjective(), educationnalObjectiveData)); this.role.educationnalObjectives = (this.copyRoleService.role as Role).educationnalObjectives.map((educationnalObjectiveData: any) => Object.assign(new RoleEducationnalObjective(), educationnalObjectiveData));
this.role.supplementaryRoles = (this.copyRoleService.role as Role).supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData)); this.role.supplementaryRoles = (this.copyRoleService.role as Role).supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData));
...@@ -167,6 +185,19 @@ export class RoleComponent implements OnInit { ...@@ -167,6 +185,19 @@ export class RoleComponent implements OnInit {
newReward.character = (reward as CharacterReward).character; newReward.character = (reward as CharacterReward).character;
this.role.rewards.push(newReward); this.role.rewards.push(newReward);
} }
if (reward.type == 'object') {
let newReward: ObjectReward = new ObjectReward();
newReward.type = reward.type;
newReward.quantity = (reward as ObjectReward).quantity;
if (this.scenario.ressources.some(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type)) {
let i: number = this.scenario.ressources.findIndex(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type);
newReward.object = this.scenario.ressources[i];
} else {
let i: number = this.role.ressources.findIndex(ressource => ressource.name == (reward as ObjectReward).object.name && ressource.number == (reward as ObjectReward).object.number && ressource.type == (reward as ObjectReward).object.type);
newReward.object = this.role.ressources[i];
}
this.role.rewards.push(newReward);
}
if (reward.type == 'other') { if (reward.type == 'other') {
let newReward: OtherReward = new OtherReward(); let newReward: OtherReward = new OtherReward();
newReward.type = reward.type; newReward.type = reward.type;
...@@ -315,6 +346,21 @@ export class RoleComponent implements OnInit { ...@@ -315,6 +346,21 @@ export class RoleComponent implements OnInit {
const dialogRef = this.dialog.open(SuppressDialogComponent, { data: this.translate.instant('role_ressource_delete') }); const dialogRef = this.dialog.open(SuppressDialogComponent, { data: this.translate.instant('role_ressource_delete') });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result == true) { if (result == true) {
for (let i = 0; i < this.role.rewards.length; i++) {
let reward: Reward = this.role.rewards[i];
if (reward.type = 'object') {
if (this.role.ressources[index] == (reward as ObjectReward).object) {
this.role.rewards.splice(i,1);
i--;
}
}
if (reward.type = 'skill') {
if (this.role.ressources[index] == (reward as SkillReward).skill) {
this.role.rewards.splice(i,1);
i--;
}
}
}
this.role.tasks.forEach(inlineTasks => { this.role.tasks.forEach(inlineTasks => {
inlineTasks.forEach(task => { inlineTasks.forEach(task => {
if (task instanceof Task) { if (task instanceof Task) {
...@@ -399,17 +445,26 @@ export class RoleComponent implements OnInit { ...@@ -399,17 +445,26 @@ export class RoleComponent implements OnInit {
changeRewardType(index: number, type: string): void { changeRewardType(index: number, type: string): void {
switch(type) { switch(type) {
case 'objects': this.role.rewards[index] = new ObjectsReward(); 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; 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(); 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; 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(); 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; 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(); 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; 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(); 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; 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(); 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; 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;
case 'object': this.role.rewards[index] = new ObjectReward();
this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform',this.missionIndex,this.i,'Reward_['+index+']_transform_into_[ObjectReward]', 'Role_['+this.i+']', '#9AD5EC', '*'));
break;
} }
} }
...@@ -442,6 +497,10 @@ export class RoleComponent implements OnInit { ...@@ -442,6 +497,10 @@ export class RoleComponent implements OnInit {
return this.role.rewards[index] as SkillReward; return this.role.rewards[index] as SkillReward;
} }
getObjectReward(index: number): ObjectReward {
return this.role.rewards[index] as ObjectReward;
}
getOtherReward(index: number): OtherReward { getOtherReward(index: number): OtherReward {
return this.role.rewards[index] as OtherReward; return this.role.rewards[index] as OtherReward;
} }
......
...@@ -11,6 +11,7 @@ import { Trace } from 'src/app/class/trace/trace'; ...@@ -11,6 +11,7 @@ import { Trace } from 'src/app/class/trace/trace';
import { MinimapService } from 'src/app/services/minimap/minimap.service'; import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ObjectReward } from 'src/app/class/rewards/object-reward/object-reward'; import { ObjectReward } from 'src/app/class/rewards/object-reward/object-reward';
import { Reward } from 'src/app/class/rewards/reward';
@Component({ @Component({
selector: 'app-rules', selector: 'app-rules',
...@@ -39,9 +40,18 @@ export class RulesComponent implements OnInit { ...@@ -39,9 +40,18 @@ export class RulesComponent implements OnInit {
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result == true) { if (result == true) {
this.scenario.gameRules = ''; this.scenario.gameRules = '';
this.scenario.ressources.forEach((ressource, i) => { this.scenario.ressources.forEach((ressource) => {
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
mission.roles.forEach(role => { mission.roles.forEach(role => {
for (let i = 0; i < role.rewards.length; i++) {
let reward: Reward = role.rewards[i];
if (reward.type == 'object') {
if (ressource == (reward as ObjectReward).object) {
role.rewards.splice(i,1);
i--;
}
}
}
role.tasks.forEach(inlineTasks => { role.tasks.forEach(inlineTasks => {
inlineTasks.forEach(task => { inlineTasks.forEach(task => {
if (task instanceof Task) { if (task instanceof Task) {
...@@ -106,6 +116,15 @@ export class RulesComponent implements OnInit { ...@@ -106,6 +116,15 @@ export class RulesComponent implements OnInit {
if (result == true) { if (result == true) {
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
mission.roles.forEach(role => { mission.roles.forEach(role => {
for (let i = 0; i < role.rewards.length; i++) {
let reward: Reward = role.rewards[i];
if (reward.type == 'object') {
if (this.scenario.ressources[index] == (reward as ObjectReward).object) {
role.rewards.splice(i,1);
i--;
}
}
}
role.tasks.forEach(inlineTasks => { role.tasks.forEach(inlineTasks => {
inlineTasks.forEach(task => { inlineTasks.forEach(task => {
if (task instanceof Task) { if (task instanceof Task) {
......
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