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