View Javadoc

1   package nl.tudelft.goal.unreal.translators;
2   
3   import java.util.Map.Entry;
4   import java.util.logging.Level;
5   
6   import nl.tudelft.goal.unreal.messages.BotParameters;
7   import nl.tudelft.goal.unreal.messages.BotParametersKey;
8   import nl.tudelft.goal.unreal.messages.ParameterMap;
9   import nl.tudelft.goal.ut2004.util.Skin;
10  import nl.tudelft.goal.ut2004.util.Team;
11  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
12  import cz.cuni.amis.pogamut.base3d.worldview.object.Rotation;
13  import eis.eis2java.exception.TranslationException;
14  import eis.eis2java.translation.Parameter2Java;
15  import eis.eis2java.translation.Translator;
16  import eis.iilang.Identifier;
17  import eis.iilang.Parameter;
18  
19  public class BotParametersTranslator implements Parameter2Java<BotParameters> {
20  
21  	@Override
22  	public BotParameters translate(Parameter parameter) throws TranslationException {
23  		Translator t = Translator.getInstance();
24  
25  		ParameterMap parameterMap = t.translate2Java(parameter, ParameterMap.class);
26  
27  		BotParameters parameters = new BotParameters();
28  
29  		for (Entry<Identifier, Parameter> entry : parameterMap.entrySet()) {
30  			BotParametersKey key = t.translate2Java(entry.getKey(), BotParametersKey.class);
31  			Parameter value = entry.getValue();
32  
33  			switch (key) {
34  			case LEADTARGET:
35  				parameters.setShouldLeadTarget(t.translate2Java(value, Boolean.class));
36  				break;
37  			case LOGLEVEL:
38  				parameters.setLogLevel(t.translate2Java(value, Level.class));
39  				break;
40  			case SKILL:
41  				parameters.setSkill(t.translate2Java(value, Integer.class));
42  				break;
43  			case SKIN:
44  				parameters.setSkin(t.translate2Java(value, Skin.class));
45  				break;
46  			case STARTLOCATION: 
47  				parameters.setInitialLocation(t.translate2Java(value, Location.class));
48  				break;
49  			case STARTROTATION:
50  				parameters.setInitialRotation(t.translate2Java(value, Rotation.class));
51  				break;
52  			case TEAM:
53  				parameters.setTeam(t.translate2Java(value, Team.class));
54  				break;
55  			case NAME: 
56  				parameters.setAgentId(t.translate2Java(value, String.class));
57  				break;
58  			}
59  		}
60  
61  		return parameters;
62  
63  	}
64  
65  	@Override
66  	public Class<BotParameters> translatesTo() {
67  		return BotParameters.class;
68  	}
69  
70  }