Files
node-metaverse/lib/classes/messages/AgentAnimation.ts
2017-11-26 01:14:02 +00:00

117 lines
3.7 KiB
TypeScript

// This file has been automatically generated by writeMessageClasses.js
import {UUID} from '../UUID';
import {MessageFlags} from '../../enums/MessageFlags';
import {MessageBase} from '../MessageBase';
import {Message} from '../../enums/Message';
export class AgentAnimationMessage implements MessageBase
{
name = 'AgentAnimation';
messageFlags = MessageFlags.FrequencyHigh;
id = Message.AgentAnimation;
AgentData: {
AgentID: UUID;
SessionID: UUID;
};
AnimationList: {
AnimID: UUID;
StartAnim: boolean;
}[];
PhysicalAvatarEventList: {
TypeData: string;
}[];
getSize(): number
{
return ((17) * this.AnimationList.length) + ((this.calculateVarVarSize(this.PhysicalAvatarEventList, 'TypeData', 1)) * this.PhysicalAvatarEventList.length) + 34;
}
calculateVarVarSize(block: object[], paramName: string, extraPerVar: number): number
{
let size = 0;
block.forEach((bl: any) =>
{
size += bl[paramName].length + extraPerVar;
});
return size;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.AgentData['AgentID'].writeToBuffer(buf, pos);
pos += 16;
this.AgentData['SessionID'].writeToBuffer(buf, pos);
pos += 16;
let count = this.AnimationList.length;
buf.writeUInt8(this.AnimationList.length, pos++);
for (let i = 0; i < count; i++)
{
this.AnimationList[i]['AnimID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt8((this.AnimationList[i]['StartAnim']) ? 1 : 0, pos++);
}
count = this.PhysicalAvatarEventList.length;
buf.writeUInt8(this.PhysicalAvatarEventList.length, pos++);
for (let i = 0; i < count; i++)
{
buf.writeUInt8(this.PhysicalAvatarEventList[i]['TypeData'].length, pos++);
buf.write(this.PhysicalAvatarEventList[i]['TypeData'], pos);
pos += this.PhysicalAvatarEventList[i]['TypeData'].length;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
let varLength = 0;
const newObjAgentData: {
AgentID: UUID,
SessionID: UUID
} = {
AgentID: UUID.zero(),
SessionID: UUID.zero()
};
newObjAgentData['AgentID'] = new UUID(buf, pos);
pos += 16;
newObjAgentData['SessionID'] = new UUID(buf, pos);
pos += 16;
this.AgentData = newObjAgentData;
let count = buf.readUInt8(pos++);
this.AnimationList = [];
for (let i = 0; i < count; i++)
{
const newObjAnimationList: {
AnimID: UUID,
StartAnim: boolean
} = {
AnimID: UUID.zero(),
StartAnim: false
};
newObjAnimationList['AnimID'] = new UUID(buf, pos);
pos += 16;
newObjAnimationList['StartAnim'] = (buf.readUInt8(pos++) === 1);
this.AnimationList.push(newObjAnimationList);
}
count = buf.readUInt8(pos++);
this.PhysicalAvatarEventList = [];
for (let i = 0; i < count; i++)
{
const newObjPhysicalAvatarEventList: {
TypeData: string
} = {
TypeData: ''
};
varLength = buf.readUInt8(pos++);
newObjPhysicalAvatarEventList['TypeData'] = buf.toString('utf8', pos, pos + (varLength - 1));
pos += varLength;
this.PhysicalAvatarEventList.push(newObjPhysicalAvatarEventList);
}
return pos - startPos;
}
}