Skip to content

Commit

Permalink
refactor(kimi): 移除KimiService,使用GenerateService
Browse files Browse the repository at this point in the history
  • Loading branch information
Encaik committed Sep 29, 2024
1 parent 16c3b34 commit 26d358b
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 86 deletions.
7 changes: 1 addition & 6 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
108 changes: 55 additions & 53 deletions src/app/components/init-modal/init-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,59 @@
<nz-step nzTitle="选择世界"></nz-step>
</nz-steps>

<div class="my-4">
@if (current === 0) {
<div class="h-full grid grid-cols-2 md:grid-cols-4 gap-4 overflow-auto border rounded p-4 bg-slate-100">
@for (item of characters; track $index) {
<div
[ngClass]="[item.baseInfo.gender === '男' ? ' border-blue-300 bg-blue-100' : ' border-red-300 bg-red-100']"
class="flex flex-col justify-center items-center text-center p-4 rounded cursor-pointer hover:shadow-lg w-full border"
(click)="onCharacterClick(item)"
>
<nz-descriptions [nzColumn]="{ xxl: 2, xl: 2, lg: 2, md: 2, sm: 2, xs: 1 }">
<nz-descriptions-item nzTitle="姓名" [nzSpan]="2">{{ item.baseInfo.name }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="性别">{{ item.baseInfo.gender }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="年龄">{{ item.baseInfo.age }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="天赋" [nzSpan]="2">
@for (item of item.baseInfo.talent; track $index) {
<nz-tag>{{ item.name }}</nz-tag>
}
</nz-descriptions-item>
<nz-descriptions-item nzTitle="生命">{{ item.innateInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ item.innateInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ item.innateInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ item.innateInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ item.innateInfo.speed }}</nz-descriptions-item>
</nz-descriptions>
</div>
}
</div>
}
@if (current === 1) {
<div class="h-full grid grid-cols-1 sm:grid-cols-2 gap-4 overflow-auto border rounded p-4 bg-slate-100">
@for (item of envs; track $index) {
<div
class="flex flex-col justify-center items-center text-center p-4 rounded cursor-pointer hover:shadow-lg w-full bg-white"
(click)="onEnvClick(item)"
>
<nz-descriptions [nzColumn]="1">
<nz-descriptions-item nzTitle="名称">{{ item.name }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="修炼速度">{{ item.weight }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="最大经验">{{ item.maxExp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="世界类型">{{ envSrv.getEnvType(item.type) }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="等级体系">
<app-level-map-view [levelMap]="item.levelMap" />
</nz-descriptions-item>
<nz-descriptions-item nzTitle="功法体系">
@for (item of item.methodSuits; track $index) {
<nz-tag>{{ item.name }}</nz-tag>
}
</nz-descriptions-item>
</nz-descriptions>
</div>
}
</div>
}
<div class="my-4 relative">
<nz-spin [nzSpinning]="!characters.length || !envs.length">
@if (current === 0) {
<div class="h-full grid grid-cols-2 md:grid-cols-4 gap-4 overflow-auto border rounded p-4 bg-slate-100">
@for (item of characters; track $index) {
<div
[ngClass]="[item.baseInfo.gender === '男' ? ' border-blue-300 bg-blue-100' : ' border-red-300 bg-red-100']"
class="flex flex-col justify-center items-center text-center p-4 rounded cursor-pointer hover:shadow-lg w-full border"
(click)="onCharacterClick(item)"
>
<nz-descriptions [nzColumn]="{ xxl: 2, xl: 2, lg: 2, md: 2, sm: 2, xs: 1 }">
<nz-descriptions-item nzTitle="姓名" [nzSpan]="2">{{ item.baseInfo.name }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="性别">{{ item.baseInfo.gender }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="年龄">{{ item.baseInfo.age }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="天赋" [nzSpan]="2">
@for (item of item.baseInfo.talent; track $index) {
<nz-tag>{{ item.name }}</nz-tag>
}
</nz-descriptions-item>
<nz-descriptions-item nzTitle="生命">{{ item.innateInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ item.innateInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ item.innateInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ item.innateInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ item.innateInfo.speed }}</nz-descriptions-item>
</nz-descriptions>
</div>
}
</div>
}
@if (current === 1) {
<div class="h-full grid grid-cols-1 sm:grid-cols-2 gap-4 overflow-auto border rounded p-4 bg-slate-100">
@for (item of envs; track $index) {
<div
class="flex flex-col justify-center items-center text-center p-4 rounded cursor-pointer hover:shadow-lg w-full bg-white"
(click)="onEnvClick(item)"
>
<nz-descriptions [nzColumn]="1">
<nz-descriptions-item nzTitle="名称">{{ item.name }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="修炼速度">{{ item.weight }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="最大经验">{{ item.maxExp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="世界类型">{{ envSrv.getEnvType(item.type) }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="等级体系">
<app-level-map-view [levelMap]="item.levelMap" />
</nz-descriptions-item>
<nz-descriptions-item nzTitle="功法体系">
@for (item of item.methodSuits; track $index) {
<nz-tag>{{ item.name }}</nz-tag>
}
</nz-descriptions-item>
</nz-descriptions>
</div>
}
</div>
}
</nz-spin>
</div>
25 changes: 19 additions & 6 deletions src/app/components/init-modal/init-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/app/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'; // 任务管理
Expand Down
15 changes: 0 additions & 15 deletions src/app/services/kimi.service.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/app/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './services/generate.service';
11 changes: 11 additions & 0 deletions src/app/shared/models/http.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum ResStatus {
Success = 200,
AuthError = 400,
ServerError = 500,
}

export interface Res<T=any>{
status: ResStatus;
msg:string;
data:T
}
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
51 changes: 51 additions & 0 deletions src/app/shared/services/generate.service.ts
Original file line number Diff line number Diff line change
@@ -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<InitCharacter[]> {
return this.http.get<Res<InitCharacter[]>>('/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<Res<{ envs: Env[]; galaxiesId: string }>>('/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<BattleCharacter[]> {
return this.http.get<Res<BattleCharacter[]>>('/api/generate/enemy', {
params: { length,level }
}).pipe(map(res=>{
if(res.status === ResStatus.Success){
return res.data;
}else{
return []
}
}));
}
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"@services": [
"app/services/index"
],
"@shared": [
"app/shared/index"
],
"@storages/*": [
"app/storages/*"
],
Expand Down

1 comment on commit 26d358b

@vercel
Copy link

@vercel vercel bot commented on 26d358b Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wanjie – ./

wanjie.vercel.app
wanjie-encaiks-projects.vercel.app
wanjie-git-main-encaiks-projects.vercel.app

Please sign in to comment.