Ejemplo n.º 1
0
        private Tileset GetTileSet()
        {
            Tileset toReturn = null;

            if (!string.IsNullOrEmpty(this.tbTilesheet.Text) && !string.IsNullOrEmpty(this.tbName.Text))
            {
                toReturn = new Tileset();
                toReturn.Name = this.tbName.Text;
                toReturn.TileWidth = (int)this.nmTileWidth.Value;
                toReturn.TileHeight = (int)this.nmTileHeight.Value;
                toReturn.MapObjects = new Collections.MapObjects();
                toReturn.ObjectDirectories = new Collections.ObjectDirectories();
            }

            return toReturn;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts or Updates a tileset
        /// </summary>
        /// <param name="o">The tileset to insert/update</param>
        /// <param name="parent">The parent of the tileset</param>
        public static void InsertUpdateTileset(Tileset o)
        {
            string query = string.Empty;
            SqlCommand cmd = null;
            long id = 0;

            if (o != null)
            {
                cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;

                //Update
                if (o.ID > 0)
                {
                    query = "UPDATE [ObjectDirectory] SET Name = @Name, Parent = NULL WHERE ID = @ID; " +
                            "UPDATE [Tileset] Set TileHeight = @TileHeight, TileWidth = @TileWidth WHERE ID = @ID; " +
                            "SELECT SCOPE_IDENTITY();";
                    cmd.CommandText = query;

                    cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value = o.ID;
                    cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = o.Name;
                    cmd.Parameters.Add("@TileHeight", SqlDbType.Int).Value = o.TileHeight;
                    cmd.Parameters.Add("@TileWidth", SqlDbType.Int).Value = o.TileWidth;
                    id = DatabaseHelper.ExecuteCommand(GetConnectionString(), cmd);
                    if (id > 0)
                    {
                        id = o.ID;
                    }
                }
                //Insert
                else
                {
                    query = "INSERT INTO [ObjectDirectory] (Name, Parent) VALUES (@Name, NULL); " +
                            "SELECT SCOPE_IDENTITY();";
                    cmd.CommandText = query;

                    cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = o.Name;

                    id = DatabaseHelper.ExecuteCommandContainingGetIdentity(GetConnectionString(), cmd);

                    cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;

                    query = "INSERT INTO [Tileset] (ID, TileHeight, TileWidth) VALUES (@ID, @TileHeight, @TileWidth)";
                    cmd.CommandText = query;

                    cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value = id;
                    cmd.Parameters.Add("@TileHeight", SqlDbType.Int).Value = o.TileHeight;
                    cmd.Parameters.Add("@TileWidth", SqlDbType.Int).Value = o.TileWidth;

                    DatabaseHelper.ExecuteCommand(GetConnectionString(), cmd);
                }

                if (id > 0)
                {
                    InsertUpdateObjectDirectories(o.ObjectDirectories, id);
                    InsertUpdateMapObjects(o.MapObjects, id);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all tilesets.
        /// </summary>
        /// <returns>All tilesets</returns>
        public static Tilesets GetTilesets()
        {
            Tilesets toReturn = new Tilesets();
            Tileset temp = null;
            DataTable dt = null;
            string query = "SELECT * FROM [Tileset] " +
                           "JOIN ObjectDirectory ON Tileset.ID = ObjectDirectory.ID";

            dt = DatabaseHelper.ExecuteTextCommandQuery(GetConnectionString(), query);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    temp = new Tileset();
                    temp.ID = DatabaseHelper.GetValidValueFromObject(dr["ID"], (long)0);
                    temp.Name = DatabaseHelper.GetValidValueFromObject(dr["Name"], string.Empty);
                    temp.TileHeight = DatabaseHelper.GetValidValueFromObject(dr["TileHeight"], (int)0);
                    temp.TileWidth = DatabaseHelper.GetValidValueFromObject(dr["TileWidth"], (int)0);

                    toReturn.Add(temp);
                }
            }

            return toReturn;
        }