CT-38 #17
@ -21,6 +21,7 @@
|
||||
],
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"no-console": "warn",
|
||||
"@typescript-eslint/ban-ts-ignore": "off"
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"guard-for-in": "off"
|
||||
}
|
||||
}
|
||||
|
@ -34,55 +34,47 @@ export class ForceComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getArmyId();
|
||||
this.loadArmy().then();
|
||||
}
|
||||
|
||||
getArmyId(): void {
|
||||
if (this.forceList[0] && this.forceList[0].unit.id) {
|
||||
const armyIdOrNull: Observable<HttpResponse<number>> = this.unitArmyService.getArmy(this.forceList[0].unit.id);
|
||||
armyIdOrNull.toPromise().then(
|
||||
async loadArmy(): Promise<HttpResponse<number>> {
|
||||
// @ts-ignore
|
||||
const armyIdPromise: Observable<HttpResponse<number>> = this.unitArmyService.getArmy(this.forceList[0].unit.id);
|
||||
await armyIdPromise.toPromise().then(
|
||||
res => {
|
||||
Promise.resolve(res.body);
|
||||
this.armyId = res.body? res.body : 0;
|
||||
if (res.body) {
|
||||
this.armyId = res.body;
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
getArmyIdPromise(): Promise<number | void> | null {
|
||||
if (this.forceList[0] && this.forceList[0].unit.id) {
|
||||
const armyIdOrNull: Observable<HttpResponse<number>> = this.unitArmyService.getArmy(this.forceList[0].unit.id);
|
||||
return armyIdOrNull.toPromise().then(
|
||||
res => {
|
||||
Promise.resolve(res.body);
|
||||
}
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getArmyPromise(): Promise<HttpResponse<Army>> {
|
||||
this.getArmyId();
|
||||
const armyObs: Observable<HttpResponse<Army>> = this.armyService.find(this.armyId);
|
||||
const armyPromise: Promise<HttpResponse<Army>> = armyObs.toPromise().then(
|
||||
res => {
|
||||
Promise.resolve(res.body);
|
||||
return res;
|
||||
}
|
||||
)
|
||||
return armyPromise;
|
||||
}
|
||||
|
||||
loadArmy(): void {
|
||||
this.getArmyId();
|
||||
const armyObs: Observable<HttpResponse<Army>> = this.armyService.find(this.armyId);
|
||||
armyObs.toPromise().then(
|
||||
const armyPromise: Observable<HttpResponse<Army>> = this.armyService.find(this.armyId);
|
||||
await armyPromise.toPromise().then(
|
||||
res => {
|
||||
Promise.resolve(res.body);
|
||||
this.army = res.body;
|
||||
}
|
||||
);
|
||||
|
||||
for (let i = 0; i < this.forceList.length; i++) {
|
||||
if (this.army && this.army.units) {
|
||||
this.army.units.forEach(
|
||||
armyyUnit => {
|
||||
if (this.forceList[i].unit.id === armyyUnit.id) {
|
||||
for (const key in armyyUnit) {
|
||||
if (key !== "army") {
|
||||
this.forceList[i].unit[key] = armyyUnit[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
localStorage.setItem('forceAddedListStored', JSON.stringify(this.forceList));
|
||||
return armyIdPromise.toPromise();
|
||||
}
|
||||
|
||||
resetAll(): void {
|
||||
for (const fu of this.forceList) {
|
||||
@ -141,17 +133,7 @@ export class ForceComponent implements OnInit {
|
||||
localStorage.setItem('forceAddedListStored', JSON.stringify(this.forceList));
|
||||
}
|
||||
|
||||
async saveList(): Promise<void> {
|
||||
const armyPromise: Promise<HttpResponse<Army>> = this.getArmyPromise();
|
||||
|
||||
await armyPromise.then(
|
||||
res => {
|
||||
Promise.resolve(res.body);
|
||||
this.army = res.body;
|
||||
return this.army;
|
||||
}
|
||||
)
|
||||
|
||||
saveList(): void {
|
||||
for (const fu of this.forceList) {
|
||||
let newExperience: number
|
||||
let newUnitsDestroyed: number
|
||||
@ -194,6 +176,7 @@ export class ForceComponent implements OnInit {
|
||||
|
||||
fu.unit.enemyUnitsDestroyed = newUnitsDestroyed;
|
||||
fu.unit.experiencePoints = newExperience;
|
||||
// console.log(fu.unit);
|
||||
this.unitArmyService.update(fu.unit).toPromise().then();
|
||||
}
|
||||
|
||||
@ -216,6 +199,7 @@ export class ForceComponent implements OnInit {
|
||||
}
|
||||
|
||||
if (this.army) {
|
||||
// console.log(this.army)
|
||||
this.armyService.update(this.army).toPromise().then()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user