@cyclonium/2d 0.0.102 → 0.0.104

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.
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { MAX_ORDER_IN_LAYER, MIN_ORDER_IN_LAYER, SortableRenderer, computeLocalSortingKey, } from './sortable.js';
1
+ export { MAX_ORDER_IN_LAYER, MIN_ORDER_IN_LAYER, SortableRenderer, SortingTreeGroup, computeLocalSortingKey, } from './sortable.js';
2
2
  export { SortSettings } from './sort-settings.js';
3
3
  export { SortingGroup } from './sorting-group.component.js';
4
4
  export { SortingLayer } from './sorting-layer.js';
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { MAX_ORDER_IN_LAYER, MIN_ORDER_IN_LAYER, SortableRenderer, computeLocalSortingKey, } from './sortable.js';
1
+ export { MAX_ORDER_IN_LAYER, MIN_ORDER_IN_LAYER, SortableRenderer, SortingTreeGroup, computeLocalSortingKey, } from './sortable.js';
2
2
  export { SortSettings } from './sort-settings.js';
3
3
  export { SortingGroup } from './sorting-group.component.js';
4
4
  export { SortingLayer } from './sorting-layer.js';
@@ -1,5 +1,4 @@
1
- import { SortableRenderer } from './sortable.js';
2
- import type { SortingGroup } from './sorting-group.component.js';
1
+ import { type SortableRenderer, type SortingTreeGroup } from './sortable.js';
3
2
  export declare class SortSettings {
4
3
  get sortingLayer(): number;
5
4
  set sortingLayer(value: number);
@@ -7,7 +6,7 @@ export declare class SortSettings {
7
6
  set orderInLayer(value: number);
8
7
  get connected(): boolean;
9
8
  get sortingKey(): number;
10
- connect(sortableRenderer: SortableRenderer | SortingGroup): void;
9
+ connect(sortableRenderer: SortableRenderer | SortingTreeGroup): void;
11
10
  disconnect(): void;
12
11
  private _sortingLayer;
13
12
  private _orderInLayer;
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { cycloClass, editable, idem, designType, serializable } from '@cyclonium/core/legacy-decorator';
8
8
  import { CCInteger } from 'cc';
9
- import { MIN_ORDER_IN_LAYER, MAX_ORDER_IN_LAYER, SortableRenderer } from './sortable.js';
9
+ import { MIN_ORDER_IN_LAYER, MAX_ORDER_IN_LAYER } from './sortable.js';
10
10
  import { SortingLayer } from './sorting-layer.js';
11
11
  import { SortingTreeNode } from './sorting-tree.js';
12
12
  let SortSettings = class SortSettings {
package/lib/sortable.d.ts CHANGED
@@ -10,6 +10,15 @@ export declare namespace SortableRenderer {
10
10
  }
11
11
  function is(component: Component): component is SortableRenderer;
12
12
  }
13
+ export interface SortingTreeGroup extends Component {
14
+ readonly [SortingTreeGroup.Tags.sortSettings]: SortSettings;
15
+ }
16
+ export declare namespace SortingTreeGroup {
17
+ namespace Tags {
18
+ const sortSettings: unique symbol;
19
+ }
20
+ function is(component: Component): component is SortingTreeGroup;
21
+ }
13
22
  export declare const MIN_ORDER_IN_LAYER: number;
14
23
  export declare const MAX_ORDER_IN_LAYER: number;
15
24
  export declare function computeLocalSortingKey(sortSettings: SortSettings): number;
package/lib/sortable.js CHANGED
@@ -11,6 +11,19 @@ export var SortableRenderer;
11
11
  }
12
12
  SortableRenderer.is = is;
13
13
  })(SortableRenderer || (SortableRenderer = {}));
14
+ // eslint-disable-next-line @typescript-eslint/no-namespace
15
+ export var SortingTreeGroup;
16
+ (function (SortingTreeGroup) {
17
+ // eslint-disable-next-line @typescript-eslint/no-namespace
18
+ let Tags;
19
+ (function (Tags) {
20
+ Tags.sortSettings = Symbol('isSortingTreeGroup');
21
+ })(Tags = SortingTreeGroup.Tags || (SortingTreeGroup.Tags = {}));
22
+ function is(component) {
23
+ return Tags.sortSettings in component;
24
+ }
25
+ SortingTreeGroup.is = is;
26
+ })(SortingTreeGroup || (SortingTreeGroup = {}));
14
27
  const MAX_ORDER_IN_LAYER_POW = 16;
15
28
  export const MIN_ORDER_IN_LAYER = -(2 ** (MAX_ORDER_IN_LAYER_POW - 1));
16
29
  export const MAX_ORDER_IN_LAYER = 2 ** (MAX_ORDER_IN_LAYER_POW - 1);
@@ -1,7 +1,9 @@
1
1
  import { CycloComponent } from '@cyclonium/core/framework';
2
+ import { SortingTreeGroup } from './sortable.js';
2
3
  import { SortSettings } from './sort-settings.js';
3
- export declare class SortingGroup extends CycloComponent {
4
+ export declare class SortingGroup extends CycloComponent implements SortingTreeGroup {
4
5
  get sortSettings(): SortSettings;
6
+ get [SortingTreeGroup.Tags.sortSettings](): SortSettings;
5
7
  protected onDestroy(): void;
6
8
  protected onEnabled(): void;
7
9
  protected onDisabled(): void;
@@ -7,11 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  import { CycloComponent } from '@cyclonium/core/framework';
9
9
  import { editable, executeInEditMode, cycloClass, serializable } from '@cyclonium/core/legacy-decorator';
10
+ import { SortingTreeGroup } from './sortable.js';
10
11
  import { SortSettings } from './sort-settings.js';
11
12
  let SortingGroup = class SortingGroup extends CycloComponent {
12
13
  get sortSettings() {
13
14
  return this._sortSettings;
14
15
  }
16
+ get [SortingTreeGroup.Tags.sortSettings]() {
17
+ return this._sortSettings;
18
+ }
15
19
  onDestroy() {
16
20
  this._sortSettings.disconnect();
17
21
  }
@@ -1,9 +1,9 @@
1
- import { SortingGroup } from './sorting-group.component.js';
2
- import { SortableRenderer } from './sortable.js';
1
+ import { SortableRenderer, SortingTreeGroup } from './sortable.js';
2
+ type SortingTreeComponent = SortingTreeGroup | SortableRenderer;
3
3
  export declare class SortingTreeNode {
4
4
  private readonly _component;
5
5
  private readonly _treeNodeMap;
6
- static create(component: SortingGroup | SortableRenderer): SortingTreeNode;
6
+ static create(component: SortingTreeComponent): SortingTreeNode;
7
7
  get sortingKeyStart(): number;
8
8
  destroy(): void;
9
9
  update(): void;
@@ -13,6 +13,7 @@ export declare class SortingTreeNode {
13
13
  private static _computeLCA;
14
14
  private static _computeLocalSortingKey;
15
15
  private static _compareLocalSortingKey;
16
+ private static _getSortingGroup;
16
17
  private static _ensureSceneSortingRecord;
17
18
  private static _getOrCreateParent;
18
19
  private static _getOrCreateNode;
@@ -35,4 +36,5 @@ export declare class SortingTreeNode {
35
36
  private _updateChildRangeSlightly;
36
37
  private _updateChildFrom;
37
38
  }
39
+ export {};
38
40
  //# sourceMappingURL=sorting-tree.d.ts.map
@@ -1,9 +1,7 @@
1
- import { Node, Scene } from 'cc';
2
- import { SortingGroup } from './sorting-group.component.js';
3
1
  import { assert } from '@cyclonium/core/utils';
4
2
  import { logger } from '@cyclonium/core/log';
5
3
  import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
6
- import { computeLocalSortingKey, SortableRenderer } from './sortable.js';
4
+ import { computeLocalSortingKey, SortableRenderer, SortingTreeGroup } from './sortable.js';
7
5
  const ENABLE_SORTING_TREE_DEBUG = false && !EDITOR_NOT_IN_PREVIEW;
8
6
  const debugLog = ENABLE_SORTING_TREE_DEBUG
9
7
  ? (() => {
@@ -143,6 +141,9 @@ export class SortingTreeNode {
143
141
  static _compareLocalSortingKey(a, b) {
144
142
  return this._computeLocalSortingKey(a) - this._computeLocalSortingKey(b);
145
143
  }
144
+ static _getSortingGroup(node) {
145
+ return node.components.find(SortingTreeGroup.is);
146
+ }
146
147
  static _ensureSceneSortingRecord(component) {
147
148
  const scene = component.node.scene;
148
149
  let sceneSortingRecord = this._sceneSortingRecordMap.get(scene);
@@ -182,9 +183,9 @@ export class SortingTreeNode {
182
183
  return sceneSortingRecord;
183
184
  }
184
185
  static _getOrCreateParent(sceneSortingRecord, component) {
185
- const startSceneNode = component instanceof SortingGroup ? component.node.parent : component.node;
186
+ const startSceneNode = SortingTreeGroup.is(component) ? component.node.parent : component.node;
186
187
  for (let currentNode = startSceneNode; currentNode; currentNode = currentNode.parent) {
187
- const sortingGroup = currentNode.getComponent(SortingGroup);
188
+ const sortingGroup = this._getSortingGroup(currentNode);
188
189
  if (sortingGroup && sortingGroup.enabledInHierarchy) {
189
190
  const sortingTreeNode = this._getOrCreateNode(sceneSortingRecord, sortingGroup);
190
191
  return sortingTreeNode;
@@ -214,7 +215,7 @@ export class SortingTreeNode {
214
215
  const newSortingTreeNode = this._createComponentSortingTreeNode(sceneSortingRecord, component);
215
216
  parentTreeNode._addChildSlightly(newSortingTreeNode);
216
217
  SortingTreeNode._queueUpdate(sceneSortingRecord, parentTreeNode);
217
- if (component instanceof SortingGroup) {
218
+ if (SortingTreeGroup.is(component)) {
218
219
  debugLog?.log(`[NOTICE] Creating subtrees from ${component.name} top-to-bottom`);
219
220
  this._constructSubTree(sceneSortingRecord, newSortingTreeNode, component.node);
220
221
  }
@@ -251,7 +252,7 @@ export class SortingTreeNode {
251
252
  for (const childSceneNode of sceneNode.children) {
252
253
  // If child scene node is a sorting group, then itself is our child,
253
254
  // but its child scene nodes are not our children.
254
- const childSortingGroup = childSceneNode.getComponent(SortingGroup);
255
+ const childSortingGroup = this._getSortingGroup(childSceneNode);
255
256
  if (childSortingGroup && childSortingGroup.enabledInHierarchy) {
256
257
  let childTreeNode = sceneSortingRecord.treeNodeMap.get(childSortingGroup);
257
258
  if (childTreeNode) {
@@ -291,11 +292,11 @@ export class SortingTreeNode {
291
292
  constructor(_component, _treeNodeMap) {
292
293
  this._component = _component;
293
294
  this._treeNodeMap = _treeNodeMap;
294
- this._sortSettings = _component instanceof SortingGroup
295
- ? _component.sortSettings
296
- : _component
297
- ? _component[SortableRenderer.Tags.sortSettings]
298
- : undefined;
295
+ this._sortSettings = _component
296
+ ? SortingTreeGroup.is(_component)
297
+ ? _component[SortingTreeGroup.Tags.sortSettings]
298
+ : _component[SortableRenderer.Tags.sortSettings]
299
+ : undefined;
299
300
  }
300
301
  _parent = undefined;
301
302
  _children = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonium/2d",
3
- "version": "0.0.102",
3
+ "version": "0.0.104",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shrinktofit/cyclonium",
@@ -21,8 +21,8 @@
21
21
  }
22
22
  },
23
23
  "peerDependencies": {
24
- "@cyclonium/core": "0.0.102",
25
- "@cyclonium/editor": "0.0.102"
24
+ "@cyclonium/core": "0.0.104",
25
+ "@cyclonium/editor": "0.0.104"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@cyclonium/editor": {
@@ -36,7 +36,7 @@
36
36
  "typescript": "^6.0.2",
37
37
  "vitest": "^4.1.5",
38
38
  "@cyclonium/cc-test": "0.0.102",
39
- "@cyclonium/editor": "0.0.102",
39
+ "@cyclonium/editor": "0.0.104",
40
40
  "@cyclonium/workflow": "0.0.100",
41
41
  "@cyclonium/types-cc": "0.0.100"
42
42
  },