public Wall EntityToWall(WallEntity toConvert) { Point origin = new Point(toConvert.BeginningX, toConvert.BeginningY); Point end = new Point(toConvert.EndX, toConvert.EndY); return(new Wall(origin, end)); }
// assumes cell has been checked for any containing entities public void AddWallEntity(Cell cell) { ICellEntity ent = new WallEntity(cell); entities[cell.GetCellIndexX(), cell.GetCellIndexY()] = ent; GameObject go = Instantiate(prefabs[0], new Vector3(cell.getCenterPosition().x, cell.getCenterPosition().y, -2), Quaternion.identity); ent.gameObject = go; }
/// <summary> /// When overridden in the derived class, handles drawing to the map after all of the map drawing finishes. /// </summary> /// <param name="map">The map the drawing is taking place on.</param> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> that describes the view of the map being drawn.</param> protected override void HandleDrawAfterMap(IDrawableMap map, ISpriteBatch spriteBatch, ICamera2D camera) { var p = Parent; if (p == null) { return; } // Ensure the map is valid var clientMap = map as EditorMap; if (clientMap == null) { return; } var viewArea = camera.GetViewArea(); // Draw the walls if (p.DrawWalls) { var visibleWalls = map.Spatial.GetMany <WallEntityBase>(viewArea); foreach (var wall in visibleWalls) { EntityDrawer.Draw(spriteBatch, camera, wall); } } // Draw the MapGrh walls if (p.DrawMapGrhWalls) { var mapGrhWalls = GlobalState.Instance.MapGrhWalls; var toDraw = clientMap.Spatial.GetMany <MapGrh>(viewArea); var tmpWall = new WallEntity(Vector2.Zero, Vector2.Zero); foreach (var mg in toDraw) { var boundWalls = mapGrhWalls[mg.Grh.GrhData]; if (boundWalls == null) { continue; } foreach (var wall in boundWalls) { tmpWall.Size = wall.Size != Vector2.Zero ? wall.Size * mg.Scale : mg.Size; tmpWall.Position = mg.Position + (wall.Position * mg.Scale); tmpWall.IsPlatform = wall.IsPlatform; EntityDrawer.Draw(spriteBatch, camera, tmpWall); } } } }
void RebuildMapGrhWalls(IEnumerable <KeyValuePair <GrhData, GrhData.FileTags> > grhDataFileTags) { MapGrhWalls.Clear(); foreach (var kvp in grhDataFileTags) { if (kvp.Value.Walls == null || kvp.Value.Walls.Count == 0) { continue; } List <WallEntityBase> wallList = new List <WallEntityBase>(); GrhData gd = kvp.Key; // Create the wall entities foreach (var wallInfo in kvp.Value.Walls) { GrhData.BoundWallType wallType = wallInfo.Item1; Rectangle? area = wallInfo.Item2; Vector2 position; Vector2 size; if (area.HasValue) { position = new Vector2(area.Value.X, area.Value.Y); size = new Vector2(area.Value.Width, area.Value.Height); } else { position = Vector2.Zero; size = Vector2.Zero; } if (wallType == GrhData.BoundWallType.Solid || wallType == GrhData.BoundWallType.Platform) { WallEntity wall = new WallEntity(position, size) { IsPlatform = wallType == GrhData.BoundWallType.Platform }; wallList.Add(wall); } } // If there are any walls, trim the list and set it if (wallList.Count > 0) { wallList.TrimExcess(); MapGrhWalls[gd] = wallList; } } }
public WallEntity WallToEntity(Wall toConvert, BlueprintEntity bearer) { WallEntity conversion = new WallEntity() { BeginningX = toConvert.Beginning().CoordX, BeginningY = toConvert.Beginning().CoordY, EndX = toConvert.End().CoordX, EndY = toConvert.End().CoordY, Height = toConvert.Height(), Width = toConvert.Width(), BearerBlueprint = bearer }; return(conversion); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); if (e.Button == MouseButtons.Right) { var entity = new WallEntity(worldPos, new Vector2(4)); GridAligner.Instance.Fit(entity); map.AddEntity(entity); SOM.SetSelected(entity); } base.MapContainer_MouseDown(sender, map, camera, e); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "api/Generate/Image")] HttpRequestMessage request, TraceWriter log, ExecutionContext context) { if (IsAuthenticated) { auth = request.GetAuthInfoAsync(log).Result; } log.Info("Is Authenticated: " + IsAuthenticated); //We can zip a bunch of them var generator = new UrlGenerator(new Uri(QrCodeUrl), 1); var guid = generator.Guids.First(); //Create Blob/Table references var wallPath = string.Format($"{guid.ToString("N")}/wall"); var wallblob = BlobStorage.GetBlob(Constants.BlobContainerNames.Wall, wallPath); var contents = new WallEntity(new Message() { Text = Constants.Default.Wall.WelcomeMessage, Username = Constants.Default.Wall.User }); var json = JsonConvert.SerializeObject(contents); wallblob.UploadText(json); if (IsAuthenticated) { var name = auth.GetClaim(ClaimTypes.Name).Value; var nameId = auth.GetClaim(ClaimTypes.NameIdentifier).Value; var user = new Users(name, nameId); TableStorage.Insert(Constants.TableNames.Users, user); var trackedWall = new Tracked(nameId, guid.ToString("N")); TableStorage.Insert(Constants.TableNames.Tracked, trackedWall); } var urls = generator.ToUri(); var bitmap = new QrCode().GenerateImage(urls.First(), 10); var ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); var logoPath = context.FunctionAppDirectory + logoLocation; var footerPath = context.FunctionAppDirectory + footerLocation; var logo = new Logo(logoPath); var footer = new Logo(footerPath); ms.Position = 0; var qrCodeWithLogo = logo.Image.AppendImage(Image.FromStream(ms), 10, 10); ms.Position = 0; var footerImage = qrCodeWithLogo.AppendImage(footer.Image, 0, 0); var result = footerImage.WriteText(guid.ToString("N").Substring(0, 5), new PointF(40, footerImage.Height - 160)); var msreadathon = new MemoryStream(); ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg); Encoder myEncoder = Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L); myEncoderParameters.Param[0] = myEncoderParameter; result.Save(msreadathon, jpgEncoder, myEncoderParameters); //Save image to blob var qrCodePath = string.Format($"{guid.ToString("N")}/qrCode"); var container = BlobStorage.GetContainer(Constants.BlobContainerNames.Wall); var qrCodeBlob = container.GetBlockBlobReference(qrCodePath); qrCodeBlob.Properties.ContentType = "image/png"; ms.Position = 0; qrCodeBlob.UploadFromStream(ms); log.Info("Image uploaded to: " + qrCodeBlob.Uri.AbsoluteUri); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new ByteArrayContent(msreadathon.ToArray()); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(CONTENT_DISPOSITION_TYPE); response.Content.Headers.ContentDisposition.FileName = FILENAME; response.Content.Headers.ContentType = new MediaTypeHeaderValue(MEDIA_TYPE); return(response); }
private static Entity JSONToEntity(Level level, JToken entity, List <Action> delayedParseActions) { var entityType = entity["Type"]?.ToObject <EntityTypes>(); if (entityType == null) { throw new InvalidSerializedContentException($"Invalid entity type specified [{entityType}]"); } var entityX = entity.Value <int>("X"); if (entityX < 0 || entityX >= level.LevelWidth) { throw new InvalidSerializedContentException($"Invalid entity X specified [{entityX}]"); } var entityY = entity.Value <int>("Y"); if (entityY < 0 || entityY >= level.LevelHeight) { throw new InvalidSerializedContentException($"Invalid entity Y specified [{entityY}]"); } switch (entityType.Value) { case EntityTypes.Pit: case EntityTypes.HaltTile: case EntityTypes.FinishFlag: case EntityTypes.JumpTile: var genericEntity = new StaticEntity(entityType.Value, level.GetNextEntityID(), entityX, entityY); return(genericEntity); case EntityTypes.Wall: var adjacentWalls = entity.Value <byte>("AdjacentWalls"); var wallEntity = new WallEntity(level.GetNextEntityID(), entityX, entityY, adjacentWalls); return(wallEntity); case EntityTypes.RedirectTile: var redirectDir = entity.Value <int>("RedirectDir"); if (redirectDir < 0 || redirectDir > 3) { throw new InvalidSerializedContentException($"Invalid redirect direction [{redirectDir}]"); } var redirectEntity = new RedirectTile(level.GetNextEntityID(), entityX, entityY, redirectDir); return(redirectEntity); case EntityTypes.Portal: var portalTargetX = entity["PortalTarget"]?.Value <int>("X"); var portalTargetY = entity["PortalTarget"]?.Value <int>("Y"); if (!portalTargetX.HasValue || portalTargetX < 0 || portalTargetX >= level.LevelWidth) { throw new InvalidSerializedContentException($"Invalid portal target X specified [{portalTargetX}]"); } if (!portalTargetY.HasValue || portalTargetY < 0 || portalTargetY >= level.LevelHeight) { throw new InvalidSerializedContentException($"Invalid portal target Y specified [{portalTargetY}]"); } var portalEntity = new PortalEntity(level.GetNextEntityID(), entityX, entityY, new IntVector2(portalTargetX.Value, portalTargetY.Value)); return(portalEntity); case EntityTypes.Player: var playerEntity = new PlayerEntity(-(level.PlayerEntities.Count + 1), entityX, entityY); return(playerEntity); case EntityTypes.SlidingCrate: var slidingCrateEntity = new SlidingCrate(level.GetNextEntityID(), entityX, entityY); return(slidingCrateEntity); case EntityTypes.WireButton: var buttonMode = entity["Mode"]?.ToObject <WireButtonEntity.ButtonModes>(); if (buttonMode == null) { throw new InvalidSerializedContentException($"Invalid button mode specified [{buttonMode}]"); } var wireButtonEntity = new WireButtonEntity(level.GetNextEntityID(), entityX, entityY, buttonMode.Value); delayedParseActions.Add(() => { var wireInteractionsJSON = (JArray)entity["Wire"]; if (wireInteractionsJSON == null || wireInteractionsJSON.Count < 1) { throw new InvalidSerializedContentException($"Invalid wire interactions specified for [{wireButtonEntity.EntityType}] at [{wireButtonEntity.Position}]"); } foreach (var wireInteractionJSON in wireInteractionsJSON) { var wireX = wireInteractionJSON.Value <int>("X"); if (wireX < 0 || wireX >= level.LevelWidth) { throw new InvalidSerializedContentException($"Invalid wire X specified [{wireX}]"); } var wireY = wireInteractionJSON.Value <int>("Y"); if (wireY < 0 || wireY >= level.LevelHeight) { throw new InvalidSerializedContentException($"Invalid entity Y specified [{wireY}]"); } var invert = wireInteractionJSON.Value <bool>("Invert"); var interactables = level .GetEntitiesAtPosition(wireX, wireY) .Where(i => i is IWireInteractable); foreach (var interactable in interactables) { wireButtonEntity.WireInteractions.Add(new WireInteraction() { Interactable = (IWireInteractable)interactable, Invert = invert }); } } }); return(wireButtonEntity); case EntityTypes.WireDoor: var wireDoorEntity = new WireDoorEntity(level.GetNextEntityID(), entityX, entityY, false); return(wireDoorEntity); case EntityTypes.Sushi: var sushiEntity = new SushiEntity(level.GetNextEntityID(), entityX, entityY, true); return(sushiEntity); case EntityTypes.None: return(null); default: throw new NotSupportedException($"Entity type [{entityType}] is not parsable. Please implement JSON to entity."); } }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); if (e.Button == MouseButtons.Right) { var ga = GridAligner.Instance; var entity = new WallEntity(worldPos, ga.GridSize); ga.Fit(entity); map.AddEntity(entity); SOM.SetSelected(entity); } base.MapContainer_MouseDown(sender, map, camera, e); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "api/generate")] HttpRequestMessage req, TraceWriter log) { if (IsAuthenticated) { auth = req.GetAuthInfoAsync(log).Result; } log.Info("Is Authenticated: " + IsAuthenticated); var queryTracked = req.GetQueryValue("tracked"); var title = req.GetQueryValue("title"); var queryLogo = req.GetQueryValue("logo"); var queryLatitude = req.GetQueryValue("latitude"); var queryLongitude = req.GetQueryValue("longitude"); var queryWallToken = req.GetQueryValue("wallToken"); var wallToken = DecryptWallToken(queryWallToken); var isTracked = Boolean.TryParse(queryTracked, out bool tracked); var logoParsed = Boolean.TryParse(queryTracked, out bool hasLogo); var isLatitude = double.TryParse(queryLatitude, out double latitude); var isLongitude = double.TryParse(queryLongitude, out double longitude); var isWallId = Guid.TryParse(wallToken, out Guid wallId); //There's no validation on the values if (!isTracked || !logoParsed || (!isLatitude && queryLatitude != null) || (!isLongitude && queryLongitude != null) || !isWallId) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } var wallPath = string.Format($"{wallId.ToString("N")}/wall"); var wallblob = BlobStorage.GetBlob(Constants.BlobContainerNames.Wall, wallPath); var contents = new WallEntity(new Message { Text = Constants.Default.Wall.WelcomeMessage, Username = Constants.Default.Wall.User }); var json = JsonConvert.SerializeObject(contents); wallblob.UploadText(json); var wall = new Walls(wallId.ToString("N"), latitude, longitude, title); TableStorage.Insert(Constants.TableNames.Walls, wall); var host = req.GetHost(); var generator = new UrlGenerator(new Uri(host + path), 1); var uri = generator.ToUri().First(); var bitmap = new QrCode().GenerateImage(uri, 50); var qrCodePath = string.Format($"{wallId.ToString("N")}/qrCode"); var container = BlobStorage.GetContainer(Constants.BlobContainerNames.Wall); var qrCodeBlob = container.GetBlockBlobReference(qrCodePath); qrCodeBlob.Properties.ContentType = "image/jpeg"; var ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Jpeg); qrCodeBlob.UploadFromStream(ms); log.Info("Image uploaded to: " + qrCodeBlob.Uri.AbsoluteUri); if (tracked && IsAuthenticated) { var name = auth.GetClaim(ClaimTypes.Name).Value; var nameId = auth.GetClaim(ClaimTypes.NameIdentifier).Value; var user = new Users(name, nameId); TableStorage.Insert(Constants.TableNames.Users, user); var trackedWall = new Tracked(nameId, wallId.ToString("N")); TableStorage.Insert(Constants.TableNames.Tracked, trackedWall); } if (tracked) { return(req.CreateResponse(HttpStatusCode.OK, new { Created = DateTime.UtcNow, WallId = wallId.ToString("N") })); } else { return(req.CreateResponse(HttpStatusCode.OK, new { Created = DateTime.UtcNow })); } }
/// <summary> /// When overridden in the derived class, handles drawing to the map after all of the map drawing finishes. /// </summary> /// <param name="map">The map the drawing is taking place on.</param> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> that describes the view of the map being drawn.</param> protected override void HandleDrawAfterMap(IDrawableMap map, ISpriteBatch spriteBatch, ICamera2D camera) { var p = Parent; if (p == null) return; // Ensure the map is valid var clientMap = map as EditorMap; if (clientMap == null) return; var viewArea = camera.GetViewArea(); // Draw the walls if (p.DrawWalls) { var visibleWalls = map.Spatial.GetMany<WallEntityBase>(viewArea); foreach (var wall in visibleWalls) { EntityDrawer.Draw(spriteBatch, camera, wall); } } // Draw the MapGrh walls if (p.DrawMapGrhWalls) { var mapGrhWalls = GlobalState.Instance.MapGrhWalls; var toDraw = clientMap.Spatial.GetMany<MapGrh>(viewArea); var tmpWall = new WallEntity(Vector2.Zero, Vector2.Zero); foreach (var mg in toDraw) { var boundWalls = mapGrhWalls[mg.Grh.GrhData]; if (boundWalls == null) continue; foreach (var wall in boundWalls) { tmpWall.Size = wall.Size != Vector2.Zero ? wall.Size * mg.Scale : mg.Size; tmpWall.Position = mg.Position + (wall.Position * mg.Scale); tmpWall.IsPlatform = wall.IsPlatform; EntityDrawer.Draw(spriteBatch, camera, tmpWall); } } } }
void RebuildMapGrhWalls(IEnumerable<KeyValuePair<GrhData, GrhData.FileTags>> grhDataFileTags) { MapGrhWalls.Clear(); foreach (var kvp in grhDataFileTags) { if (kvp.Value.Walls == null || kvp.Value.Walls.Count == 0) continue; List<WallEntityBase> wallList = new List<WallEntityBase>(); GrhData gd = kvp.Key; // Create the wall entities foreach (var wallInfo in kvp.Value.Walls) { GrhData.BoundWallType wallType = wallInfo.Item1; Rectangle? area = wallInfo.Item2; Vector2 position; Vector2 size; if (area.HasValue) { position = new Vector2(area.Value.X, area.Value.Y); size = new Vector2(area.Value.Width, area.Value.Height); } else { position = Vector2.Zero; size = Vector2.Zero; } if (wallType == GrhData.BoundWallType.Solid || wallType == GrhData.BoundWallType.Platform) { WallEntity wall = new WallEntity(position, size) { IsPlatform = wallType == GrhData.BoundWallType.Platform }; wallList.Add(wall); } } // If there are any walls, trim the list and set it if (wallList.Count > 0) { wallList.TrimExcess(); MapGrhWalls[gd] = wallList; } } }
void BuyWallMenuEntrySelected(object sender, PlayerIndexEventArgs e) { if (Tile_Engine.SelectedTile.IsBlocked == false && Tile_Engine.SelectedTile.DrawEntityList.Count() == 1 && this.player_CurrentGold >= WallEntity.GoldCost && this.player_CurrentEnergy >= WallEntity.EnergyCost) { Tile_Engine.PlayerEntity.Gold -= WallEntity.GoldCost; Tile_Engine.PlayerEntity.Energy -= WallEntity.EnergyCost; WallEntity entity = new WallEntity(Tile_Engine.SelectedTile, wallTexture[random.Next(0, 2)], Color.White, true); Tile_Engine.SelectedTile.AddEntity(entity); } }