Fix status parser

This commit is contained in:
Bill 2021-12-10 23:55:26 -05:00
parent 116eaa4913
commit b2ef1d7530

View File

@ -61,53 +61,99 @@ export class RoomUnitStatusParser implements IMessageParser
if(actions) if(actions)
{ {
const actionParts = actions.split('/'); const actionParts = actions.split('/');
const totalActions = actionParts.length;
const statusActions: RoomUnitStatusAction[] = []; const statusActions: RoomUnitStatusAction[] = [];
if(totalActions) for(const action of actionParts)
{ {
for(let i = 0; i < totalActions; i++) const parts = action.split(' ');
if(parts[0] === '') continue;
if(parts.length >= 2)
{ {
const action = actionParts[i]; switch(parts[0])
if(!action) continue;
const [ key, value, extra ] = action.split(' ');
if(!key || !value) continue;
switch(key)
{ {
case 'mv': case 'mv': {
[ targetX, targetY, targetZ ] = value.split(',').map(a => parseFloat(a)); const values = parts[1].split(',');
if(values.length >= 3)
{
targetX = parseInt(values[0]);
targetY = parseInt(values[1]);
targetZ = parseFloat(values[2]);
didMove = true; didMove = true;
}
break; break;
}
case 'sit': { case 'sit': {
const sitHeight = parseFloat(value); const sitHeight = parseFloat(parts[1]);
if(extra !== undefined) canStandUp = value === '1'; if(parts.length >= 3) canStandUp = (parts[2] === '1');
height = sitHeight; height = sitHeight;
break; break;
} }
case 'lay': { case 'lay': {
const layHeight = parseFloat(value); const layHeight = parseFloat(parts[1]);
height = layHeight; height = Math.abs(layHeight);
break; break;
} }
} }
statusActions.push(new RoomUnitStatusAction(key, value)); statusActions.push(new RoomUnitStatusAction(parts[0], parts[1]));
} }
} }
// const totalActions = actionParts.length;
// if(totalActions)
// {
// for(let i = 0; i < totalActions; i++)
// {
// const action = actionParts[i];
// if(!action) continue;
// console.log(action);
// const [ key, value, extra ] = action.split(' ');
// if(!key || !value) continue;
// switch(key)
// {
// case 'mv':
// [ targetX, targetY, targetZ ] = value.split(',').map(a => parseFloat(a));
// didMove = true;
// break;
// case 'sit': {
// const sitHeight = parseFloat(value);
// if(extra !== undefined) canStandUp = value === '1';
// height = sitHeight;
// break;
// }
// case 'lay': {
// const layHeight = parseFloat(value);
// height = layHeight;
// break;
// }
// }
// statusActions.push(new RoomUnitStatusAction(key, value));
// }
// }
this._statuses.push(new RoomUnitStatusMessage(unitId, x, y, z, height, headDirection, direction, targetX, targetY, targetZ, didMove, canStandUp, statusActions)); this._statuses.push(new RoomUnitStatusMessage(unitId, x, y, z, height, headDirection, direction, targetX, targetY, targetZ, didMove, canStandUp, statusActions));
} }
} }