mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
use protodef utils, fix #295
This commit is contained in:
parent
3007740135
commit
d86a59c393
4 changed files with 2 additions and 47 deletions
|
@ -1,5 +1,3 @@
|
|||
var utils = require("./utils");
|
||||
|
||||
module.exports = {
|
||||
Client: require('./client'),
|
||||
supportedVersions:require("./version").supportedVersions
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
var Client = require('./client');
|
||||
var Server = require('./server');
|
||||
var serializer = require("./transforms/serializer");
|
||||
var utils = require("./utils");
|
||||
var createClient = require("./createClient");
|
||||
var createServer = require("./createServer");
|
||||
|
||||
|
|
42
src/utils.js
42
src/utils.js
|
@ -1,42 +0,0 @@
|
|||
module.exports = {
|
||||
getField: getField,
|
||||
getFieldInfo: getFieldInfo,
|
||||
addErrorField: addErrorField,
|
||||
tryCatch: tryCatch,
|
||||
};
|
||||
|
||||
function getField(countField, context) {
|
||||
var countFieldArr = countField.split("/");
|
||||
var i = 0;
|
||||
if (countFieldArr[i] === "") {
|
||||
while (context.hasOwnProperty(".."))
|
||||
context = context[".."];
|
||||
i++;
|
||||
}
|
||||
for(; i < countFieldArr.length; i++) {
|
||||
context = context[countFieldArr[i]];
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
function getFieldInfo(fieldInfo) {
|
||||
if (typeof fieldInfo === "string")
|
||||
return { type: fieldInfo };
|
||||
else if (Array.isArray(fieldInfo))
|
||||
return { type: fieldInfo[0], typeArgs: fieldInfo[1] };
|
||||
else if (typeof fieldInfo.type === "string")
|
||||
return fieldInfo;
|
||||
else
|
||||
throw new Error("Not a fieldinfo");
|
||||
}
|
||||
|
||||
function addErrorField(e, field) {
|
||||
if (e.field)
|
||||
e.field = field + "." + e.field;
|
||||
else
|
||||
e.field = field;
|
||||
}
|
||||
|
||||
function tryCatch(tryfn, catchfn) {
|
||||
try { tryfn(); } catch (e) { catchfn(e); }
|
||||
}
|
|
@ -4,8 +4,8 @@ var Client = mc.Client;
|
|||
var Server = mc.Server;
|
||||
var net = require('net');
|
||||
var assert = require('power-assert');
|
||||
var getFieldInfo = require('../dist/utils').getFieldInfo;
|
||||
var getField = require('../dist/utils').getField;
|
||||
var getFieldInfo = require('protodef').utils.getFieldInfo;
|
||||
var getField = require('protodef').utils.getField;
|
||||
|
||||
function evalCount(count, fields) {
|
||||
if(fields[count["field"]] in count["map"])
|
||||
|
|
Loading…
Reference in a new issue