Skip to content

Commit f4ca814

Browse files
committed
refactor(entity): replace createComponentId with component function
Updated the code to replace the usage of createComponentId with the new component function across multiple test files. This change enhances consistency and aligns with the latest component management practices.
1 parent f7943e2 commit f4ca814

6 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/archetype.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { describe, expect, it } from "bun:test";
2-
import { Archetype, createComponentId, createEntityId, relation, type EntityId } from "./index";
2+
import { Archetype, component, createEntityId, relation, type EntityId } from "./index";
33

44
describe("Archetype", () => {
55
type Position = { x: number; y: number };
66
type Velocity = { x: number; y: number };
77

8-
const positionComponent = createComponentId<Position>(1);
9-
const velocityComponent = createComponentId<Velocity>(2);
8+
const positionComponent = component<Position>();
9+
const velocityComponent = component<Velocity>();
1010

1111
it("should create an archetype with component types", () => {
1212
const archetype = new Archetype([positionComponent, velocityComponent]);

src/query.example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { World, createComponentId } from "./index";
1+
import { World, component } from "./index";
22

33
// 定义组件类型
44
type Position = { x: number; y: number };
55
type Velocity = { x: number; y: number };
66
type Health = { value: number };
77

88
// 创建组件ID
9-
const positionComponent = createComponentId<Position>(1);
10-
const velocityComponent = createComponentId<Velocity>(2);
11-
const healthComponent = createComponentId<Health>(3);
9+
const positionComponent = component<Position>();
10+
const velocityComponent = component<Velocity>();
11+
const healthComponent = component<Health>();
1212

1313
// 创建世界
1414
const world = new World();

src/query.perf.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { World, createComponentId } from "./index";
1+
import { World, component } from "./index";
22

33
// 定义组件类型
44
type Position = { x: number; y: number };
55
type Velocity = { x: number; y: number };
66
type Health = { value: number };
77

88
// 创建组件ID
9-
const positionComponent = createComponentId<Position>(1);
10-
const velocityComponent = createComponentId<Velocity>(2);
11-
const healthComponent = createComponentId<Health>(3);
9+
const positionComponent = component<Position>();
10+
const velocityComponent = component<Velocity>();
11+
const healthComponent = component<Health>();
1212

1313
// 性能测试函数
1414
function performanceTest() {

src/query.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { describe, it, expect } from "bun:test";
22
import { World } from "./world";
33
import { Query } from "./query";
4-
import { createComponentId, relation, type EntityId } from "./entity";
4+
import { component, relation, type EntityId } from "./entity";
55

66
describe("Query", () => {
77
describe("Query Creation and Basic Functionality", () => {
88
type Position = { x: number; y: number };
99
type Velocity = { x: number; y: number };
1010
type Health = { value: number };
1111

12-
const positionComponent = createComponentId<Position>(1);
13-
const velocityComponent = createComponentId<Velocity>(2);
14-
const healthComponent = createComponentId<Health>(3);
12+
const positionComponent = component<Position>();
13+
const velocityComponent = component<Velocity>();
14+
const healthComponent = component<Health>();
1515

1616
it("should create a query and return matching entities", () => {
1717
const world = new World();

src/world.perf.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { describe, it, expect } from "bun:test";
22
import { World } from "./world";
3-
import { createComponentId } from "./entity";
3+
import { component } from "./entity";
44

55
describe("World Performance", () => {
66
it("should handle archetype creation efficiently", () => {
77
const world = new World();
88

99
// Create multiple component types
10-
const component1 = createComponentId<{}>(1);
11-
const component2 = createComponentId<{}>(2);
12-
const component3 = createComponentId<{}>(3);
10+
const component1 = component<{}>();
11+
const component2 = component<{}>();
12+
const component3 = component<{}>();
1313

1414
// Create entities with different component combinations
1515
const startTime = performance.now();
@@ -40,9 +40,9 @@ describe("World Performance", () => {
4040
type Velocity = { x: number; y: number };
4141
type Health = { value: number };
4242

43-
const positionComponent = createComponentId<Position>(1);
44-
const velocityComponent = createComponentId<Velocity>(2);
45-
const healthComponent = createComponentId<Health>(3);
43+
const positionComponent = component<Position>();
44+
const velocityComponent = component<Velocity>();
45+
const healthComponent = component<Health>();
4646

4747
// Create many entities
4848
for (let i = 0; i < 1000; i++) {

src/world.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "bun:test";
2-
import { createComponentId, createEntityId, relation, type EntityId } from "./entity";
2+
import { component, createEntityId, relation, type EntityId } from "./entity";
33
import { World } from "./world";
44

55
describe("World", () => {
@@ -37,8 +37,8 @@ describe("World", () => {
3737
type Position = { x: number; y: number };
3838
type Velocity = { x: number; y: number };
3939

40-
const positionComponent = createComponentId<Position>(1);
41-
const velocityComponent = createComponentId<Velocity>(2);
40+
const positionComponent = component<Position>();
41+
const velocityComponent = component<Velocity>();
4242

4343
it("should add components to entities", () => {
4444
const world = new World();
@@ -230,8 +230,8 @@ describe("World", () => {
230230
type Position = { x: number; y: number };
231231
type Velocity = { x: number; y: number };
232232

233-
const positionComponent = createComponentId<Position>(1);
234-
const velocityComponent = createComponentId<Velocity>(2);
233+
const positionComponent = component<Position>();
234+
const velocityComponent = component<Velocity>();
235235

236236
it("should query entities with specific components", () => {
237237
const world = new World();
@@ -330,8 +330,8 @@ describe("World", () => {
330330
const world = new World();
331331

332332
// Create component IDs
333-
const positionComponent = createComponentId<{ x: number; y: number }>(1);
334-
const followsComponent = createComponentId<void>(2);
333+
const positionComponent = component<{ x: number; y: number }>();
334+
const followsComponent = component<void>();
335335

336336
// Create entities
337337
const entity1 = world.createEntity(); // This will be followed
@@ -418,8 +418,8 @@ describe("World", () => {
418418
type Position = { x: number; y: number };
419419
type Velocity = { x: number; y: number };
420420

421-
const positionComponent = createComponentId<Position>(1);
422-
const velocityComponent = createComponentId<Velocity>(2);
421+
const positionComponent = component<Position>();
422+
const velocityComponent = component<Velocity>();
423423

424424
it("should trigger component added hooks", () => {
425425
const world = new World();
@@ -578,7 +578,7 @@ describe("World", () => {
578578
describe("Wildcard Relation Hooks", () => {
579579
it("should trigger wildcard relation hooks for matching relation components", () => {
580580
const world = new World();
581-
const positionComponent = createComponentId<{ x: number; y: number }>(1);
581+
const positionComponent = component<{ x: number; y: number }>();
582582
const entity1 = world.createEntity();
583583
const entity2 = world.createEntity();
584584

@@ -622,8 +622,8 @@ describe("World", () => {
622622

623623
it("should not trigger wildcard relation hooks for non-matching components", () => {
624624
const world = new World();
625-
const positionComponent = createComponentId<{ x: number; y: number }>(1);
626-
const velocityComponent = createComponentId<{ vx: number; vy: number }>(2);
625+
const positionComponent = component<{ x: number; y: number }>();
626+
const velocityComponent = component<{ vx: number; vy: number }>();
627627
const entity1 = world.createEntity();
628628
const entity2 = world.createEntity();
629629

0 commit comments

Comments
 (0)