Commit 9cfe12e3 authored by Romain DELEAU's avatar Romain DELEAU

success/fail load save file

parent acef9781
...@@ -28,6 +28,9 @@ import { ZoomService } from './services/zoom/zoom.service'; ...@@ -28,6 +28,9 @@ import { ZoomService } from './services/zoom/zoom.service';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component'; import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { MatSnackBar } from '@angular/material/snack-bar';
import { LoadingsucessSnackbarComponent } from './components/snackbars/loadingsucess-snackbar/loadingsucess-snackbar.component';
import { LoadingfailSnackbarComponent } from './components/snackbars/loadingfail-snackbar/loadingfail-snackbar.component';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
...@@ -41,7 +44,8 @@ export class AppComponent { ...@@ -41,7 +44,8 @@ export class AppComponent {
@ViewChild('fileInput') fileInput: any; @ViewChild('fileInput') fileInput: any;
constructor(private cdr: ChangeDetectorRef, protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, constructor(private cdr: ChangeDetectorRef, protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService,
private elementRef: ElementRef, private zoomService: ZoomService, private dialog: MatDialog, private titleService: Title) { private elementRef: ElementRef, private zoomService: ZoomService, private dialog: MatDialog, private titleService: Title,
private _snackBar: MatSnackBar) {
pieceDetailsService.piece = this.scenario; pieceDetailsService.piece = this.scenario;
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
...@@ -97,116 +101,117 @@ export class AppComponent { ...@@ -97,116 +101,117 @@ export class AppComponent {
const reader: FileReader = new FileReader(); const reader: FileReader = new FileReader();
reader.readAsText(file); reader.readAsText(file);
reader.onload = (e) => { reader.onload = (e) => {
const fileContent: string = reader.result as string; try {
const jsonData: any = JSON.parse(fileContent); const fileContent: string = reader.result as string;
const scenario: Scenario = Object.assign(new Scenario(), jsonData); const jsonData: any = JSON.parse(fileContent);
this.tooltipService.activatedTooltips = scenario.tooltips; const scenario: Scenario = Object.assign(new Scenario(), jsonData);
scenario.context = Object.assign(new GameContext(), jsonData.context); this.tooltipService.activatedTooltips = scenario.tooltips;
scenario.context.comments = jsonData.context.comments.map((commentData: any) => Object.assign(new Comment(), commentData)); scenario.context = Object.assign(new GameContext(), jsonData.context);
scenario.educationnalObjective = Object.assign(new GameEducationnalObjective(), jsonData.educationnalObjective); scenario.context.comments = jsonData.context.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
scenario.educationnalObjective.comments = jsonData.educationnalObjective.comments.map((commentData: any) => Object.assign(new Comment(), commentData)); scenario.educationnalObjective = Object.assign(new GameEducationnalObjective(), jsonData.educationnalObjective);
scenario.gameRules = jsonData.gameRules; scenario.educationnalObjective.comments = jsonData.educationnalObjective.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
scenario.characters = jsonData.characters.map((characterData: any) => Object.assign(new Character(), characterData)); scenario.gameRules = jsonData.gameRules;
scenario.ressources = jsonData.ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData)); scenario.characters = jsonData.characters.map((characterData: any) => Object.assign(new Character(), characterData));
scenario.comments = jsonData.comments.map((commentData: any) => Object.assign(new Comment(), commentData)); scenario.ressources = jsonData.ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData));
scenario.missions = jsonData.missions.map((missionData: any) => Object.assign(new Mission(), missionData)); scenario.comments = jsonData.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
scenario.missions.forEach((mission, index)=> { scenario.missions = jsonData.missions.map((missionData: any) => Object.assign(new Mission(), missionData));
mission.chronologie = jsonData.missions[index].chronologie.map((chronologieData: any) => { scenario.missions.forEach((mission, index) => {
if (chronologieData !== null) { mission.chronologie = jsonData.missions[index].chronologie.map((chronologieData: any) => {
return Object.assign(new Step(), chronologieData);
} else {
return null;
}
});
mission.chronologie.forEach((step) => {
if (step instanceof Step) {
step.comments = step.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
}
});
mission.comments = jsonData.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
mission.context = Object.assign(new MissionContext(), jsonData.missions[index].context);
mission.context.comments = jsonData.missions[index].context.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
mission.educationnalObjective = Object.assign(new EducationnalObjective(), jsonData.missions[index].educationnalObjective);
mission.educationnalObjective.comments = jsonData.missions[index].educationnalObjective.comments.map((commentData: any) => Object.assign(new Comment, commentData));
mission.roles = jsonData.missions[index].roles.map((roleData: any) => Object.assign(new Role(), roleData));
mission.roles.forEach((role, index) => {
role.comments = role.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
role.chronologie = mission.roles[index].chronologie.map((chronologieData: any) => {
if (chronologieData !== null) { if (chronologieData !== null) {
return Object.assign(new Step(), chronologieData); return Object.assign(new Step(), chronologieData);
} else { } else {
return null; return null;
} }
}); });
role.chronologie.forEach((step) => { mission.chronologie.forEach((step) => {
if (step instanceof Step) { if (step instanceof Step) {
step.comments = step.comments.map((commentData: any) => Object.assign(new Comment(), commentData)); step.comments = step.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
} }
}); });
role.ressources = role.ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData)); mission.comments = jsonData.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
role.occurences = role.occurences.map((occurrenceData: any) => Object.assign(new RoleOccurrence(), occurrenceData)); mission.context = Object.assign(new MissionContext(), jsonData.missions[index].context);
role.supplementaryRoles = role.supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData)); mission.context.comments = jsonData.missions[index].context.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
role.rewards = role.rewards.map((rewardData: any) => { mission.educationnalObjective = Object.assign(new EducationnalObjective(), jsonData.missions[index].educationnalObjective);
if (rewardData.type == 'skill') { mission.educationnalObjective.comments = jsonData.missions[index].educationnalObjective.comments.map((commentData: any) => Object.assign(new Comment, commentData));
return Object.assign(new SkillReward(), rewardData); mission.roles = jsonData.missions[index].roles.map((roleData: any) => Object.assign(new Role(), roleData));
} mission.roles.forEach((role, index) => {
if (rewardData.type == 'character') { role.comments = role.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
return Object.assign(new CharacterReward(), rewardData); role.chronologie = mission.roles[index].chronologie.map((chronologieData: any) => {
} if (chronologieData !== null) {
if (rewardData.type == 'quest') { return Object.assign(new Step(), chronologieData);
return Object.assign(new QuestReward(), rewardData);
}
if (rewardData.type == 'objects') {
return Object.assign(new ObjectsReward(), rewardData);
}
if (rewardData.type == 'objective') {
return Object.assign(new ObjectiveReward(), rewardData);
}
if (rewardData.type == 'other') {
return Object.assign(new OtherReward(), rewardData);
}
});
role.rewards.forEach((reward: Reward, index: number) => {
if (reward instanceof SkillReward) {
let i: number = role.ressources.findIndex(element => element.type == 'attribut' && element.name == reward.skill.name && element.number == reward.skill.number);
reward.skill = role.ressources[i];
}
if (reward instanceof CharacterReward) {
let i: number = scenario.characters.findIndex(element => element.color == reward.character.color && element.description == reward.character.description && element.name == reward.character.name);
reward.character = scenario.characters[i];
}
if (reward instanceof ObjectiveReward) {
let i: number = role.educationnalObjectives.findIndex(element => element.objective == reward.objective.objective);
reward.objective = role.educationnalObjectives[i];
}
});
role.tasks.forEach((inlineTasks: any[], index: number) => {
role.tasks[index] = inlineTasks.map((taskData: any) => {
if (taskData !== null) {
return Object.assign(new Task(taskData.type), taskData);
} else { } else {
return null; return null;
} }
}); });
role.tasks[index].forEach(task => { role.chronologie.forEach((step) => {
if (task instanceof Task) { if (step instanceof Step) {
task.comments = task.comments.map((commentData: any) => Object.assign(new Comment(), commentData)); step.comments = step.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
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) => { role.ressources = role.ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData));
let i: number | undefined = scenario.characters.findIndex(element => element.name == character.name && element.description == character.description && element.color == character.color); role.occurences = role.occurences.map((occurrenceData: any) => Object.assign(new RoleOccurrence(), occurrenceData));
if (typeof i !== 'undefined' && i !== -1) { role.supplementaryRoles = role.supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData));
task.characters[index] = scenario.characters[i]; role.rewards = role.rewards.map((rewardData: any) => {
} if (rewardData.type == 'skill') {
}); return Object.assign(new SkillReward(), rewardData);
task.supplementaryRole = Object.assign(new SupplementaryRole, task.supplementaryRole); }
let supplementaryRoleIndex: number | undefined = role.supplementaryRoles.findIndex(element => if (rewardData.type == 'character') {
element.name == task.supplementaryRole.name && element.color == task.supplementaryRole.color return Object.assign(new CharacterReward(), rewardData);
); }
task.supplementaryRole = role.supplementaryRoles[supplementaryRoleIndex]; if (rewardData.type == 'quest') {
task.prerequireRessources = task.prerequireRessources.map((prerequireData: any) => Object.assign(new PrerequireRessource(), prerequireData)); return Object.assign(new QuestReward(), rewardData);
task.prerequireRessources.forEach((prerequire, index) => { }
if (rewardData.type == 'objects') {
return Object.assign(new ObjectsReward(), rewardData);
}
if (rewardData.type == 'objective') {
return Object.assign(new ObjectiveReward(), rewardData);
}
if (rewardData.type == 'other') {
return Object.assign(new OtherReward(), rewardData);
}
});
role.rewards.forEach((reward: Reward, index: number) => {
if (reward instanceof SkillReward) {
let i: number = role.ressources.findIndex(element => element.type == 'attribut' && element.name == reward.skill.name && element.number == reward.skill.number);
reward.skill = role.ressources[i];
}
if (reward instanceof CharacterReward) {
let i: number = scenario.characters.findIndex(element => element.color == reward.character.color && element.description == reward.character.description && element.name == reward.character.name);
reward.character = scenario.characters[i];
}
if (reward instanceof ObjectiveReward) {
let i: number = role.educationnalObjectives.findIndex(element => element.objective == reward.objective.objective);
reward.objective = role.educationnalObjectives[i];
}
});
role.tasks.forEach((inlineTasks: any[], index: number) => {
role.tasks[index] = inlineTasks.map((taskData: any) => {
if (taskData !== null) {
return Object.assign(new Task(taskData.type), taskData);
} else {
return null;
}
});
role.tasks[index].forEach(task => {
if (task instanceof Task) {
task.comments = task.comments.map((commentData: any) => Object.assign(new Comment(), commentData));
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) => {
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[index] = scenario.characters[i];
}
});
task.supplementaryRole = Object.assign(new SupplementaryRole, task.supplementaryRole);
let supplementaryRoleIndex: number | undefined = role.supplementaryRoles.findIndex(element =>
element.name == task.supplementaryRole.name && element.color == task.supplementaryRole.color
);
task.supplementaryRole = role.supplementaryRoles[supplementaryRoleIndex];
task.prerequireRessources = task.prerequireRessources.map((prerequireData: any) => Object.assign(new PrerequireRessource(), prerequireData));
task.prerequireRessources.forEach((prerequire, index) => {
if (scenario.ressources.some(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number)) { if (scenario.ressources.some(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number)) {
let i: number = scenario.ressources.findIndex(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number); let i: number = scenario.ressources.findIndex(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number);
prerequire.ressource = scenario.ressources[i]; prerequire.ressource = scenario.ressources[i];
...@@ -214,21 +219,24 @@ export class AppComponent { ...@@ -214,21 +219,24 @@ export class AppComponent {
let i: number = role.ressources.findIndex(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number); let i: number = role.ressources.findIndex(element => element.name == prerequire.ressource.name && element.number == prerequire.ressource.number);
prerequire.ressource = role.ressources[i]; prerequire.ressource = role.ressources[i];
} }
}) })
} }
});
}); });
}); });
}); });
}); this.scenario = scenario;
this.scenario = scenario; this.pieceDetailsService.piece = this.scenario;
this.pieceDetailsService.piece = this.scenario; if (scenario.projectName) {
if (scenario.projectName) { this.titleService.setTitle('RLG Maker - ' + this.scenario.projectName);
this.titleService.setTitle('RLG Maker - '+this.scenario.projectName); } else {
} else { this.titleService.setTitle('RLG Maker');
this.titleService.setTitle('RLG Maker'); }
this.cdr.detectChanges();
this._snackBar.openFromComponent(LoadingsucessSnackbarComponent, { duration: 5000 });
} catch {
this._snackBar.openFromComponent(LoadingfailSnackbarComponent, { duration: 5000 });
} }
this.cdr.detectChanges();
}; };
} }
} }
......
...@@ -40,6 +40,8 @@ import { CreateDialogComponent } from './components/dialogs/create-dialog/create ...@@ -40,6 +40,8 @@ import { CreateDialogComponent } from './components/dialogs/create-dialog/create
import { GameCharactersComponent } from './pieces/game-characters/game-characters.component'; import { GameCharactersComponent } from './pieces/game-characters/game-characters.component';
import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component'; import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component';
import { IdentifierSnackbarComponent } from './components/snackbars/identifier-snackbar/identifier-snackbar.component'; import { IdentifierSnackbarComponent } from './components/snackbars/identifier-snackbar/identifier-snackbar.component';
import { LoadingsucessSnackbarComponent } from './components/snackbars/loadingsucess-snackbar/loadingsucess-snackbar.component';
import { LoadingfailSnackbarComponent } from './components/snackbars/loadingfail-snackbar/loadingfail-snackbar.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -71,7 +73,9 @@ import { IdentifierSnackbarComponent } from './components/snackbars/identifier-s ...@@ -71,7 +73,9 @@ import { IdentifierSnackbarComponent } from './components/snackbars/identifier-s
CreateDialogComponent, CreateDialogComponent,
GameCharactersComponent, GameCharactersComponent,
SaveDialogComponent, SaveDialogComponent,
IdentifierSnackbarComponent IdentifierSnackbarComponent,
LoadingsucessSnackbarComponent,
LoadingfailSnackbarComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
::ng-deep .mat-snack-bar-container { ::ng-deep .mat-snack-bar-container {
background-color: #f8aa14; background-color: #fec001;
color: black; color: black;
box-shadow: 0px 0px 15px 5px #f8aa14; box-shadow: 0px 0px 15px 5px #fec001;
//font-family: 'Glacial Indifference Bold'; text-align: center;
justify-content: space-between;
} }
\ No newline at end of file
...@@ -8,8 +8,6 @@ import { MatSnackBarRef } from '@angular/material/snack-bar'; ...@@ -8,8 +8,6 @@ import { MatSnackBarRef } from '@angular/material/snack-bar';
}) })
export class IdentifierSnackbarComponent implements OnInit { export class IdentifierSnackbarComponent implements OnInit {
snackBarRef = inject(MatSnackBarRef);
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
......
<span matSnackBarLabel>Chargement du fichier échoué</span>
\ No newline at end of file
::ng-deep .mat-snack-bar-container {
background-color: #de3e44;
color: white;
box-shadow: 0px 0px 15px 5px #de3e44;
text-align: center;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoadingfailSnackbarComponent } from './loadingfail-snackbar.component';
describe('LoadingfailSnackbarComponent', () => {
let component: LoadingfailSnackbarComponent;
let fixture: ComponentFixture<LoadingfailSnackbarComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ LoadingfailSnackbarComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(LoadingfailSnackbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-loadingfail-snackbar',
templateUrl: './loadingfail-snackbar.component.html',
styleUrls: ['./loadingfail-snackbar.component.scss']
})
export class LoadingfailSnackbarComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
<span matSnackBarLabel>Chargement du fichier réussi</span>
\ No newline at end of file
::ng-deep .mat-snack-bar-container {
background-color: #1ba345;
color: white;
box-shadow: 0px 0px 15px 5px #1ba345;
text-align: center;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoadingsucessSnackbarComponent } from './loadingsucess-snackbar.component';
describe('LoadingsucessSnackbarComponent', () => {
let component: LoadingsucessSnackbarComponent;
let fixture: ComponentFixture<LoadingsucessSnackbarComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ LoadingsucessSnackbarComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(LoadingsucessSnackbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-loadingsucess-snackbar',
templateUrl: './loadingsucess-snackbar.component.html',
styleUrls: ['./loadingsucess-snackbar.component.scss']
})
export class LoadingsucessSnackbarComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
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