Skip to content

Commit 28bae66

Browse files
authored
feat: new class DomainOption and lifecycle Update (#9)
* feat: new class DomainOption and lifecycle Update * chore: update README, some warnninng * chore: add @NetVarr example for unit test * chore: add dirty-data-class for unit test * feat: add quick accessor for IComp * refactor: comp-* * refactor: handle class 'Domain' ref in class 'Entity'
1 parent c6eac24 commit 28bae66

25 files changed

+2376
-2155
lines changed

.husky/.gitignore

-1
This file was deleted.

.husky/commit-msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn commitlint --edit $1
4+
npx commitlint --edit $1

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn lint-staged
4+
npx lint-staged

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ For [example](https://netcodejs.github.io/netcode/example/) site, you can view c
2323
Component is not class in the real sense. All class with `@NetComp(className: string)` will be collectively referred to as component.You should mark the property that need synchronize with `@NetVar(type: DataType)` and `@NetArr(type: DataType)` for array.
2424

2525
```typescript
26-
@NetComp("Vector")
27-
class VectorComp {
26+
@NetSerable("Vector")
27+
class Vector {
2828
@NetVar(DataType.float)
2929
x: number = 0;
3030
@NetVar(DataType.float)
@@ -37,10 +37,10 @@ class VectorComp {
3737
It allows for nested use.
3838

3939
```typescript
40-
@NetComp("Transform")
41-
class TransformComp {
42-
@NetVar(VectorComp)
43-
position: VectorComp = new VectorComp();
40+
@NetSerable("Transform")
41+
class TransformComp extends IComp {
42+
@NetVar(Vector)
43+
position: Vector = new Vector();
4444
@NetVar(DataType.float)
4545
rotation: number = 0;
4646
}
@@ -51,7 +51,8 @@ class TransformComp {
5151
Component also support rpc. When tagged with `@NetRpc(type: RpcType)`, the method could convert to networking function.
5252

5353
```typescript
54-
class TransformComp {
54+
@NetSerable("Transform")
55+
class TransformComp extends IComp {
5556
// ... as above
5657
@NetRpc(RpcType.CLIENT)
5758
move(x: number, y: number) {
@@ -66,12 +67,11 @@ class TransformComp {
6667
In netcode, entity is unit node.It can include and manage a series of _components_. It can be registed by _Domain_. For usage refer to Cocos(Node-Component) or unity(GameObject-Monobehaviour).
6768

6869
```typescript
69-
const people = new Entity();
70-
const transAdd = people.add(TransformComp);
70+
const people = new Entity(new TransformComp());
7171
// It is the same as transAdd above.
7272
const transGet = people.get(TransformComp);
7373
people.has(TransformComp); // It will be true;
74-
trans.x = 123;
74+
trans.position.x = 123;
7575
```
7676

7777
Otherwises, it provides a more accessible way that use property `$comps` after `add()`.

babel.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
],
66
plugins: [
77
["@babel/plugin-proposal-decorators", { legacy: true }],
8-
["@babel/plugin-proposal-class-properties", { loose: true }],
8+
["@babel/proposal-class-properties", { legacy: true }],
9+
"babel-plugin-parameter-decorator",
910
],
1011
};

0 commit comments

Comments
 (0)