Skip to content

Commit 9fd9bf3

Browse files
committed
Add Fuse component
1 parent 971db37 commit 9fd9bf3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type ComponentName = keyof typeof transcoders;
55
export type BasicDecay = transcoders.BasicDecay.BasicDecay;
66
export type DurabilityModule = transcoders.DurabilityModule.DurabilityModule;
77
export type Fire = transcoders.Fire.Fire;
8+
export type Fuse = transcoders.Fuse.Fuse;
89
export type HeatSourceBase = transcoders.HeatSourceBase.HeatSourceBase;
910
export type LiquidContainer = transcoders.LiquidContainer.LiquidContainer;
1011
export type NetworkRigidbody = transcoders.NetworkRigidbody.NetworkRigidbody;
@@ -20,6 +21,7 @@ export type KnownComponent =
2021
| BasicDecay
2122
| DurabilityModule
2223
| Fire
24+
| Fuse
2325
| HeatSourceBase
2426
| LiquidContainer
2527
| NetworkRigidbody

src/components/transcoders/fuse.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ComponentHash } from '../../ComponentHash';
2+
import { BinaryReader, createBinaryWriter } from '../../utils';
3+
4+
export type Fuse = {
5+
isFinished?: boolean;
6+
isLit?: boolean;
7+
currentFuseAmount?: number;
8+
};
9+
10+
export const decode = (reader: BinaryReader): Fuse => ({
11+
isFinished: reader.boolean(),
12+
isLit: reader.boolean(),
13+
currentFuseAmount: reader.float()
14+
});
15+
16+
export const encode = ({ isFinished = false, isLit = false, currentFuseAmount = 1 }: Fuse): string => {
17+
const writer = createBinaryWriter();
18+
19+
/* Component hash. */
20+
writer.uInt(ComponentHash.Fuse);
21+
const hashBits = writer.flush();
22+
23+
/* Component data. */
24+
writer.boolean(isFinished);
25+
writer.boolean(isLit);
26+
writer.float(currentFuseAmount);
27+
const dataBits = writer.flush();
28+
29+
/* Component data length. */
30+
writer.uInt(dataBits.length);
31+
const sizeBits = writer.flush();
32+
33+
/* Return encoded component. */
34+
writer.binary(hashBits);
35+
writer.binary(sizeBits);
36+
writer.binary(dataBits);
37+
38+
return writer.flush();
39+
};

src/components/transcoders/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * as BasicDecay from './basicDecay';
22
export * as DurabilityModule from './durabilityModule';
33
export * as Fire from './fire';
4+
export * as Fuse from './fuse';
45
export * as HeatSourceBase from './heatSourceBase';
56
export * as LiquidContainer from './liquidContainer';
67
export * as NetworkRigidbody from './networkRigidbody';

0 commit comments

Comments
 (0)