CT-38 #17

Merged
mitch merged 2 commits from CT-38 into master 2022-04-19 12:36:10 +00:00
2 changed files with 33 additions and 50 deletions

View File

@ -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"
}
}

View File

@ -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