Skip to content

Commit a5c41da

Browse files
committed
Add LogicIntSender component
1 parent 3144115 commit a5c41da

8 files changed

+529
-0
lines changed

docs/LogicIntSenderComponent.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Class: `LogicIntSenderComponent`
2+
3+
- [Types](#types)
4+
- [`<ComponentProps>`](#componentprops)
5+
- [`<LogicIntSenderComponentProps>`](#logicintsendercomponentprops)
6+
- [Constructors](#constructors)
7+
- [`new LogicIntSenderComponent(props)`](#new-logicintsendercomponentprops)
8+
- [`LogicIntSenderComponent.fromBinary(reader, version)`](#logicintsendercomponentfrombinaryreader-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+
### `<LogicIntSenderComponentProps>`
30+
31+
A portion of the configuration object to pass to the `LogicIntSenderComponent` constructor.
32+
33+
```ts
34+
type LogicIntSenderComponentPropsV1 = {
35+
updatedValue?: number | undefined;
36+
changedExternally?: number | undefined;
37+
identifier?: number | undefined;
38+
value?: number | undefined;
39+
};
40+
41+
type LogicIntSenderComponentProps = LogicIntSenderComponentPropsV1;
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 `false`) `<intean>`
50+
51+
## Constructors
52+
53+
### `new LogicIntSenderComponent(props)`
54+
55+
Creates a versioned `LogicIntSender` component.
56+
57+
- `props` [`<ComponentProps & LogicIntSenderComponentProps>`](#types) Configuration of the component to create.
58+
- Returns: `<LogicIntSenderComponent>`
59+
60+
```ts
61+
import { LogicIntSenderComponent } from 'att-string-transcoder';
62+
63+
const componentVersion = 1;
64+
const component = new LogicIntSenderComponent({ version: componentVersion });
65+
```
66+
67+
---
68+
69+
### `LogicIntSenderComponent.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 { LogicIntSenderComponent } from 'att-string-transcoder';
104+
105+
const componentVersion = 1;
106+
const component = new LogicIntSenderComponent({ 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 { LogicIntSenderComponent } from 'att-string-transcoder';
123+
124+
const componentVersion = 1;
125+
const component = new LogicIntSenderComponent({ version: componentVersion });
126+
127+
const changedExternally = component.changedExternally;
128+
// `changedExternally` is `32`
129+
```
130+
131+
---
132+
133+
### `identifier`
134+
135+
The identifier of this `LogicIntSender` that a `LogicIntReceiver` connects to.
136+
137+
- Since: `v1`
138+
- `<number>`
139+
140+
```ts
141+
import { LogicIntSenderComponent } from 'att-string-transcoder';
142+
143+
const componentVersion = 1;
144+
const component = new LogicIntSenderComponent({ 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 `LogicIntSender` that a `LogicIntReceiver` reads as its input.
155+
156+
- Since: `v1`
157+
- `<number>`
158+
159+
```ts
160+
import { LogicIntSenderComponent } from 'att-string-transcoder';
161+
162+
const componentVersion = 1;
163+
const component = new LogicIntSenderComponent({ version: componentVersion });
164+
165+
const value = component.value;
166+
// `value` is `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
@@ -24,6 +24,7 @@
2424
- [`LogicFloatSenderComponent`](./LogicFloatSenderComponent.md)
2525
- [`LogicGateReceiverComponent`](./LogicGateReceiverComponent.md)
2626
- [`LogicIntReceiverComponent`](./LogicIntReceiverComponent.md)
27+
- [`LogicIntSenderComponent`](./LogicIntSenderComponent.md)
2728
- [`LogicVector3ReceiverComponent`](./LogicVector3ReceiverComponent.md)
2829
- [`NetworkRigidbodyComponent`](./NetworkRigidbodyComponent.md)
2930
- [`PhysicalMaterialPartComponent`](./PhysicalMaterialPartComponent.md)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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 { LogicIntSenderComponent } from './LogicIntSenderComponent.js';
8+
9+
const componentHash = ComponentHash.LogicIntSender;
10+
const componentName = 'LogicIntSender';
11+
const componentVersion = 1;
12+
const componentProps = {
13+
updatedValue: 1337,
14+
changedExternally: 420,
15+
identifier: 69,
16+
value: -420
17+
};
18+
19+
describe('new LogicIntSenderComponent()', () => {
20+
describe('when given the required props', () => {
21+
it('returns an instance of the LogicIntSenderComponent class', () => {
22+
const component = new LogicIntSenderComponent({ version: componentVersion });
23+
24+
expect(component).toBeInstanceOf(LogicIntSenderComponent);
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 LogicIntSenderComponent class', () => {
33+
const component = new LogicIntSenderComponent({ version: componentVersion, ...componentProps });
34+
35+
expect(component).toBeInstanceOf(LogicIntSenderComponent);
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('LogicIntSenderComponent.fromBinary()', () => {
48+
let fastForwardedReader: BinaryReader;
49+
50+
const prefab = new Prefab('MRK_Small_Lever', {
51+
components: {
52+
LogicIntSender: new LogicIntSenderComponent({ 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(); // LogicIntSenderComponent hash.
81+
reader.readUnsignedInteger(); // LogicIntSenderComponent data length.
82+
83+
fastForwardedReader = reader;
84+
});
85+
86+
it('returns an instance of the LogicIntSenderComponent class', () => {
87+
const component = LogicIntSenderComponent.fromBinary(fastForwardedReader, componentVersion);
88+
89+
expect(component).toBeInstanceOf(LogicIntSenderComponent);
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('LogicIntSenderComponent.toBinary()', () => {
101+
it('returns a BinaryString representation of the component', () => {
102+
const component = new LogicIntSenderComponent({ version: componentVersion, ...componentProps });
103+
104+
const data = component.toBinary();
105+
106+
const expectedData =
107+
'00000000000000000000010100111001000000000000000000000001101001000000000000000000000000000100010101111111111111111111111001011100';
108+
109+
expect(data).toStrictEqual(expectedData);
110+
});
111+
});
112+
113+
describe('LogicIntSenderComponent.write()', () => {
114+
it('writes a BinaryString representation of the component to the given BinaryWriter, including component hash and data length', () => {
115+
const component = new LogicIntSenderComponent({ version: componentVersion, ...componentProps });
116+
117+
const writer = new BinaryWriter();
118+
component.write(writer);
119+
120+
const data = writer.flush();
121+
122+
const expectedData =
123+
'101010111011001001000101100111000000000000000000000000001000000000000000000000000000010100111001000000000000000000000001101001000000000000000000000000000100010101111111111111111111111001011100';
124+
125+
expect(data).toStrictEqual(expectedData);
126+
127+
const reader = new BinaryReader(data);
128+
129+
const hash = reader.readUnsignedInteger();
130+
reader.readUnsignedInteger(); // LogicIntSenderComponent data length.
131+
const updatedValue = reader.readUnsignedInteger();
132+
const changedExternally = reader.readUnsignedInteger();
133+
const identifier = reader.readUnsignedInteger();
134+
const value = reader.readSignedInteger();
135+
136+
expect(hash).toStrictEqual(componentHash);
137+
expect(updatedValue).toStrictEqual(componentProps.updatedValue);
138+
expect(changedExternally).toStrictEqual(componentProps.changedExternally);
139+
expect(identifier).toStrictEqual(componentProps.identifier);
140+
expect(value).toStrictEqual(componentProps.value);
141+
});
142+
});

0 commit comments

Comments
 (0)