mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 15:09:26 +08:00
feat: 获取天气功能 & 优化类型
This commit is contained in:
parent
760ddd6b03
commit
e7b4d4cd74
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 天气实例,可以操作天气的效果,也可以用来删除
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 摧毁传入的弹幕
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user