| |
---|
| | import java.util.Set; |
---|
| | |
---|
| | import cactusServer.entities.Entity; |
---|
| | import cactusServer.entities.Object; |
---|
| | import cactusServer.models.Instances; |
---|
| | import cactusServer.utils.RandomStringGenerator; |
---|
| | import cactusServer.entities.Character; |
---|
| | import framework.model3D.Position3D; |
---|
| | import net.arnx.jsonic.JSONHint; |
---|
| |
---|
| | */ |
---|
| | public class Instance extends Entity { |
---|
| | private String name; |
---|
| | private State state; |
---|
| | // private StageModel stage; |
---|
| | @JSONHint(ignore = true) private HashMap<String, Area> areaMap = new HashMap<>(); |
---|
| | @JSONHint(ignore = true) private HashMap<String, Object> objMap = new HashMap<>(); |
---|
| | @JSONHint(ignore = true) private HashMap<String, Character> characterMap = new HashMap<>(); |
---|
| | @JSONHint(ignore = true) private static final int UNIQUE_ID_LENGTH = 12; |
---|
| | private StageModel stage; |
---|
| | |
---|
| | private HashMap<String, Area> areaMap = new HashMap<>(); |
---|
| | private HashMap<String, Object> objMap = new HashMap<>(); |
---|
| | private HashMap<String, Character> characterMap = new HashMap<>(); |
---|
| | private static final int UNIQUE_ID_LENGTH = 12; |
---|
| | private final String INSTANCE_URI; |
---|
| | |
---|
| | |
---|
| | /** |
---|
| | * (引数は現時点での仮のもの) |
---|
| | * @param name インスタンス名 |
---|
| | */ |
---|
| | public Instance(String instanceID, String name, State state, StageModel stageModel) { |
---|
| | this.INSTANCE_URI = Instances.INSTANCES_URI + "/" + instanceID; |
---|
| | this.name = name; |
---|
| | this.state = state; |
---|
| | this.stage = stageModel; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * InstancesRestとのエラー解消用 (後で消す) |
---|
| | * @param name |
---|
| | * @param state |
---|
| | */ |
---|
| | public Instance(String name, State state) { |
---|
| | this.name = name; |
---|
| | this.state = state; |
---|
| | this.INSTANCE_URI = Instances.INSTANCES_URI + "/"; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * InstancesRestとのエラー解消用 (後で消す) |
---|
| | * @param name |
---|
| | */ |
---|
| | public Instance(String name) { |
---|
| | this.name = name; |
---|
| | this.state = State.AVAILABLE; |
---|
| | this.INSTANCE_URI = Instances.INSTANCES_URI + "/"; |
---|
| | } |
---|
| | |
---|
| | public String getName() { |
---|
| | return name; |
---|
| |
---|
| | public State getState() { |
---|
| | return state; |
---|
| | } |
---|
| | |
---|
| | public StageModel getStage() { |
---|
| | return stage; |
---|
| | } |
---|
| | |
---|
| | @JSONHint(ignore = true) |
---|
| | public Set<String> getAreaIdSet() { |
---|
| | return areaMap.keySet(); |
---|
| | } |
---|
| |
---|
| | public void setState(State state) { |
---|
| | this.state = state; |
---|
| | } |
---|
| | |
---|
| | public Map<String, Area> createArea(Area area) { |
---|
| | public AddressedEntity createArea(Area area) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, areaMap.keySet()); |
---|
| | areaMap.put(id, area); |
---|
| | return new HashMap<String, Area>() { |
---|
| | {put(id, area);} |
---|
| | }; |
---|
| | return new AddressedEntity((INSTANCE_URI + "/areas/" + id), area); |
---|
| | } |
---|
| | |
---|
| | // public Map<String, Area> createArea(Area area) { |
---|
| | // String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, areaMap.keySet()); |
---|
| | // areaMap.put(id, area); |
---|
| | // return new HashMap<String, Area>() { |
---|
| | // {put(id, area);} |
---|
| | // }; |
---|
| | // } |
---|
| | |
---|
| | public AddressedEntity createObject(Object object) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, objMap.keySet()); |
---|
| | objMap.put(id, object); |
---|
| | return new AddressedEntity((INSTANCE_URI + "/objects/" + id), object); |
---|
| | } |
---|
| | |
---|
| | public Map<String, Object> createObject(Object object) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, objMap.keySet()); |
---|
| | objMap.put(id, object); |
---|
| | return new HashMap<String, Object>() { |
---|
| | {put(id, object);} |
---|
| | }; |
---|
| | } |
---|
| | |
---|
| | public Map<String, Character> createCharacter(Character character) { |
---|
| | // public Map<String, Object> createObject(Object object) { |
---|
| | // String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, objMap.keySet()); |
---|
| | // objMap.put(id, object); |
---|
| | // return new HashMap<String, Object>() { |
---|
| | // {put(id, object);} |
---|
| | // }; |
---|
| | // } |
---|
| | |
---|
| | public AddressedEntity createObject(Character character) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, characterMap.keySet()); |
---|
| | characterMap.put(id, character); |
---|
| | return new HashMap<String, Character>() { |
---|
| | {put(id, character);} |
---|
| | }; |
---|
| | return new AddressedEntity((INSTANCE_URI + "/characters/" + id), character); |
---|
| | } |
---|
| | |
---|
| | // public Map<String, Character> createCharacter(Character character) { |
---|
| | // String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, characterMap.keySet()); |
---|
| | // characterMap.put(id, character); |
---|
| | // return new HashMap<String, Character>() { |
---|
| | // {put(id, character);} |
---|
| | // }; |
---|
| | // } |
---|
| | |
---|
| | public Character updateCharacter(String characterId, Position3D position) { |
---|
| | Character character = characterMap.get(characterId); |
---|
| | character.setPosition(position); |
---|
| |
---|
| | |