captainbattle 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,40 @@
1
- /**
2
- * cc —— Cocos Creator 引擎 API 在 Node 侧的替身实现
3
- *
4
- * 为什么需要它:core/ 是从 Cocos Creator 工程里抽出的战斗逻辑,源码里到处写
5
- * `import { ... } from "cc"`。Node 里没有引擎,这层替身把用到的 API 按原语义补齐,
6
- * 让战斗逻辑能脱离引擎跑(离线复算战斗、和回放对 hash、跑单测)。
7
- *
8
- * 三条原则:
9
- * 1. 逻辑侧真实现。log/warn/error、js、math、director + Scheduler 是全真的,
10
- * Node 下和引擎行为一致,拿到就能用。
11
- * 2. 引擎侧不撒谎。Node/Vec3/资源这些只做到"能构造、不崩、语义可预期";
12
- * 没实现的 API 一律不导出——用到了在编译期就报错,而不是运行期悄悄给 undefined。
13
- * 3. 零依赖。只用 Node 自带能力;`node:fs` 在真要读盘时才动态 import,
14
- * 保证 `import "cc"` 本身在任何宿主里都不会有副作用。
15
- *
16
- * 只覆盖本项目实际用到的子集,不是引擎的完整实现。以后补 API 请照引擎原语义写,
17
- * 别按调用点的巧合行为写。
18
- *
19
- * 放在单文件里是有意的:编译产物是 ESM,一旦拆成多个文件,相对 import 就得带
20
- * `.js` 后缀 Node 才解析得了;这里没有相对 import,省掉这个坑。
21
- */
1
+ export const __esModule: boolean;
2
+ export const js: {};
3
+ export const math: {};
4
+ export const director: Director;
5
+ export namespace _decorator {
6
+ function ccclass(nameOrTarget: any): (target: any) => any;
7
+ function property(...args: any[]): (target: any, propertyKey: any) => void;
8
+ function executeInEditMode(target: any): any;
9
+ function requireComponent(_type: any): (target: any) => any;
10
+ function executionOrder(_order: any): (target: any) => any;
11
+ function disallowMultiple(target: any): any;
12
+ function allowMultiple(target: any): any;
13
+ function menu(_path: any): (target: any) => any;
14
+ function help(_url: any): (target: any) => any;
15
+ function type(_type: any): (target: any, _key: any) => any;
16
+ function integer(target: any, _key: any): any;
17
+ function float(target: any, _key: any): any;
18
+ function boolean(target: any, _key: any): any;
19
+ function string(target: any, _key: any): any;
20
+ function serializable(target: any, _key: any): any;
21
+ function editable(target: any, _key: any): any;
22
+ function override(target: any, _key: any): any;
23
+ function visible(target: any, _key: any): any;
24
+ function displayName(_name: any): (target: any, _key: any) => any;
25
+ function tooltip(_text: any): (target: any, _key: any) => any;
26
+ function range(_min: any, _max: any, _step: any): (target: any, _key: any) => any;
27
+ function min(_value: any): (target: any, _key: any) => any;
28
+ function max(_value: any): (target: any, _key: any) => any;
29
+ function slide(_value: any): (target: any, _key: any) => any;
30
+ function group(_value: any): (target: any, _key: any) => any;
31
+ function notify(_fn: any): (target: any, _key: any) => any;
32
+ }
33
+ export const assetManager: AssetManager;
34
+ export const resources: any;
22
35
  export function log(...args: any[]): void;
23
36
  export function warn(...args: any[]): void;
24
37
  export function error(...args: any[]): void;
25
- export const js: any;
26
- export const math: any;
27
38
  /** 引擎的 EventTarget。Node / director 都靠它做 on/off/emit */
28
39
  export class EventTarget {
29
40
  _listeners: any;
@@ -54,7 +65,32 @@ export class Scheduler {
54
65
  resume(): void;
55
66
  isPaused(): boolean;
56
67
  }
57
- export const director: Director;
68
+ /** 引擎的全局单例 director */
69
+ declare class Director extends EventTarget {
70
+ static EVENT_BEFORE_UPDATE: string;
71
+ static EVENT_AFTER_UPDATE: string;
72
+ _scheduler: Scheduler;
73
+ _deltaTime: number;
74
+ _totalTime: number;
75
+ _totalFrames: number;
76
+ _paused: boolean;
77
+ getScheduler(): Scheduler;
78
+ getDeltaTime(): number;
79
+ getTotalTime(): number;
80
+ getTotalFrames(): number;
81
+ isPaused(): boolean;
82
+ pause(): void;
83
+ resume(): void;
84
+ /**
85
+ * 非 cc API。
86
+ * 引擎里时间由主循环推进,Node 下没有主循环,所以开这个口子让宿主
87
+ * (战斗模拟的驱动方)手动推帧。
88
+ *
89
+ * dt 不乘 timeScale:引擎里 timeScale 影响的是派发给组件的 dt,由主循环负责,
90
+ * 这里保持原样传入,免得和 core 自己的 Time.ts 重复缩放。
91
+ */
92
+ tick(dt: any): void;
93
+ }
58
94
  export class CCInteger {
59
95
  constructor(value: any);
60
96
  value: any;
@@ -71,34 +107,6 @@ export class CCString {
71
107
  constructor(value: any);
72
108
  value: any;
73
109
  }
74
- export namespace _decorator {
75
- function ccclass(nameOrTarget: any): (target: any) => any;
76
- function property(...args: any[]): (target: any, propertyKey: any) => void;
77
- function executeInEditMode(target: any): any;
78
- function requireComponent(_type: any): (target: any) => any;
79
- function executionOrder(_order: any): (target: any) => any;
80
- function disallowMultiple(target: any): any;
81
- function allowMultiple(target: any): any;
82
- function menu(_path: any): (target: any) => any;
83
- function help(_url: any): (target: any) => any;
84
- function type(_type: any): (target: any, _key: any) => any;
85
- function integer(target: any, _key: any): any;
86
- function float(target: any, _key: any): any;
87
- function boolean(target: any, _key: any): any;
88
- function string(target: any, _key: any): any;
89
- function serializable(target: any, _key: any): any;
90
- function editable(target: any, _key: any): any;
91
- function override(target: any, _key: any): any;
92
- function visible(target: any, _key: any): any;
93
- function displayName(_name: any): (target: any, _key: any) => any;
94
- function tooltip(_text: any): (target: any, _key: any) => any;
95
- function range(_min: any, _max: any, _step: any): (target: any, _key: any) => any;
96
- function min(_value: any): (target: any, _key: any) => any;
97
- function max(_value: any): (target: any, _key: any) => any;
98
- function slide(_value: any): (target: any, _key: any) => any;
99
- function group(_value: any): (target: any, _key: any) => any;
100
- function notify(_fn: any): (target: any, _key: any) => any;
101
- }
102
110
  /** 引擎的 Component 基类 */
103
111
  export class Component extends EventTarget {
104
112
  node: any;
@@ -213,51 +221,6 @@ export class Bundle {
213
221
  _readDir(dir: any, type: any): Promise<any[]>;
214
222
  _noSourceError(method: any, path: any): Error;
215
223
  }
216
- export const assetManager: AssetManager;
217
- /** 引擎内置的 resources bundle。Cfg.ts 从这里读 config/*.json */
218
- export const resources: any;
219
- export const Vec2: any;
220
- export const Vec3: any;
221
- export const EPSILON: any;
222
- export const PI: any;
223
- export const HALF_PI: any;
224
- export const TWO_PI: any;
225
- export const RAD: any;
226
- export const DEG: any;
227
- export const lerp: any;
228
- export const clamp: any;
229
- export const clamp01: any;
230
- export const toRadian: any;
231
- export const toDegree: any;
232
- export const randomRange: any;
233
- export const randomRangeInt: any;
234
- export const sign: any;
235
- /** 引擎的全局单例 director */
236
- declare class Director extends EventTarget {
237
- static EVENT_BEFORE_UPDATE: string;
238
- static EVENT_AFTER_UPDATE: string;
239
- _scheduler: Scheduler;
240
- _deltaTime: number;
241
- _totalTime: number;
242
- _totalFrames: number;
243
- _paused: boolean;
244
- getScheduler(): Scheduler;
245
- getDeltaTime(): number;
246
- getTotalTime(): number;
247
- getTotalFrames(): number;
248
- isPaused(): boolean;
249
- pause(): void;
250
- resume(): void;
251
- /**
252
- * 非 cc API。
253
- * 引擎里时间由主循环推进,Node 下没有主循环,所以开这个口子让宿主
254
- * (战斗模拟的驱动方)手动推帧。
255
- *
256
- * dt 不乘 timeScale:引擎里 timeScale 影响的是派发给组件的 dt,由主循环负责,
257
- * 这里保持原样传入,免得和 core 自己的 Time.ts 重复缩放。
258
- */
259
- tick(dt: any): void;
260
- }
261
224
  declare class AssetManager {
262
225
  _bundles: Map<any, any>;
263
226
  getBundle(name: any): any;
@@ -1,42 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.sign = exports.randomRangeInt = exports.randomRange = exports.toDegree = exports.toRadian = exports.clamp01 = exports.clamp = exports.lerp = exports.DEG = exports.RAD = exports.TWO_PI = exports.HALF_PI = exports.PI = exports.EPSILON = exports.Vec3 = exports.Vec2 = exports.resources = exports.assetManager = exports.Bundle = exports.BufferAsset = exports.TextAsset = exports.JsonAsset = exports.Asset = exports.ProgressBar = exports.Label = exports.Node = exports.Component = exports._decorator = exports.CCString = exports.CCBoolean = exports.CCFloat = exports.CCInteger = exports.director = exports.Scheduler = exports.EventTarget = exports.math = exports.js = void 0;
37
- exports.log = log;
38
- exports.warn = warn;
39
- exports.error = error;
40
2
  /**
41
3
  * cc —— Cocos Creator 引擎 API 在 Node 侧的替身实现
42
4
  *
@@ -58,6 +20,11 @@ exports.error = error;
58
20
  * 放在单文件里是有意的:编译产物是 ESM,一旦拆成多个文件,相对 import 就得带
59
21
  * `.js` 后缀 Node 才解析得了;这里没有相对 import,省掉这个坑。
60
22
  */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.sign = exports.randomRangeInt = exports.randomRange = exports.toDegree = exports.toRadian = exports.clamp01 = exports.clamp = exports.lerp = exports.DEG = exports.RAD = exports.TWO_PI = exports.HALF_PI = exports.PI = exports.EPSILON = exports.Vec3 = exports.Vec2 = exports.resources = exports.assetManager = exports.Bundle = exports.BufferAsset = exports.TextAsset = exports.JsonAsset = exports.Asset = exports.ProgressBar = exports.Label = exports.Node = exports.Component = exports._decorator = exports.CCString = exports.CCBoolean = exports.CCFloat = exports.CCInteger = exports.director = exports.Scheduler = exports.EventTarget = exports.math = exports.js = void 0;
25
+ exports.log = log;
26
+ exports.warn = warn;
27
+ exports.error = error;
61
28
  /* -------------------------------------------------------------------------- */
62
29
  /* 日志:log / warn / error */
63
30
  /* -------------------------------------------------------------------------- */
@@ -81,6 +48,7 @@ function error(...args) {
81
48
  /* -------------------------------------------------------------------------- */
82
49
  const _classByName = new Map();
83
50
  const _classById = new Map();
51
+ var js;
84
52
  (function (js) {
85
53
  /**
86
54
  * 建一个纯字典对象。
@@ -258,7 +226,14 @@ const _classById = new Map();
258
226
  _classByName.set(getClassName(constructor), constructor);
259
227
  }
260
228
  js.registerClass = registerClass;
261
- })(exports.js || (exports.js = {}));
229
+ })(js || (exports.js = js = {}));
230
+ /* -------------------------------------------------------------------------- */
231
+ /* math 命名空间 */
232
+ /* */
233
+ /* Vec2/Vec3 定义在命名空间里,再桥到顶层导出(见文件末尾)。这样 cc.Vec3 和 */
234
+ /* math.Vec3 拿到的是同一个类对象,instanceof / 装饰器检查都安全。 */
235
+ /* -------------------------------------------------------------------------- */
236
+ var math;
262
237
  (function (math) {
263
238
  math.EPSILON = 0.000001;
264
239
  math.PI = Math.PI;
@@ -544,7 +519,7 @@ const _classById = new Map();
544
519
  return value < 0 ? -1 : (value > 0 ? 1 : 0);
545
520
  }
546
521
  math.sign = sign;
547
- })(exports.math || (exports.math = {}));
522
+ })(math || (exports.math = math = {}));
548
523
  /** 引擎的 EventTarget。Node / director 都靠它做 on/off/emit */
549
524
  class EventTarget {
550
525
  _listeners = null;
@@ -744,8 +719,8 @@ exports._decorator = {
744
719
  ccclass(nameOrTarget) {
745
720
  return (target) => {
746
721
  target.__isCCClass__ = true;
747
- exports.js.setClassName(target, typeof nameOrTarget === "string" ? nameOrTarget : target.name);
748
- exports.js.registerClass(target);
722
+ js.setClassName(target, typeof nameOrTarget === "string" ? nameOrTarget : target.name);
723
+ js.registerClass(target);
749
724
  return target;
750
725
  };
751
726
  },
@@ -793,7 +768,7 @@ exports._decorator = {
793
768
  class Component extends EventTarget {
794
769
  node = null;
795
770
  enabled = true;
796
- get name() { return exports.js.getClassName(this.constructor); }
771
+ get name() { return js.getClassName(this.constructor); }
797
772
  get isValid() { return this.node != null && this.node.isValid; }
798
773
  getComponent(type) {
799
774
  return this.node ? this.node.getComponent(type) : null;
@@ -821,9 +796,9 @@ class Node extends EventTarget {
821
796
  _children = [];
822
797
  _components = [];
823
798
  _destroyed = false;
824
- position = new exports.math.Vec3();
825
- scale = new exports.math.Vec3(1, 1, 1);
826
- worldPosition = new exports.math.Vec3();
799
+ position = new math.Vec3();
800
+ scale = new math.Vec3(1, 1, 1);
801
+ worldPosition = new math.Vec3();
827
802
  constructor(name = "Node") {
828
803
  super();
829
804
  this._name = name;
@@ -895,7 +870,7 @@ class Node extends EventTarget {
895
870
  }
896
871
  _matchComponent(component, type) {
897
872
  if (typeof type === "string")
898
- return exports.js.getClassName(component.constructor) === type;
873
+ return js.getClassName(component.constructor) === type;
899
874
  return component instanceof type;
900
875
  }
901
876
  destroy() {
@@ -1030,8 +1005,8 @@ class Bundle {
1030
1005
  async _readOne(path, type) {
1031
1006
  if (!this.localRoot)
1032
1007
  throw this._noSourceError("load", path);
1033
- const fs = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
1034
- const pathMod = await Promise.resolve().then(() => __importStar(require("node:path")));
1008
+ const fs = await Promise.resolve().then(() => require("node:fs/promises"));
1009
+ const pathMod = await Promise.resolve().then(() => require("node:path"));
1035
1010
  const base = pathMod.join(this.localRoot, path);
1036
1011
  // 用 any 比较:type 是泛型构造签名,和具体类之间 TS 认为没有重叠
1037
1012
  const ctor = type;
@@ -1077,8 +1052,8 @@ class Bundle {
1077
1052
  async _readDir(dir, type) {
1078
1053
  if (!this.localRoot)
1079
1054
  throw this._noSourceError("loadDir", dir);
1080
- const fs = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
1081
- const pathMod = await Promise.resolve().then(() => __importStar(require("node:path")));
1055
+ const fs = await Promise.resolve().then(() => require("node:fs/promises"));
1056
+ const pathMod = await Promise.resolve().then(() => require("node:path"));
1082
1057
  const ctor = type;
1083
1058
  const exts = ctor === JsonAsset ? [".json"] : (ctor === TextAsset ? [".txt"] : null);
1084
1059
  const entries = await fs.readdir(pathMod.join(this.localRoot, dir), { withFileTypes: true });
@@ -1167,19 +1142,19 @@ exports.resources = exports.assetManager.getBundle("resources");
1167
1142
  /* - cc.Vec3 === math.Vec3(同一个类对象,instanceof / 装饰器检查都安全) */
1168
1143
  /* - Vec3 既能当值用(new / instanceof),也能当类型用(let v: Vec3) */
1169
1144
  /* -------------------------------------------------------------------------- */
1170
- exports.Vec2 = exports.math.Vec2;
1171
- exports.Vec3 = exports.math.Vec3;
1172
- exports.EPSILON = exports.math.EPSILON;
1173
- exports.PI = exports.math.PI;
1174
- exports.HALF_PI = exports.math.HALF_PI;
1175
- exports.TWO_PI = exports.math.TWO_PI;
1176
- exports.RAD = exports.math.RAD;
1177
- exports.DEG = exports.math.DEG;
1178
- exports.lerp = exports.math.lerp;
1179
- exports.clamp = exports.math.clamp;
1180
- exports.clamp01 = exports.math.clamp01;
1181
- exports.toRadian = exports.math.toRadian;
1182
- exports.toDegree = exports.math.toDegree;
1183
- exports.randomRange = exports.math.randomRange;
1184
- exports.randomRangeInt = exports.math.randomRangeInt;
1185
- exports.sign = exports.math.sign;
1145
+ exports.Vec2 = math.Vec2;
1146
+ exports.Vec3 = math.Vec3;
1147
+ exports.EPSILON = math.EPSILON;
1148
+ exports.PI = math.PI;
1149
+ exports.HALF_PI = math.HALF_PI;
1150
+ exports.TWO_PI = math.TWO_PI;
1151
+ exports.RAD = math.RAD;
1152
+ exports.DEG = math.DEG;
1153
+ exports.lerp = math.lerp;
1154
+ exports.clamp = math.clamp;
1155
+ exports.clamp01 = math.clamp01;
1156
+ exports.toRadian = math.toRadian;
1157
+ exports.toDegree = math.toDegree;
1158
+ exports.randomRange = math.randomRange;
1159
+ exports.randomRangeInt = math.randomRangeInt;
1160
+ exports.sign = math.sign;
@@ -97,7 +97,7 @@ export declare class GameUtil {
97
97
  /**
98
98
  * 版本号比较
99
99
  */
100
- static compareVersion(v1: any, v2: any): 1 | 0 | -1;
100
+ static compareVersion(v1: any, v2: any): 0 | 1 | -1;
101
101
  /**
102
102
  * 深拷贝
103
103
  * @param {} obj
package/dist/index.d.ts CHANGED
@@ -27,6 +27,9 @@ export interface IGameParam {
27
27
  */
28
28
  forcePass?: boolean;
29
29
  }
30
+ export interface IGuildGameParam extends IGameParam {
31
+ cheerLayer: number;
32
+ }
30
33
  /**
31
34
  * 开始战斗验证
32
35
  * @param type 游戏模块
@@ -37,7 +40,7 @@ export interface IGameParam {
37
40
  export declare function startBattleVerify(type: EGameModule, battlePlayer: PlayerProto.IBattlePlayer, param: IGameParam, callback?: (game: Game) => void): boolean;
38
41
  export declare function startStageVerify(battlePlayer: PlayerProto.IBattlePlayer, param: IGameParam): boolean;
39
42
  export declare function startRelicDungeonVerify(battlePlayer: PlayerProto.IBattlePlayer, param: IGameParam): boolean;
40
- export declare function startGuildVerify(battlePlayer: PlayerProto.IBattlePlayer, param: IGameParam): {
43
+ export declare function startGuildVerify(battlePlayer: PlayerProto.IBattlePlayer, param: IGuildGameParam): {
41
44
  killHpCount: number;
42
45
  damage: number;
43
46
  };
package/dist/index.js CHANGED
@@ -18,11 +18,13 @@ const node_zlib_1 = __importDefault(require("node:zlib"));
18
18
  require("./adb-url-resolver");
19
19
  const Cfg_1 = require("./core/config/Cfg");
20
20
  const Const_1 = require("./core/config/Const");
21
+ const GuildBossConfigCfg_1 = require("./core/config/GuildBossConfigCfg");
21
22
  const battle_interface_1 = require("./core/module/battle/battle.interface");
22
23
  Object.defineProperty(exports, "EGameModule", { enumerable: true, get: function () { return battle_interface_1.EGameModule; } });
23
24
  const Game_1 = __importDefault(require("./core/module/battle/Game"));
24
25
  const BattleInputCodec_1 = __importDefault(require("./core/module/battle/util/BattleInputCodec"));
25
26
  const BattleUtils_1 = require("./core/module/battle/util/BattleUtils");
27
+ const Property_1 = require("./core/module/property/Property");
26
28
  require("./register-all");
27
29
  /** 包内配置的相对路径。源码跑时 __dirname 是仓库根,产物跑时是 dist/ */
28
30
  const CFG_RELATIVE = node_path_1.default.join("resources", "config", "GameJsonCfg.bin");
@@ -144,7 +146,7 @@ function loadFighterInfo(battlePlayer) {
144
146
  */
145
147
  function startBattleVerify(type, battlePlayer, param, callback) {
146
148
  if (param.forcePass) {
147
- callback(null);
149
+ callback && callback(null);
148
150
  return true;
149
151
  }
150
152
  // 配置按需加载:入口 import 本包不再有读盘副作用,直接调用也能跑
@@ -182,6 +184,17 @@ function startBattleVerify(type, battlePlayer, param, callback) {
182
184
  enemyData = BattleUtils_1.BattleUtils.getBornInfoByWavesId(relicDungeon.lvMould, 2, param.seed);
183
185
  }
184
186
  }
187
+ else if (type === battle_interface_1.EGameModule.GuildBoss) {
188
+ const guildParam = param;
189
+ const cheerLayer = guildParam.cheerLayer ?? 0;
190
+ const cheerBuffs = Cfg_1.Cfg.GuildBossConfig.get(GuildBossConfigCfg_1.GuildBossConfigDefine.boss_support_buff)?.value2 || [];
191
+ for (let i = 0; i < myFightDatas.length; i++) {
192
+ const myRoleData = myFightDatas[i];
193
+ for (const element of cheerBuffs) {
194
+ Property_1.PropertyHelper.addPropertyByKeyValue(myRoleData.property, element[0], element[1] * cheerLayer);
195
+ }
196
+ }
197
+ }
185
198
  let isWin = false;
186
199
  let inputs = [];
187
200
  if (param.inputs && param.inputs.length) {
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * cc —— Cocos Creator 引擎 API 在 Node 侧的替身实现
3
4
  *
@@ -19,6 +20,11 @@
19
20
  * 放在单文件里是有意的:编译产物是 ESM,一旦拆成多个文件,相对 import 就得带
20
21
  * `.js` 后缀 Node 才解析得了;这里没有相对 import,省掉这个坑。
21
22
  */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.sign = exports.randomRangeInt = exports.randomRange = exports.toDegree = exports.toRadian = exports.clamp01 = exports.clamp = exports.lerp = exports.DEG = exports.RAD = exports.TWO_PI = exports.HALF_PI = exports.PI = exports.EPSILON = exports.Vec3 = exports.Vec2 = exports.resources = exports.assetManager = exports.Bundle = exports.BufferAsset = exports.TextAsset = exports.JsonAsset = exports.Asset = exports.ProgressBar = exports.Label = exports.Node = exports.Component = exports._decorator = exports.CCString = exports.CCBoolean = exports.CCFloat = exports.CCInteger = exports.director = exports.Scheduler = exports.EventTarget = exports.math = exports.js = void 0;
25
+ exports.log = log;
26
+ exports.warn = warn;
27
+ exports.error = error;
22
28
  /* -------------------------------------------------------------------------- */
23
29
  /* 日志:log / warn / error */
24
30
  /* -------------------------------------------------------------------------- */
@@ -28,13 +34,13 @@
28
34
  * Node 的 console 是同一套规则,所以这里直接转发,不做二次格式化——
29
35
  * 自己实现反而会在 "%s" 和普通 "%" 混用时和引擎对不上。
30
36
  */
31
- export function log(...args) {
37
+ function log(...args) {
32
38
  console.log(...args);
33
39
  }
34
- export function warn(...args) {
40
+ function warn(...args) {
35
41
  console.warn(...args);
36
42
  }
37
- export function error(...args) {
43
+ function error(...args) {
38
44
  console.error(...args);
39
45
  }
40
46
  /* -------------------------------------------------------------------------- */
@@ -42,7 +48,7 @@ export function error(...args) {
42
48
  /* -------------------------------------------------------------------------- */
43
49
  const _classByName = new Map();
44
50
  const _classById = new Map();
45
- export var js;
51
+ var js;
46
52
  (function (js) {
47
53
  /**
48
54
  * 建一个纯字典对象。
@@ -220,14 +226,14 @@ export var js;
220
226
  _classByName.set(getClassName(constructor), constructor);
221
227
  }
222
228
  js.registerClass = registerClass;
223
- })(js || (js = {}));
229
+ })(js || (exports.js = js = {}));
224
230
  /* -------------------------------------------------------------------------- */
225
231
  /* math 命名空间 */
226
232
  /* */
227
233
  /* Vec2/Vec3 定义在命名空间里,再桥到顶层导出(见文件末尾)。这样 cc.Vec3 和 */
228
234
  /* math.Vec3 拿到的是同一个类对象,instanceof / 装饰器检查都安全。 */
229
235
  /* -------------------------------------------------------------------------- */
230
- export var math;
236
+ var math;
231
237
  (function (math) {
232
238
  math.EPSILON = 0.000001;
233
239
  math.PI = Math.PI;
@@ -513,9 +519,9 @@ export var math;
513
519
  return value < 0 ? -1 : (value > 0 ? 1 : 0);
514
520
  }
515
521
  math.sign = sign;
516
- })(math || (math = {}));
522
+ })(math || (exports.math = math = {}));
517
523
  /** 引擎的 EventTarget。Node / director 都靠它做 on/off/emit */
518
- export class EventTarget {
524
+ class EventTarget {
519
525
  _listeners = null;
520
526
  on(type, callback, target) {
521
527
  this._addListener(type, callback, target, false);
@@ -596,6 +602,7 @@ export class EventTarget {
596
602
  this._listeners.delete(type);
597
603
  }
598
604
  }
605
+ exports.EventTarget = EventTarget;
599
606
  /* -------------------------------------------------------------------------- */
600
607
  /* director + Scheduler */
601
608
  /* -------------------------------------------------------------------------- */
@@ -606,7 +613,7 @@ export class EventTarget {
606
613
  *
607
614
  * 定时器那部分不走这里:core 里由 Time.ts 自己的 Watcher 实现。
608
615
  */
609
- export class Scheduler {
616
+ class Scheduler {
610
617
  _timeScale = 1;
611
618
  _paused = false;
612
619
  setTimeScale(scale) {
@@ -619,6 +626,7 @@ export class Scheduler {
619
626
  resume() { this._paused = false; }
620
627
  isPaused() { return this._paused; }
621
628
  }
629
+ exports.Scheduler = Scheduler;
622
630
  /** 引擎的全局单例 director */
623
631
  class Director extends EventTarget {
624
632
  static EVENT_BEFORE_UPDATE = "director_before_update";
@@ -655,34 +663,38 @@ class Director extends EventTarget {
655
663
  this.emit(Director.EVENT_AFTER_UPDATE, dt);
656
664
  }
657
665
  }
658
- export const director = new Director();
666
+ exports.director = new Director();
659
667
  /* -------------------------------------------------------------------------- */
660
668
  /* _decorator + 属性类型标记 */
661
669
  /* -------------------------------------------------------------------------- */
662
- export class CCInteger {
670
+ class CCInteger {
663
671
  value;
664
672
  constructor(value) {
665
673
  this.value = value;
666
674
  }
667
675
  }
668
- export class CCFloat {
676
+ exports.CCInteger = CCInteger;
677
+ class CCFloat {
669
678
  value;
670
679
  constructor(value) {
671
680
  this.value = value;
672
681
  }
673
682
  }
674
- export class CCBoolean {
683
+ exports.CCFloat = CCFloat;
684
+ class CCBoolean {
675
685
  value;
676
686
  constructor(value) {
677
687
  this.value = value;
678
688
  }
679
689
  }
680
- export class CCString {
690
+ exports.CCBoolean = CCBoolean;
691
+ class CCString {
681
692
  value;
682
693
  constructor(value) {
683
694
  this.value = value;
684
695
  }
685
696
  }
697
+ exports.CCString = CCString;
686
698
  /** 把属性装饰器的各种写法(@property / @property(Vec3) / @property({...}))归一成 options */
687
699
  function normalizePropertyArgs(args) {
688
700
  const options = {};
@@ -703,7 +715,7 @@ function normalizePropertyArgs(args) {
703
715
  * Node 下没有编辑器序列化,装饰器退化成"打标记 + 记类名":类名要记,
704
716
  * 因为 js.getClassName / getClassByName 和日志都依赖它。
705
717
  */
706
- export const _decorator = {
718
+ exports._decorator = {
707
719
  ccclass(nameOrTarget) {
708
720
  return (target) => {
709
721
  target.__isCCClass__ = true;
@@ -753,7 +765,7 @@ export const _decorator = {
753
765
  /* Component / Node */
754
766
  /* -------------------------------------------------------------------------- */
755
767
  /** 引擎的 Component 基类 */
756
- export class Component extends EventTarget {
768
+ class Component extends EventTarget {
757
769
  node = null;
758
770
  enabled = true;
759
771
  get name() { return js.getClassName(this.constructor); }
@@ -767,6 +779,7 @@ export class Component extends EventTarget {
767
779
  this.enabled = false;
768
780
  }
769
781
  }
782
+ exports.Component = Component;
770
783
  /**
771
784
  * 引擎的 Node。
772
785
  *
@@ -776,7 +789,7 @@ export class Component extends EventTarget {
776
789
  * 有意的取舍:不跑 onLoad/onEnable/update 这些生命周期——Node 下没有主循环去驱动它们,
777
790
  * 与其假装调了,不如让它们根本不触发。
778
791
  */
779
- export class Node extends EventTarget {
792
+ class Node extends EventTarget {
780
793
  _name;
781
794
  _active = true;
782
795
  _parent = null;
@@ -870,27 +883,30 @@ export class Node extends EventTarget {
870
883
  }
871
884
  toString() { return `<Node ${this._name}>`; }
872
885
  }
886
+ exports.Node = Node;
873
887
  /* -------------------------------------------------------------------------- */
874
888
  /* 渲染组件(占位) */
875
889
  /* */
876
890
  /* 只是让 Cfg.ts 里 `test?: Label` / `pro?: ProgressBar` 这类签名有类型,并且真 */
877
891
  /* new 出来不会崩。它们不接任何渲染后端,属性怎么写都不会画到屏幕上。 */
878
892
  /* -------------------------------------------------------------------------- */
879
- export class Label extends Component {
893
+ class Label extends Component {
880
894
  string = "";
881
895
  fontSize = 40;
882
896
  lineHeight = 40;
883
897
  enableWrapText = true;
884
898
  }
885
- export class ProgressBar extends Component {
899
+ exports.Label = Label;
900
+ class ProgressBar extends Component {
886
901
  /** 0 ~ 1 */
887
902
  progress = 0;
888
903
  totalLength = 100;
889
904
  }
905
+ exports.ProgressBar = ProgressBar;
890
906
  /* -------------------------------------------------------------------------- */
891
907
  /* 资源 */
892
908
  /* -------------------------------------------------------------------------- */
893
- export class Asset {
909
+ class Asset {
894
910
  name = "";
895
911
  _uuid = "";
896
912
  nativeUrl = "";
@@ -912,20 +928,24 @@ export class Asset {
912
928
  return true;
913
929
  }
914
930
  }
915
- export class JsonAsset extends Asset {
931
+ exports.Asset = Asset;
932
+ class JsonAsset extends Asset {
916
933
  json = null;
917
934
  }
918
- export class TextAsset extends Asset {
935
+ exports.JsonAsset = JsonAsset;
936
+ class TextAsset extends Asset {
919
937
  text = "";
920
938
  }
939
+ exports.TextAsset = TextAsset;
921
940
  /** 二进制资源。引擎里 _file 还可能是 Blob,Node 侧只会是 ArrayBuffer。 */
922
- export class BufferAsset extends Asset {
941
+ class BufferAsset extends Asset {
923
942
  _file = null;
924
943
  /** 引擎语义:返回二进制数据 */
925
944
  buffer() {
926
945
  return this._file;
927
946
  }
928
947
  }
948
+ exports.BufferAsset = BufferAsset;
929
949
  /**
930
950
  * 资源包。
931
951
  *
@@ -939,7 +959,7 @@ export class BufferAsset extends Asset {
939
959
  * BufferAsset → <root>/<path>,按二进制读(Cfg 的 gzip 配置用)
940
960
  * asset.name → 文件名去掉扩展名,和引擎里 element.name 的取值口径对齐
941
961
  */
942
- export class Bundle {
962
+ class Bundle {
943
963
  name;
944
964
  /** 非 cc API:磁盘目录。设了它 load/loadDir 才真读得到东西 */
945
965
  localRoot = null;
@@ -985,8 +1005,8 @@ export class Bundle {
985
1005
  async _readOne(path, type) {
986
1006
  if (!this.localRoot)
987
1007
  throw this._noSourceError("load", path);
988
- const fs = await import("node:fs/promises");
989
- const pathMod = await import("node:path");
1008
+ const fs = await Promise.resolve().then(() => require("node:fs/promises"));
1009
+ const pathMod = await Promise.resolve().then(() => require("node:path"));
990
1010
  const base = pathMod.join(this.localRoot, path);
991
1011
  // 用 any 比较:type 是泛型构造签名,和具体类之间 TS 认为没有重叠
992
1012
  const ctor = type;
@@ -1032,8 +1052,8 @@ export class Bundle {
1032
1052
  async _readDir(dir, type) {
1033
1053
  if (!this.localRoot)
1034
1054
  throw this._noSourceError("loadDir", dir);
1035
- const fs = await import("node:fs/promises");
1036
- const pathMod = await import("node:path");
1055
+ const fs = await Promise.resolve().then(() => require("node:fs/promises"));
1056
+ const pathMod = await Promise.resolve().then(() => require("node:path"));
1037
1057
  const ctor = type;
1038
1058
  const exts = ctor === JsonAsset ? [".json"] : (ctor === TextAsset ? [".txt"] : null);
1039
1059
  const entries = await fs.readdir(pathMod.join(this.localRoot, dir), { withFileTypes: true });
@@ -1054,6 +1074,7 @@ export class Bundle {
1054
1074
  + `Node 下没有 asset-db,需要先把 bundle.localRoot 指向磁盘目录`);
1055
1075
  }
1056
1076
  }
1077
+ exports.Bundle = Bundle;
1057
1078
  class AssetManager {
1058
1079
  _bundles = new Map();
1059
1080
  constructor() {
@@ -1110,9 +1131,9 @@ class AssetManager {
1110
1131
  }, (e) => finish(e, null));
1111
1132
  }
1112
1133
  }
1113
- export const assetManager = new AssetManager();
1134
+ exports.assetManager = new AssetManager();
1114
1135
  /** 引擎内置的 resources bundle。Cfg.ts 从这里读 config/*.json */
1115
- export const resources = assetManager.getBundle("resources");
1136
+ exports.resources = exports.assetManager.getBundle("resources");
1116
1137
  /* -------------------------------------------------------------------------- */
1117
1138
  /* 顶层桥接 */
1118
1139
  /* */
@@ -1121,19 +1142,19 @@ export const resources = assetManager.getBundle("resources");
1121
1142
  /* - cc.Vec3 === math.Vec3(同一个类对象,instanceof / 装饰器检查都安全) */
1122
1143
  /* - Vec3 既能当值用(new / instanceof),也能当类型用(let v: Vec3) */
1123
1144
  /* -------------------------------------------------------------------------- */
1124
- export const Vec2 = math.Vec2;
1125
- export const Vec3 = math.Vec3;
1126
- export const EPSILON = math.EPSILON;
1127
- export const PI = math.PI;
1128
- export const HALF_PI = math.HALF_PI;
1129
- export const TWO_PI = math.TWO_PI;
1130
- export const RAD = math.RAD;
1131
- export const DEG = math.DEG;
1132
- export const lerp = math.lerp;
1133
- export const clamp = math.clamp;
1134
- export const clamp01 = math.clamp01;
1135
- export const toRadian = math.toRadian;
1136
- export const toDegree = math.toDegree;
1137
- export const randomRange = math.randomRange;
1138
- export const randomRangeInt = math.randomRangeInt;
1139
- export const sign = math.sign;
1145
+ exports.Vec2 = math.Vec2;
1146
+ exports.Vec3 = math.Vec3;
1147
+ exports.EPSILON = math.EPSILON;
1148
+ exports.PI = math.PI;
1149
+ exports.HALF_PI = math.HALF_PI;
1150
+ exports.TWO_PI = math.TWO_PI;
1151
+ exports.RAD = math.RAD;
1152
+ exports.DEG = math.DEG;
1153
+ exports.lerp = math.lerp;
1154
+ exports.clamp = math.clamp;
1155
+ exports.clamp01 = math.clamp01;
1156
+ exports.toRadian = math.toRadian;
1157
+ exports.toDegree = math.toDegree;
1158
+ exports.randomRange = math.randomRange;
1159
+ exports.randomRangeInt = math.randomRangeInt;
1160
+ exports.sign = math.sign;
@@ -3,12 +3,13 @@
3
3
  "version": "3.8.0-node",
4
4
  "private": true,
5
5
  "description": "Cocos Creator 引擎 API 在 Node 侧的替身实现(只覆盖本项目用到的子集)",
6
- "type": "module",
6
+ "type": "commonjs",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
+ "require": "./dist/index.js",
12
13
  "import": "./dist/index.js",
13
14
  "default": "./dist/index.js"
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "captainbattle",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "水上大乱斗后端战斗模拟",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,16 +20,13 @@
20
20
  "scripts": {
21
21
  "gen": "node scripts/gen-registry.mjs",
22
22
  "gen:check": "node scripts/gen-registry.mjs --check",
23
- "prestart": "npm run gen",
24
- "start": "tsx cli.ts",
25
- "start:dist": "node dist/cli.js",
26
- "dev": "tsx watch cli.ts",
27
23
  "prebuild": "npm run gen",
28
24
  "build": "npm run build:cc && tsc -p tsconfig.json && node scripts/copy-proto-dts.mjs",
29
25
  "build:cc": "tsc -p cc/tsconfig.json",
30
26
  "pretypecheck": "npm run gen",
31
27
  "typecheck": "tsc -p tsconfig.json --noEmit",
32
28
  "prepack": "npm run build",
29
+ "release": "node scripts/release.mjs",
33
30
  "test": "echo \"Error: no test specified\" && exit 1"
34
31
  },
35
32
  "repository": {
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/cli.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 本地冒烟入口:加载配置后退出,验证包能正常初始化。
5
- * 库的正式用法见 index.ts 的导出(initCfg / startBattleVerify 等)。
6
- */
7
- const index_1 = require("./index");
8
- (0, index_1.initCfg)();
9
- console.log("[captainbattle] 配置加载完成");