mcdevs-wiki-extractor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +14 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/commands.yml +22 -0
- package/.github/workflows/publish.yml +34 -0
- package/README.md +35 -3
- package/bin/entities_to_json.js +12 -12
- package/bin/protocol_comments_to_json.js +11 -11
- package/bin/protocol_to_json.js +11 -11
- package/index.js +4 -4
- package/lib/common/table_parser.js +75 -95
- package/lib/common/toOldNames.js +98 -0
- package/lib/entities_extractor.js +54 -48
- package/lib/protocol_extractor.js +286 -428
- package/lib/relink.js +10 -0
- package/package.json +8 -4
- package/test/test_protocol_extractor.js +220 -221
- package/.npmignore +0 -1
- package/circle.yml +0 -3
package/lib/relink.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/node
|
|
2
|
+
const pandoc = require('pandoc-filter')
|
|
3
|
+
const Link = pandoc.Link
|
|
4
|
+
const toOldNames = require('./common/toOldNames').transformPacketName
|
|
5
|
+
|
|
6
|
+
function relink (key, value, format, meta) {
|
|
7
|
+
if (key === 'Link' && value[2][0].indexOf('#') === 0) { return Link(value[0], value[1], ['#' + toOldNames(value[2][0].substr(1)), value[2][1]]) }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
pandoc.stdio(relink)
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcdevs-wiki-extractor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Extract structured data from the mcdevs wiki",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "mocha --reporter spec"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"async": "^2.6.1",
|
|
11
|
+
"pandoc-filter": "^1.0.0",
|
|
12
|
+
"pdc": "^0.2.3",
|
|
13
|
+
"ramda": "^0.30.1",
|
|
14
|
+
"parse-wikitext": "^1.0.0"
|
|
12
15
|
},
|
|
13
16
|
"devDependencies": {
|
|
14
|
-
"mocha": "
|
|
17
|
+
"mocha": "^11.0.1",
|
|
18
|
+
"standard": "^17.0.0"
|
|
15
19
|
},
|
|
16
20
|
"repository": {
|
|
17
21
|
"type": "git",
|
|
@@ -1,236 +1,235 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
1
3
|
// items tests
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe(
|
|
7
|
-
it(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const assert = require('assert')
|
|
6
|
+
const protocolExtractor = require('../').protocol_extractor
|
|
7
|
+
|
|
8
|
+
describe('protocol_extractor', function () {
|
|
9
|
+
it('parse a simple packet correctly', function () {
|
|
10
|
+
const testTable = '{| class="wikitable"\n' +
|
|
11
|
+
' ! Packet ID\n' +
|
|
12
|
+
' ! State\n' +
|
|
13
|
+
' ! Bound To\n' +
|
|
14
|
+
' ! Field Name\n' +
|
|
15
|
+
' ! Field Type\n' +
|
|
16
|
+
' ! Notes\n' +
|
|
17
|
+
' |-\n' +
|
|
18
|
+
' |rowspan="2"| 0x0D\n' +
|
|
19
|
+
' |rowspan="2"| Play\n' +
|
|
20
|
+
' |rowspan="2"| Client\n' +
|
|
21
|
+
' | Collected Entity ID\n' +
|
|
22
|
+
' | VarInt\n' +
|
|
23
|
+
' | \n' +
|
|
24
|
+
' |- \n' +
|
|
25
|
+
' | Collector Entity ID\n' +
|
|
26
|
+
' | VarInt\n' +
|
|
27
|
+
' | \n' +
|
|
28
|
+
' |}'
|
|
29
|
+
|
|
30
|
+
const expectedTable = [
|
|
29
31
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
'Packet ID': '0x0D',
|
|
33
|
+
State: 'Play',
|
|
34
|
+
'Bound To': 'Client',
|
|
35
|
+
'Field Name': 'Collected Entity ID',
|
|
36
|
+
'Field Type': 'VarInt',
|
|
37
|
+
Notes: ''
|
|
36
38
|
},
|
|
37
39
|
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
'Packet ID': '0x0D',
|
|
41
|
+
State: 'Play',
|
|
42
|
+
'Bound To': 'Client',
|
|
43
|
+
'Field Name': 'Collector Entity ID',
|
|
44
|
+
'Field Type': 'VarInt',
|
|
45
|
+
Notes: ''
|
|
44
46
|
}
|
|
45
|
-
]
|
|
47
|
+
]
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const expectedPacket = {
|
|
50
|
+
id: '0x0D',
|
|
51
|
+
fields: [
|
|
50
52
|
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
name: 'Collected Entity ID',
|
|
54
|
+
type: 'VarInt'
|
|
53
55
|
},
|
|
54
56
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
name: 'Collector Entity ID',
|
|
58
|
+
type: 'VarInt'
|
|
57
59
|
}
|
|
58
60
|
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
" |
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
" |}\n";
|
|
165
|
-
|
|
166
|
-
var expectedTable4=[
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const actualTable = protocolExtractor.parseWikiTable(testTable.split('\n'))
|
|
64
|
+
// console.log(actualTable);
|
|
65
|
+
|
|
66
|
+
const actualPacket = protocolExtractor.tableToPacket(actualTable)
|
|
67
|
+
|
|
68
|
+
// console.log(actualPacket);
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(actualTable, expectedTable)
|
|
71
|
+
|
|
72
|
+
assert.deepEqual(actualPacket, expectedPacket)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('parse a more complicated packet', function () {
|
|
76
|
+
const testTable2 = '{| class="wikitable"\n' +
|
|
77
|
+
' ! Packet ID\n' +
|
|
78
|
+
' ! State\n' +
|
|
79
|
+
' ! Bound To\n' +
|
|
80
|
+
' ! Field Name\n' +
|
|
81
|
+
' ! Field Type\n' +
|
|
82
|
+
' ! Notes\n' +
|
|
83
|
+
' |-\n' +
|
|
84
|
+
' |rowspan="3"| 0x06\n' +
|
|
85
|
+
' |rowspan="3"| Play\n' +
|
|
86
|
+
' |rowspan="3"| Client\n' +
|
|
87
|
+
' | Health\n' +
|
|
88
|
+
' | Float\n' +
|
|
89
|
+
' | 0 or less = dead, 20 = full HP\n' +
|
|
90
|
+
' |-\n' +
|
|
91
|
+
' | Food\n' +
|
|
92
|
+
' | VarInt\n' +
|
|
93
|
+
' | 0–20\n' +
|
|
94
|
+
' |- \n' +
|
|
95
|
+
' | Food Saturation\n' +
|
|
96
|
+
' | Float\n' +
|
|
97
|
+
' | Seems to vary from 0.0 to 5.0 in integer increments\n' +
|
|
98
|
+
' |}'
|
|
99
|
+
console.log(testTable2)
|
|
100
|
+
|
|
101
|
+
// console.log(protocol_extractor.tableToPacket(protocol_extractor.parseWikiTable(testTable2.split("\n"))));
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('parse a packet with colspan', function () {
|
|
105
|
+
const testTable3 = '{| class="wikitable"\n' +
|
|
106
|
+
' ! Packet ID\n' +
|
|
107
|
+
' ! State\n' +
|
|
108
|
+
' ! Bound To\n' +
|
|
109
|
+
' !colspan="2"| Field Name\n' +
|
|
110
|
+
' !colspan="2"| Field Type\n' +
|
|
111
|
+
' ! Notes\n' +
|
|
112
|
+
' |-\n' +
|
|
113
|
+
' |rowspan="6"| 0x22\n' +
|
|
114
|
+
' |rowspan="6"| Play\n' +
|
|
115
|
+
' |rowspan="6"| Client\n' +
|
|
116
|
+
' |colspan="2"| Chunk X\n' +
|
|
117
|
+
' |colspan="2"| Int\n' +
|
|
118
|
+
' | Chunk X coordinate\n' +
|
|
119
|
+
' |-\n' +
|
|
120
|
+
' |colspan="2"| Chunk Z\n' +
|
|
121
|
+
' |colspan="2"| Int\n' +
|
|
122
|
+
' | Chunk Z coordinate\n' +
|
|
123
|
+
' |-\n' +
|
|
124
|
+
' |colspan="2"| Record Count\n' +
|
|
125
|
+
' |colspan="2"| VarInt\n' +
|
|
126
|
+
' | Number of elements in the following array, a.k.a. the number of blocks affected\n' +
|
|
127
|
+
' |-\n' +
|
|
128
|
+
' |rowspan="3"| Record\n' +
|
|
129
|
+
' | Horizontal Position\n' +
|
|
130
|
+
' |rowspan="3"| Array\n' +
|
|
131
|
+
' | Unsigned Byte\n' +
|
|
132
|
+
' | The 4 most significant bits (<code>0xF0</code>) encode the X coordinate, relative to the chunk. The 4 least significant bits (<code>0x0F</code>) encode the Z coordinate, relative to the chunk.\n' +
|
|
133
|
+
' |-\n' +
|
|
134
|
+
' | Y Coordinate\n' +
|
|
135
|
+
' | Unsigned Byte\n' +
|
|
136
|
+
' | \n' +
|
|
137
|
+
' |-\n' +
|
|
138
|
+
' | Block ID\n' +
|
|
139
|
+
' | VarInt\n' +
|
|
140
|
+
' | The new block ID for the block. <code><nowiki>id << 4 | data</nowiki></code>\n' +
|
|
141
|
+
' |}'
|
|
142
|
+
|
|
143
|
+
console.log(testTable3)
|
|
144
|
+
// need special handling
|
|
145
|
+
// not done yet : colspan in th
|
|
146
|
+
|
|
147
|
+
// console.log(JSON.stringify(protocol_extractor.parseWikiTable(testTable3.split("\n")),null,2));
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('parse a packet with rowspan', function () {
|
|
151
|
+
const testTable4 = '{| class="wikitable"\n' +
|
|
152
|
+
' ! Packet ID\n' +
|
|
153
|
+
' ! State\n' +
|
|
154
|
+
' ! Bound To\n' +
|
|
155
|
+
' ! Field Name\n' +
|
|
156
|
+
' ! Field Type\n' +
|
|
157
|
+
' ! Notes\n' +
|
|
158
|
+
' |-\n' +
|
|
159
|
+
' |rowspan="1"| 0x00\n' +
|
|
160
|
+
' | Status\n' +
|
|
161
|
+
' | Server\n' +
|
|
162
|
+
" |colspan=\"3\"| ''no fields''\n" +
|
|
163
|
+
' |}\n'
|
|
164
|
+
|
|
165
|
+
const expectedTable4 = [
|
|
167
166
|
{
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
'Packet ID': '0x00',
|
|
168
|
+
State: 'Status',
|
|
169
|
+
'Bound To': 'Server',
|
|
170
|
+
'Field Name': "''no fields''",
|
|
171
|
+
'Field Type': "''no fields''",
|
|
172
|
+
Notes: "''no fields''"
|
|
174
173
|
}
|
|
175
|
-
]
|
|
176
|
-
|
|
177
|
-
// need to handle colspan
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
//console.log(JSON.stringify(protocol_extractor.tableToRows(lines4),null,2));
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
//console.log(JSON.stringify(expectedTable4,null,2));
|
|
185
|
-
//console.log(JSON.stringify(actualTable4,null,2));
|
|
186
|
-
|
|
187
|
-
assert.deepEqual(actualTable4,expectedTable4)
|
|
188
|
-
//console.log(actualTable4);
|
|
189
|
-
//console.log(protocol_extractor.tableToPacket(actualTable4));
|
|
190
|
-
|
|
191
|
-
//console.log(protocol_extractor.tableToPacket(actualTable4));
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
//console.log(JSON.stringify(protocol_extractor.tableToRows(testTable5.split("\n")),null,2));
|
|
234
|
-
//console.log(protocol_extractor.parseWikiTable(testTable5.split("\n")));
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
// need to handle colspan
|
|
177
|
+
|
|
178
|
+
const lines4 = testTable4.split('\n')
|
|
179
|
+
// console.log(JSON.stringify(protocol_extractor.tableToRows(lines4),null,2));
|
|
180
|
+
|
|
181
|
+
const actualTable4 = protocolExtractor.parseWikiTable(lines4)
|
|
182
|
+
|
|
183
|
+
// console.log(JSON.stringify(expectedTable4,null,2));
|
|
184
|
+
// console.log(JSON.stringify(actualTable4,null,2));
|
|
185
|
+
|
|
186
|
+
assert.deepEqual(actualTable4, expectedTable4)
|
|
187
|
+
// console.log(actualTable4);
|
|
188
|
+
// console.log(protocol_extractor.tableToPacket(actualTable4));
|
|
189
|
+
|
|
190
|
+
// console.log(protocol_extractor.tableToPacket(actualTable4));
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('parse a packet with more rowspan', function () {
|
|
194
|
+
const testTable5 = '{| class="wikitable"\n' +
|
|
195
|
+
' |-\n' +
|
|
196
|
+
' ! Packet ID\n' +
|
|
197
|
+
' ! State\n' +
|
|
198
|
+
' ! Bound To\n' +
|
|
199
|
+
' ! Field Name\n' +
|
|
200
|
+
' ! Field Type\n' +
|
|
201
|
+
' ! Notes\n' +
|
|
202
|
+
' |-\n' +
|
|
203
|
+
' |rowspan="6"| 0x08\n' +
|
|
204
|
+
' |rowspan="6"| Play\n' +
|
|
205
|
+
' |rowspan="6"| Server\n' +
|
|
206
|
+
' | Location\n' +
|
|
207
|
+
' | Position\n' +
|
|
208
|
+
' | Block position\n' +
|
|
209
|
+
' |-\n' +
|
|
210
|
+
' | Face\n' +
|
|
211
|
+
' | Byte\n' +
|
|
212
|
+
' | The face on which the block is placed (see above)\n' +
|
|
213
|
+
' |-\n' +
|
|
214
|
+
' | Held Item\n' +
|
|
215
|
+
' | [[Slot Data|Slot]]\n' +
|
|
216
|
+
' | \n' +
|
|
217
|
+
' |-\n' +
|
|
218
|
+
' | Cursor Position X\n' +
|
|
219
|
+
' | Byte\n' +
|
|
220
|
+
' | The position of the crosshair on the block\n' +
|
|
221
|
+
' |-\n' +
|
|
222
|
+
' | Cursor Position Y \n' +
|
|
223
|
+
' | Byte\n' +
|
|
224
|
+
' | \n' +
|
|
225
|
+
' |-\n' +
|
|
226
|
+
' | Cursor Position Z\n' +
|
|
227
|
+
' | Byte\n' +
|
|
228
|
+
' | \n' +
|
|
229
|
+
' |}'
|
|
230
|
+
console.log(testTable5)
|
|
231
|
+
|
|
232
|
+
// console.log(JSON.stringify(protocol_extractor.tableToRows(testTable5.split("\n")),null,2));
|
|
233
|
+
// console.log(protocol_extractor.parseWikiTable(testTable5.split("\n")));
|
|
235
234
|
})
|
|
236
|
-
})
|
|
235
|
+
})
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|
package/circle.yml
DELETED