Skip to content

Commit dfa873a

Browse files
authored
Merge pull request #6 from mdingena/v2.0.0
Refactor for v2
2 parents f49fa8b + b1a122d commit dfa873a

19 files changed

+1681
-2126
lines changed

README.md

Lines changed: 19 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -4,142 +4,16 @@
44

55
Allows you to decode _A Township Tale_'s save strings for analysing, and encode JS objects into ATT save strings for spawning.
66

7-
## ⚡️ Quick Start
7+
⚠️ Use this library primarily when creating bots for ATT, or when building your own ATT save string project. **If you just want to make string weapons, check out my [ATT String Workshop](https://github.com/mdingena/att-string-workshop) project.**
8+
9+
## Installation
810

911
Add this library to your project's dependencies:
1012

1113
```shell
1214
npm install --save att-string-transcoder
1315
```
1416

15-
Next, create an `encode.js` file in your project and add the following code:
16-
17-
```js
18-
const { createPrefab, PrefabHash } = require('att-string-transcoder');
19-
20-
createPrefab(PrefabHash.Handle_Short).print();
21-
```
22-
23-
⚠️ Don't forget to save the file!
24-
25-
Finally, execute this code by running this command in your terminal (while in your project's directory):
26-
27-
```shell
28-
node encode.js
29-
```
30-
31-
The string should appear in the terminal for you to copy and paste.
32-
33-
### User-friendly guide to `createPrefab`
34-
35-
Starting with the very basics, you can create a string for a handle using this code:
36-
37-
```
38-
createPrefab(PrefabHash.Handle_Short).print();
39-
```
40-
41-
Running this code will print the string you can use to spawn a weapon handle.
42-
You'll include this string in a spawn command that looks like this:
43-
44-
```css
45-
spawn string EthynWyrmbane [string]
46-
```
47-
48-
But so far, this is just a really complicated way of spawning a handle. The point of strings is that you can spawn intricate contraptions that regular spawn commands can't.
49-
50-
Let's change this handle's material:
51-
52-
```
53-
createPrefab(PrefabHash.Handle_Short).setMaterial(PhysicalMaterialPartHash.Redwood).print();
54-
```
55-
56-
That's getting kinda long, so we can write it across multiple lines to keep things readible:
57-
58-
```
59-
createPrefab(PrefabHash.Handle_Short)
60-
.setMaterial(PhysicalMaterialPartHash.Redwood)
61-
.print();
62-
```
63-
64-
Now let's add a guard to this handle (the green lines show what's new since last example):
65-
66-
```diff
67-
createPrefab(PrefabHash.Handle_Short)
68-
.setMaterial(PhysicalMaterialPartHash.Redwood)
69-
+ .useSlot(
70-
+ PrefabSlot.Handle_Short.Slot_Multi_1,
71-
+ createPrefab(PrefabHash.Guard)
72-
+ )
73-
.print();
74-
```
75-
76-
So, what's happening here? We're telling the program to use one of the handle's slots, and we insert another prefab into that. The program needs to know _which_ slot to use, since prefabs like this handle have more than one slot you can use.
77-
78-
The inserted prefab works the same way as the handle prefab we've been making so far. Let's change the guard's material as well:
79-
80-
```diff
81-
createPrefab(PrefabHash.Handle_Short)
82-
.setMaterial(PhysicalMaterialPartHash.Redwood)
83-
.useSlot(
84-
PrefabSlot.Handle_Short.Slot_Multi_1,
85-
createPrefab(PrefabHash.Guard)
86-
+ .setMaterial(PhysicalMaterialPartHash.CarsiAlloy)
87-
)
88-
.print();
89-
```
90-
91-
And like the handle, we can insert prefabs into this guard's slots:
92-
93-
```diff
94-
createPrefab(PrefabHash.Handle_Short)
95-
.setMaterial(PhysicalMaterialPartHash.Redwood)
96-
.useSlot(
97-
PrefabSlot.Handle_Short.Slot_Multi_1,
98-
createPrefab(PrefabHash.Guard)
99-
.setMaterial(PhysicalMaterialPartHash.CarsiAlloy)
100-
+ .useSlot(
101-
+ PrefabSlot.Guard.Slot_SwordType,
102-
+ createPrefab(PrefabHash.Metal_Hebios_Wakizashi_Blade)
103-
+ .setMaterial(PhysicalMaterialPartHash.Mythril)
104-
+ )
105-
)
106-
.print();
107-
```
108-
109-
There are also some other interesting things we can do with prefabs:
110-
111-
- Changing the integrity (repairing or damaging it).
112-
- Giving the prefab a velocity to hurl it through the air (works on non-slotted prefabs only).
113-
- Changing its position and orientation (works on non-slotted prefabs only).
114-
- Making it "noclip" (kinematic).
115-
- Setting it on fire.
116-
117-
In the end, the game server decides what is possible. For example, some prefabs simply don't have a material, such as the iron handles. But it's fun to experiment and trying to figure out all the crazy things you _can_ do.
118-
119-
Let's complete our sword:
120-
121-
```diff
122-
createPrefab(PrefabHash.Handle_Short)
123-
.setMaterial(PhysicalMaterialPartHash.Redwood)
124-
.useSlot(
125-
PrefabSlot.Handle_Short.Slot_Multi_1,
126-
createPrefab(PrefabHash.Guard)
127-
.setMaterial(PhysicalMaterialPartHash.CarsiAlloy)
128-
.useSlot(
129-
PrefabSlot.Guard.Slot_SwordType,
130-
createPrefab(PrefabHash.Metal_Hebios_Wakizashi_Blade)
131-
.setMaterial(PhysicalMaterialPartHash.Mythril)
132-
+ .setIntegrity(0.25)
133-
)
134-
)
135-
+ .useSlot(
136-
+ PrefabSlot.Handle_Short.Slot_PommelType_1,
137-
+ createPrefab(PrefabHash.Pommel_Diamond)
138-
+ .setMaterial(PhysicalMaterialPartHash.EvinonSteelAlloy)
139-
+ )
140-
.print();
141-
```
142-
14317
### Decoding a string
14418

14519
```ts
@@ -241,17 +115,17 @@ const decodedString = {
241115

242116
</details>
243117

244-
### Encoding a string (the hard way)
118+
### Encoding a string
245119

246120
<details>
247121
<summary>First, create a <code>blade</code> prefab object:</summary>
248122

249123
```ts
250-
import { Prefab, PrefabHash, PhysicalMaterialPartHash } from 'att-string-transcoder';
124+
import { Prefab, PrefabData, PhysicalMaterialPartHash } from 'att-string-transcoder';
251125

252-
const blade: Prefab = {
126+
const blade: PrefabData = {
253127
prefabObject: {
254-
hash: PrefabHash.Large_Longsword_Blade
128+
hash: Prefab.Large_Longsword_Blade.hash
255129
},
256130
components: {
257131
PhysicalMaterialPart: {
@@ -270,11 +144,11 @@ const blade: Prefab = {
270144
<summary>Then, create a <code>guard</code> prefab object:</summary>
271145

272146
```ts
273-
import { Prefab, PrefabHash, PhysicalMaterialPartHash } from 'att-string-transcoder';
147+
import { Prefab, PrefabData, PhysicalMaterialPartHash } from 'att-string-transcoder';
274148

275-
export const guard: Prefab = {
149+
export const guard: PrefabData = {
276150
prefabObject: {
277-
hash: PrefabHash.Large_Guard_Rectangle
151+
hash: Prefab.Large_Guard_Rectangle.hash
278152
},
279153
components: {
280154
PhysicalMaterialPart: {
@@ -286,7 +160,7 @@ export const guard: Prefab = {
286160
},
287161
childPrefabs: [
288162
{
289-
parentHash: 51896,
163+
parentHash: Prefab.Large_Guard_Rectangle.slots.Slot_Large_SwordType,
290164
prefab: blade
291165
}
292166
]
@@ -299,17 +173,17 @@ export const guard: Prefab = {
299173
<summary>Finally, create a <code>handle</code> prefab object:</summary>
300174

301175
```ts
302-
import { Prefab, PrefabHash } from 'att-string-transcoder';
176+
import { Prefab, PrefabData } from 'att-string-transcoder';
303177

304178
const position = {
305179
x: -701,
306180
y: 128.2,
307181
z: 100
308182
};
309183

310-
export const handle: Prefab = {
184+
export const handle: PrefabData = {
311185
prefabObject: {
312-
hash: PrefabHash.Handle_Short,
186+
hash: Prefab.Handle_Short.hash,
313187
position
314188
},
315189
components: {
@@ -319,7 +193,7 @@ export const handle: Prefab = {
319193
},
320194
childPrefabs: [
321195
{
322-
parentHash: 6136,
196+
parentHash: Prefab.Handle_Short.slots.Slot_Large_SwordType_Craft_1,
323197
prefab: guard
324198
}
325199
]
@@ -350,3 +224,7 @@ const encodedSword = createString(handle);
350224
```
351225

352226
</details>
227+
228+
### Encoding a string (alternative method)
229+
230+
You can also use the `createPrefab` helper function of this library. See the [ATT String Workshop](https://github.com/mdingena/att-string-workshop) project for documentation about this.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"name": "att-string-transcoder",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"description": "Trancode integer strings for A Township Tale.",
55
"main": "build/index.js",
66
"scripts": {
77
"prepare": "npm run build",
88
"prebuild": "rimraf build/",
99
"build": "tsc",
1010
"compile": "tsc --noEmit",
11-
"pretest": "npm run build",
1211
"test": "jest"
1312
},
1413
"author": "Marc Dingena",
@@ -32,14 +31,14 @@
3231
"ieee754": "^1.2.1"
3332
},
3433
"devDependencies": {
35-
"@types/jest": "^26.0.24",
34+
"@types/jest": "^27.0.2",
3635
"@types/node": "^16.9.1",
3736
"husky": "^4.3.8",
3837
"jest": "^27.0.6",
3938
"lint-staged": "^11.1.1",
4039
"prettier": "^2.3.0",
4140
"rimraf": "^3.0.2",
4241
"ts-jest": "^27.0.4",
43-
"typescript": "^4.2.4"
42+
"typescript": "^4.4.4"
4443
}
4544
}

0 commit comments

Comments
 (0)