Extract movementDescriptionMessages()
This commit is contained in:
parent
4cd558eba2
commit
175aa62a7e
|
@ -173,37 +173,13 @@ function spawnVessel(vesselId, initialHere, _isRoot) {
|
|||
break;
|
||||
case 'goto':
|
||||
if (!isRootVessel(vessel) || !isLocalVessel(cmd.location)) {
|
||||
const oldLocation = location.value;
|
||||
let { outMsg, inMsg } = movementDescriptionMessages(cmd.action,
|
||||
vessel,
|
||||
agent,
|
||||
location.value,
|
||||
cmd.location);
|
||||
const id = outMsg ? sendEvent(null, location.value, ... outMsg) : null;
|
||||
location.value = cmd.location;
|
||||
let outMsg = void 0, inMsg = void 0;
|
||||
switch (cmd.action) {
|
||||
case 'initial':
|
||||
break;
|
||||
case 'link':
|
||||
inMsg = [vessel, ` joined the network.`];
|
||||
break;
|
||||
case 'give':
|
||||
outMsg = inMsg = [agent, ` gave `, _theThing(vessel), ` to `, _theThing(cmd.location), `.`];
|
||||
break;
|
||||
case 'put':
|
||||
outMsg = inMsg = [agent, ` put `, _theThing(vessel), ` down in `, _thePlace(cmd.location), `.`];
|
||||
break;
|
||||
case 'take':
|
||||
outMsg = inMsg = [agent, ` picked up `, _theThing(vessel), ` from `, _thePlace(oldLocation), `.`];
|
||||
break;
|
||||
case 'drop':
|
||||
outMsg = inMsg = [agent, ` dropped `, _theThing(vessel), ` in `, _thePlace(cmd.location), `.`];
|
||||
break;
|
||||
case 'enter':
|
||||
outMsg = [vessel, ` entered `, _thePlace(cmd.location), `.`];
|
||||
inMsg = [vessel, ` left `, _thePlace(oldLocation), ` for `, _thePlace(cmd.location), `.`];
|
||||
break;
|
||||
case 'move':
|
||||
default:
|
||||
outMsg = inMsg = [agent, ` moved `, _theThing(vessel), ` from `, _thePlace(oldLocation), ` into `, _thePlace(cmd.location), `.`];
|
||||
break;
|
||||
}
|
||||
const id = outMsg ? sendEvent(null, oldLocation, ... outMsg) : null;
|
||||
if (inMsg) broadcast(id, ... inMsg);
|
||||
}
|
||||
break;
|
||||
|
@ -254,3 +230,35 @@ function spawnVessel(vesselId, initialHere, _isRoot) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function movementDescriptionMessages(action, vessel, agent, oldLocation, newLocation) {
|
||||
let outMsg = void 0, inMsg = void 0;
|
||||
switch (action) {
|
||||
case 'initial':
|
||||
break;
|
||||
case 'link':
|
||||
inMsg = [vessel, ` joined the network.`];
|
||||
break;
|
||||
case 'give':
|
||||
outMsg = inMsg = [agent, ` gave `, _theThing(vessel), ` to `, _theThing(newLocation), `.`];
|
||||
break;
|
||||
case 'put':
|
||||
outMsg = inMsg = [agent, ` put `, _theThing(vessel), ` down in `, _thePlace(newLocation), `.`];
|
||||
break;
|
||||
case 'take':
|
||||
outMsg = inMsg = [agent, ` picked up `, _theThing(vessel), ` from `, _thePlace(oldLocation), `.`];
|
||||
break;
|
||||
case 'drop':
|
||||
outMsg = inMsg = [agent, ` dropped `, _theThing(vessel), ` in `, _thePlace(newLocation), `.`];
|
||||
break;
|
||||
case 'enter':
|
||||
outMsg = [vessel, ` entered `, _thePlace(newLocation), `.`];
|
||||
inMsg = [vessel, ` left `, _thePlace(oldLocation), ` for `, _thePlace(newLocation), `.`];
|
||||
break;
|
||||
case 'move':
|
||||
default:
|
||||
outMsg = inMsg = [agent, ` moved `, _theThing(vessel), ` from `, _thePlace(oldLocation), ` into `, _thePlace(newLocation), `.`];
|
||||
break;
|
||||
}
|
||||
return { outMsg, inMsg };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue