mirror of
https://github.com/motajs/template.git
synced 2026-05-02 12:23:13 +08:00
chore: 注释调整与接口微调
This commit is contained in:
parent
79d06c31df
commit
ebfe59b4f5
4
dev.md
4
dev.md
@ -47,6 +47,8 @@
|
|||||||
- 长文件可使用 `#region` 分段,可以写上 `#endretion` 允许折叠。
|
- 长文件可使用 `#region` 分段,可以写上 `#endretion` 允许折叠。
|
||||||
- TODO 使用 `// TODO:` 或 `// todo:` 格式。
|
- TODO 使用 `// TODO:` 或 `// todo:` 格式。
|
||||||
- 单行注释的双斜杠与注释内容之间添加一个空格,多行注释只允许出现 `jsDoc` 注释,如果需要多行非 `jsDoc` 注释,使用多个单行注释。
|
- 单行注释的双斜杠与注释内容之间添加一个空格,多行注释只允许出现 `jsDoc` 注释,如果需要多行非 `jsDoc` 注释,使用多个单行注释。
|
||||||
|
- 注释进行合理换行,考虑到中文字符较宽,建议 40-60 个字符进行换行。不允许在句中换行,必须在标点符号后换行。
|
||||||
|
- 单行注释结尾不添加句号,对于多行长注释,可以在结尾添加句号。
|
||||||
- 类型:
|
- 类型:
|
||||||
- 不允许出现非必要的 `any` 类型。
|
- 不允许出现非必要的 `any` 类型。
|
||||||
- 所有类的成员必须显式声明类型。
|
- 所有类的成员必须显式声明类型。
|
||||||
@ -54,7 +56,7 @@
|
|||||||
- 没用到的变量、方法使用下划线开头。
|
- 没用到的变量、方法使用下划线开头。
|
||||||
- 合理运用 `readonly` `protected` `private` 关键字。
|
- 合理运用 `readonly` `protected` `private` 关键字。
|
||||||
- 函数不建议使用过多可选参数,如果可选参数过多,可以考虑换用对象。
|
- 函数不建议使用过多可选参数,如果可选参数过多,可以考虑换用对象。
|
||||||
- 尽量少地使用 `as` 关键字进行类型断言,一般情况下不建议进行任何 `as` 类型断言。
|
- 尽量少地使用 `as` 关键字进行类型断言,一般情况下不建议进行任何 `as` 类型断言,除非必要。
|
||||||
- 其他要求:
|
- 其他要求:
|
||||||
- 严格遵循 `eslint` 配置,不允许出现 `eslint` 报错。
|
- 严格遵循 `eslint` 配置,不允许出现 `eslint` 报错。
|
||||||
- 尽量不使用 `?.` 运算符,一般建议仅在副作用函数调用(如 `this.obj?.func()`,`this.obj.func?.()`),或对象 `Required` 化(如 `{ value: obj?.value ?? 0 }`)中使用 `?.` 运算符。
|
- 尽量不使用 `?.` 运算符,一般建议仅在副作用函数调用(如 `this.obj?.func()`,`this.obj.func?.()`),或对象 `Required` 化(如 `{ value: obj?.value ?? 0 }`)中使用 `?.` 运算符。
|
||||||
|
|||||||
@ -22,40 +22,56 @@ import { MapLocIndexer } from './utils';
|
|||||||
import { IReadonlyHeroAttribute } from '../hero';
|
import { IReadonlyHeroAttribute } from '../hero';
|
||||||
|
|
||||||
export class EnemyContext<TAttr, THero> implements IEnemyContext<TAttr, THero> {
|
export class EnemyContext<TAttr, THero> implements IEnemyContext<TAttr, THero> {
|
||||||
|
/** 坐标索引 -> 怪物视图 */
|
||||||
private readonly enemyViewMap: Map<number, EnemyView<TAttr>> = new Map();
|
private readonly enemyViewMap: Map<number, EnemyView<TAttr>> = new Map();
|
||||||
|
/** 坐标索引 -> 计算前怪物对象 */
|
||||||
private readonly enemyMap: Map<number, IEnemy<TAttr>> = new Map();
|
private readonly enemyMap: Map<number, IEnemy<TAttr>> = new Map();
|
||||||
|
/** 怪物视图 -> 坐标索引 */
|
||||||
private readonly locatorViewMap: Map<IEnemyView<TAttr>, number> = new Map();
|
private readonly locatorViewMap: Map<IEnemyView<TAttr>, number> = new Map();
|
||||||
|
/** 计算前怪物对象 -> 坐标索引 */
|
||||||
private readonly locatorEnemyMap: Map<IEnemy<TAttr>, number> = new Map();
|
private readonly locatorEnemyMap: Map<IEnemy<TAttr>, number> = new Map();
|
||||||
|
/** 计算后怪物对象 -> 怪物视图 */
|
||||||
private readonly computedToView: Map<
|
private readonly computedToView: Map<
|
||||||
IReadonlyEnemy<TAttr>,
|
IReadonlyEnemy<TAttr>,
|
||||||
EnemyView<TAttr>
|
EnemyView<TAttr>
|
||||||
> = new Map();
|
> = new Map();
|
||||||
|
|
||||||
|
/** 当前已注册的光环转换器 */
|
||||||
private readonly auraConverter: Set<IAuraConverter<TAttr, THero>> =
|
private readonly auraConverter: Set<IAuraConverter<TAttr, THero>> =
|
||||||
new Set();
|
new Set();
|
||||||
|
/** 光环转换器是否启用 */
|
||||||
private readonly converterStatus: Map<
|
private readonly converterStatus: Map<
|
||||||
IAuraConverter<TAttr, THero>,
|
IAuraConverter<TAttr, THero>,
|
||||||
boolean
|
boolean
|
||||||
> = new Map();
|
> = new Map();
|
||||||
|
/** 所有已被转换的光环 */
|
||||||
private readonly convertedAura: Map<ISpecial<any>, IAuraView<TAttr>> =
|
private readonly convertedAura: Map<ISpecial<any>, IAuraView<TAttr>> =
|
||||||
new Map();
|
new Map();
|
||||||
|
|
||||||
|
/** 普通查询效果注册,特殊属性 -> 此特殊属性的查询效果列表,按照优先级从高到低排序 */
|
||||||
private readonly commonQueryMap: Map<
|
private readonly commonQueryMap: Map<
|
||||||
number,
|
number,
|
||||||
IEnemyCommonQueryEffect<TAttr, THero>[]
|
IEnemyCommonQueryEffect<TAttr, THero>[]
|
||||||
> = new Map();
|
> = new Map();
|
||||||
|
|
||||||
|
/** 特殊查询效果注册,特殊属性 -> 此特殊属性的特殊查询效果列表,按照优先级从高到低排序 */
|
||||||
private readonly specialQueryEffects: Map<
|
private readonly specialQueryEffects: Map<
|
||||||
number,
|
number,
|
||||||
IEnemySpecialQueryEffect<TAttr, THero>[]
|
IEnemySpecialQueryEffect<TAttr, THero>[]
|
||||||
> = new Map();
|
> = new Map();
|
||||||
|
|
||||||
|
/** 最终效果列表,按照优先级从高到低排列 */
|
||||||
private readonly finalEffects: IEnemyFinalEffect<TAttr, THero>[] = [];
|
private readonly finalEffects: IEnemyFinalEffect<TAttr, THero>[] = [];
|
||||||
|
/** 添加的无来源全局光环列表 */
|
||||||
private readonly globalAuraList: Set<IAuraView<TAttr>> = new Set();
|
private readonly globalAuraList: Set<IAuraView<TAttr>> = new Set();
|
||||||
|
/** 排序后的光环视图,视图优先级 -> 光环视图列表 */
|
||||||
private readonly sortedAura: Map<number, Set<IAuraView<TAttr>>> = new Map();
|
private readonly sortedAura: Map<number, Set<IAuraView<TAttr>>> = new Map();
|
||||||
|
|
||||||
|
/** 当怪物更新后,需要对上下文进行全量刷新的怪物列表 */
|
||||||
private readonly needTotallyRefresh: Set<IEnemyView<TAttr>> = new Set();
|
private readonly needTotallyRefresh: Set<IEnemyView<TAttr>> = new Set();
|
||||||
|
/** 所有实际查询了上下文的常规查询效果,这些怪物需要在上下文或其他怪物刷新时一并刷新 */
|
||||||
private readonly requestedCommonContext: Set<IEnemyView<TAttr>> = new Set();
|
private readonly requestedCommonContext: Set<IEnemyView<TAttr>> = new Set();
|
||||||
|
/** 所有需要被标记为脏的怪物 */
|
||||||
private readonly dirtyEnemy: Set<IEnemyView<TAttr>> = new Set();
|
private readonly dirtyEnemy: Set<IEnemyView<TAttr>> = new Set();
|
||||||
|
|
||||||
/** 当前绑定的勇士属性对象 */
|
/** 当前绑定的勇士属性对象 */
|
||||||
|
|||||||
@ -8,7 +8,8 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export class Enemy<TAttr> implements IEnemy<TAttr> {
|
export class Enemy<TAttr> implements IEnemy<TAttr> {
|
||||||
readonly specials: Set<ISpecial<any>> = new Set();
|
/** 怪物身上的特殊属性列表 */
|
||||||
|
private readonly specials: Set<ISpecial<any>> = new Set();
|
||||||
/** code -> ISpecial 映射,用于快速查找 */
|
/** code -> ISpecial 映射,用于快速查找 */
|
||||||
private readonly specialMap: Map<number, ISpecial<any>> = new Map();
|
private readonly specialMap: Map<number, ISpecial<any>> = new Map();
|
||||||
|
|
||||||
@ -89,7 +90,8 @@ export class Enemy<TAttr> implements IEnemy<TAttr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EnemyView<TAttr> implements IEnemyView<TAttr> {
|
export class EnemyView<TAttr> implements IEnemyView<TAttr> {
|
||||||
private computedEnemy: IEnemy<TAttr>;
|
/** 计算后怪物 */
|
||||||
|
private readonly computedEnemy: IEnemy<TAttr>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly baseEnemy: IEnemy<TAttr>,
|
readonly baseEnemy: IEnemy<TAttr>,
|
||||||
|
|||||||
@ -90,6 +90,14 @@ export class HeroAttribute<THero> implements IHeroAttribute<THero> {
|
|||||||
this.markDirty(name);
|
this.markDirty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addBaseAttribute<K extends keyof SelectType<THero, number>>(
|
||||||
|
name: K,
|
||||||
|
value: number
|
||||||
|
): void {
|
||||||
|
(this.attribute[name] as number) += value;
|
||||||
|
this.markDirty(name);
|
||||||
|
}
|
||||||
|
|
||||||
addModifier<K extends keyof THero>(
|
addModifier<K extends keyof THero>(
|
||||||
name: K,
|
name: K,
|
||||||
modifier: IHeroModifier<THero[K], unknown>
|
modifier: IHeroModifier<THero[K], unknown>
|
||||||
|
|||||||
@ -87,6 +87,16 @@ export interface IHeroAttribute<THero> extends IReadonlyHeroAttribute<THero> {
|
|||||||
*/
|
*/
|
||||||
setBaseAttribute<K extends keyof THero>(name: K, value: THero[K]): void;
|
setBaseAttribute<K extends keyof THero>(name: K, value: THero[K]): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增减勇士属性
|
||||||
|
* @param name 属性名称
|
||||||
|
* @param value 属性增减值
|
||||||
|
*/
|
||||||
|
addBaseAttribute<K extends SelectKey<THero, number>>(
|
||||||
|
name: K,
|
||||||
|
value: number
|
||||||
|
): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向一个属性添加属性修饰器
|
* 向一个属性添加属性修饰器
|
||||||
* @param name 属性名称
|
* @param name 属性名称
|
||||||
|
|||||||
@ -68,8 +68,8 @@ export class CoreState implements ICoreState {
|
|||||||
// 怪物上下文初始化
|
// 怪物上下文初始化
|
||||||
const enemyContext = new EnemyContext<IEnemyAttr, IHeroAttr>();
|
const enemyContext = new EnemyContext<IEnemyAttr, IHeroAttr>();
|
||||||
const damageSystem = new DamageSystem(enemyContext);
|
const damageSystem = new DamageSystem(enemyContext);
|
||||||
damageSystem.useCalculator(new MainDamageCalculator());
|
|
||||||
const mapDamage = new MapDamage(enemyContext);
|
const mapDamage = new MapDamage(enemyContext);
|
||||||
|
damageSystem.useCalculator(new MainDamageCalculator());
|
||||||
mapDamage.useConverter(new MainMapDamageConverter());
|
mapDamage.useConverter(new MainMapDamageConverter());
|
||||||
mapDamage.useReducer(new MainMapDamageReducer());
|
mapDamage.useReducer(new MainMapDamageReducer());
|
||||||
enemyContext.attachDamageSystem(damageSystem);
|
enemyContext.attachDamageSystem(damageSystem);
|
||||||
|
|||||||
@ -2,12 +2,14 @@ import { loading } from '@user/data-base';
|
|||||||
import { CoreState } from './core';
|
import { CoreState } from './core';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import { FaceDirection } from './common';
|
import { FaceDirection } from './common';
|
||||||
|
import { ICoreState } from './types';
|
||||||
|
import { TILE_HEIGHT, TILE_WIDTH } from './shared';
|
||||||
|
|
||||||
function createCoreState() {
|
function createCoreState(state: ICoreState) {
|
||||||
//#region 地图部分
|
//#region 地图部分
|
||||||
|
|
||||||
const width = core._WIDTH_;
|
const width = TILE_WIDTH;
|
||||||
const height = core._HEIGHT_;
|
const height = TILE_HEIGHT;
|
||||||
const bg = state.layer.addLayer(width, height);
|
const bg = state.layer.addLayer(width, height);
|
||||||
const bg2 = state.layer.addLayer(width, height);
|
const bg2 = state.layer.addLayer(width, height);
|
||||||
const event = state.layer.addLayer(width, height);
|
const event = state.layer.addLayer(width, height);
|
||||||
@ -56,7 +58,7 @@ function createCoreState() {
|
|||||||
export function create() {
|
export function create() {
|
||||||
loading.once('loaded', () => {
|
loading.once('loaded', () => {
|
||||||
// 加载后初始化全局状态
|
// 加载后初始化全局状态
|
||||||
createCoreState();
|
createCoreState(state);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
prompt.md
Normal file
16
prompt.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 必须规则
|
||||||
|
|
||||||
|
以下规则必须时刻遵守,任何情况下都不允许违反。
|
||||||
|
|
||||||
|
1. 将我已经写好的代码视为绝对正确,除非我明确允许,否则不允许修改,哪怕因为接口变化或其他原因导致其中出现类型错误。如果你认为我的代码中存在逻辑错误,应当在对话中提出,而不是直接修改。
|
||||||
|
2. 我做的任何代码修改都是有原因的,如果我在两次对话期间新增、删除或修改了部分代码,不要将其恢复。
|
||||||
|
3. 时刻以目的进行驱动,想明白我为什么要这么设计接口,这个接口设计的目的是什么,而不是简单地以实现接口为目标。
|
||||||
|
4. 如果思考或实现时有任何问题,应该立刻提问,而不是按照自己的想法去写。
|
||||||
|
|
||||||
|
# 建议规则
|
||||||
|
|
||||||
|
以下规则为建议性,尽量遵守,但是一些特殊情况也可以违反,由你自己把控。
|
||||||
|
|
||||||
|
1. 我有时会在对话中给你提出实现建议,你应该对建议内容进行合理的参考,合理运用建议内容,一定注意不要滥用。
|
||||||
|
2. 如果实现与类型标注有冲突,应当以类型标注(一般是 `types.ts`)中的内容为参考来源。
|
||||||
|
3. 如果你认为类型标注中的接口设计有问题,或在实现中发现其缺少某些接口,应该向我提问是否添加,我同意后方可添加。
|
||||||
Loading…
Reference in New Issue
Block a user