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.
@@ -1,543 +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
- writeComments:writeComments
17
- };
16
+ tableToRows: tableToRows,
17
+ parseWikiTable: parseWikiTable,
18
+ tableToPacket: tableToPacket,
19
+ writeProtocol: writeProtocol,
20
+ writeComments: writeComments
21
+ }
18
22
 
19
- function writeComments(protocolFilePath,cb)
20
- {
23
+ function writeComments (protocolFilePath, cb) {
21
24
  async.waterfall([
22
- getProtocolComments
23
- ],
24
- function(err,protocol) {
25
- if(err)
26
- return cb(err);
27
- //console.log(JSON.stringify(protocol,null,2));
28
- fs.writeFile(protocolFilePath, JSON.stringify(protocol,null,2),cb);
29
- }
30
- );
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
+ )
31
33
  }
32
34
 
33
-
34
- function writeProtocol(protocolFilePath,cb)
35
- {
35
+ function writeProtocol (protocolFilePath, cb) {
36
36
  async.waterfall([
37
- getProtocol
38
- ],
39
- function(err,protocol) {
40
- if(err)
41
- return cb(err);
42
- //console.log(JSON.stringify(protocol,null,2));
43
- fs.writeFile(protocolFilePath, JSON.stringify(protocol,null,2),cb);
44
- }
45
- );
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
+ )
46
45
  }
47
46
 
48
-
49
- function retrieveProtocol(cb)
50
- {
51
- wikiTextParser.getArticle("Protocol", function(err, data) {
52
- if(err)
53
- {
54
- cb(err);
55
- return;
47
+ function retrieveProtocol (cb) {
48
+ wikiTextParser.getArticle('Protocol', function (err, data) {
49
+ if (err) {
50
+ cb(err)
51
+ return
56
52
  }
57
- var sectionObject = wikiTextParser.pageToSectionObject(data);
58
- cb(err,sectionObject);
59
- });
53
+ const sectionObject = wikiTextParser.pageToSectionObject(data)
54
+ cb(err, sectionObject)
55
+ })
60
56
  }
61
57
 
62
- function getProtocol(cb) {
58
+ function getProtocol (cb) {
63
59
  async.waterfall([
64
60
  retrieveProtocol,
65
61
  extractProtocol.bind(null, parsePacket),
66
- transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket, transformPacketName)
67
- ],cb);
62
+ transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket, toOldNames)
63
+ ], cb)
68
64
  }
69
65
 
70
- function getProtocolComments(cb) {
66
+ function getProtocolComments (cb) {
71
67
  async.waterfall([
72
68
  retrieveProtocol,
73
69
  extractProtocol.bind(null, commentsForPacket),
74
- transformProtocol.bind(null, function() { return {}; }, function(obj, name, v) { obj[name] = v; return obj; }, function(v) { return v; }, transformPacketName)
75
- ],cb);
70
+ transformProtocol.bind(null, function () { return {} }, function (obj, name, v) { obj[name] = v; return obj }, function (v) { return v }, toOldNames)
71
+ ], cb)
76
72
  }
77
73
 
78
- function extractProtocol(fnPacket, sectionObject,cb)
79
- {
80
- var notStates = ["content", "Definitions", "Packet format"];
81
-
82
- var protocol = Object
83
- .keys(sectionObject)
84
- .filter(function(key) {
85
- return notStates.indexOf(key) == -1;
86
- })
87
- .reduce(function(protocol, state) {
88
- protocol[state] = Object
89
- .keys(sectionObject[state])
90
- .filter(function(key) {
91
- return key != "content"
92
- })
93
- .reduce(function(stateO, direction) {
94
- stateO[direction] = Object
95
- .keys(sectionObject[state][direction])
96
- .filter(function(key) {
97
- return key != "content"
98
- })
99
- .reduce(function(packetsO, packetName) {
100
- packetsO[packetName] = fnPacket(sectionObject[state][direction][packetName]['content']);
101
- return packetsO;
102
- }, {});
103
- return stateO;
104
- }, {});
105
- return protocol;
106
- }, {});
74
+ function extractProtocol (fnPacket, sectionObject, cb) {
75
+ const notStates = R.omit(['content', 'Definitions', 'Packet format'])
107
76
 
108
- 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)
109
84
  }
110
85
 
111
- function commentsForPacket(packetText) {
112
- var afterFirstTable = false;
113
- var inTable = false;
114
- var table = parseWikiTable(getFirstTable(packetText));
115
- var id = table.length > 0 && table[0]["Packet ID"] && table[0]["Packet ID"].toLowerCase();
116
- return packetText.reduce(function(acc, line){
117
- if(!afterFirstTable && line == '{| class="wikitable"')
118
- inTable=true;
119
- else if(inTable && line == ' |}') {
120
- inTable = false;
121
- afterFirstTable = true;
122
- }
123
- else if(afterFirstTable)
124
- acc.after.push(line);
125
- else if (!inTable)
126
- acc.before.push(line);
127
- return acc;
128
- }, { before: [], after: [], id: id });
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
+ })
129
107
  }
130
108
 
131
- function parsePacket(packetText)
132
- {
133
- return tableToPacket(parseWikiTable(getFirstTable(packetText)));
109
+ function parsePacket (packetText, cb) {
110
+ cb(null, tableToPacket(parseWikiTable(getFirstTable(packetText))))
134
111
  }
135
112
 
136
-
137
- function tableToPacket(table)
138
- {
139
- var packet={};
140
- if(table.length==0 || table[0]["Packet ID"]==undefined)
141
- return null;
142
- packet["id"]=table[0]["Packet ID"];
143
- packet["fields"]=table
144
- .filter(function(value){
145
- 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''"
146
120
  })
147
- .map(function(value){
148
- if(value["Field Name"]==undefined || value["Field Type"]==undefined) {
149
- //console.log(value);
150
- return null;
151
- }
152
- return {
153
- "name":value["Field Name"],
154
- "type":value["Field Type"]
155
- }
156
- });
157
- return packet;
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
158
132
  }
159
133
 
160
- function initialPacket() {
134
+ function initialPacket () {
161
135
  return {
162
136
  types: {
163
137
  packet: ['container', [
164
138
  {
165
- name: "name",
166
- type: ["mapper", {
167
- type: "varint",
139
+ name: 'name',
140
+ type: ['mapper', {
141
+ type: 'varint',
168
142
  mappings: {}
169
143
  }]
170
144
  }, {
171
- name: "params",
172
- type: ["switch", {
173
- compareTo: "name",
145
+ name: 'params',
146
+ type: ['switch', {
147
+ compareTo: 'name',
174
148
  fields: {}
175
149
  }]
176
150
  }
177
151
  ]]
178
152
  }
179
- };
153
+ }
180
154
  }
181
155
 
182
- function appendPacketToProto(state, name, packet) {
183
- state.types["packet_" + name] = ['container', packet.fields];
184
- state.types.packet[1][0].type[1].mappings[packet.id] = name;
185
- state.types.packet[1][1].type[1].fields[name] = "packet_" + name;
186
- return state;
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
187
161
  }
188
162
 
189
163
  // transforms
190
- function transformProtocol(initialState, addToPacket, transformPacket, transformPacketName, protocol,cb)
191
- {
192
- var transformedProtocol = Object
164
+ function transformProtocol (initialState, addToPacket, transformPacket, transformPacketName, protocol, cb) {
165
+ let transformedProtocol = Object
193
166
  .keys(protocol)
194
- .reduce(function(transformedProtocol, state) {
195
- var transformedState=transformState(state);
167
+ .reduce(function (transformedProtocol, state) {
168
+ const transformedState = transformState(state)
196
169
  transformedProtocol[transformedState] = Object
197
170
  .keys(protocol[state])
198
- .reduce(function(stateO, direction) {
199
- var transformedDirection=transformDirection(direction);
171
+ .reduce(function (stateO, direction) {
172
+ const transformedDirection = transformDirection(direction)
200
173
  stateO[transformedDirection] = Object
201
174
  .keys(protocol[state][direction])
202
- .reduce(function(packetsO, packetName) {
203
- var transformedPacket=transformPacket(protocol[state][direction][packetName],transformedState,transformedDirection);
204
- var transformedPacketName=transformPacketName(packetName,transformedState,transformedDirection,transformedPacket ? transformedPacket["id"] : null);
205
- return addToPacket(packetsO, transformedPacketName, transformedPacket);
206
- }, initialState());
207
- return stateO;
208
- }, {});
209
- return transformedProtocol;
210
- }, {});
211
- transformedProtocol=reorder(["handshaking","status","login","play"],transformedProtocol);
212
- 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)
213
186
  }
214
187
 
215
188
  function reorder (order, obj) {
216
- return order.reduce (function (rslt, prop) {
217
- rslt[prop] = obj[prop];
218
- return rslt;
219
- }, {});
189
+ return order.reduce(function (rslt, prop) {
190
+ rslt[prop] = obj[prop]
191
+ return rslt
192
+ }, {})
220
193
  }
221
194
 
222
- function transformPacket(packet,state,direction)
223
- {
224
- if(!packet)
225
- return null;
226
- var transformedId=transformId(packet["id"]);
195
+ function transformPacket (packet, state, direction) {
196
+ if (!packet) { return null }
197
+ const transformedId = transformId(packet.id)
227
198
  return {
228
- "id":transformedId,
229
- "fields":packet["fields"] ? packet["fields"].map(function(field){return transformField(field,state,direction,transformedId);}) : null
230
- };
231
- }
232
-
233
- function transformId(id)
234
- {
235
- return id ? id.toLowerCase() : null;
236
- }
237
-
238
- function transformField(field,state,direction,id)
239
- {
240
- return field ? {
241
- "name":transformFieldName(field["name"],state,direction,id),
242
- "type":transformFieldType(field["type"])
243
- } : null;
199
+ id: transformedId,
200
+ fields: packet.fields ? packet.fields.map(function (field) { return transformField(field, state, direction, transformedId) }) : null
201
+ }
244
202
  }
245
203
 
246
-
247
- function transformState(state)
248
- {
249
- return state.toLowerCase();
204
+ function transformId (id) {
205
+ return id ? id.toLowerCase() : null
250
206
  }
251
207
 
252
- function transformDirection(direction)
253
- {
254
- if(direction=="Serverbound") return "toServer";
255
- if(direction=="Clientbound") return "toClient";
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
256
215
  }
257
216
 
258
- function toSnakeCase(name)
259
- {
260
- return name.split(" ").map(function(word){return word.toLowerCase();}).join("_");
217
+ function transformState (state) {
218
+ return state.toLowerCase()
261
219
  }
262
220
 
263
- function toCamelCase(name)
264
- {
265
- var words=name.split(" ");
266
- words[0]=words[0].toLowerCase();
267
- for(i=1;i<words.length;i++) words[i]=words[i].charAt(0).toUpperCase()+words[i].slice(1).toLowerCase();
268
- return words.join("");
221
+ function transformDirection (direction) {
222
+ if (direction === 'Serverbound') return 'toServer'
223
+ if (direction === 'Clientbound') return 'toClient'
269
224
  }
270
225
 
271
- var oldNames={
272
- "handshaking": {
273
- "toServer": {
274
- "handshake":"set_protocol"
275
- }
276
- },
277
- "status": {
278
- "toClient": {
279
- "response":"server_info",
280
- "pong":"ping"
281
- },
282
- "toServer": {
283
- "request":"ping_start"
284
- }
285
- },
286
- "login": {
287
- "toClient": {
288
- "disconnect":"disconnect",
289
- "encryption_request":"encryption_begin",
290
- "login_success":"success",
291
- "set_compression":"compress"
292
- },
293
- "toServer": {
294
- "encryption_response":"encryption_begin"
295
- }
296
- },
297
- "play": {
298
- "toClient":{
299
- "join_game":"login",
300
- "chat_message":"chat",
301
- "time_update":"update_time",
302
- "player_position_and_look":"position",
303
- "held_item_change":"held_item_slot",
304
- "use_bed":"bed",
305
- "spawn_player":"named_entity_spawn",
306
- "collect_item":"collect",
307
- "spawn_object":"spawn_entity",
308
- "spawn_mob":"spawn_entity_living",
309
- "spawn_painting":"spawn_entity_painting",
310
- "spawn_experience_orb":"spawn_entity_experience_orb",
311
- "destroy_entities":"entity_destroy",
312
- "entity_relative_move":"rel_entity_move",
313
- "entity_look_and_relative_move":"entity_move_look",
314
- "entity_head_look":"entity_head_rotation",
315
- "set_experience":"experience",
316
- "entity_properties":"entity_update_attributes",
317
- "chunk_data":"map_chunk",
318
- "effect":"world_event",
319
- "particle":"world_particles",
320
- "change_game_state":"game_state_change",
321
- "spawn_global_entity":"spawn_entity_weather",
322
- "window_property":"craft_progress_bar",
323
- "confirm_transaction":"transaction",
324
- "update_block_entity":"tile_entity_data",
325
- "open_sign_editor":"open_sign_entity",
326
- "player_list_item":"player_info",
327
- "player_abilities":"abilities",
328
- "update_score":"scoreboard_score",
329
- "display_scoreboard":"scoreboard_display_objective",
330
- "plugin_message":"custom_payload",
331
- "disconnect":"kick_disconnect",
332
- "server_difficulty":"difficulty",
333
- "player_list_header_and_footer":"playerlist_header"
334
- },
335
- "toServer": {
336
- "chat_message":"chat",
337
- "player":"flying",
338
- "player_position":"position",
339
- "player_look":"look",
340
- "player_position_and_look":"position_look",
341
- "player_digging":"block_dig",
342
- "player_block_placement":"block_place",
343
- "held_item_change":"held_item_slot",
344
- "animation":"arm_animation",
345
- "click_window":"window_click",
346
- "confirm_transaction":"transaction",
347
- "creative_inventory_action":"set_creative_slot",
348
- "player_abilities":"abilities",
349
- "client_settings":"settings",
350
- "client_status":"client_command",
351
- "plugin_message":"custom_payload",
352
- "resource_pack_status":"resource_pack_receive"
353
- }
354
- }
355
- };
356
-
357
- function toOldNames(name,state,direction)
358
- {
359
- var x = oldNames[state] && oldNames[state][direction] && oldNames[state][direction][name] ? oldNames[state][direction][name] : name;
360
- console.log(state, direction, name, x);
361
- return x;
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('')
362
231
  }
363
232
 
364
- function transformPacketName(packetName,state,direction,id)
365
- {
366
- return toOldNames(toSnakeCase(packetName).replace("-", "_").replace(/_\(.+\)$/, ""),state,direction,id);
367
- }
368
-
369
- function transformFieldType(fieldType)
370
- {
371
- fieldType=fieldType.toLowerCase().replace("unsigned ","u").replace("boolean","bool").replace("[[chat]]","string")
372
- .replace("angle","byte").replace("uuid","UUID");
373
- if(fieldType.indexOf("varint")!=-1) return "varint";
374
- if(fieldType.indexOf("slot")!=-1) return "slot";
375
- if(fieldType.indexOf("entity metadata")!=-1) return "entityMetadata";
376
- if(fieldType.indexOf("nbt")!=-1) return "restBuffer";
377
- if(fieldType.indexOf("ubyte")!=-1) return "u8";
378
- if(fieldType.indexOf("byte")!=-1) return "i8";
379
- if(fieldType.indexOf("ushort")!=-1) return "u16";
380
- if(fieldType.indexOf("short")!=-1) return "i16";
381
- if(fieldType.indexOf("uint")!=-1) return "u32";
382
- if(fieldType.indexOf("int")!=-1) return "i32";
383
- if(fieldType.indexOf("ulong")!=-1) return "u64";
384
- if(fieldType.indexOf("long")!=-1) return "i64";
385
- 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
386
249
  }
387
250
 
388
251
  // specific has priority over general
389
252
 
390
253
  // specific
391
- var newToOldFieldNamesSpecific={
392
- "status":{
393
- "toClient":{
394
- "0x01":{
395
- "payload":"time"
254
+ const newToOldFieldNamesSpecific = {
255
+ status: {
256
+ toClient: {
257
+ '0x01': {
258
+ payload: 'time'
396
259
  }
397
260
  },
398
- "toServer":{
399
- "0x01":{
400
- "payload":"time"
261
+ toServer: {
262
+ '0x01': {
263
+ payload: 'time'
401
264
  }
402
265
  }
403
266
  },
404
- "login": {
405
- "toServer": {
406
- "0x00":{
407
- "name":"username"
267
+ login: {
268
+ toServer: {
269
+ '0x00': {
270
+ name: 'username'
408
271
  }
409
272
  }
410
273
  },
411
- "play": {
412
- "toClient": {
413
- "0x01":{
414
- "gamemode":"gameMode"
274
+ play: {
275
+ toClient: {
276
+ '0x01': {
277
+ gamemode: 'gameMode'
415
278
  },
416
- "0x0e":{
417
- "data":"objectData"
279
+ '0x0e': {
280
+ data: 'objectData'
418
281
  },
419
- "0x21":{
420
- "data":"chunkData"
282
+ '0x21': {
283
+ data: 'chunkData'
421
284
  },
422
- "0x2b":{
423
- "value":"gameMode"
285
+ '0x2b': {
286
+ value: 'gameMode'
424
287
  },
425
- "0x2f":{
426
- "slotData":"item"
288
+ '0x2f': {
289
+ slotData: 'item'
427
290
  },
428
- "0x30":{
429
- "slotData":"items"
291
+ '0x30': {
292
+ slotData: 'items'
430
293
  },
431
- "0x32":{
432
- "actionNumber":"action"
294
+ '0x32': {
295
+ actionNumber: 'action'
433
296
  },
434
- "0x3b":{
435
- "mode":"action",
436
- "objectiveName":"name"
297
+ '0x3b': {
298
+ mode: 'action',
299
+ objectiveName: 'name'
437
300
  },
438
- "0x3c":{
439
- "scoreName":"itemName",
440
- "objectiveName":"scoreName"
301
+ '0x3c': {
302
+ scoreName: 'itemName',
303
+ objectiveName: 'scoreName'
441
304
  },
442
- "0x3d":{
443
- "scoreName":"name"
305
+ '0x3d': {
306
+ scoreName: 'name'
444
307
  }
445
308
  },
446
- "toServer":{
447
- "0x02":{
448
- "type":"mouse"
309
+ toServer: {
310
+ '0x02': {
311
+ type: 'mouse'
449
312
  },
450
- "0x08":{
451
- "face":"direction",
452
- "cursorPositionX":"cursorX",
453
- "cursorPositionY":"cursorY",
454
- "cursorPositionZ":"cursorZ"
313
+ '0x08': {
314
+ face: 'direction',
315
+ cursorPositionX: 'cursorX',
316
+ cursorPositionY: 'cursorY',
317
+ cursorPositionZ: 'cursorZ'
455
318
  },
456
- "0x09":{
457
- "slot":"slotId"
319
+ '0x09': {
320
+ slot: 'slotId'
458
321
  },
459
- "0x0b":{
460
- "payload":"actionId"
322
+ '0x0b': {
323
+ payload: 'actionId'
461
324
  },
462
- "0x0c":{
463
- "flags":"jump"
325
+ '0x0c': {
326
+ flags: 'jump'
464
327
  },
465
- "0x0e":{
466
- "actionNumber":"action"
328
+ '0x0e': {
329
+ actionNumber: 'action'
467
330
  },
468
- "0x0f":{
469
- "actionNumber":"action"
331
+ '0x0f': {
332
+ actionNumber: 'action'
470
333
  },
471
- "0x16":{
472
- "actionId":"payload"
334
+ '0x16': {
335
+ actionId: 'payload'
473
336
  }
474
337
  }
475
338
  }
476
- };
339
+ }
477
340
 
478
341
  // should probably be converted entirely in the specific format
479
342
  // general
480
- var newToOldFieldNamesGeneral={
481
- "serverAddress":"serverHost",
482
- "jsonResponse":"response",
483
- "jsonData":"message",
484
- "worldAge":"age",
485
- "timeOfDay":"time",
486
- "playerUuid":"playerUUID",
487
- "deltaX":"dX",
488
- "deltaY":"dY",
489
- "deltaZ":"dZ",
490
- "chunkX":"x",
491
- "chunkZ":"z",
492
- "ground-upContinuous":"groundUp",
493
- "primaryBitMask":"bitMap",
494
- "size":"chunkDataLength",
495
- "blockId":"type",
496
- "blockType":"blockId",
497
- "recordCount":"count",
498
- "records":"affectedBlockOffsets",
499
- "disableRelativeVolume":"global",
500
- "effectPositionX":"x",
501
- "effectPositionY":"y",
502
- "effectPositionZ":"z",
503
- "particleCount":"particles",
504
- "windowType":"inventoryType",
505
- "numberOfSlots":"slotCount",
506
- "line1":"text1",
507
- "line2":"text2",
508
- "line3":"text3",
509
- "line4":"text4",
510
- "objectiveValue":"displayText",
511
- "teamName":"team",
512
- "teamDisplayName":"name",
513
- "teamPrefix":"prefix",
514
- "teamSuffix":"suffix",
515
- "targetX":"x",
516
- "targetY":"y",
517
- "targetZ":"z",
518
- "feetY":"y",
519
- "button":"mouseButton",
520
- "clickedItem":"item",
521
- "lookedAtBlock":"block",
522
- "chatMode":"chatFlags",
523
- "displayedSkinParts":"skinParts",
524
- "targetPlayer":"target"
525
- };
526
-
527
- function toOldFieldName(fieldName,state,direction,id)
528
- {
529
- if(newToOldFieldNamesSpecific[state]
530
- && newToOldFieldNamesSpecific[state][direction]
531
- && newToOldFieldNamesSpecific[state][direction][id]
532
- && newToOldFieldNamesSpecific[state][direction][id][fieldName])
533
- return newToOldFieldNamesSpecific[state][direction][id][fieldName];
534
- if(newToOldFieldNamesGeneral[fieldName])
535
- return newToOldFieldNamesGeneral[fieldName];
536
- 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'
537
388
  }
538
389
 
539
- function transformFieldName(fieldName,state,direction,id)
540
- {
541
- 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
542
397
  }
543
398
 
399
+ function transformFieldName (fieldName, state, direction, id) {
400
+ return toOldFieldName(toCamelCase(fieldName), state, direction, id)
401
+ }