Skip to content

Commit fa9a922

Browse files
authored
Merge pull request #7 from mdingena/support-component-versioning
Support component versioning
2 parents 19d98a0 + 196dc8f commit fa9a922

24 files changed

+494
-294
lines changed

src/components/ComponentVersion.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const ComponentVersion = new Map([
22
[1908922854, 1],
33
[159391088, 1],
44
[3801256786, 3],
5+
[1198377566, 1],
56
[272188517, 1],
67
[237360636, 2],
78
[391977879, 2],
@@ -26,6 +27,7 @@ export const ComponentVersion = new Map([
2627
[276353327, 1],
2728
[1823429789, 1],
2829
[3402094521, 1],
30+
[2363255897, 1],
2931
[751359624, 1],
3032
[3608460219, 1],
3133
[1390862571, 1],
@@ -36,7 +38,7 @@ export const ComponentVersion = new Map([
3638
[1871432223, 1],
3739
[3373651539, 1],
3840
[654225716, 1],
39-
[1454441398, 1],
41+
[1454441398, 2],
4042
[3704379512, 1],
4143
[3257374625, 1],
4244
[2262399392, 2],
@@ -121,6 +123,7 @@ export const ComponentVersion = new Map([
121123
[1454955908, 1],
122124
[788405183, 1],
123125
[2563567105, 2],
126+
[2971871217, 1],
124127
[766675725, 1],
125128
[2882590463, 1],
126129
[1499506132, 1],
@@ -132,7 +135,7 @@ export const ComponentVersion = new Map([
132135
[2629079826, 1],
133136
[963907309, 1],
134137
[1753993206, 2],
135-
[1923918202, 2],
138+
[1923918202, 3],
136139
[1776498660, 3],
137140
[3638500874, 2],
138141
[1098050191, 3],

src/components/transcoders/basicDecay.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ export type BasicDecay = {
88
timelineEntry?: number;
99
};
1010

11-
export const decode = (reader: BinaryReader): BasicDecay => ({
12-
isDisabled: reader.boolean(),
13-
timelineEntry: reader.uLong()
14-
});
11+
export const decode = (reader: BinaryReader, version: number): BasicDecay => {
12+
const component: BasicDecay = {};
13+
14+
if (version >= 3) component.isDisabled = reader.boolean();
15+
16+
if (version >= 3) component.timelineEntry = reader.uLong();
17+
18+
return component;
19+
};
1520

1621
export const encode = ({ isDisabled = true, timelineEntry = HUNDRED_YEARS_TICKS }: BasicDecay): string => {
1722
const writer = createBinaryWriter();

src/components/transcoders/durabilityModule.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ export type DurabilityModule = {
55
integrity?: number;
66
};
77

8-
export const decode = (reader: BinaryReader): DurabilityModule => ({
9-
integrity: reader.float()
10-
});
8+
export const decode = (reader: BinaryReader, version: number): DurabilityModule => {
9+
const component: DurabilityModule = {};
10+
11+
if (version >= 1) component.integrity = reader.float();
12+
13+
return component;
14+
};
1115

1216
export const encode = ({ integrity = 1 }: DurabilityModule): string => {
1317
const writer = createBinaryWriter();

src/components/transcoders/fire.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ export type Fire = {
55
fuelConsumptionProgress?: number;
66
};
77

8-
export const decode = (reader: BinaryReader): Fire => ({
9-
fuelConsumptionProgress: reader.float()
10-
});
8+
export const decode = (reader: BinaryReader, version: number): Fire => {
9+
const component: Fire = {};
10+
11+
if (version >= 2) component.fuelConsumptionProgress = reader.float();
12+
13+
return component;
14+
};
1115

1216
export const encode = ({ fuelConsumptionProgress = 0 }: Fire): string => {
1317
const writer = createBinaryWriter();

src/components/transcoders/fuse.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ export type Fuse = {
77
currentFuseAmount?: number;
88
};
99

10-
export const decode = (reader: BinaryReader): Fuse => ({
11-
isFinished: reader.boolean(),
12-
isLit: reader.boolean(),
13-
currentFuseAmount: reader.float()
14-
});
10+
export const decode = (reader: BinaryReader, version: number): Fuse => {
11+
const component: Fuse = {};
12+
13+
if (version >= 1) component.isFinished = reader.boolean();
14+
15+
if (version >= 1) component.isLit = reader.boolean();
16+
17+
if (version >= 1) component.currentFuseAmount = reader.float();
18+
19+
return component;
20+
};
1521

1622
export const encode = ({ isFinished = false, isLit = false, currentFuseAmount = 1 }: Fuse): string => {
1723
const writer = createBinaryWriter();

src/components/transcoders/heatSourceBase.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ export type HeatSourceBase = {
99
time?: number;
1010
};
1111

12-
export const decode = (reader: BinaryReader): HeatSourceBase => ({
13-
isLit: reader.boolean(),
14-
progress: reader.float(),
15-
time: reader.uLong()
16-
});
12+
export const decode = (reader: BinaryReader, version: number): HeatSourceBase => {
13+
const component: HeatSourceBase = {};
14+
15+
if (version >= 1) component.isLit = reader.boolean();
16+
17+
if (version >= 1) component.progress = reader.float();
18+
19+
if (version >= 1) component.time = reader.uLong();
20+
21+
return component;
22+
};
1723

1824
export const encode = ({ isLit = true, progress = 0, time = HUNDRED_YEARS_TICKS }: HeatSourceBase): string => {
1925
const writer = createBinaryWriter();

src/components/transcoders/liquidContainer.ts

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -33,65 +33,72 @@ export type LiquidContainer = {
3333
customData?: null | CustomData;
3434
};
3535

36-
export const decode = (reader: BinaryReader): LiquidContainer => {
37-
const result: LiquidContainer = {
38-
canAddTo: reader.boolean(),
39-
canRemoveFrom: reader.boolean(),
40-
contentLevel: reader.int(),
41-
hasContent: reader.boolean(),
42-
isCustom: reader.boolean(),
43-
presetHash: reader.uInt()
44-
};
45-
46-
/* Get custom data */
47-
const isNull = reader.boolean();
48-
if (isNull) {
49-
result.customData = null;
50-
} else {
51-
const customData = {
52-
color: {
53-
r: reader.float(),
54-
g: reader.float(),
55-
b: reader.float(),
56-
a: reader.float()
57-
},
58-
isConsumableThroughSkin: reader.boolean(),
59-
visualDataHash: reader.uInt()
60-
};
61-
62-
/* Get the effects array. */
63-
const effectsLength = reader.uInt();
64-
const effects: Effect[] = [];
65-
for (let index = 0; index < effectsLength; ++index) {
66-
/* Skip effect if is null. */
67-
const isNull = reader.boolean();
68-
if (isNull) {
69-
effects.push(null);
70-
continue;
36+
export const decode = (reader: BinaryReader, version: number): LiquidContainer => {
37+
const component: LiquidContainer = {};
38+
39+
if (version >= 1) component.canAddTo = reader.boolean();
40+
41+
if (version >= 1) component.canRemoveFrom = reader.boolean();
42+
43+
if (version >= 1) component.contentLevel = reader.int();
44+
45+
if (version >= 1) component.hasContent = reader.boolean();
46+
47+
if (version >= 1) component.isCustom = reader.boolean();
48+
49+
if (version >= 1) component.presetHash = reader.uInt();
50+
51+
if (version >= 1) {
52+
/* Get custom data */
53+
const isNull = reader.boolean();
54+
if (isNull) {
55+
component.customData = null;
56+
} else {
57+
const customData = {
58+
color: {
59+
r: reader.float(),
60+
g: reader.float(),
61+
b: reader.float(),
62+
a: reader.float()
63+
},
64+
isConsumableThroughSkin: reader.boolean(),
65+
visualDataHash: reader.uInt()
66+
};
67+
68+
/* Get the effects array. */
69+
const effectsLength = reader.uInt();
70+
const effects: Effect[] = [];
71+
for (let index = 0; index < effectsLength; ++index) {
72+
/* Skip effect if is null. */
73+
const isNull = reader.boolean();
74+
if (isNull) {
75+
effects.push(null);
76+
continue;
77+
}
78+
79+
effects.push({
80+
hash: reader.uInt(),
81+
strengthMultiplier: reader.float()
82+
});
7183
}
7284

73-
effects.push({
74-
hash: reader.uInt(),
75-
strengthMultiplier: reader.float()
76-
});
77-
}
85+
/* Get the food chunks array. */
86+
const foodChunksLength = reader.uInt();
87+
const foodChunks: FoodChunk[] = [];
88+
for (let index = 0; index < foodChunksLength; ++index) {
89+
foodChunks.push(reader.uInt());
90+
}
7891

79-
/* Get the food chunks array. */
80-
const foodChunksLength = reader.uInt();
81-
const foodChunks: FoodChunk[] = [];
82-
for (let index = 0; index < foodChunksLength; ++index) {
83-
foodChunks.push(reader.uInt());
92+
/* Append custom data to result. */
93+
component.customData = {
94+
...customData,
95+
effects,
96+
foodChunks
97+
};
8498
}
85-
86-
/* Append custom data to result. */
87-
result.customData = {
88-
...customData,
89-
effects,
90-
foodChunks
91-
};
9299
}
93100

94-
return result;
101+
return component;
95102
};
96103

97104
export const encode = ({

src/components/transcoders/networkRigidbody.ts

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,48 @@ export type NetworkRigidbody = {
2727
};
2828
};
2929

30-
export const decode = (reader: BinaryReader): NetworkRigidbody => ({
31-
position: {
32-
x: reader.float(),
33-
y: reader.float(),
34-
z: reader.float()
35-
},
36-
rotation: {
37-
x: reader.float(),
38-
y: reader.float(),
39-
z: reader.float(),
40-
w: reader.float()
41-
},
42-
isKinematic: reader.boolean(),
43-
isServerSleeping: reader.boolean(),
44-
velocity: {
45-
x: reader.float(),
46-
y: reader.float(),
47-
z: reader.float()
48-
},
49-
angularVelocity: {
50-
x: reader.float(),
51-
y: reader.float(),
52-
z: reader.float()
30+
export const decode = (reader: BinaryReader, version: number): NetworkRigidbody => {
31+
const component: NetworkRigidbody = {};
32+
33+
if (version >= 1) {
34+
component.position = {
35+
x: reader.float(),
36+
y: reader.float(),
37+
z: reader.float()
38+
};
39+
}
40+
41+
if (version >= 1) {
42+
component.rotation = {
43+
x: reader.float(),
44+
y: reader.float(),
45+
z: reader.float(),
46+
w: reader.float()
47+
};
5348
}
54-
});
49+
50+
if (version >= 1) component.isKinematic = reader.boolean();
51+
52+
if (version >= 1) component.isServerSleeping = reader.boolean();
53+
54+
if (version >= 1) {
55+
component.velocity = {
56+
x: reader.float(),
57+
y: reader.float(),
58+
z: reader.float()
59+
};
60+
}
61+
62+
if (version >= 1) {
63+
component.angularVelocity = {
64+
x: reader.float(),
65+
y: reader.float(),
66+
z: reader.float()
67+
};
68+
}
69+
70+
return component;
71+
};
5572

5673
export const encode = ({
5774
position = { x: 0, y: 0, z: 0 },

src/components/transcoders/physicalMaterialPart.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ export type PhysicalMaterialPart = {
66
materialHash?: number;
77
};
88

9-
export const decode = (reader: BinaryReader): PhysicalMaterialPart => ({
10-
materialHash: reader.uInt()
11-
});
9+
export const decode = (reader: BinaryReader, version: number): PhysicalMaterialPart => {
10+
const component: PhysicalMaterialPart = {};
11+
12+
if (version >= 1) component.materialHash = reader.uInt();
13+
14+
return component;
15+
};
1216

1317
export const encode = ({ materialHash = PhysicalMaterialPartHash.Iron }: PhysicalMaterialPart): string => {
1418
const writer = createBinaryWriter();

0 commit comments

Comments
 (0)