| |
---|
| | private HashMap<String, Player> playerMap = new HashMap<>(); |
---|
| | |
---|
| | private Instances() { |
---|
| | //ダミーコード |
---|
| | // instanceMap.put("test1", new Instance("test1", State.AVAILABLE, 0)); |
---|
| | // instanceMap.put("test2", new Instance("test2", State.AVAILABLE, 1)); |
---|
| | instanceMap.put("test1", new Instance("test1", 0)); |
---|
| | instanceMap.put("test2", new Instance("test2", 1)); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * Instancesクラスを取得する (シングルトン) |
---|
| | * |
---|
| | * @return |
---|
| | */ |
---|
| | public static Instances getInstance() { |
---|
| | if (theInstance == null) { |
---|
| |
---|
| | } |
---|
| | return theInstance; |
---|
| | } |
---|
| | |
---|
| | public IDAddressedEntity createInstance(String name, int stageID) { |
---|
| | public HashMap<String, Instance> createInstance(String name, int stageID) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(Instance.UNIQUE_ID_LENGTH, |
---|
| | RandomStringGenerator.ALPHA_NUMERIC, instanceMap.keySet()); |
---|
| | //Instance instance = new Instance(name, Instance.State.AVAILABLE, stageID); |
---|
| | Instance instance = new Instance(name, stageID); |
---|
| | instanceMap.put(id, instance); |
---|
| | return new IDAddressedEntity(id, instance); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * InstanceRestとのエラー解消用 (後で消す) |
---|
| | */ |
---|
| | public IDAddressedEntity createInstance(String name, Instance.State state, String stageID) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(Instance.UNIQUE_ID_LENGTH, |
---|
| | RandomStringGenerator.ALPHA_NUMERIC, instanceMap.keySet()); |
---|
| | //Instance instance = new Instance(name, state, Integer.parseInt(stageID)); |
---|
| | Instance instance = new Instance(name, Integer.parseInt(stageID)); |
---|
| | instanceMap.put(id, instance); |
---|
| | return new IDAddressedEntity(id, instance); |
---|
| | HashMap<String, Instance> returnMap = new HashMap<>(); |
---|
| | returnMap.put(id, instance); |
---|
| | return returnMap; |
---|
| | } |
---|
| | |
---|
| | public IDAddressedEntity createPlayer(String instanceURI, String characterURI, CameraState cameraState, |
---|
| | public HashMap<String, Player> createPlayer(String instanceURI, String characterURI, CameraState cameraState, |
---|
| | EmoteState.EmoteType animationClassToStart) { |
---|
| | String id = RandomStringGenerator.generateUniqueString(Player.UNIQUE_ID_LENGTH, |
---|
| | RandomStringGenerator.ALPHA_NUMERIC, playerMap.keySet()); |
---|
| | Player player = new Player(instanceURI, characterURI, cameraState, animationClassToStart); |
---|
| | playerMap.put(id, player); |
---|
| | return new IDAddressedEntity(id, player); |
---|
| | } |
---|
| | |
---|
| | public List<Instance> getInstances() { |
---|
| | return new ArrayList<Instance>(instanceMap.values()); |
---|
| | HashMap<String, Player> returnMap = new HashMap<>(); |
---|
| | returnMap.put(id, player); |
---|
| | return returnMap; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * IDに対応するInstanceを取得して返す |
---|
| | * |
---|
| | * @param instanceId |
---|
| | * 取得したいInstanceのID |
---|
| | * @return IDに対応するInstance |
---|
| | */ |
---|
| | public HashMap<String, Instance> getInstances() { |
---|
| | return instanceMap; |
---|
| | } |
---|
| | |
---|
| | public Instance getInstance(String instanceId) { |
---|
| | return instanceMap.get(instanceId); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 全playerを返す |
---|
| | * @return |
---|
| | */ |
---|
| | public List<Player> getPlayers() { |
---|
| | return new ArrayList<Player>(playerMap.values()); |
---|
| | public HashMap<String, Player> getPlayers() { |
---|
| | return playerMap; |
---|
| | } |
---|
| | |
---|
| | |
---|
| | /** |
---|
| | * IDに対応するinstanceにいる全playerを返す |
---|
| | * @param instanceId |
---|
| | * @return |
---|
| | */ |
---|
| | public List<Player> getPlayers(String instanceId) { |
---|
| | public HashMap<String, Player> getPlayers(String instanceId) { |
---|
| | if (instanceId == null || instanceId.isEmpty()) { |
---|
| | return getPlayers(); |
---|
| | } |
---|
| | List<Player> responsePlayers = new ArrayList<>(); |
---|
| | for (Player player : playerMap.values()) { |
---|
| | HashMap<String, Player> responsePlayers = new HashMap<>(); |
---|
| | for (String id : playerMap.keySet()) { |
---|
| | Player player = playerMap.get(id); |
---|
| | String[] instanceURISplit = player.getInstanceURI().split("/"); // …/instances/{instanceId} |
---|
| | if (instanceId.equals(instanceURISplit[instanceURISplit.length - 1])) { |
---|
| | responsePlayers.add(player); |
---|
| | responsePlayers.put(id, player); |
---|
| | } |
---|
| | } |
---|
| | return responsePlayers; |
---|
| | } |
---|
| |
---|
| | player.update(characterURI, position, angle, cameraState, animationClassToStart); |
---|
| | return player; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * IDに対応するInstanceをMapから削除して返す |
---|
| | * |
---|
| | * @param instanceId |
---|
| | * Instanceを識別する一意のID |
---|
| | * @return Mapから削除されたInstance |
---|
| | */ |
---|
| | public Instance destroyInstance(String instanceId) { |
---|
| | return instanceMap.remove(instanceId); |
---|
| | } |
---|
| | |
---|
| |
---|
| | |