diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b6ddf99..349c5f2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,7 +2,7 @@ import { Component, inject, OnInit } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { NavigationEnd, Router, RouterOutlet } from '@angular/router'; import { EventType, SystemEventOperate } from '@models'; -import { EventService, KimiService } from '@services'; +import { EventService } from '@services'; import { NzLayoutModule } from 'ng-zorro-antd/layout'; import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal'; import { NzSegmentedModule } from 'ng-zorro-antd/segmented'; @@ -34,12 +34,7 @@ export class AppComponent implements OnInit { segmentedRoutes: string[] = ['/home', '/method', '/universe', '/challenge', '/shop', '/statistics']; currentSegmented: number = 0; - private kimi = inject(KimiService); - ngOnInit() { - this.kimi.getCharacterList(5).subscribe(res => { - console.log(res); - }); this.event .sendEvent({ type: EventType.System, diff --git a/src/app/components/init-modal/init-modal.component.html b/src/app/components/init-modal/init-modal.component.html index a894bd1..8abb4a1 100644 --- a/src/app/components/init-modal/init-modal.component.html +++ b/src/app/components/init-modal/init-modal.component.html @@ -3,57 +3,59 @@ -
- @if (current === 0) { -
- @for (item of characters; track $index) { -
- - {{ item.baseInfo.name }} - {{ item.baseInfo.gender }} - {{ item.baseInfo.age }} - - @for (item of item.baseInfo.talent; track $index) { - {{ item.name }} - } - - {{ item.innateInfo.hp }} - {{ item.innateInfo.mp }} - {{ item.innateInfo.attack }} - {{ item.innateInfo.defence }} - {{ item.innateInfo.speed }} - -
- } -
- } - @if (current === 1) { -
- @for (item of envs; track $index) { -
- - {{ item.name }} - {{ item.weight }} - {{ item.maxExp }} - {{ envSrv.getEnvType(item.type) }} - - - - - @for (item of item.methodSuits; track $index) { - {{ item.name }} - } - - -
- } -
- } +
+ + @if (current === 0) { +
+ @for (item of characters; track $index) { +
+ + {{ item.baseInfo.name }} + {{ item.baseInfo.gender }} + {{ item.baseInfo.age }} + + @for (item of item.baseInfo.talent; track $index) { + {{ item.name }} + } + + {{ item.innateInfo.hp }} + {{ item.innateInfo.mp }} + {{ item.innateInfo.attack }} + {{ item.innateInfo.defence }} + {{ item.innateInfo.speed }} + +
+ } +
+ } + @if (current === 1) { +
+ @for (item of envs; track $index) { +
+ + {{ item.name }} + {{ item.weight }} + {{ item.maxExp }} + {{ envSrv.getEnvType(item.type) }} + + + + + @for (item of item.methodSuits; track $index) { + {{ item.name }} + } + + +
+ } +
+ } +
diff --git a/src/app/components/init-modal/init-modal.component.ts b/src/app/components/init-modal/init-modal.component.ts index 92986d3..c46f034 100644 --- a/src/app/components/init-modal/init-modal.component.ts +++ b/src/app/components/init-modal/init-modal.component.ts @@ -2,23 +2,25 @@ import { CommonModule, KeyValuePipe } from '@angular/common'; import { Component, inject, OnInit } from '@angular/core'; import { Env, InitCharacter } from '@models'; import { EnvService } from '@services'; -import { Generate } from '@utils/generate'; import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions'; import { NzModalRef } from 'ng-zorro-antd/modal'; import { NzStepsModule } from 'ng-zorro-antd/steps'; import { NzTagModule } from 'ng-zorro-antd/tag'; import { LevelMapViewComponent } from '../level-map-view/level-map-view.component'; +import { GenerateService } from '@shared'; +import { NzSpinModule } from 'ng-zorro-antd/spin'; @Component({ selector: 'app-init-modal', standalone: true, - imports: [CommonModule, NzDescriptionsModule, NzStepsModule, NzTagModule, KeyValuePipe, LevelMapViewComponent], + imports: [CommonModule, NzDescriptionsModule, NzStepsModule, NzTagModule, KeyValuePipe, LevelMapViewComponent,NzSpinModule ], templateUrl: './init-modal.component.html' }) export class InitModalComponent implements OnInit { public envSrv = inject(EnvService); private ref = inject(NzModalRef); + private generateSrv = inject(GenerateService); current: number = 0; characters: InitCharacter[] = []; envs: Env[] = []; @@ -27,10 +29,21 @@ export class InitModalComponent implements OnInit { selectEnv: Env | undefined; ngOnInit() { - this.characters = Generate.characters(8); - const { envs, galaxiesId } = Generate.envs(8); - this.envs = envs; - this.galaxiesId = galaxiesId; + this.getCharacterList(8); + this.getEnvList(8); + } + + getCharacterList(length: number) { + this.generateSrv.getCharacterList(length).subscribe(res => { + this.characters = res; + }) + } + + getEnvList(length: number) { + this.generateSrv.getEnvList(length).subscribe(({envs,galaxiesId}) => { + this.envs = envs; + this.galaxiesId = galaxiesId; + }) } onCharacterClick(item: InitCharacter) { diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 7655820..f24f960 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -8,6 +8,7 @@ import { NzModalModule } from 'ng-zorro-antd/modal'; import { NzTypographyModule } from 'ng-zorro-antd/typography'; import { BackpackComponent } from './components/backpack/backpack.component'; +import { GenerateService } from '@shared'; @Component({ selector: 'app-home', @@ -24,6 +25,7 @@ export class HomeComponent implements OnInit { public envSrv = inject(EnvService); private backpackSrv = inject(BackpackService); private event = inject(EventService); + private generateSrv = inject(GenerateService); isAutoCultivate = false; isUpgrade = false; @@ -32,11 +34,17 @@ export class HomeComponent implements OnInit { ngOnInit() { // TODO: 初始化8个敌人,用来测试战斗 - this.enemys = Generate.enemys(8, this.characterSrv.levelInfo.level); + this.getEnemyList(); // 初始化升级状态 this.isUpgrade = this.characterSrv.canUpgrade; } + getEnemyList(){ + this.generateSrv.getEnemyList(8,this.characterSrv.levelInfo.level).subscribe(res=>{ + this.enemys = res + }) + } + onCultivationClick() { this.isLocked = true; this.event diff --git a/src/app/services/index.ts b/src/app/services/index.ts index 069bf00..7160209 100644 --- a/src/app/services/index.ts +++ b/src/app/services/index.ts @@ -3,7 +3,6 @@ export * from './battle.service'; // 战斗管理 export * from './character.service'; // 角色管理 export * from './env.service'; // 环境管理 export * from './event.service'; // 事件管理 -export * from './kimi.service'; // kimi export * from './log.service'; // 日志管理 export * from './runtime.service'; // 运行时管理 export * from './task.service'; // 任务管理 diff --git a/src/app/services/kimi.service.ts b/src/app/services/kimi.service.ts deleted file mode 100644 index 0085084..0000000 --- a/src/app/services/kimi.service.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { inject, Injectable } from '@angular/core'; - -@Injectable({ - providedIn: 'root' -}) -export class KimiService { - private http = inject(HttpClient); - - getCharacterList(length: number) { - return this.http.get('/api/generate/character', { - params: { length } - }); - } -} diff --git a/src/app/shared/index.ts b/src/app/shared/index.ts new file mode 100644 index 0000000..8a55f25 --- /dev/null +++ b/src/app/shared/index.ts @@ -0,0 +1 @@ +export * from './services/generate.service'; diff --git a/src/app/shared/models/http.model.ts b/src/app/shared/models/http.model.ts new file mode 100644 index 0000000..7211e89 --- /dev/null +++ b/src/app/shared/models/http.model.ts @@ -0,0 +1,11 @@ +export enum ResStatus { + Success = 200, + AuthError = 400, + ServerError = 500, +} + +export interface Res{ + status: ResStatus; + msg:string; + data:T +} diff --git a/src/app/services/kimi.service.spec.ts b/src/app/shared/services/generate.service.spec.ts similarity index 51% rename from src/app/services/kimi.service.spec.ts rename to src/app/shared/services/generate.service.spec.ts index 75d1421..06edd8d 100644 --- a/src/app/services/kimi.service.spec.ts +++ b/src/app/shared/services/generate.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { KimiService } from './kimi.service'; +import { GenerateService } from './generate.service'; -describe('KimiService', () => { - let service: KimiService; +describe('GenerateService', () => { + let service: GenerateService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(KimiService); + service = TestBed.inject(GenerateService); }); it('should be created', () => { diff --git a/src/app/shared/services/generate.service.ts b/src/app/shared/services/generate.service.ts new file mode 100644 index 0000000..19e6b6a --- /dev/null +++ b/src/app/shared/services/generate.service.ts @@ -0,0 +1,51 @@ +import { HttpClient } from '@angular/common/http'; +import { inject, Injectable } from '@angular/core'; +import { map, Observable } from 'rxjs'; +import { Res, ResStatus } from '../models/http.model'; +import { BattleCharacter, Env, InitCharacter } from '@models'; + +@Injectable({ + providedIn: 'root' +}) +export class GenerateService { + private http = inject(HttpClient); + + getCharacterList(length: number):Observable { + return this.http.get>('/api/generate/character', { + params: { length } + }).pipe(map(res=>{ + if(res.status === ResStatus.Success){ + return res.data; + }else{ + return [] + } + })); + } + + getEnvList(length: number):Observable<{ envs: Env[]; galaxiesId: string }> { + return this.http.get>('/api/generate/env', { + params: { length } + }).pipe(map(res=>{ + if(res.status === ResStatus.Success){ + return res.data; + }else{ + return { + envs:[], + galaxiesId: '' + } + } + })); + } + + getEnemyList(length: number,level:number):Observable { + return this.http.get>('/api/generate/enemy', { + params: { length,level } + }).pipe(map(res=>{ + if(res.status === ResStatus.Success){ + return res.data; + }else{ + return [] + } + })); + } +} diff --git a/tsconfig.json b/tsconfig.json index 3eb02ff..b7d2a54 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -49,6 +49,9 @@ "@services": [ "app/services/index" ], + "@shared": [ + "app/shared/index" + ], "@storages/*": [ "app/storages/*" ],