diff --git a/src/main/java/cactusServer/resources/InstancesRest.java b/src/main/java/cactusServer/resources/InstancesRest.java index ebd3de6..e38a0f5 100644 --- a/src/main/java/cactusServer/resources/InstancesRest.java +++ b/src/main/java/cactusServer/resources/InstancesRest.java @@ -3,8 +3,7 @@ import java.util.HashSet; import java.util.Map; -import javax.validation.Valid; -import javax.ws.rs.BeanParam; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.FormParam; @@ -23,11 +22,16 @@ import cactusServer.entities.Angle; import cactusServer.entities.Area; import cactusServer.entities.Area.Allowed; +import cactusServer.entities.CameraState; +import cactusServer.entities.Character; +import cactusServer.entities.CharacterModel; +import cactusServer.entities.EmoteState; import cactusServer.entities.IDAddressedEntity; import cactusServer.entities.Instance; import cactusServer.entities.Object.Attribute; import cactusServer.entities.ObjectModel; import cactusServer.entities.Plain; +import cactusServer.entities.Player; import cactusServer.entities.StageModel; import cactusServer.entities.URIAddressedEntity; import cactusServer.models.Instances; @@ -81,30 +85,35 @@ return null; } -// @Path("/{instanceId}/characters/{charactersId}") -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public Character getCharacter(@PathParam("instanceId") String instanceId, @PathParam("characterId") String characterId) { -// Instance instance = Instances.getInstance().getInstance(instanceId); -// if (instance != null) { -// return Instances.getCharacter(characterId); -// } -// return null; -// } - - - - - - - @POST + @Path("/{instanceId}/characters/{characterId}") + @GET @Produces(MediaType.APPLICATION_JSON) - public URIAddressedEntity create(@FormParam("int") int a, @FormParam("name") String name, @FormParam("state") Instance.State state, @FormParam("stageModel") String stageModel) { - System.out.println(a); - IDAddressedEntity ae = Instances.getInstance().createInstance(name, Instance.State.AVAILABLE, "11111"); - return new URIAddressedEntity((INSTANCES_URI + "/" + ae.getId()), ae.getBody()); + public Character getCharacter(@PathParam("instanceId") String instanceId, @PathParam("characterId") String characterId) { + Instance instance = Instances.getInstance().getInstance(instanceId); + if (instance != null) { + return instance.getCharacter(characterId); + } + return null; } + @Path("/players/{playerId}") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Player getPlayer(@PathParam("instanceId") String instanceId, @PathParam("playerId") String playerId) { + Instances instances = Instances.getInstance(); + if (instances != null) { + return instances.getPlayer(playerId); + } + return null; + } + + @POST + @Produces(MediaType.APPLICATION_JSON) + public URIAddressedEntity create(@FormParam("name") String name, @FormParam("state") Instance.State state, @FormParam("stageModel") String stageModel) { + IDAddressedEntity ae = Instances.getInstance().createInstance(name, state, stageModel); + return new URIAddressedEntity((INSTANCES_URI + "/" + ae.getId()), ae.getBody()); + } + @Path("/{instanceId}/areas") @POST @Produces(MediaType.APPLICATION_JSON) @@ -118,14 +127,52 @@ @Path("/{instanceId}/objects") @POST @Produces(MediaType.APPLICATION_JSON) - public URIAddressedEntity create(@PathParam("instanceId") String instanceId, @FormParam("position") Position3D position, + public URIAddressedEntity createObject(@PathParam("instanceId") String instanceId, @FormParam("position") Position3D position, @FormParam("velocity") Velocity3D velocity, @FormParam("angularVelocity") AngularVelocity3D angularVelocity, - @FormParam("angle") Angle angle, @FormParam("attribute") Attribute attribute, @FormParam("model") ObjectModel model) { + @FormParam("angle") Angle angle, @FormParam("attribute") Attribute attribute, @FormParam("model") String model) { Instance instance = Instances.getInstance().getInstance(instanceId); IDAddressedEntity ae = instance.createObject(position, velocity, angularVelocity, angle, attribute, model); return new URIAddressedEntity((INSTANCES_URI + "/" + instanceId + "/objects/" + ae.getId()), ae.getBody()); } - + + @Path("/{instanceId}/characters") + @POST + @Produces(MediaType.APPLICATION_JSON) + public URIAddressedEntity createCharacter(@PathParam("instanceId") String instanceId, @FormParam("accountURI") String accountURI, + @FormParam("name") String name, @FormParam("position") Position3D position, @FormParam("angle") Angle angle, + @FormParam("model") String model) { + Instance instance = Instances.getInstance().getInstance(instanceId); + IDAddressedEntity ae = instance.createCharacter(instanceId, accountURI, name, position, angle, model); + return new URIAddressedEntity((INSTANCES_URI + "/" + instanceId + "/characters/" + ae.getId()), ae.getBody()); + } + + @Path("/players") + @POST + @Produces(MediaType.APPLICATION_JSON) + public URIAddressedEntity createPlayer(@PathParam("instanceId") String instanceURI, @FormParam("characterURI") String characterURI, + @FormParam("cameraState") CameraState cameraState, @FormParam("animationClassToStart") EmoteState.EmoteType animationClassToStart) { + Instances instances = Instances.getInstance(); + IDAddressedEntity ae = instances.createPlayer(instanceURI, characterURI, cameraState, animationClassToStart); + return new URIAddressedEntity((INSTANCES_URI + "/" + instanceURI + "/players/" + ae.getId()), ae.getBody()); + } + +// @Path("/players/{playerId}") +// @PUT +// @Produces(MediaType.APPLICATION_JSON) +// public Player putPlayer(@PathParam("instanceId") String instanceId, @FormParam("characterURI") String characterURI, +// @FormParam("position") Position3D position, @FormParam("angle") Angle angle, +// @FormParam("cameraState") CameraState cameraState, @FormParam("animationClassToStart") EmoteState animationClassToStart) { +// return Instances.getInstance().putPlayer(characterURI, position, angle, cameraState, animationClassToStart); +// } + +// @Path("/characters/{characterId}") +// @PUT +// @Produces(MediaType.APPLICATION_JSON) +// public Character putCharacter(@FormParam("position") Position3D position, @FormParam("angle") Angle angle, +// @FormParam("model") CharacterModel model) { +// HttpServletResponse response = Instance.putCharacter(position, angle, model); +// response.setStatus(HttpServletResponse.SC_OK); +// } // @DELETE // @Path("/destroyInstance")