优化:武将初始加载

This commit is contained in:
luying
2021-09-01 19:56:19 +08:00
parent 9d25fafbde
commit e572cb2fa5
15 changed files with 507 additions and 86 deletions
@@ -1,8 +1,11 @@
import { Application, ChannelService, FrontendSession, RemoterClass, HandlerService, } from 'pinus';
import { STATUS } from '../../../consts/statusCode';
import { resResult } from '../../../pubUtils/util';
import { Application, ChannelService, HandlerService, } from 'pinus';
// import { sendRolesMails } from '../../../services/mailService';
import { reloadResources } from '../../../pubUtils/data';
import { HeroUpdate } from '../../../db/Hero';
import { RoleUpdate } from '../../../db/Role';
import { SkinUpdate } from '../../../db/Skin';
import { getInitRoleInfo } from '../../../pubUtils/roleUtil';
import { DEFAULT_HEROES } from '../../../consts';
export default function (app: Application) {
new HandlerService(app, {});
return new RoleRemote(app);
@@ -13,13 +16,53 @@ export class RoleRemote {
constructor(private app: Application) {
this.app = app;
this.channelService = app.get('channelService');
this.setInitRole();
}
private channelService: ChannelService;
private initHeroes: Map<number, HeroUpdate> = new Map(); // hid => hero
private initRole: RoleUpdate = {};
private initSkins: Map<number, SkinUpdate> = new Map(); // hid => skin
public setInitRole() {
let result = getInitRoleInfo();
let { role, heroes, skins } = result;
for(let hero of heroes) {
this.initHeroes.set(hero.hid, hero);
}
for(let skin of skins) {
this.initSkins.set(skin.hid, skin);
}
this.initRole = role;
}
public getInitRoleInfos() {
return {
heroes: this.getInitHeroes(),
skins: this.getInitSkins(),
role: this.initRole
};
}
public getInitHeroes() {
let result: HeroUpdate[] = [];
for(let hid of DEFAULT_HEROES) {
result.push(this.initHeroes.get(hid));
}
return result;
}
public getInitSkins() {
let result: SkinUpdate[] = [];
for(let hid of DEFAULT_HEROES) {
result.push(this.initSkins.get(hid));
}
return result;
}
public getInitHeroById(hid: number) {
return this.initHeroes.get(hid)
}
// sendGmMailsToRoles(mails) {
// sendRolesMails(mails)
// }
/**
* 重载json资源