mcdevs-wiki-extractor 0.1.1 → 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.
@@ -1,465 +1,401 @@
1
- var WikiTextParser = require('parse-wikitext');
2
- var async=require('async');
3
- var fs = require('fs');
1
+ const WikiTextParser = require('parse-wikitext')
2
+ const async = require('async')
3
+ const R = require('ramda')
4
+ const fs = require('fs')
5
+ const pandoc = require('pdc')
6
+ const path = require('path')
4
7
 
5
- var wikiTextParser = new WikiTextParser("wiki.vg");
8
+ const wikiTextParser = new WikiTextParser('wiki.vg')
6
9
 
7
- var parseWikiTable=require("./common/table_parser").parseWikiTable;
8
- var getFirstTable=require("./common/table_parser").getFirstTable;
9
- var tableToRows=require("./common/table_parser").tableToRows;
10
+ const parseWikiTable = require('./common/table_parser').parseWikiTable
11
+ const getFirstTable = require('./common/table_parser').getFirstTable
12
+ const tableToRows = require('./common/table_parser').tableToRows
13
+ const toOldNames = require('./common/toOldNames').transformPacketName
10
14
 
11
15
  module.exports = {
12
- tableToRows:tableToRows,
13
- parseWikiTable:parseWikiTable,
14
- tableToPacket:tableToPacket,
15
- writeProtocol:writeProtocol
16
- };
16
+ tableToRows: tableToRows,
17
+ parseWikiTable: parseWikiTable,
18
+ tableToPacket: tableToPacket,
19
+ writeProtocol: writeProtocol,
20
+ writeComments: writeComments
21
+ }
17
22
 
18
- function writeProtocol(protocolFilePath,cb)
19
- {
23
+ function writeComments (protocolFilePath, cb) {
20
24
  async.waterfall([
21
- getProtocol
22
- ],
23
- function(err,protocol) {
24
- if(err)
25
- return cb(err);
26
- //console.log(JSON.stringify(protocol,null,2));
27
- fs.writeFile(protocolFilePath, JSON.stringify(protocol,null,2),cb);
28
- }
29
- );
25
+ getProtocolComments
26
+ ],
27
+ function (err, protocol) {
28
+ if (err) { return cb(err) }
29
+ // console.log(JSON.stringify(protocol,null,2));
30
+ fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
31
+ }
32
+ )
30
33
  }
31
34
 
35
+ function writeProtocol (protocolFilePath, cb) {
36
+ async.waterfall([
37
+ getProtocol
38
+ ],
39
+ function (err, protocol) {
40
+ if (err) { return cb(err) }
41
+ // console.log(JSON.stringify(protocol,null,2));
42
+ fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
43
+ }
44
+ )
45
+ }
32
46
 
33
- function retrieveProtocol(cb)
34
- {
35
- wikiTextParser.getArticle("Protocol", function(err, data) {
36
- if(err)
37
- {
38
- cb(err);
39
- return;
47
+ function retrieveProtocol (cb) {
48
+ wikiTextParser.getArticle('Protocol', function (err, data) {
49
+ if (err) {
50
+ cb(err)
51
+ return
40
52
  }
41
- var sectionObject = wikiTextParser.pageToSectionObject(data);
42
- cb(err,sectionObject);
43
- });
53
+ const sectionObject = wikiTextParser.pageToSectionObject(data)
54
+ cb(err, sectionObject)
55
+ })
44
56
  }
45
57
 
46
- function getProtocol(cb) {
58
+ function getProtocol (cb) {
47
59
  async.waterfall([
48
60
  retrieveProtocol,
49
- extractProtocol,
50
- transformProtocol
51
- ],cb);
61
+ extractProtocol.bind(null, parsePacket),
62
+ transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket, toOldNames)
63
+ ], cb)
52
64
  }
53
65
 
54
- function extractProtocol(sectionObject,cb)
55
- {
56
- var notStates = ["content", "Definitions", "Packet format"];
66
+ function getProtocolComments (cb) {
67
+ async.waterfall([
68
+ retrieveProtocol,
69
+ extractProtocol.bind(null, commentsForPacket),
70
+ transformProtocol.bind(null, function () { return {} }, function (obj, name, v) { obj[name] = v; return obj }, function (v) { return v }, toOldNames)
71
+ ], cb)
72
+ }
57
73
 
58
- var protocol = Object
59
- .keys(sectionObject)
60
- .filter(function(key) {
61
- return notStates.indexOf(key) == -1;
62
- })
63
- .reduce(function(protocol, state) {
64
- protocol[state] = Object
65
- .keys(sectionObject[state])
66
- .filter(function(key) {
67
- return key != "content"
68
- })
69
- .reduce(function(stateO, direction) {
70
- stateO[direction] = Object
71
- .keys(sectionObject[state][direction])
72
- .filter(function(key) {
73
- return key != "content"
74
- })
75
- .reduce(function(packetsO, packetName) {
76
- packetsO[packetName] = parsePacket(sectionObject[state][direction][packetName]['content']);
77
- return packetsO;
78
- }, {});
79
- return stateO;
80
- }, {});
81
- return protocol;
82
- }, {});
74
+ function extractProtocol (fnPacket, sectionObject, cb) {
75
+ const notStates = R.omit(['content', 'Definitions', 'Packet format'])
83
76
 
84
- cb(null,protocol);
77
+ async.mapValues(notStates(sectionObject), function (state, stateName, cb) {
78
+ async.mapValues(notStates(state), function (direction, directionName, cb) {
79
+ async.mapValues(notStates(direction), function (packet, packetName, cb) {
80
+ fnPacket(packet.content, cb)
81
+ }, cb)
82
+ }, cb)
83
+ }, cb)
85
84
  }
86
85
 
87
-
88
- function parsePacket(packetText)
89
- {
90
- return tableToPacket(parseWikiTable(getFirstTable(packetText)));
86
+ function commentsForPacket (packetText, cb) {
87
+ let afterFirstTable = false
88
+ let inTable = false
89
+ const table = parseWikiTable(getFirstTable(packetText))
90
+ const id = table.length > 0 && table[0]['Packet ID'] && table[0]['Packet ID'].toLowerCase()
91
+ const packet = packetText.reduce(function (acc, line) {
92
+ if (!afterFirstTable && line === '{| class="wikitable"') { inTable = true } else if (inTable && line === ' |}') {
93
+ inTable = false
94
+ afterFirstTable = true
95
+ } else if (afterFirstTable) { acc.after.push(line) } else if (!inTable) { acc.before.push(line) }
96
+ return acc
97
+ }, { before: [], after: [], id: id })
98
+ pandoc(packet.before.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
99
+ if (err) return cb(err)
100
+ packet.before = result.split('\n')
101
+ pandoc(packet.after.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
102
+ if (err) return cb(err)
103
+ packet.after = result.split('\n')
104
+ return cb(null, packet)
105
+ })
106
+ })
91
107
  }
92
108
 
109
+ function parsePacket (packetText, cb) {
110
+ cb(null, tableToPacket(parseWikiTable(getFirstTable(packetText))))
111
+ }
93
112
 
94
- function tableToPacket(table)
95
- {
96
- var packet={};
97
- if(table.length==0 || table[0]["Packet ID"]==undefined)
98
- return null;
99
- packet["id"]=table[0]["Packet ID"];
100
- packet["fields"]=table
101
- .filter(function(value){
102
- return !value["Field Name"] || value["Field Name"]!="''no fields''"
113
+ function tableToPacket (table) {
114
+ const packet = {}
115
+ if (table.length === 0 || table[0]['Packet ID'] === undefined) { return null }
116
+ packet.id = table[0]['Packet ID']
117
+ packet.fields = table
118
+ .filter(function (value) {
119
+ return !value['Field Name'] || value['Field Name'] !== "''no fields''"
103
120
  })
104
- .map(function(value){
105
- if(value["Field Name"]==undefined || value["Field Type"]==undefined) {
106
- //console.log(value);
107
- return null;
108
- }
109
- return {
110
- "name":value["Field Name"],
111
- "type":value["Field Type"]
121
+ .map(function (value) {
122
+ if (value['Field Name'] === undefined || value['Field Type'] === undefined) {
123
+ // console.log(value);
124
+ return null
125
+ }
126
+ return {
127
+ name: value['Field Name'],
128
+ type: value['Field Type']
129
+ }
130
+ })
131
+ return packet
132
+ }
133
+
134
+ function initialPacket () {
135
+ return {
136
+ types: {
137
+ packet: ['container', [
138
+ {
139
+ name: 'name',
140
+ type: ['mapper', {
141
+ type: 'varint',
142
+ mappings: {}
143
+ }]
144
+ }, {
145
+ name: 'params',
146
+ type: ['switch', {
147
+ compareTo: 'name',
148
+ fields: {}
149
+ }]
150
+ }
151
+ ]]
112
152
  }
113
- });
114
- return packet;
153
+ }
154
+ }
155
+
156
+ function appendPacketToProto (state, name, packet) {
157
+ state.types['packet_' + name] = ['container', packet.fields]
158
+ state.types.packet[1][0].type[1].mappings[packet.id] = name
159
+ state.types.packet[1][1].type[1].fields[name] = 'packet_' + name
160
+ return state
115
161
  }
116
162
 
117
163
  // transforms
118
- function transformProtocol(protocol,cb)
119
- {
120
- var transformedProtocol = Object
164
+ function transformProtocol (initialState, addToPacket, transformPacket, transformPacketName, protocol, cb) {
165
+ let transformedProtocol = Object
121
166
  .keys(protocol)
122
- .reduce(function(transformedProtocol, state) {
123
- var transformedState=transformState(state);
167
+ .reduce(function (transformedProtocol, state) {
168
+ const transformedState = transformState(state)
124
169
  transformedProtocol[transformedState] = Object
125
170
  .keys(protocol[state])
126
- .reduce(function(stateO, direction) {
127
- var transformedDirection=transformDirection(direction);
171
+ .reduce(function (stateO, direction) {
172
+ const transformedDirection = transformDirection(direction)
128
173
  stateO[transformedDirection] = Object
129
174
  .keys(protocol[state][direction])
130
- .reduce(function(packetsO, packetName) {
131
- var transformedPacket=transformPacket(protocol[state][direction][packetName],transformedState,transformedDirection);
132
- var transformedPacketName=transformPacketName(packetName,transformedState,transformedDirection,transformedPacket ? transformedPacket["id"] : null);
133
- packetsO[transformedPacketName] = transformedPacket;
134
- return packetsO;
135
- }, {});
136
- return stateO;
137
- }, {});
138
- return transformedProtocol;
139
- }, {});
140
- transformedProtocol=reorder(["handshaking","status","login","play"],transformedProtocol);
141
- cb(null,transformedProtocol);
175
+ .reduce(function (packetsO, packetName) {
176
+ const transformedPacket = transformPacket(protocol[state][direction][packetName], transformedState, transformedDirection)
177
+ const transformedPacketName = transformPacketName(packetName, transformedState, transformedDirection, transformedPacket ? transformedPacket.id : null)
178
+ return addToPacket(packetsO, transformedPacketName, transformedPacket)
179
+ }, initialState())
180
+ return stateO
181
+ }, {})
182
+ return transformedProtocol
183
+ }, {})
184
+ transformedProtocol = reorder(['handshaking', 'status', 'login', 'play'], transformedProtocol)
185
+ cb(null, transformedProtocol)
142
186
  }
143
187
 
144
188
  function reorder (order, obj) {
145
- return order.reduce (function (rslt, prop) {
146
- rslt[prop] = obj[prop];
147
- return rslt;
148
- }, {});
189
+ return order.reduce(function (rslt, prop) {
190
+ rslt[prop] = obj[prop]
191
+ return rslt
192
+ }, {})
149
193
  }
150
194
 
151
- function transformPacket(packet,state,direction)
152
- {
153
- if(!packet)
154
- return null;
155
- var transformedId=transformId(packet["id"]);
195
+ function transformPacket (packet, state, direction) {
196
+ if (!packet) { return null }
197
+ const transformedId = transformId(packet.id)
156
198
  return {
157
- "id":transformedId,
158
- "fields":packet["fields"] ? packet["fields"].map(function(field){return transformField(field,state,direction,transformedId);}) : null
159
- };
160
- }
161
-
162
- function transformId(id)
163
- {
164
- return id ? id.toLowerCase() : null;
199
+ id: transformedId,
200
+ fields: packet.fields ? packet.fields.map(function (field) { return transformField(field, state, direction, transformedId) }) : null
201
+ }
165
202
  }
166
203
 
167
- function transformField(field,state,direction,id)
168
- {
169
- return field ? {
170
- "name":transformFieldName(field["name"],state,direction,id),
171
- "type":transformFieldType(field["type"])
172
- } : null;
204
+ function transformId (id) {
205
+ return id ? id.toLowerCase() : null
173
206
  }
174
207
 
175
-
176
- function transformState(state)
177
- {
178
- return state.toLowerCase();
208
+ function transformField (field, state, direction, id) {
209
+ return field
210
+ ? {
211
+ name: transformFieldName(field.name, state, direction, id),
212
+ type: transformFieldType(field.type)
213
+ }
214
+ : null
179
215
  }
180
216
 
181
- function transformDirection(direction)
182
- {
183
- if(direction=="Serverbound") return "toServer";
184
- if(direction=="Clientbound") return "toClient";
217
+ function transformState (state) {
218
+ return state.toLowerCase()
185
219
  }
186
220
 
187
- function toSnakeCase(name)
188
- {
189
- return name.split(" ").map(function(word){return word.toLowerCase();}).join("_");
221
+ function transformDirection (direction) {
222
+ if (direction === 'Serverbound') return 'toServer'
223
+ if (direction === 'Clientbound') return 'toClient'
190
224
  }
191
225
 
192
- function toCamelCase(name)
193
- {
194
- var words=name.split(" ");
195
- words[0]=words[0].toLowerCase();
196
- for(i=1;i<words.length;i++) words[i]=words[i].charAt(0).toUpperCase()+words[i].slice(1).toLowerCase();
197
- return words.join("");
226
+ function toCamelCase (name) {
227
+ const words = name.split(' ')
228
+ words[0] = words[0].toLowerCase()
229
+ for (let i = 1; i < words.length; i++) words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase()
230
+ return words.join('')
198
231
  }
199
232
 
200
- var oldNames={
201
- "handshaking": {
202
- "toServer": {
203
- "0x00":"set_protocol"
204
- }
205
- },
206
- "status": {
207
- "toClient": {
208
- "0x00":"server_info",
209
- "0x01":"ping"
210
- },
211
- "toServer": {
212
- "0x00":"ping_start"
213
- }
214
- },
215
- "login": {
216
- "toClient": {
217
- "0x01":"encryption_begin",
218
- "0x02":"success",
219
- "0x03":"compress"
220
- },
221
- "toServer": {
222
- "0x01":"encryption_begin"
223
- }
224
- },
225
- "play": {
226
- "toClient":{
227
- "0x01":"login",
228
- "0x02":"chat",
229
- "0x03":"update_time",
230
- "0x08":"position",
231
- "0x09":"held_item_slot",
232
- "0x0a":"bed",
233
- "0x0c":"named_entity_spawn",
234
- "0x0d":"collect",
235
- "0x0e":"spawn_entity",
236
- "0x0f":"spawn_entity_living",
237
- "0x10":"spawn_entity_painting",
238
- "0x11":"spawn_entity_experience_orb",
239
- "0x13":"entity_destroy",
240
- "0x15":"rel_entity_move",
241
- "0x17":"entity_move_look",
242
- "0x19":"entity_head_rotation",
243
- "0x1f":"experience",
244
- "0x20":"update_attributes",
245
- "0x21":"map_chunk",
246
- "0x28":"world_event",
247
- "0x29":"named_sound_effect",
248
- "0x2a":"world_particles",
249
- "0x2b":"game_state_change",
250
- "0x2c":"spawn_entity_weather",
251
- "0x31":"craft_progress_bar",
252
- "0x32":"transaction",
253
- "0x34":"map",
254
- "0x35":"tile_entity_data",
255
- "0x36":"open_sign_entity",
256
- "0x38":"player_info",
257
- "0x39":"abilities",
258
- "0x3a":"tab_complete",
259
- "0x3c":"scoreboard_score",
260
- "0x3d":"scoreboard_display_objective",
261
- "0x3e":"scoreboard_team",
262
- "0x3f":"custom_payload",
263
- "0x40":"kick_disconnect",
264
- "0x41":"difficulty",
265
- "0x47":"playerlist_header"
266
- },
267
- "toServer": {
268
- "0x01":"chat",
269
- "0x03":"flying",
270
- "0x04":"position",
271
- "0x05":"look",
272
- "0x06":"position_look",
273
- "0x07":"block_dig",
274
- "0x08":"block_place",
275
- "0x09":"held_item_slot",
276
- "0x0a":"arm_animation",
277
- "0x0e":"window_click",
278
- "0x0f":"transaction",
279
- "0x10":"set_creative_slot",
280
- "0x13":"abilities",
281
- "0x14":"tab_complete",
282
- "0x15":"settings",
283
- "0x16":"client_command",
284
- "0x17":"custom_payload",
285
- "0x19":"resource_pack_receive"
286
- }
287
- }
288
- };
289
-
290
- function toOldNames(name,state,direction,id)
291
- {
292
- return oldNames[state] && oldNames[state][direction] && oldNames[state][direction][id] ? oldNames[state][direction][id] : name;
293
- }
294
-
295
- function transformPacketName(packetName,state,direction,id)
296
- {
297
- return toOldNames(toSnakeCase(packetName),state,direction,id);
298
- }
299
-
300
- function transformFieldType(fieldType)
301
- {
302
- fieldType=fieldType.toLowerCase().replace("unsigned ","u").replace("boolean","bool").replace("[[chat]]","string")
303
- .replace("angle","byte").replace("uuid","UUID");
304
- if(fieldType.indexOf("slot")!=-1) return "slot";
305
- if(fieldType.indexOf("entity metadata")!=-1) return "entityMetadata";
306
- if(fieldType.indexOf("nbt")!=-1) return "restBuffer";
307
- return fieldType;
233
+ function transformFieldType (fieldType) {
234
+ fieldType = fieldType.toLowerCase().replace('unsigned ', 'u').replace('boolean', 'bool').replace('[[chat]]', 'string')
235
+ .replace('angle', 'byte').replace('uuid', 'UUID')
236
+ if (fieldType.indexOf('varint') !== -1) return 'varint'
237
+ if (fieldType.indexOf('slot') !== -1) return 'slot'
238
+ if (fieldType.indexOf('entity metadata') !== -1) return 'entityMetadata'
239
+ if (fieldType.indexOf('nbt') !== -1) return 'restBuffer'
240
+ if (fieldType.indexOf('ubyte') !== -1) return 'u8'
241
+ if (fieldType.indexOf('byte') !== -1) return 'i8'
242
+ if (fieldType.indexOf('ushort') !== -1) return 'u16'
243
+ if (fieldType.indexOf('short') !== -1) return 'i16'
244
+ if (fieldType.indexOf('uint') !== -1) return 'u32'
245
+ if (fieldType.indexOf('int') !== -1) return 'i32'
246
+ if (fieldType.indexOf('ulong') !== -1) return 'u64'
247
+ if (fieldType.indexOf('long') !== -1) return 'i64'
248
+ return fieldType
308
249
  }
309
250
 
310
251
  // specific has priority over general
311
252
 
312
253
  // specific
313
- var newToOldFieldNamesSpecific={
314
- "status":{
315
- "toClient":{
316
- "0x01":{
317
- "payload":"time"
254
+ const newToOldFieldNamesSpecific = {
255
+ status: {
256
+ toClient: {
257
+ '0x01': {
258
+ payload: 'time'
318
259
  }
319
260
  },
320
- "toServer":{
321
- "0x01":{
322
- "payload":"time"
261
+ toServer: {
262
+ '0x01': {
263
+ payload: 'time'
323
264
  }
324
265
  }
325
266
  },
326
- "login": {
327
- "toServer": {
328
- "0x00":{
329
- "name":"username"
267
+ login: {
268
+ toServer: {
269
+ '0x00': {
270
+ name: 'username'
330
271
  }
331
272
  }
332
273
  },
333
- "play": {
334
- "toClient": {
335
- "0x01":{
336
- "gamemode":"gameMode"
274
+ play: {
275
+ toClient: {
276
+ '0x01': {
277
+ gamemode: 'gameMode'
337
278
  },
338
- "0x0e":{
339
- "data":"objectData"
279
+ '0x0e': {
280
+ data: 'objectData'
340
281
  },
341
- "0x21":{
342
- "data":"chunkData"
282
+ '0x21': {
283
+ data: 'chunkData'
343
284
  },
344
- "0x2b":{
345
- "value":"gameMode"
285
+ '0x2b': {
286
+ value: 'gameMode'
346
287
  },
347
- "0x2f":{
348
- "slotData":"item"
288
+ '0x2f': {
289
+ slotData: 'item'
349
290
  },
350
- "0x30":{
351
- "slotData":"items"
291
+ '0x30': {
292
+ slotData: 'items'
352
293
  },
353
- "0x32":{
354
- "actionNumber":"action"
294
+ '0x32': {
295
+ actionNumber: 'action'
355
296
  },
356
- "0x3b":{
357
- "mode":"action",
358
- "objectiveName":"name"
297
+ '0x3b': {
298
+ mode: 'action',
299
+ objectiveName: 'name'
359
300
  },
360
- "0x3c":{
361
- "scoreName":"itemName",
362
- "objectiveName":"scoreName"
301
+ '0x3c': {
302
+ scoreName: 'itemName',
303
+ objectiveName: 'scoreName'
363
304
  },
364
- "0x3d":{
365
- "scoreName":"name"
305
+ '0x3d': {
306
+ scoreName: 'name'
366
307
  }
367
308
  },
368
- "toServer":{
369
- "0x02":{
370
- "type":"mouse"
309
+ toServer: {
310
+ '0x02': {
311
+ type: 'mouse'
371
312
  },
372
- "0x08":{
373
- "face":"direction",
374
- "cursorPositionX":"cursorX",
375
- "cursorPositionY":"cursorY",
376
- "cursorPositionZ":"cursorZ"
313
+ '0x08': {
314
+ face: 'direction',
315
+ cursorPositionX: 'cursorX',
316
+ cursorPositionY: 'cursorY',
317
+ cursorPositionZ: 'cursorZ'
377
318
  },
378
- "0x09":{
379
- "slot":"slotId"
319
+ '0x09': {
320
+ slot: 'slotId'
380
321
  },
381
- "0x0b":{
382
- "payload":"actionId"
322
+ '0x0b': {
323
+ payload: 'actionId'
383
324
  },
384
- "0x0c":{
385
- "flags":"jump"
325
+ '0x0c': {
326
+ flags: 'jump'
386
327
  },
387
- "0x0e":{
388
- "actionNumber":"action"
328
+ '0x0e': {
329
+ actionNumber: 'action'
389
330
  },
390
- "0x0f":{
391
- "actionNumber":"action"
331
+ '0x0f': {
332
+ actionNumber: 'action'
392
333
  },
393
- "0x16":{
394
- "actionId":"payload"
334
+ '0x16': {
335
+ actionId: 'payload'
395
336
  }
396
337
  }
397
338
  }
398
- };
339
+ }
399
340
 
400
341
  // should probably be converted entirely in the specific format
401
342
  // general
402
- var newToOldFieldNamesGeneral={
403
- "serverAddress":"serverHost",
404
- "jsonResponse":"response",
405
- "jsonData":"message",
406
- "worldAge":"age",
407
- "timeOfDay":"time",
408
- "playerUuid":"playerUUID",
409
- "deltaX":"dX",
410
- "deltaY":"dY",
411
- "deltaZ":"dZ",
412
- "chunkX":"x",
413
- "chunkZ":"z",
414
- "ground-upContinuous":"groundUp",
415
- "primaryBitMask":"bitMap",
416
- "size":"chunkDataLength",
417
- "blockId":"type",
418
- "blockType":"blockId",
419
- "recordCount":"count",
420
- "records":"affectedBlockOffsets",
421
- "disableRelativeVolume":"global",
422
- "effectPositionX":"x",
423
- "effectPositionY":"y",
424
- "effectPositionZ":"z",
425
- "particleCount":"particles",
426
- "windowType":"inventoryType",
427
- "numberOfSlots":"slotCount",
428
- "line1":"text1",
429
- "line2":"text2",
430
- "line3":"text3",
431
- "line4":"text4",
432
- "objectiveValue":"displayText",
433
- "teamName":"team",
434
- "teamDisplayName":"name",
435
- "teamPrefix":"prefix",
436
- "teamSuffix":"suffix",
437
- "targetX":"x",
438
- "targetY":"y",
439
- "targetZ":"z",
440
- "feetY":"y",
441
- "button":"mouseButton",
442
- "clickedItem":"item",
443
- "lookedAtBlock":"block",
444
- "chatMode":"chatFlags",
445
- "displayedSkinParts":"skinParts",
446
- "targetPlayer":"target"
447
- };
448
-
449
- function toOldFieldName(fieldName,state,direction,id)
450
- {
451
- if(newToOldFieldNamesSpecific[state]
452
- && newToOldFieldNamesSpecific[state][direction]
453
- && newToOldFieldNamesSpecific[state][direction][id]
454
- && newToOldFieldNamesSpecific[state][direction][id][fieldName])
455
- return newToOldFieldNamesSpecific[state][direction][id][fieldName];
456
- if(newToOldFieldNamesGeneral[fieldName])
457
- return newToOldFieldNamesGeneral[fieldName];
458
- return fieldName;
343
+ const newToOldFieldNamesGeneral = {
344
+ serverAddress: 'serverHost',
345
+ jsonResponse: 'response',
346
+ jsonData: 'message',
347
+ worldAge: 'age',
348
+ timeOfDay: 'time',
349
+ playerUuid: 'playerUUID',
350
+ deltaX: 'dX',
351
+ deltaY: 'dY',
352
+ deltaZ: 'dZ',
353
+ chunkX: 'x',
354
+ chunkZ: 'z',
355
+ 'ground-upContinuous': 'groundUp',
356
+ primaryBitMask: 'bitMap',
357
+ size: 'chunkDataLength',
358
+ blockId: 'type',
359
+ blockType: 'blockId',
360
+ recordCount: 'count',
361
+ records: 'affectedBlockOffsets',
362
+ disableRelativeVolume: 'global',
363
+ effectPositionX: 'x',
364
+ effectPositionY: 'y',
365
+ effectPositionZ: 'z',
366
+ particleCount: 'particles',
367
+ windowType: 'inventoryType',
368
+ numberOfSlots: 'slotCount',
369
+ line1: 'text1',
370
+ line2: 'text2',
371
+ line3: 'text3',
372
+ line4: 'text4',
373
+ objectiveValue: 'displayText',
374
+ teamName: 'team',
375
+ teamDisplayName: 'name',
376
+ teamPrefix: 'prefix',
377
+ teamSuffix: 'suffix',
378
+ targetX: 'x',
379
+ targetY: 'y',
380
+ targetZ: 'z',
381
+ feetY: 'y',
382
+ button: 'mouseButton',
383
+ clickedItem: 'item',
384
+ lookedAtBlock: 'block',
385
+ chatMode: 'chatFlags',
386
+ displayedSkinParts: 'skinParts',
387
+ targetPlayer: 'target'
459
388
  }
460
389
 
461
- function transformFieldName(fieldName,state,direction,id)
462
- {
463
- return toOldFieldName(toCamelCase(fieldName),state,direction,id);
390
+ function toOldFieldName (fieldName, state, direction, id) {
391
+ if (newToOldFieldNamesSpecific[state] &&
392
+ newToOldFieldNamesSpecific[state][direction] &&
393
+ newToOldFieldNamesSpecific[state][direction][id] &&
394
+ newToOldFieldNamesSpecific[state][direction][id][fieldName]) { return newToOldFieldNamesSpecific[state][direction][id][fieldName] }
395
+ if (newToOldFieldNamesGeneral[fieldName]) { return newToOldFieldNamesGeneral[fieldName] }
396
+ return fieldName
464
397
  }
465
398
 
399
+ function transformFieldName (fieldName, state, direction, id) {
400
+ return toOldFieldName(toCamelCase(fieldName), state, direction, id)
401
+ }