Skip to content

Commit f003424

Browse files
committed
Add LogicVector3Sender component
1 parent ccd897d commit f003424

8 files changed

+540
-0
lines changed

docs/LogicVector3SenderComponent.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Class: `LogicVector3SenderComponent`
2+
3+
- [Types](#types)
4+
- [`<ComponentProps>`](#componentprops)
5+
- [`<LogicVector3SenderComponentProps>`](#logicvector3sendercomponentprops)
6+
- [Constructors](#constructors)
7+
- [`new LogicVector3SenderComponent(props)`](#new-logicvector3sendercomponentprops)
8+
- [`LogicVector3SenderComponent.fromBinary(reader, version)`](#logicvector3sendercomponentfrombinaryreader-version)
9+
- [Properties](#properties)
10+
- [`hash`](#hash)
11+
- [`name`](#name)
12+
- [`version`](#version)
13+
- [`updatedValue`](#updatedvalue)
14+
- [`changedExternally`](#changedexternally)
15+
- [`identifier`](#identifier)
16+
- [`value`](#value)
17+
- [Methods](#methods)
18+
- [`toBinary(version?)`](#tobinaryversion)
19+
- [`write(writer, version?)`](#writewriter-version)
20+
21+
## Types
22+
23+
### `<ComponentProps>`
24+
25+
See [`<ComponentProps>`](./Component.md#componentprops)
26+
27+
---
28+
29+
### `<LogicVector3SenderComponentProps>`
30+
31+
A portion of the configuration object to pass to the `LogicVector3SenderComponent` constructor.
32+
33+
```ts
34+
type LogicVector3SenderComponentPropsV1 = {
35+
updatedValue?: number | undefined;
36+
changedExternally?: number | undefined;
37+
identifier?: number | undefined;
38+
value?: vector3ean | undefined;
39+
};
40+
41+
type LogicVector3SenderComponentProps = LogicVector3SenderComponentPropsV1;
42+
```
43+
44+
#### Since v1
45+
46+
- `updatedValue` (optional, default `3171294583`) `<number>`
47+
- `changedExternally` (optional, default `32`) `<number>`
48+
- `identifier` (optional, default `0`) `<number>`
49+
- `value` (optional, default `{ x: 0, y: 0, z: 0 }`) `<Vector3>`
50+
51+
## Constructors
52+
53+
### `new LogicVector3SenderComponent(props)`
54+
55+
Creates a versioned `LogicVector3Sender` component.
56+
57+
- `props` [`<ComponentProps & LogicVector3SenderComponentProps>`](#types) Configuration of the component to create.
58+
- Returns: `<LogicVector3SenderComponent>`
59+
60+
```ts
61+
import { LogicVector3SenderComponent } from 'att-string-transcoder';
62+
63+
const componentVersion = 1;
64+
const component = new LogicVector3SenderComponent({ version: componentVersion });
65+
```
66+
67+
---
68+
69+
### `LogicVector3SenderComponent.fromBinary(reader, version)`
70+
71+
See [`Component.fromBinary(reader, version)`](./Component.md#componentfrombinaryreader-version)
72+
73+
## Properties
74+
75+
Note that the following properties are sorted in order of appearance when decoding component binary data.
76+
77+
### `hash`
78+
79+
See [`Component.hash`](./Component.md#hash)
80+
81+
---
82+
83+
### `name`
84+
85+
See [`Component.name`](./Component.md#name)
86+
87+
---
88+
89+
### `version`
90+
91+
See [`Component.version`](./Component.md#version)
92+
93+
---
94+
95+
### `updatedValue`
96+
97+
We're not quite sure what this property does.
98+
99+
- Since: `v1`
100+
- `<number>`
101+
102+
```ts
103+
import { LogicVector3SenderComponent } from 'att-string-transcoder';
104+
105+
const componentVersion = 1;
106+
const component = new LogicVector3SenderComponent({ version: componentVersion });
107+
108+
const updatedValue = component.updatedValue;
109+
// `updatedValue` is `3171294583`
110+
```
111+
112+
---
113+
114+
### `changedExternally`
115+
116+
We're not quite sure what this property does.
117+
118+
- Since: `v1`
119+
- `<number>`
120+
121+
```ts
122+
import { LogicVector3SenderComponent } from 'att-string-transcoder';
123+
124+
const componentVersion = 1;
125+
const component = new LogicVector3SenderComponent({ version: componentVersion });
126+
127+
const changedExternally = component.changedExternally;
128+
// `changedExternally` is `32`
129+
```
130+
131+
---
132+
133+
### `identifier`
134+
135+
The identifier of this `LogicVector3Sender` that a `LogicVector3Receiver` connects to.
136+
137+
- Since: `v1`
138+
- `<number>`
139+
140+
```ts
141+
import { LogicVector3SenderComponent } from 'att-string-transcoder';
142+
143+
const componentVersion = 1;
144+
const component = new LogicVector3SenderComponent({ version: componentVersion });
145+
146+
const identifier = component.identifier;
147+
// `identifier` is `0`
148+
```
149+
150+
---
151+
152+
### `value`
153+
154+
The output value of this `LogicVector3Sender` that a `LogicVector3Receiver` reads as its input.
155+
156+
- Since: `v1`
157+
- `<Vector3>`
158+
159+
```ts
160+
import { LogicVector3SenderComponent } from 'att-string-transcoder';
161+
162+
const componentVersion = 1;
163+
const component = new LogicVector3SenderComponent({ version: componentVersion });
164+
165+
const value = component.value;
166+
// `value` is `{ x: 0, y: 0, z: 0 }`
167+
```
168+
169+
## Methods
170+
171+
### `toBinary(version?)`
172+
173+
See [`Component.toBinary(version?)`](./Component.md#tobinaryversion)
174+
175+
---
176+
177+
### `write(writer, version?)`
178+
179+
See [`Component.write(writer, version?)`](./Component.md#writewriter-version)

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [`LogicIntReceiverComponent`](./LogicIntReceiverComponent.md)
2727
- [`LogicIntSenderComponent`](./LogicIntSenderComponent.md)
2828
- [`LogicVector3ReceiverComponent`](./LogicVector3ReceiverComponent.md)
29+
- [`LogicVector3SenderComponent`](./LogicVector3SenderComponent.md)
2930
- [`NetworkRigidbodyComponent`](./NetworkRigidbodyComponent.md)
3031
- [`PhysicalMaterialPartComponent`](./PhysicalMaterialPartComponent.md)
3132
- [`PickupComponent`](./PickupComponent.md)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { BinaryData } from '../BinaryData.js';
2+
import { BinaryReader } from '../BinaryReader.js';
3+
import { BinaryWriter } from '../BinaryWriter.js';
4+
import { Prefab } from '../Prefab.js';
5+
import { ComponentHash } from '../types/ComponentHash.js';
6+
7+
import { LogicVector3SenderComponent } from './LogicVector3SenderComponent.js';
8+
9+
const componentHash = ComponentHash.LogicVector3Sender;
10+
const componentName = 'LogicVector3Sender';
11+
const componentVersion = 1;
12+
const componentProps = {
13+
updatedValue: 1337,
14+
changedExternally: 420,
15+
identifier: 69,
16+
value: { x: 69, y: 420, z: 1337 }
17+
};
18+
19+
describe('new LogicVector3SenderComponent()', () => {
20+
describe('when given the required props', () => {
21+
it('returns an instance of the LogicVector3SenderComponent class', () => {
22+
const component = new LogicVector3SenderComponent({ version: componentVersion });
23+
24+
expect(component).toBeInstanceOf(LogicVector3SenderComponent);
25+
expect(component.hash).toStrictEqual(componentHash);
26+
expect(component.name).toStrictEqual(componentName);
27+
expect(component.version).toStrictEqual(componentVersion);
28+
});
29+
});
30+
31+
describe('when given additional props', () => {
32+
it('returns an instance of the LogicVector3SenderComponent class', () => {
33+
const component = new LogicVector3SenderComponent({ version: componentVersion, ...componentProps });
34+
35+
expect(component).toBeInstanceOf(LogicVector3SenderComponent);
36+
expect(component.hash).toStrictEqual(componentHash);
37+
expect(component.name).toStrictEqual(componentName);
38+
expect(component.version).toStrictEqual(componentVersion);
39+
expect(component.updatedValue).toStrictEqual(componentProps.updatedValue);
40+
expect(component.changedExternally).toStrictEqual(componentProps.changedExternally);
41+
expect(component.identifier).toStrictEqual(componentProps.identifier);
42+
expect(component.value).toStrictEqual(componentProps.value);
43+
});
44+
});
45+
});
46+
47+
describe('LogicVector3SenderComponent.fromBinary()', () => {
48+
let fastForwardedReader: BinaryReader;
49+
50+
const prefab = new Prefab('MRK_Small_Lever', {
51+
components: {
52+
LogicVector3Sender: new LogicVector3SenderComponent({ version: componentVersion, ...componentProps })
53+
}
54+
});
55+
56+
beforeEach(() => {
57+
const saveString = prefab.toSaveString();
58+
const [dataString] = saveString.split('|');
59+
60+
if (typeof dataString === 'undefined') {
61+
throw new Error('Invalid test data.');
62+
}
63+
64+
const unsignedIntegers = dataString.split(',').map(Number);
65+
66+
const data = BinaryData.fromUnsignedIntegerArray(unsignedIntegers);
67+
const reader = new BinaryReader(data.toBinaryString());
68+
69+
reader.readUnsignedInteger(); // Root prefab hash.
70+
reader.readUnsignedInteger(); // SaveString bytes.
71+
reader.readUnsignedInteger(); // Parent prefab hash.
72+
reader.readFloat(); // Parent position X.
73+
reader.readFloat(); // Parent position Y.
74+
reader.readFloat(); // Parent position Z.
75+
reader.readFloat(); // Parent rotation X.
76+
reader.readFloat(); // Parent rotation Y.
77+
reader.readFloat(); // Parent rotation Z.
78+
reader.readFloat(); // Parent rotation W.
79+
reader.readFloat(); // Parent scale.
80+
reader.readUnsignedInteger(); // LogicVector3SenderComponent hash.
81+
reader.readUnsignedInteger(); // LogicVector3SenderComponent data length.
82+
83+
fastForwardedReader = reader;
84+
});
85+
86+
it('returns an instance of the LogicVector3SenderComponent class', () => {
87+
const component = LogicVector3SenderComponent.fromBinary(fastForwardedReader, componentVersion);
88+
89+
expect(component).toBeInstanceOf(LogicVector3SenderComponent);
90+
expect(component.hash).toStrictEqual(componentHash);
91+
expect(component.name).toStrictEqual(componentName);
92+
expect(component.version).toStrictEqual(componentVersion);
93+
expect(component.updatedValue).toStrictEqual(componentProps.updatedValue);
94+
expect(component.changedExternally).toStrictEqual(componentProps.changedExternally);
95+
expect(component.identifier).toStrictEqual(componentProps.identifier);
96+
expect(component.value).toStrictEqual(componentProps.value);
97+
});
98+
});
99+
100+
describe('LogicVector3SenderComponent.toBinary()', () => {
101+
it('returns a BinaryString representation of the component', () => {
102+
const component = new LogicVector3SenderComponent({ version: componentVersion, ...componentProps });
103+
104+
const data = component.toBinary();
105+
106+
const expectedData =
107+
'000000000000000000000101001110010000000000000000000000011010010000000000000000000000000001000101010000101000101000000000000000000100001111010010000000000000000001000100101001110010000000000000';
108+
109+
expect(data).toStrictEqual(expectedData);
110+
});
111+
});
112+
113+
describe('LogicVector3SenderComponent.write()', () => {
114+
it('writes a BinaryString representation of the component to the given BinaryWriter, including component hash and data length', () => {
115+
const component = new LogicVector3SenderComponent({ version: componentVersion, ...componentProps });
116+
117+
const writer = new BinaryWriter();
118+
component.write(writer);
119+
120+
const data = writer.flush();
121+
122+
const expectedData =
123+
'0111100011001101101001111011001100000000000000000000000011000000000000000000000000000101001110010000000000000000000000011010010000000000000000000000000001000101010000101000101000000000000000000100001111010010000000000000000001000100101001110010000000000000';
124+
125+
expect(data).toStrictEqual(expectedData);
126+
127+
const reader = new BinaryReader(data);
128+
129+
const hash = reader.readUnsignedInteger();
130+
reader.readUnsignedInteger(); // LogicVector3SenderComponent data length.
131+
const updatedValue = reader.readUnsignedInteger();
132+
const changedExternally = reader.readUnsignedInteger();
133+
const identifier = reader.readUnsignedInteger();
134+
const value = {
135+
x: reader.readFloat(),
136+
y: reader.readFloat(),
137+
z: reader.readFloat()
138+
};
139+
140+
expect(hash).toStrictEqual(componentHash);
141+
expect(updatedValue).toStrictEqual(componentProps.updatedValue);
142+
expect(changedExternally).toStrictEqual(componentProps.changedExternally);
143+
expect(identifier).toStrictEqual(componentProps.identifier);
144+
expect(value).toStrictEqual(componentProps.value);
145+
});
146+
});

0 commit comments

Comments
 (0)