mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
put getField in a utils.js file, create a datatypes dir in src/ make it compile by gulp, move byte to numeric.js
This commit is contained in:
parent
cf65197e12
commit
6660a3aa39
@ -14,6 +14,13 @@ gulp.task('compile', function() {
|
||||
.pipe(babel(options))
|
||||
.pipe(sourcemaps.write('maps/'))
|
||||
.pipe(gulp.dest('dist/'));
|
||||
|
||||
gulp
|
||||
.src('src/datatypes/*.js')
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(babel(options))
|
||||
.pipe(sourcemaps.write('maps/'))
|
||||
.pipe(gulp.dest('dist/datatypes/'));
|
||||
});
|
||||
|
||||
gulp.task('watch', function() {
|
||||
|
16
src/datatypes/numeric.js
Normal file
16
src/datatypes/numeric.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports={'byte': [readByte, writeByte, 1]};
|
||||
|
||||
function readByte(buffer, offset) {
|
||||
if (offset + 1 > buffer.length) return null;
|
||||
var value = buffer.readInt8(offset);
|
||||
return {
|
||||
value: value,
|
||||
size: 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function writeByte(value, buffer, offset) {
|
||||
buffer.writeInt8(value, offset);
|
||||
return offset + 1;
|
||||
}
|
@ -3,6 +3,8 @@ var util = require('util');
|
||||
var zlib = require('zlib');
|
||||
var nbt = require('prismarine-nbt');
|
||||
|
||||
var getField= require("./utils").getField;
|
||||
|
||||
var STRING_MAX_LENGTH = 240;
|
||||
var SRV_STRING_MAX_LENGTH = 32767;
|
||||
|
||||
@ -50,10 +52,10 @@ var packetStates = {toClient: {}, toServer: {}};
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
var numeric=require("./datatypes/numeric");
|
||||
|
||||
var types = {
|
||||
'byte': [readByte, writeByte, 1],
|
||||
'byte': numeric.byte,
|
||||
'ubyte': [readUByte, writeUByte, 1],
|
||||
'short': [readShort, writeShort, 2],
|
||||
'ushort': [readUShort, writeUShort, 2],
|
||||
@ -314,14 +316,7 @@ function readLong(buffer, offset) {
|
||||
};
|
||||
}
|
||||
|
||||
function readByte(buffer, offset) {
|
||||
if (offset + 1 > buffer.length) return null;
|
||||
var value = buffer.readInt8(offset);
|
||||
return {
|
||||
value: value,
|
||||
size: 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function readUByte(buffer, offset) {
|
||||
if (offset + 1 > buffer.length) return null;
|
||||
@ -448,11 +443,6 @@ function writeString(value, buffer, offset) {
|
||||
return offset + length;
|
||||
}
|
||||
|
||||
function writeByte(value, buffer, offset) {
|
||||
buffer.writeInt8(value, offset);
|
||||
return offset + 1;
|
||||
}
|
||||
|
||||
function writeBool(value, buffer, offset) {
|
||||
buffer.writeInt8(+value, offset);
|
||||
return offset + 1;
|
||||
@ -606,6 +596,7 @@ function readRestBuffer(buffer, offset, typeArgs, rootNode) {
|
||||
};
|
||||
}
|
||||
|
||||
// begin array
|
||||
function evalCount(count,fields)
|
||||
{
|
||||
if(fields[count["field"]] in count["map"])
|
||||
@ -647,15 +638,7 @@ function sizeOfArray(value, typeArgs, rootNode) {
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
function getField(countField, rootNode) {
|
||||
var countFieldArr = countField.split(".");
|
||||
var count = rootNode;
|
||||
for (var index = 0; index < countFieldArr.length; index++) {
|
||||
count = count[countFieldArr[index]];
|
||||
}
|
||||
return count;
|
||||
}
|
||||
// end array
|
||||
|
||||
function readCount(buffer, offset, typeArgs, rootNode) {
|
||||
return read(buffer, offset, { type: typeArgs.type }, rootNode);
|
||||
|
10
src/utils.js
Normal file
10
src/utils.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports= {getField:getField};
|
||||
|
||||
function getField(countField, rootNode) {
|
||||
var countFieldArr = countField.split(".");
|
||||
var count = rootNode;
|
||||
for (var index = 0; index < countFieldArr.length; index++) {
|
||||
count = count[countFieldArr[index]];
|
||||
}
|
||||
return count;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user