mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -04:00
remove condition property checks, also remove that property from the schema
This commit is contained in:
parent
faed176631
commit
63b332ce38
@ -42,8 +42,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"name": {"$ref" : "#/definitions/fieldName"},
|
"name": {"$ref" : "#/definitions/fieldName"},
|
||||||
"type": {"$ref" : "#/definitions/fieldType"},
|
"type": {"$ref" : "#/definitions/fieldType"},
|
||||||
"typeArgs": {"$ref" : "#/definitions/fieldTypeArgs"},
|
"typeArgs": {"$ref" : "#/definitions/fieldTypeArgs"}
|
||||||
"condition": {"$ref" : "#/definitions/fieldCondition"}
|
|
||||||
},
|
},
|
||||||
"required":["name","type"],
|
"required":["name","type"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
@ -110,28 +109,6 @@
|
|||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"fieldCondition": {
|
|
||||||
"type": "object",
|
|
||||||
"properties":{
|
|
||||||
"field": {"$ref" : "#/definitions/fieldName"},
|
|
||||||
"values": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": ["integer","boolean"]
|
|
||||||
},
|
|
||||||
"additionalItems": false,
|
|
||||||
"minItems": 1
|
|
||||||
},
|
|
||||||
"different": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"this": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["field","values"],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -559,7 +559,8 @@ function writeContainer(value, buffer, offset, typeArgs, rootNode) {
|
|||||||
var context = value.this ? value.this : value;
|
var context = value.this ? value.this : value;
|
||||||
rootNode.this = value;
|
rootNode.this = value;
|
||||||
for (var index in typeArgs.fields) {
|
for (var index in typeArgs.fields) {
|
||||||
if (!context.hasOwnProperty(typeArgs.fields[index].name) && typeArgs.fields[index].type != "count" && !typeArgs.fields[index].condition)
|
if (!context.hasOwnProperty(typeArgs.fields[index].name) && typeArgs.fields[index].type != "count" &&
|
||||||
|
(typeArgs.fields[index].type !="condition" || evalCondition(typeArgs.fields[index].typeArgs,rootNode)))
|
||||||
{
|
{
|
||||||
debug(new Error("Missing Property " + typeArgs.fields[index].name).stack);
|
debug(new Error("Missing Property " + typeArgs.fields[index].name).stack);
|
||||||
console.log(context);
|
console.log(context);
|
||||||
@ -672,9 +673,6 @@ function sizeOfCount(value, typeArgs, rootNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function read(buffer, cursor, fieldInfo, rootNodes) {
|
function read(buffer, cursor, fieldInfo, rootNodes) {
|
||||||
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNodes)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return {
|
return {
|
||||||
@ -690,9 +688,6 @@ function read(buffer, cursor, fieldInfo, rootNodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function write(value, buffer, offset, fieldInfo, rootNode) {
|
function write(value, buffer, offset, fieldInfo, rootNode) {
|
||||||
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNode)) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return {
|
return {
|
||||||
@ -703,9 +698,6 @@ function write(value, buffer, offset, fieldInfo, rootNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sizeOf(value, fieldInfo, rootNode) {
|
function sizeOf(value, fieldInfo, rootNode) {
|
||||||
if (fieldInfo.condition && !evalCondition(fieldInfo.condition,rootNode)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
var type = types[fieldInfo.type];
|
var type = types[fieldInfo.type];
|
||||||
if (!type) {
|
if (!type) {
|
||||||
throw new Error("missing data type: " + fieldInfo.type);
|
throw new Error("missing data type: " + fieldInfo.type);
|
||||||
@ -756,7 +748,7 @@ function createPacketBuffer(packetId, state, params, isServer) {
|
|||||||
packet.forEach(function(fieldInfo) {
|
packet.forEach(function(fieldInfo) {
|
||||||
var value = params[fieldInfo.name];
|
var value = params[fieldInfo.name];
|
||||||
// TODO : A better check is probably needed
|
// TODO : A better check is probably needed
|
||||||
if(typeof value === "undefined" && fieldInfo.type != "count" && !fieldInfo.condition)
|
if(typeof value === "undefined" && fieldInfo.type != "count" && (fieldInfo.type !="condition" || evalCondition(fieldInfo.typeArgs,params)))
|
||||||
debug(new Error("Missing Property " + fieldInfo.name).stack);
|
debug(new Error("Missing Property " + fieldInfo.name).stack);
|
||||||
offset = write(value, buffer, offset, fieldInfo, params);
|
offset = write(value, buffer, offset, fieldInfo, params);
|
||||||
});
|
});
|
||||||
|
@ -178,7 +178,7 @@ describe("packets", function() {
|
|||||||
// empty object uses default values
|
// empty object uses default values
|
||||||
var packet = {};
|
var packet = {};
|
||||||
packetInfo.forEach(function(field) {
|
packetInfo.forEach(function(field) {
|
||||||
if ((!field.hasOwnProperty("condition") || protocol.evalCondition(field.condition,packet)) && (field.type!=="condition" || protocol.evalCondition(field.typeArgs,packet))) {
|
if (field.type!=="condition" || protocol.evalCondition(field.typeArgs,packet)) {
|
||||||
var fieldVal = values[field.type];
|
var fieldVal = values[field.type];
|
||||||
if (typeof fieldVal === "undefined") {
|
if (typeof fieldVal === "undefined") {
|
||||||
throw new Error("No value for type " + field.type);
|
throw new Error("No value for type " + field.type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user