Skip to content

Commit

Permalink
feat(运行时): 新增上次保存时间显示和RuntimeService中时间处理优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Encaik committed Sep 28, 2024
1 parent e7ef630 commit d917574
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/app/layouts/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
<nz-descriptions-item nzTitle="天时"></nz-descriptions-item>
</nz-descriptions>
</div>
<div class="w-full sm:w-1/4 flex justify-end gap-2">
<button nz-button (click)="onSaveClick()">保存</button>
<button nz-button (click)="onDeleteClick()">删档</button>
<div class="w-full sm:w-1/4 flex flex-col gap-2 justify-center">
<div> 上次保存时间:{{ lastSaveTime?.toLocaleString() || '未保存过游戏' }} </div>
<div class="flex gap-2">
<button nz-button (click)="onSaveClick()">保存</button>
<button nz-button (click)="onDeleteClick()">删档</button>
</div>
</div>
</div>
7 changes: 6 additions & 1 deletion src/app/layouts/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, inject } from '@angular/core';
import { LevelMapViewComponent } from '@components/level-map-view/level-map-view.component';
import { EventType, SystemEventOperate } from '@models';
import { TimeFormatPipe } from '@pipes/time-format.pipe';
import { EnvService, CharacterService, TimeTickService, EventService } from '@services';
import { EnvService, CharacterService, TimeTickService, EventService, RuntimeService } from '@services';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { NzGridModule } from 'ng-zorro-antd/grid';
Expand All @@ -22,6 +22,11 @@ export class HeaderComponent {
private timeTickSrv = inject(TimeTickService);
private event = inject(EventService);
private notice = inject(NzNotificationService);
private rtSrv = inject(RuntimeService);

get lastSaveTime() {
return this.rtSrv.lastSaveTime;
}

get timeTick() {
return this.timeTickSrv.getTimeTick();
Expand Down
1 change: 1 addition & 0 deletions src/app/models/runtime.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Env } from './env.model';
import { BagItem } from './item.model';

export interface StorageData {
lastSaveTime?: number;
timeTickData: number; // 时间刻
characterData: Character; // 角色信息
envData: Env; // 环境信息
Expand Down
14 changes: 9 additions & 5 deletions src/app/services/runtime.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventRes, StorageData, SystemEventOperate, TASKS, Event } from '@models
import { BackpackService, CharacterService, EnvService, TaskService, TimeTickService } from '@services';
import { StatisticsService } from '@storages/statistics.service';
import * as CryptoJS from 'crypto-js';
import { Observable, of, timer } from 'rxjs';
import { Observable, of } from 'rxjs';

const WANJIE_TOKEN = 'wanjie_data';

Expand All @@ -18,6 +18,7 @@ export class RuntimeService {
private timeTickSrv = inject(TimeTickService);
private statisticsSrv = inject(StatisticsService);

lastSaveTime: Date | undefined;
isInit: boolean = false;

eventDetail(event: Event): Observable<EventRes> {
Expand All @@ -42,6 +43,9 @@ export class RuntimeService {
if (storageData.statisticsData) {
this.statisticsSrv.setStatistics(storageData.statisticsData);
}
if (storageData.lastSaveTime) {
this.lastSaveTime = new Date(storageData.lastSaveTime);
}
this.isInit = true;
}

Expand All @@ -52,12 +56,12 @@ export class RuntimeService {
const taskData = this.taskSrv.getCurrentTask()?.id;
const timeTickData = this.timeTickSrv.getTimeTick();
const statisticsData = this.statisticsSrv.getStatistics();
const time = new Date();
this.lastSaveTime = new Date();
localStorage.setItem(
WANJIE_TOKEN,
CryptoJS.AES.encrypt(
JSON.stringify({
time: time.getTime(),
lastSaveTime: this.lastSaveTime.getTime(),
timeTickData,
characterData,
envData,
Expand All @@ -70,8 +74,8 @@ export class RuntimeService {
);
return of({
status: 'success',
msg: `您的数据已保存,本次保存时间为${time.toLocaleString()}`,
data: time
msg: `您的数据已保存,本次保存时间为${this.lastSaveTime.toLocaleString()}`,
data: this.lastSaveTime
});
}

Expand Down

1 comment on commit d917574

@vercel
Copy link

@vercel vercel bot commented on d917574 Sep 28, 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-git-main-encaiks-projects.vercel.app
wanjie-encaiks-projects.vercel.app

Please sign in to comment.