/// <summary> /// Render a textured instance of a tile at the given coordinates. /// </summary> /// <param name="def">The definition of the tile to use.</param> /// <param name="xTopLeft"></param> /// <param name="yTopLeft"></param> /// <param name="batch">The SpriteBatch to queue into.</param> public static void RenderTile(ITileDefinition def, float xTopLeft, float yTopLeft, SpriteBatch batch) { var tileSprite = IoCManager.Resolve <IResourceCache>().GetSprite(def.SpriteName); tileSprite.Position = new Vector2f(xTopLeft, yTopLeft); batch.Draw(tileSprite); }
///<summary> /// Method to handle clicking on a tile to then appropriately RCD it. This can have several behaviours depending on mode. /// @param eventAargs = An action event telling us what tile was clicked on. We use this to exrapolate where to place the new tile / remove the old one etc. ///</summary> public void AfterInteract(AfterInteractEventArgs eventArgs) { var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); //Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed. if (_ammo <= 0 || coordinates == GridCoordinates.InvalidGrid || !InteractionChecks.InRangeUnobstructed(eventArgs)) { return; } var targetTile = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; var canPlaceTile = targetTile.IsSubFloor; //Boolean to check if we're able to build the desired tile. This defaults to checking for subfloors, but is overridden by "deconstruct" which sets it to the inverse. switch (this._mode) { //Floor mode just needs the tile to be a space tile (subFloor) case RcdMode.Floors: break; //We don't want to place a space tile on something that's already a space tile. Let's do the inverse of the last check. case RcdMode.Deconstruct: canPlaceTile = !targetTile.IsSubFloor; break; //Walls are a special behaviour, and require us to build a new object with a transform rather than setting a grid tile, thus we early return to avoid the tile set code. case RcdMode.Walls: var snapPos = mapGrid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center); var ent = _serverEntityManager.SpawnEntity("solid_wall", mapGrid.GridTileToLocal(snapPos)); ent.Transform.LocalRotation = Owner.Transform.LocalRotation; //Now apply icon smoothing. _entitySystemManager.GetEntitySystem <AudioSystem>().PlayFromEntity("/Audio/Items/deconstruct.ogg", Owner); _ammo--; return; //Alright we're done here default: return; //I don't know why this would happen, but sure I guess. Get out of here invalid state! } ITileDefinition desiredTile = null; desiredTile = _tileDefinitionManager[_outputTile]; if (canPlaceTile) //If desiredTile is null by this point, something has gone horribly wrong and you need to fix it. { mapGrid.SetTile(eventArgs.ClickLocation, new Tile(desiredTile.TileId)); _entitySystemManager.GetEntitySystem <AudioSystem>().PlayFromEntity("/Audio/Items/deconstruct.ogg", Owner); _ammo--; } }
public override ushort Register(ITileDefinition tileDef) { var ret = base.Register(tileDef); TileSet.CreateTile(ret); if (!string.IsNullOrEmpty(tileDef.SpriteName)) { var texture = resourceCache.GetResource <TextureResource>($@"/Textures/Tiles/{tileDef.SpriteName}.png"); TileSet.TileSetTexture(ret, texture.Texture.GodotTexture); Textures[ret] = texture; } return(ret); }
public virtual void Register(ITileDefinition tileDef) { var name = tileDef.Name; if (_tileNames.ContainsKey(name)) { throw new ArgumentException("Another tile definition with the same name has already been registered.", nameof(tileDef)); } var id = checked ((ushort)TileDefs.Count); tileDef.AssignTileId(id); TileDefs.Add(tileDef); _tileNames[name] = tileDef; _tileIds[tileDef] = id; }
public ushort Register(ITileDefinition tileDef) { ushort id; if (tileIds.TryGetValue(tileDef, out id)) return id; string name = tileDef.Name; if (tileNames.ContainsKey(name)) throw new ArgumentException("Another tile definition with the same name has already been registered.", "tileDef"); id = checked((ushort)tileDefs.Count); tileDefs.Add(tileDef); tileNames[name] = tileDef; tileIds[tileDef] = id; return id; }
public static void DrawTiles(IEnumerable <TileRef> tileRefs, SpriteBatch floorBatch, SpriteBatch gasBatch) { var cache = IoCManager.Resolve <IResourceCache>(); Sprite sprite = null; ITileDefinition lastDef = null; var ppm = CluwneLib.Camera.PixelsPerMeter; foreach (var tileReference in tileRefs) { if (tileReference.TileDef != lastDef) { lastDef = tileReference.TileDef; sprite = cache.GetSprite(lastDef.SpriteName); } sprite.Position = new Vector2(tileReference.X, tileReference.Y) * ppm; floorBatch.Draw(sprite); } }
public override void Register(ITileDefinition tileDef) { base.Register(tileDef); var id = tileDef.TileId; TileSet.CreateTile(id); if (string.IsNullOrEmpty(tileDef.SpriteName)) { return; } var texture = resourceCache.GetResource <TextureResource>( new ResourcePath("/Textures/Tiles/") / $@"{tileDef.SpriteName}.png"); TileSet.TileSetTexture(id, texture.Texture.GodotTexture); Textures[id] = texture; }
public virtual ushort Register(ITileDefinition tileDef) { if (_tileIds.TryGetValue(tileDef, out ushort id)) { throw new InvalidOperationException($"TileDefinition is already registered: {tileDef.GetType()}, id: {id}"); } var name = tileDef.Name; if (_tileNames.ContainsKey(name)) { throw new ArgumentException("Another tile definition with the same name has already been registered.", nameof(tileDef)); } id = checked ((ushort)_tileDefs.Count); _tileDefs.Add(tileDef); _tileNames[name] = tileDef; _tileIds[tileDef] = id; return(id); }
public override ushort Register(ITileDefinition tileDef) { if (!GameController.OnGodot) { return(base.Register(tileDef)); } var ret = base.Register(tileDef); TileSet.CreateTile(ret); if (!string.IsNullOrEmpty(tileDef.SpriteName)) { var texture = resourceCache.GetResource <TextureResource>( new ResourcePath("/Textures/Tiles/") / $@"{tileDef.SpriteName}.png"); TileSet.TileSetTexture(ret, texture.Texture.GodotTexture); Textures[ret] = texture; } return(ret); }
public ushort Register(ITileDefinition tileDef) { ushort id; if (tileIds.TryGetValue(tileDef, out id)) { return(id); } string name = tileDef.Name; if (tileNames.ContainsKey(name)) { throw new ArgumentException("Another tile definition with the same name has already been registered.", "tileDef"); } id = checked ((ushort)tileDefs.Count); tileDefs.Add(tileDef); tileNames[name] = tileDef; tileIds[tileDef] = id; return(id); }
//What was this supposed to do? public static void DrawDecals(ITileDefinition def, float xTopLeft, float yTopLeft, int tileSpacing, SpriteBatch decalBatch) { //TODO: Figure out what to do with this }
//What was this supposed to do? public static void RenderPosOffset(ITileDefinition def, float x, float y, int tileSpacing, Vector2f lightPosition) { }
//What was this supposed to do? public static void DrawDecals(ITileDefinition def, float xTopLeft, float yTopLeft, int tileSpacing, SpriteBatch decalBatch) { }
//What was this supposed to do? public static void RenderGas(ITileDefinition def, float xTopLeft, float yTopLeft, uint tileSpacing, SpriteBatch gasBatch) { }
//What was this supposed to do? public static void RenderTop(ITileDefinition def, float xTopLeft, float yTopLeft, SpriteBatch wallTopsBatch) { }
//What was this supposed to do? public static void RenderTop(ITileDefinition def, float xTopLeft, float yTopLeft, SpriteBatch wallTopsBatch) { //TODO: Figure out what to do with this }
//What was this supposed to do? public static void RenderGas(ITileDefinition def, float xTopLeft, float yTopLeft, uint tileSpacing, SpriteBatch gasBatch) { //TODO: Figure out what to do with this }
//What was this supposed to do? public static void RenderPosOffset(ITileDefinition def, float x, float y, int tileSpacing, Vector2 lightPosition) { //TODO: Figure out what to do with this }