@cyclonium/core 0.0.105 → 1.0.1

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.
@@ -7,8 +7,8 @@ export declare enum TransformFlag {
7
7
  scale = 4
8
8
  }
9
9
  declare class TransformChangeFlags {
10
- get token(): boolean;
11
10
  frontValue: number;
11
+ get token(): boolean;
12
12
  get backValue(): number;
13
13
  reset(): void;
14
14
  private _token;
@@ -12,7 +12,6 @@ import { Mat3 } from "../math/mat3.js";
12
12
  import { mat3FromSRT } from "../math/transform-2d.js";
13
13
  import { Vec2 } from "../math/vec2.js";
14
14
  import { to0ToPI2 } from "../math/trigonometry.js";
15
- import { logger } from "../utils/logger.js";
16
15
  import { clamp } from "../math/number.js";
17
16
  export var TransformFlag;
18
17
  (function (TransformFlag) {
@@ -21,10 +20,10 @@ export var TransformFlag;
21
20
  TransformFlag[TransformFlag["scale"] = 4] = "scale";
22
21
  })(TransformFlag || (TransformFlag = {}));
23
22
  class TransformChangeFlags {
23
+ frontValue = 0;
24
24
  get token() {
25
25
  return this._token;
26
26
  }
27
- frontValue = 0;
28
27
  get backValue() {
29
28
  return this._backValue;
30
29
  }
@@ -3,6 +3,7 @@ export function createDecoratorForSetEditableMetadata(opts) {
3
3
  return (target, propertyKey, descriptor) => {
4
4
  const normalizedOptions = {
5
5
  ...opts,
6
+ serializable: false,
6
7
  };
7
8
  if (normalizedOptions.visible === undefined) {
8
9
  if (typeof propertyKey === 'string' && propertyKey.startsWith('_')) {
@@ -10,7 +11,8 @@ export function createDecoratorForSetEditableMetadata(opts) {
10
11
  normalizedOptions.displayName = propertyKey.slice(1);
11
12
  }
12
13
  }
13
- return _decorator.property(normalizedOptions)(target, propertyKey, descriptor);
14
+ _decorator.property(normalizedOptions)(target, propertyKey, descriptor);
15
+ _decorator.editable(target, propertyKey, descriptor);
14
16
  };
15
17
  }
16
18
  //# sourceMappingURL=common.js.map
@@ -1,4 +1,4 @@
1
- import { CCInteger, type CCBoolean, type CCFloat, type CCString } from 'cc';
1
+ import { CCInteger, type CCBoolean, type CCString } from 'cc';
2
2
  export interface EditableDecoratorOptions {
3
3
  type?: Function | typeof CCInteger;
4
4
  min?: number;
@@ -17,7 +17,7 @@ export interface EditableDecoratorOptions {
17
17
  }
18
18
  declare function editable(options?: EditableDecoratorOptions): PropertyDecorator;
19
19
  declare function editable(type?: Function): PropertyDecorator;
20
- declare function editable(type?: typeof CCInteger | typeof CCBoolean | typeof CCFloat | typeof CCString): PropertyDecorator;
20
+ declare function editable(type?: typeof CCInteger | typeof CCBoolean | typeof CCString): PropertyDecorator;
21
21
  declare function editable(target: object, propertyKey: string | symbol): void;
22
22
  export { editable };
23
23
  //# sourceMappingURL=editable.d.ts.map
@@ -50,9 +50,7 @@ function editableWithOptions(options) {
50
50
  modifiedOptions.min = 0;
51
51
  modifiedOptions.max = Math.PI * 2;
52
52
  }
53
- if (modifiedOptions.step === undefined) {
54
- modifiedOptions.step = 1;
55
- }
53
+ modifiedOptions.step ??= 1;
56
54
  }
57
55
  createDecoratorForSetEditableMetadata(modifiedOptions)(...args);
58
56
  };
@@ -1,11 +1,12 @@
1
- import { Component } from 'cc';
1
+ import { Component, type Constructor } from 'cc';
2
2
  import { CycloComponent } from '../../framework/component.ts';
3
3
  export declare function executionOrder(order: number): ClassDecorator;
4
4
  export declare namespace executionOrder {
5
5
  function lateThan(component: CycloComponentClass): ClassDecorator;
6
6
  }
7
+ export declare const disallowMultiple: ((value?: boolean) => ClassDecorator) & ClassDecorator;
7
8
  export declare const executeInEditMode: ((value?: boolean) => ClassDecorator) & ClassDecorator;
8
- export declare function requiresComponent<T extends Component>(componentType: new (...args: never[]) => T): MethodDecorator;
9
+ export declare function requiresComponent<T extends Component>(componentType: Constructor<T>): MethodDecorator;
9
10
  type CycloComponentClass = new (...args: never[]) => CycloComponent;
10
11
  export {};
11
12
  //# sourceMappingURL=legacy-component-decorator.d.ts.map
@@ -2,7 +2,6 @@
2
2
  import { _decorator, Component } from 'cc';
3
3
  import { CycloComponent } from "../../framework/component.js";
4
4
  import { getExecutionOrder, setExecutionOrder } from "../../framework/execution-order.js";
5
- import { logger } from "../../utils/logger.js";
6
5
  export function executionOrder(order) {
7
6
  return defineComponentDecorator((target) => {
8
7
  setExecutionOrder(target, order);
@@ -17,6 +16,9 @@ export function executionOrder(order) {
17
16
  }
18
17
  executionOrder.lateThan = lateThan;
19
18
  })(executionOrder || (executionOrder = {}));
19
+ export const disallowMultiple = defineComponentDecoratorWithOptionalBoolean((target, value) => {
20
+ _decorator.disallowMultiple(value)(target);
21
+ });
20
22
  export const executeInEditMode = defineComponentDecoratorWithOptionalBoolean((target, value) => {
21
23
  _decorator.executeInEditMode(value)(target);
22
24
  });
@@ -36,17 +38,16 @@ function addRequiredComponent(target, componentType) {
36
38
  export function requiresComponent(componentType) {
37
39
  return defineComponentMethodDecorator((target, propertyKey, descriptor) => {
38
40
  addRequiredComponent(target, componentType);
39
- const { get, set, value, ...remain } = descriptor;
40
- if (set) {
41
+ if (descriptor.set !== undefined) {
41
42
  throw new Error(`Property ${String(propertyKey)} of should not has set`);
42
43
  }
43
- if (value !== undefined) {
44
+ if (descriptor.value !== undefined) {
44
45
  throw new Error(`Property ${String(propertyKey)} of should not has value`);
45
46
  }
46
47
  return {
47
- ...remain,
48
+ configurable: descriptor.configurable,
49
+ enumerable: descriptor.enumerable,
48
50
  get() {
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
51
  const component = this.getComponent(componentType);
51
52
  if (!component) {
52
53
  throw new Error(`Component ${componentType.name} is not found.`);
@@ -82,7 +83,7 @@ function defineComponentDecoratorWithOptionalBoolean(decorate) {
82
83
  function defineComponentMethodDecorator(decorate) {
83
84
  return (target, propertyKey, descriptor) => {
84
85
  if (!(target instanceof CycloComponent)) {
85
- throw new Error(`Class ${target} is not a subclass of CycloComponent.`);
86
+ throw new Error(`Class ${String(target)} is not a subclass of CycloComponent.`);
86
87
  }
87
88
  return decorate(target, propertyKey, descriptor);
88
89
  };
@@ -16,7 +16,7 @@ export declare function createScopedCycloClassDecorator(opts: {
16
16
  declare const cycloClass: CycloClassDecorator;
17
17
  declare const cycloBuiltinClass: CycloClassDecorator;
18
18
  export { cycloClass, cycloBuiltinClass };
19
- export declare const serializable: typeof _decorator.property;
19
+ export declare const stored: PropertyDecorator;
20
20
  /**
21
21
  * Marks that the property's default value might vary between instances.
22
22
  * @description
@@ -44,7 +44,7 @@ const cycloBuiltinClass = createScopedCycloClassDecorator({
44
44
  scope: 'cyclo.',
45
45
  });
46
46
  export { cycloClass, cycloBuiltinClass };
47
- export const serializable = _decorator.property;
47
+ export const stored = _decorator.serializable;
48
48
  /**
49
49
  * Marks that the property's default value might vary between instances.
50
50
  * @description
@@ -1,6 +1,6 @@
1
- export interface ShortenPropertyDecorator<TArgs extends any[]> {
1
+ export interface ShortenPropertyDecorator<TArgs extends unknown[]> {
2
2
  (...args: TArgs): PropertyDecorator;
3
- (target: Object, propertyKey: string | symbol): void;
3
+ (target: object, propertyKey: string | symbol): void;
4
4
  }
5
- export declare function defineShortenPropertyDecorator<TArgs extends any[]>(decorator: (...args: TArgs) => PropertyDecorator, ...defaultArgs: TArgs): ShortenPropertyDecorator<TArgs>;
5
+ export declare function defineShortenPropertyDecorator<TArgs extends unknown[]>(decorator: (...args: TArgs) => PropertyDecorator, ...defaultArgs: TArgs): ShortenPropertyDecorator<TArgs>;
6
6
  //# sourceMappingURL=utils.d.ts.map
@@ -4,7 +4,7 @@ export function defineShortenPropertyDecorator(decorator, ...defaultArgs) {
4
4
  // @x()
5
5
  return decorator(...defaultArgs);
6
6
  }
7
- else if (!(typeof args[0] === 'object' && args[0] && typeof args[1] === 'string' || typeof args[1] === 'symbol')) {
7
+ else if (!((typeof args[0] === 'object' && args[0] && typeof args[1] === 'string') || typeof args[1] === 'symbol')) {
8
8
  // @x(opts)
9
9
  return decorator(...args);
10
10
  }
@@ -1,4 +1,4 @@
1
- export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, serializable, type CycloClassOptions, type CycloClassDecorator, } from '../decorator/legacy/legacy-general-decorator.ts';
2
- export { executionOrder, executeInEditMode, requiresComponent, } from '../decorator/legacy/legacy-component-decorator.ts';
1
+ export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, stored, type CycloClassOptions, type CycloClassDecorator, } from '../decorator/legacy/legacy-general-decorator.ts';
2
+ export { disallowMultiple, executionOrder, executeInEditMode, requiresComponent, } from '../decorator/legacy/legacy-component-decorator.ts';
3
3
  export { applyLegacyDecorators } from '../decorator/legacy/apply-legacy-decorators.ts';
4
4
  //# sourceMappingURL=legacy-decorator.d.ts.map
@@ -1,4 +1,4 @@
1
- export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, serializable, } from "../decorator/legacy/legacy-general-decorator.js";
2
- export { executionOrder, executeInEditMode, requiresComponent, } from "../decorator/legacy/legacy-component-decorator.js";
1
+ export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, stored, } from "../decorator/legacy/legacy-general-decorator.js";
2
+ export { disallowMultiple, executionOrder, executeInEditMode, requiresComponent, } from "../decorator/legacy/legacy-component-decorator.js";
3
3
  export { applyLegacyDecorators } from "../decorator/legacy/apply-legacy-decorators.js";
4
4
  //# sourceMappingURL=legacy-decorator.js.map
@@ -111,19 +111,35 @@ let CycloComponent = class CycloComponent extends Component {
111
111
  get disablingSignal() {
112
112
  return (this._disablingController ??= new AbortController()).signal;
113
113
  }
114
- onAwake() { }
115
- onEnabled() { }
116
- onDisabled() { }
114
+ onAwake() {
115
+ // Optional lifecycle hook for subclasses.
116
+ }
117
+ onEnabled() {
118
+ // Optional lifecycle hook for subclasses.
119
+ }
120
+ onDisabled() {
121
+ // Optional lifecycle hook for subclasses.
122
+ }
117
123
  onDestroy() {
118
124
  this.stopAllCoroutines();
119
125
  this._destroyingController?.abort();
120
126
  this._destroyingController = undefined;
121
127
  }
122
- onStart() { }
123
- onUpdate(_deltaTime) { }
124
- onFixedUpdate(_deltaTime) { }
125
- onLateUpdate(_deltaTime) { }
126
- onFrameEnd() { }
128
+ onStart() {
129
+ // Optional lifecycle hook for subclasses.
130
+ }
131
+ onUpdate(_deltaTime) {
132
+ // Optional lifecycle hook for subclasses.
133
+ }
134
+ onFixedUpdate(_deltaTime) {
135
+ // Optional lifecycle hook for subclasses.
136
+ }
137
+ onLateUpdate(_deltaTime) {
138
+ // Optional lifecycle hook for subclasses.
139
+ }
140
+ onFrameEnd() {
141
+ // Optional lifecycle hook for subclasses.
142
+ }
127
143
  /**
128
144
  * Starts a coroutine owned by this component.
129
145
  * @param coroutine - Coroutine iterator to start.
@@ -295,15 +311,17 @@ class FixedUpdateTask {
295
311
  }
296
312
  if (!EDITOR_NOT_IN_PREVIEW) {
297
313
  const fixedUpdatePriority = TaskPriority.before(TaskPriority.predefined.componentsLateUpdate);
314
+ const coroutineUpdateTask = new CoroutineUpdateTask();
315
+ const fixedUpdateTask = new FixedUpdateTask();
298
316
  addFrameTask({
299
- thisArg: new CoroutineUpdateTask(),
317
+ thisArg: coroutineUpdateTask,
300
318
  priority: TaskPriority.between(fixedUpdatePriority, TaskPriority.predefined.componentsLateUpdate),
301
- fn: CoroutineUpdateTask.prototype.update,
319
+ fn: coroutineUpdateTask.update.bind(coroutineUpdateTask),
302
320
  });
303
321
  addFrameTask({
304
- thisArg: new FixedUpdateTask(),
322
+ thisArg: fixedUpdateTask,
305
323
  priority: fixedUpdatePriority,
306
- fn: FixedUpdateTask.prototype.update,
324
+ fn: fixedUpdateTask.update.bind(fixedUpdateTask),
307
325
  });
308
326
  addFrameTask({
309
327
  thisArg: undefined,
@@ -84,13 +84,13 @@ export declare function waitUntil(predicate: CoroutinePredicate): CoroutineInstr
84
84
  */
85
85
  export declare function waitWhile(predicate: CoroutinePredicate): CoroutineInstruction;
86
86
  export declare class CoroutineRunner {
87
+ get frame(): number;
88
+ get deltaTime(): number;
89
+ get empty(): boolean;
87
90
  start(coroutine: CoroutineIterator, opts?: StartCoroutineOptions): Coroutine;
88
91
  update(deltaTime: number): void;
89
92
  stop(handle: Coroutine): void;
90
93
  stopAll(): void;
91
- get frame(): number;
92
- get deltaTime(): number;
93
- get empty(): boolean;
94
94
  private _records;
95
95
  private _frame;
96
96
  private _deltaTime;
@@ -52,6 +52,15 @@ export function waitWhile(predicate) {
52
52
  };
53
53
  }
54
54
  export class CoroutineRunner {
55
+ get frame() {
56
+ return this._frame;
57
+ }
58
+ get deltaTime() {
59
+ return this._deltaTime;
60
+ }
61
+ get empty() {
62
+ return this._records.length === 0;
63
+ }
55
64
  start(coroutine, opts) {
56
65
  const record = new CoroutineRecord(this, coroutine, opts);
57
66
  this._records.push(record);
@@ -89,15 +98,6 @@ export class CoroutineRunner {
89
98
  this._endPruneDeferral();
90
99
  }
91
100
  }
92
- get frame() {
93
- return this._frame;
94
- }
95
- get deltaTime() {
96
- return this._deltaTime;
97
- }
98
- get empty() {
99
- return this._records.length === 0;
100
- }
101
101
  _records = [];
102
102
  _frame = 0;
103
103
  _deltaTime = 0;
@@ -191,6 +191,7 @@ class CoroutineRecord {
191
191
  _done = false;
192
192
  _executing = false;
193
193
  _stopping = false;
194
+ _onAbort = undefined;
194
195
  _advance(frame) {
195
196
  let result;
196
197
  this._executing = true;
@@ -273,6 +274,5 @@ class CoroutineRecord {
273
274
  this._signal.removeEventListener('abort', this._onAbort);
274
275
  this._onAbort = undefined;
275
276
  }
276
- _onAbort = undefined;
277
277
  }
278
278
  //# sourceMappingURL=coroutine.js.map
@@ -6,7 +6,7 @@ export declare const TaskPriority: {
6
6
  after(priority: number): number;
7
7
  between(a: number, b: number): number;
8
8
  };
9
- interface Task<TThis = any> {
9
+ interface Task<TThis> {
10
10
  fn: (this: TThis, deltaTime: number) => void;
11
11
  thisArg: TThis;
12
12
  priority: number;
@@ -20,7 +20,10 @@ class TaskCluster {
20
20
  return false;
21
21
  }
22
22
  this._tasks.push({
23
- ...task,
23
+ fn: task.fn,
24
+ thisArg: task.thisArg,
25
+ priority: task.priority,
26
+ execute: (deltaTime) => task.fn.call(task.thisArg, deltaTime),
24
27
  });
25
28
  this._tasks.sort((a, b) => b.priority - a.priority);
26
29
  return true;
@@ -35,7 +38,7 @@ class TaskCluster {
35
38
  }
36
39
  execute(deltaTime) {
37
40
  for (const task of this._tasks) {
38
- task.fn.call(task.thisArg, deltaTime);
41
+ task.execute(deltaTime);
39
42
  }
40
43
  }
41
44
  _tasks = [];
@@ -1,13 +1,13 @@
1
1
  import { Bounds2D } from '@cyclonium/math/bounds-2d';
2
- import { applyLegacyDecorators, serializable, editable } from "../export/legacy-decorator.js";
2
+ import { applyLegacyDecorators, stored, editable } from "../export/legacy-decorator.js";
3
3
  import { cycloBuiltinClass } from "../decorator/legacy/legacy-decorator.js";
4
4
  export * from '@cyclonium/math/bounds-2d';
5
5
  applyLegacyDecorators(Bounds2D, {
6
6
  classDecorators: [cycloBuiltinClass('Bounds2D')],
7
7
  propertyDecorators: {
8
- // @ts-expect-error
9
- _min: [serializable, editable],
10
- _max: [serializable, editable],
8
+ // @ts-expect-error -- Legacy decorators intentionally target Bounds2D's private serialized fields.
9
+ _min: [stored, editable],
10
+ _max: [stored, editable],
11
11
  },
12
12
  });
13
13
  //# sourceMappingURL=bounds-2d.js.map
package/lib/math/vec2.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Vec2, v2 } from '@cyclonium/math/vec2';
2
2
  import { applyLegacyDecorators } from "../decorator/legacy/apply-legacy-decorators.js";
3
- import { editable, cycloBuiltinClass, serializable } from "../decorator/legacy/legacy-general-decorator.js";
3
+ import { editable, cycloBuiltinClass, stored } from "../decorator/legacy/legacy-general-decorator.js";
4
4
  import * as cc from 'cc';
5
5
  applyLegacyDecorators(Vec2, {
6
6
  classDecorators: [cycloBuiltinClass('Vec2')],
7
- // @ts-expect-error
7
+ // @ts-expect-error -- Legacy decorators require metadata for Vec2 fields declared by another package.
8
8
  propertyDecorators: {
9
- x: [serializable, editable],
10
- y: [serializable, editable],
9
+ x: [stored, editable],
10
+ y: [stored, editable],
11
11
  },
12
12
  });
13
13
  export { Vec2, v2 };
@@ -1,6 +1,5 @@
1
1
  export function assert(value, message) {
2
2
  if (!value) {
3
- debugger;
4
3
  throw new Error(`Assertion failed: ${message ?? '<no-message>'}`);
5
4
  }
6
5
  }
package/lib/utils/raw.js CHANGED
@@ -15,7 +15,9 @@ Raw = __decorate([
15
15
  cycloBuiltinClass('_Raw')
16
16
  ], Raw);
17
17
  export { Raw };
18
- export const dumpRaw = (target, propertyKey, descriptor) => {
18
+ export const dumpRaw = (_target, _propertyKey, descriptor) => {
19
+ // The getter is deliberately invoked later with the decorated instance as its receiver.
20
+ // eslint-disable-next-line @typescript-eslint/unbound-method
19
21
  const get = descriptor.get;
20
22
  if (get) {
21
23
  descriptor.get = function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonium/core",
3
- "version": "0.0.105",
3
+ "version": "1.0.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shrinktofit/cyclonium",