feat: 获取天气功能 & 优化类型

This commit is contained in:
unanmed 2024-11-12 15:58:56 +08:00
parent 760ddd6b03
commit e7b4d4cd74
4 changed files with 28 additions and 10 deletions

View File

@ -15,7 +15,7 @@ export type RenderItemPosition = 'absolute' | 'static';
export interface IRenderUpdater {
/**
*
* @param item
* @param item
*/
update(item?: RenderItem): void;
}
@ -333,7 +333,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
this.anchorY = y;
}
update(item?: RenderItem<any>): void {
update(item: RenderItem<any> = this): void {
if (this.needUpdate) return;
this.needUpdate = true;
this.cacheDirty = true;

View File

@ -27,7 +27,7 @@ export class MotaRenderer extends Container {
MotaRenderer.list.set(id, this);
}
update(item?: RenderItem) {
update(item: RenderItem = this) {
if (this.needUpdate) return;
this.needUpdate = true;
this.requestRenderFrame(() => {
@ -36,7 +36,7 @@ export class MotaRenderer extends Container {
});
}
protected refresh(item?: RenderItem): void {
protected refresh(item: RenderItem = this): void {
this.emit('beforeUpdate', item);
this.target.clear();
this.renderContent(this.target, Transform.identity);
@ -48,7 +48,7 @@ export class MotaRenderer extends Container {
* @param id id
* @returns
*/
getElementById(id: string): RenderItem | undefined {
getElementById(id: string): RenderItem | null {
const map = RenderItem.itemMap;
const item = map.get(id);
if (item) return item;
@ -56,18 +56,19 @@ export class MotaRenderer extends Container {
const item = this.searchElement(this, id);
if (item) {
map.set(id, item);
return item;
}
return item;
}
}
private searchElement(ele: Container, id: string): RenderItem | undefined {
private searchElement(ele: Container, id: string): RenderItem | null {
for (const child of ele.children) {
if (child.id === id) return child;
if (child instanceof Container) {
return this.searchElement(child, id);
}
}
return null;
}
/**

View File

@ -18,9 +18,9 @@ export interface IWeather {
deactivate(): void;
}
interface Weather {
interface Weather<T extends IWeather = IWeather> {
id: string;
new (level?: number): IWeather;
new (level?: number): T;
}
export class WeatherController {
@ -37,7 +37,15 @@ export class WeatherController {
};
/**
*
*
* @param weather
*/
getWeather<T extends IWeather>(weather: Weather<T>): T | null {
return ([...this.active].find(v => v instanceof weather) as T) ?? null;
}
/**
*
* @param id id
* @param level
* @returns

View File

@ -37,6 +37,15 @@ export abstract class BarrageBoss {
this.ticker.add(this.tick);
}
/**
*
*/
end() {
if (this.ticker.funcs.has(this.tick)) {
this.ticker.remove(this.tick);
}
}
/**
*
*/