refactor: Range 接口重构

This commit is contained in:
unanmed 2026-04-15 15:07:17 +08:00
parent a24911400f
commit 4c0960fff7
5 changed files with 30 additions and 34 deletions

View File

@ -32,11 +32,11 @@ export class CommonAuraConverter implements IAuraConverter<IEnemyAttributes> {
}
convert(
special: ISpecial<any>,
special: ISpecial<IHaloValue>,
enemy: IReadonlyEnemy<IEnemyAttributes>,
locator: ITileLocator
): CommonAura {
return new CommonAura(enemy, special as ISpecial<IHaloValue>, locator);
return new CommonAura(enemy, special, locator);
}
}
@ -134,17 +134,12 @@ export class GuardAuraConverter implements IAuraConverter<IEnemyAttributes> {
}
convert(
special: ISpecial<any>,
special: ISpecial<void>,
enemy: IReadonlyEnemy<IEnemyAttributes>,
locator: ITileLocator,
context: IEnemyContext<IEnemyAttributes>
): GuardAura {
return new GuardAura(
context,
enemy,
special as ISpecial<void>,
locator
);
return new GuardAura(context, enemy, special, locator);
}
}

View File

@ -1,4 +1,4 @@
export * from './aura';
export * from './damage';
export * from './mapSpecials';
export * from './mapDamage';
export * from './special';

View File

@ -74,20 +74,6 @@ abstract class BaseMapDamageView<T> implements IMapDamageView<T> {
}
};
}
/**
*
* @param x
* @param y
*/
protected isInBounds(x: number, y: number): boolean {
return (
x >= 0 &&
y >= 0 &&
x < this.context.width &&
y < this.context.height
);
}
}
export class ZoneDamageView extends BaseMapDamageView<
@ -232,7 +218,9 @@ export class BetweenDamageView extends BaseMapDamageView<IManhattanRangeParam> {
const otherX = locator.x + deltaX;
const otherY = locator.y + deltaY;
if (!this.isInBounds(otherX, otherY)) {
const range = this.getRange();
range.bindHost(this.context);
if (!range.inBound(otherX, otherY)) {
return null;
}

View File

@ -20,7 +20,7 @@ export abstract class BaseRange<T> implements IRange<T> {
* @param x
* @param y
*/
protected isInBounds(x: number, y: number) {
inBound(x: number, y: number) {
const { width, height } = this.host;
return x >= 0 && y >= 0 && x < width && y < height;
}
@ -29,7 +29,7 @@ export abstract class BaseRange<T> implements IRange<T> {
* 宿
* @param index
*/
protected isValidIndex(index: number) {
inBoundIndex(index: number) {
const { width, height } = this.host;
return index >= 0 && index < width * height;
}
@ -96,7 +96,7 @@ export class RectRange extends BaseRange<IRectRangeParam> {
const ex = Math.max(param.x, param.x + param.w);
const ey = Math.max(param.y, param.y + param.h);
return this.isInBounds(x, y) && x >= sx && y >= sy && x < ex && y < ey;
return this.inBound(x, y) && x >= sx && y >= sy && x < ex && y < ey;
}
}
@ -131,7 +131,7 @@ export class ManhattanRange extends BaseRange<IManhattanRangeParam> {
param: Readonly<IManhattanRangeParam>
): boolean {
return (
this.isInBounds(x, y) &&
this.inBound(x, y) &&
Math.abs(x - param.cx) + Math.abs(y - param.cy) <= param.radius
);
}
@ -193,7 +193,7 @@ export class RayRange extends BaseRange<IRayRangeParam> {
const { width } = this.host;
const yielded = new Set<number>();
if (this.isInBounds(param.cx, param.cy)) {
if (this.inBound(param.cx, param.cy)) {
const centerIndex = param.cy * width + param.cx;
yielded.add(centerIndex);
yield centerIndex;
@ -206,7 +206,7 @@ export class RayRange extends BaseRange<IRayRangeParam> {
let x = param.cx + direction.x;
let y = param.cy + direction.y;
while (this.isInBounds(x, y)) {
while (this.inBound(x, y)) {
const index = y * width + x;
if (!yielded.has(index)) {
yielded.add(index);
@ -219,7 +219,7 @@ export class RayRange extends BaseRange<IRayRangeParam> {
}
inRange(x: number, y: number, param: Readonly<IRayRangeParam>): boolean {
if (!this.isInBounds(x, y)) {
if (!this.inBound(x, y)) {
return false;
}
@ -263,11 +263,11 @@ export class FullRange extends BaseRange<void> {
}
inRange(x: number, y: number): boolean {
return this.isInBounds(x, y);
return this.inBound(x, y);
}
inRangeIndex(index: number): boolean {
return this.isValidIndex(index);
return this.inBoundIndex(index);
}
}

View File

@ -87,6 +87,19 @@ export interface IRange<T> {
* @param param
*/
inRangeIndex(index: number, param: Readonly<T>): boolean;
/**
* 宿
* @param x
* @param y
*/
inBound(x: number, y: number): boolean;
/**
* 宿
* @param index
*/
inBoundIndex(index: number): boolean;
}
export interface IRectRangeParam {