transform typeArgs function into object

This commit is contained in:
Romain Beaumont 2015-05-08 03:22:37 +02:00
parent bf8a7899ae
commit 9abe799715
2 changed files with 13 additions and 10 deletions

View File

@ -591,14 +591,22 @@ function readRestBuffer(buffer, offset, typeArgs, rootNode) {
};
}
function evalCount(count,fields)
{
if(fields[count["field"]] in count["map"])
return count["map"][fields[count["field"]]];
return count["default"];
}
function readArray(buffer, offset, typeArgs, rootNode) {
var results = {
value: [],
size: 0
}
var count;
if (typeof typeArgs.count === "function")
count = typeArgs.count(rootNode);
if (typeof typeArgs.count === "object") {
count = evalCount(typeArgs.count,rootNode);
}
else
count = getField(typeArgs.count, rootNode);
for (var i = 0; i < count; i++) {

View File

@ -358,14 +358,9 @@ module.exports= {
{ name: "offsetZ", type: "float" },
{ name: "particleData", type: "float" },
{ name: "particles", type: "int" },
{ name: "data", type: "array", typeArgs: { count: function(fields) {
if (fields.particleId === 36)
return 2;
else if (fields.particleId === 37 || fields.particleId === 38)
return 1;
else
return 0;
}, type: "varint" } }
{ name: "data", type: "array",
typeArgs: { count: {"field":"particleId","map":{"36":2,"37":1,"38":1},"default":0},
type: "varint" } }
]},
game_state_change: {id: 0x2b, fields: [
{ name: "reason", type: "ubyte" },