/.metadata/.plugins/org.eclipse.core.resources/.history/69/10459600d7a2001e1d98c762f0e1eac2
#! | 53 lines | 44 code | 9 blank | 0 comment | 0 complexity | edffbbb99d1537dfeb9e2de2921775ad MD5 | raw file
1package info.reflectionsofmind.connexion.platform.control.cts.message;
2
3import info.reflectionsofmind.connexion.platform.control.cts.IClientToServerMessage;
4import info.reflectionsofmind.connexion.platform.control.cts.IClientToServerMessageDispatchTarget;
5import info.reflectionsofmind.connexion.platform.game.IAction;
6import info.reflectionsofmind.connexion.transport.ITransport.INode;
7import info.reflectionsofmind.connexion.util.convert.ClassBasedJsonCoder;
8import info.reflectionsofmind.connexion.util.convert.DecodingException;
9import info.reflectionsofmind.connexion.util.convert.EncodingException;
10import info.reflectionsofmind.connexion.util.convert.ICoder;
11
12import org.json.JSONObject;
13
14public class MsgActionRequest implements IClientToServerMessage
15{
16 private final IAction action;
17
18 public MsgActionRequest(final IAction action)
19 {
20 this.action = action;
21 }
22
23 public void dispatch(final IClientToServerMessageDispatchTarget target, final INode sender)
24 {
25 target.onClientAction(this, sender);
26 }
27
28 public IAction getAction()
29 {
30 return this.action;
31 }
32
33 public static final class Coder extends ClassBasedJsonCoder<MsgActionRequest>
34 {
35 @Override
36 protected Class<? extends MsgActionRequest> getEncodableClass()
37 {
38 return MsgActionRequest.class;
39 }
40
41 @Override
42 protected MsgActionRequest decodeJson(final JSONObject json) throws DecodingException
43 {
44 return new MsgActionRequest(this.actionCoder.decode(json.getJSONObject("action").toString()));
45 }
46
47 @Override
48 protected JSONObject encodeJson(final MsgActionRequest object) throws EncodingException
49 {
50 return new JSONObject().put("action", this.actionCoder.encode(object.getAction()));
51 }
52 }
53}