mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 14:41:27 -04:00
encapsulate condition evaluation
This commit is contained in:
parent
d37d801e01
commit
e47feb1cf6
@ -119,6 +119,11 @@ for (var n in entityMetadataTypes) {
|
|||||||
entityMetadataTypeBytes[entityMetadataTypes[n].type] = n;
|
entityMetadataTypeBytes[entityMetadataTypes[n].type] = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function evalCondition(condition,arg)
|
||||||
|
{
|
||||||
|
return condition(arg);
|
||||||
|
}
|
||||||
|
|
||||||
function sizeOfEntityMetadata(value) {
|
function sizeOfEntityMetadata(value) {
|
||||||
var size = 1 + value.length;
|
var size = 1 + value.length;
|
||||||
var item;
|
var item;
|
||||||
@ -633,7 +638,7 @@ function sizeOfCount(value, typeArgs, rootNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function read(buffer, cursor, fieldInfo, rootNodes) {
|
function read(buffer, cursor, fieldInfo, rootNodes) {
|
||||||
if (fieldInfo.condition && !fieldInfo.condition(rootNodes)) {
|
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNodes)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
@ -651,7 +656,7 @@ function read(buffer, cursor, fieldInfo, rootNodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function write(value, buffer, offset, fieldInfo, rootNode) {
|
function write(value, buffer, offset, fieldInfo, rootNode) {
|
||||||
if (fieldInfo.condition && !fieldInfo.condition(rootNode)) {
|
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNode)) {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
@ -664,7 +669,7 @@ function write(value, buffer, offset, fieldInfo, rootNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sizeOf(value, fieldInfo, rootNode) {
|
function sizeOf(value, fieldInfo, rootNode) {
|
||||||
if (fieldInfo.condition && !fieldInfo.condition(rootNode)) {
|
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNode)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user