Skip to content

Commit 4e4cc27

Browse files
committed
Clean up component types
1 parent d96d961 commit 4e4cc27

14 files changed

+78
-64
lines changed

src/components/index.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
import * as transcoders from './transcoders';
22

3-
export { ComponentVersion } from './ComponentVersion';
4-
53
export type ComponentName = keyof typeof transcoders;
64

5+
export type BasicDecay = transcoders.BasicDecay.BasicDecay;
6+
export type DurabilityModule = transcoders.DurabilityModule.DurabilityModule;
7+
export type HeatSourceBase = transcoders.HeatSourceBase.HeatSourceBase;
8+
export type LiquidContainer = transcoders.LiquidContainer.LiquidContainer;
9+
export type NetworkRigidbody = transcoders.NetworkRigidbody.NetworkRigidbody;
10+
export type PhysicalMaterialPart = transcoders.PhysicalMaterialPart.PhysicalMaterialPart;
11+
export type Pickup = transcoders.Pickup.Pickup;
12+
export type PickupDock = transcoders.PickupDock.PickupDock;
13+
export type PopulationSpawnArea = transcoders.PopulationSpawnArea.PopulationSpawnArea;
14+
export type SpawnArea = transcoders.SpawnArea.SpawnArea;
15+
export type StatManager = transcoders.StatManager.StatManager;
16+
export type WoodcutTree = transcoders.WoodcutTree.WoodcutTree;
17+
718
export type KnownComponent =
8-
| transcoders.BasicDecay.Component
9-
| transcoders.DurabilityModule.Component
10-
| transcoders.HeatSourceBase.Component
11-
| transcoders.LiquidContainer.Component
12-
| transcoders.NetworkRigidbody.Component
13-
| transcoders.PhysicalMaterialPart.Component
14-
| transcoders.Pickup.Component
15-
| transcoders.PickupDock.Component
16-
| transcoders.PopulationSpawnArea.Component
17-
| transcoders.SpawnArea.Component
18-
| transcoders.StatManager.Component
19-
| transcoders.WoodcutTree.Component;
19+
| BasicDecay
20+
| DurabilityModule
21+
| HeatSourceBase
22+
| LiquidContainer
23+
| NetworkRigidbody
24+
| PhysicalMaterialPart
25+
| Pickup
26+
| PickupDock
27+
| PopulationSpawnArea
28+
| SpawnArea
29+
| StatManager
30+
| WoodcutTree;
2031

2132
export type UnknownComponent = { hash: number; data: string };
2233

2334
export type Component = KnownComponent | UnknownComponent[];
2435

36+
export { ComponentVersion } from './ComponentVersion';
37+
2538
export { transcoders };

src/components/transcoders/basicDecay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { BinaryReader, createBinaryWriter } from '../../utils';
33

44
const HUNDRED_YEARS_TICKS = 31557600000000000;
55

6-
export type Component = {
6+
export type BasicDecay = {
77
isDisabled?: boolean;
88
timelineEntry?: number;
99
};
1010

11-
export const decode = (reader: BinaryReader): Component => ({
11+
export const decode = (reader: BinaryReader): BasicDecay => ({
1212
isDisabled: reader.boolean(),
1313
timelineEntry: reader.uLong()
1414
});
1515

16-
export const encode = ({ isDisabled = true, timelineEntry = HUNDRED_YEARS_TICKS }: Component): string => {
16+
export const encode = ({ isDisabled = true, timelineEntry = HUNDRED_YEARS_TICKS }: BasicDecay): string => {
1717
const writer = createBinaryWriter();
1818

1919
/* Component hash. */

src/components/transcoders/durabilityModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ComponentHash } from '../../ComponentHash';
22
import { BinaryReader, createBinaryWriter } from '../../utils';
33

4-
export type Component = {
4+
export type DurabilityModule = {
55
integrity?: number;
66
};
77

8-
export const decode = (reader: BinaryReader): Component => ({
8+
export const decode = (reader: BinaryReader): DurabilityModule => ({
99
integrity: reader.float()
1010
});
1111

12-
export const encode = ({ integrity = 1 }: Component): string => {
12+
export const encode = ({ integrity = 1 }: DurabilityModule): string => {
1313
const writer = createBinaryWriter();
1414

1515
/* Component hash. */

src/components/transcoders/heatSourceBase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { BinaryReader, createBinaryWriter } from '../../utils';
33

44
const HUNDRED_YEARS_TICKS = 31557600000000000;
55

6-
export type Component = {
6+
export type HeatSourceBase = {
77
isLit?: boolean;
88
progress?: number;
99
time?: number;
1010
};
1111

12-
export const decode = (reader: BinaryReader): Component => ({
12+
export const decode = (reader: BinaryReader): HeatSourceBase => ({
1313
isLit: reader.boolean(),
1414
progress: reader.float(),
1515
time: reader.uLong()
1616
});
1717

18-
export const encode = ({ isLit = true, progress = 0, time = HUNDRED_YEARS_TICKS }: Component): string => {
18+
export const encode = ({ isLit = true, progress = 0, time = HUNDRED_YEARS_TICKS }: HeatSourceBase): string => {
1919
const writer = createBinaryWriter();
2020

2121
/* Component hash. */

src/components/transcoders/liquidContainer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type CustomData = {
2323
foodChunks: FoodChunk[];
2424
};
2525

26-
export type Component = {
26+
export type LiquidContainer = {
2727
canAddTo?: boolean;
2828
canRemoveFrom?: boolean;
2929
contentLevel?: number;
@@ -33,8 +33,8 @@ export type Component = {
3333
customData?: null | CustomData;
3434
};
3535

36-
export const decode = (reader: BinaryReader): Component => {
37-
const result: Component = {
36+
export const decode = (reader: BinaryReader): LiquidContainer => {
37+
const result: LiquidContainer = {
3838
canAddTo: reader.boolean(),
3939
canRemoveFrom: reader.boolean(),
4040
contentLevel: reader.int(),
@@ -102,7 +102,7 @@ export const encode = ({
102102
isCustom = false,
103103
presetHash = 0,
104104
customData = null
105-
}: Component): string => {
105+
}: LiquidContainer): string => {
106106
const writer = createBinaryWriter();
107107

108108
/* Component hash. */

src/components/transcoders/networkRigidbody.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentHash } from '../../ComponentHash';
22
import { BinaryReader, createBinaryWriter } from '../../utils';
33

4-
export type Component = {
4+
export type NetworkRigidbody = {
55
position?: {
66
x: number;
77
y: number;
@@ -27,7 +27,7 @@ export type Component = {
2727
};
2828
};
2929

30-
export const decode = (reader: BinaryReader): Component => ({
30+
export const decode = (reader: BinaryReader): NetworkRigidbody => ({
3131
position: {
3232
x: reader.float(),
3333
y: reader.float(),
@@ -60,7 +60,7 @@ export const encode = ({
6060
isServerSleeping = false,
6161
velocity = { x: 0, y: 0, z: 0 },
6262
angularVelocity = { x: 0, y: 0, z: 0 }
63-
}: Component): string => {
63+
}: NetworkRigidbody): string => {
6464
const writer = createBinaryWriter();
6565

6666
/* Component hash. */

src/components/transcoders/physicalMaterialPart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { ComponentHash } from '../../ComponentHash';
22
import { PhysicalMaterialPartHash } from '../../PhysicalMaterialPartHash';
33
import { BinaryReader, createBinaryWriter } from '../../utils';
44

5-
export type Component = {
5+
export type PhysicalMaterialPart = {
66
materialHash?: number;
77
};
88

9-
export const decode = (reader: BinaryReader): Component => ({
9+
export const decode = (reader: BinaryReader): PhysicalMaterialPart => ({
1010
materialHash: reader.uInt()
1111
});
1212

13-
export const encode = ({ materialHash = PhysicalMaterialPartHash.Iron }: Component): string => {
13+
export const encode = ({ materialHash = PhysicalMaterialPartHash.Iron }: PhysicalMaterialPart): string => {
1414
const writer = createBinaryWriter();
1515

1616
/* Component hash. */

src/components/transcoders/pickup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ComponentHash } from '../../ComponentHash';
22
import { BinaryReader, createBinaryWriter } from '../../utils';
33

4-
export type Component = {
4+
export type Pickup = {
55
lastInteractorPlayerId?: number;
66
};
77

8-
export const decode = (reader: BinaryReader): Component => ({
8+
export const decode = (reader: BinaryReader): Pickup => ({
99
lastInteractorPlayerId: reader.int()
1010
});
1111

12-
export const encode = ({ lastInteractorPlayerId = 0 }: Component): string => {
12+
export const encode = ({ lastInteractorPlayerId = 0 }: Pickup): string => {
1313
const writer = createBinaryWriter();
1414

1515
/* Component hash. */

src/components/transcoders/pickupDock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { ComponentHash } from '../../ComponentHash';
22
import { BinaryReader, createBinaryWriter } from '../../utils';
33

4-
export type Component = {
4+
export type PickupDock = {
55
dockedTypeHash?: number;
66
quantity?: number;
77
childIndex?: number;
88
};
99

10-
export const decode = (reader: BinaryReader): Component => ({
10+
export const decode = (reader: BinaryReader): PickupDock => ({
1111
dockedTypeHash: reader.uInt(),
1212
quantity: reader.int(),
1313
childIndex: reader.int()
1414
});
1515

16-
export const encode = ({ dockedTypeHash = 0, quantity = 1, childIndex = 0 }: Component): string => {
16+
export const encode = ({ dockedTypeHash = 0, quantity = 1, childIndex = 0 }: PickupDock): string => {
1717
const writer = createBinaryWriter();
1818

1919
/* Component hash. */

src/components/transcoders/populationSpawnArea.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type PopulationSaveDataChild = {
77
pointIndex: number;
88
};
99

10-
export type Component = {
10+
export type PopulationSpawnArea = {
1111
definition?: number;
1212
isPopulationStarted?: boolean;
1313
children?: PopulationSaveDataChild[];
@@ -19,7 +19,7 @@ export type Component = {
1919
isOneOff?: boolean;
2020
};
2121

22-
export const decode = (reader: BinaryReader): Component => {
22+
export const decode = (reader: BinaryReader): PopulationSpawnArea => {
2323
const definition = reader.uInt();
2424
const isPopulationStarted = reader.boolean();
2525

@@ -63,7 +63,7 @@ export const encode = ({
6363
numberOfSpawnPoints = 40,
6464
startingPopulation = 5,
6565
isOneOff = false
66-
}: Component): string => {
66+
}: PopulationSpawnArea): string => {
6767
const writer = createBinaryWriter();
6868

6969
/* Component hash. */

src/components/transcoders/spawnArea.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ComponentHash } from '../../ComponentHash';
22
import { BinaryReader, createBinaryWriter } from '../../utils';
33

4-
export type Component = {
4+
export type SpawnArea = {
55
size?: number;
66
groundLayers?: number;
77
avoidLayers?: number;
88
isAligningNormal?: boolean;
99
maxAcceptableAngleDot?: number;
1010
};
1111

12-
export const decode = (reader: BinaryReader): Component => ({
12+
export const decode = (reader: BinaryReader): SpawnArea => ({
1313
size: reader.float(),
1414
groundLayers: reader.int(),
1515
avoidLayers: reader.int(),
@@ -23,7 +23,7 @@ export const encode = ({
2323
avoidLayers = 8721,
2424
isAligningNormal = false,
2525
maxAcceptableAngleDot = -1
26-
}: Component): string => {
26+
}: SpawnArea): string => {
2727
const writer = createBinaryWriter();
2828

2929
/* Component hash. */

src/components/transcoders/statManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type IndirectStatModifier = null | {
2626
modifiers: IndirectModifierSaveData[];
2727
};
2828

29-
export type Component = {
29+
export type StatManager = {
3030
stats?: Stat[];
3131
modifiers?: TimedModifier[];
3232
indirectStatModifiers?: IndirectStatModifier[];
3333
};
3434

35-
export const decode = (reader: BinaryReader): Component => {
35+
export const decode = (reader: BinaryReader): StatManager => {
3636
/* Get stats array. */
3737
const statsLength = reader.uInt();
3838
const stats: Stat[] = [];
@@ -105,7 +105,7 @@ export const decode = (reader: BinaryReader): Component => {
105105
return { stats, modifiers, indirectStatModifiers };
106106
};
107107

108-
export const encode = ({ stats = [], modifiers = [], indirectStatModifiers = [] }: Component): string => {
108+
export const encode = ({ stats = [], modifiers = [], indirectStatModifiers = [] }: StatManager): string => {
109109
const writer = createBinaryWriter();
110110

111111
/* Component hash. */

src/components/transcoders/woodcutTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { PresetHash } from '../../PresetHash';
33
import { SpeciesHash } from '../../SpeciesHash';
44
import { BinaryReader, createBinaryWriter } from '../../utils';
55

6-
export type Component = {
6+
export type WoodcutTree = {
77
presetHash?: 0 | PresetHash;
88
speciesHash?: SpeciesHash;
99
};
1010

11-
export const decode = (reader: BinaryReader): Component => ({
11+
export const decode = (reader: BinaryReader): WoodcutTree => ({
1212
presetHash: reader.uInt(),
1313
speciesHash: reader.uInt()
1414
});
1515

16-
export const encode = ({ presetHash = 0, speciesHash = SpeciesHash.Oak }: Component): string => {
16+
export const encode = ({ presetHash = 0, speciesHash = SpeciesHash.Oak }: WoodcutTree): string => {
1717
const writer = createBinaryWriter();
1818

1919
/* Component hash. */

src/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/**
22
* COMPONENTS
33
*/
4-
import * as components from './components/transcoders';
5-
export type BasicDecay = components.BasicDecay.Component;
6-
export type DurabilityModule = components.DurabilityModule.Component;
7-
export type HeatSourceBase = components.HeatSourceBase.Component;
8-
export type LiquidContainer = components.LiquidContainer.Component;
9-
export type NetworkRigidbody = components.NetworkRigidbody.Component;
10-
export type PhysicalMaterialPart = components.PhysicalMaterialPart.Component;
11-
export type Pickup = components.Pickup.Component;
12-
export type PickupDock = components.PickupDock.Component;
13-
export type PopulationSpawnArea = components.PopulationSpawnArea.Component;
14-
export type SpawnArea = components.SpawnArea.Component;
15-
export type StatManager = components.StatManager.Component;
16-
export type WoodcutTree = components.WoodcutTree.Component;
4+
export type {
5+
BasicDecay,
6+
DurabilityModule,
7+
HeatSourceBase,
8+
LiquidContainer,
9+
NetworkRigidbody,
10+
PhysicalMaterialPart,
11+
Pickup,
12+
PickupDock,
13+
PopulationSpawnArea,
14+
SpawnArea,
15+
StatManager,
16+
WoodcutTree
17+
} from './components';
1718

1819
/**
1920
* EMBEDDED ENTITIES

0 commit comments

Comments
 (0)