private void SanityCheck(SpriteFileData data, int index)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.Id.Group < 0 || data.Id.Image < 0)
            {
                data.IsValid = false;
                Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0} has invalid SpriteId #{1}", index, data.Id);
            }

            if (data.PcxSize < 0)
            {
                data.IsValid = false;
                Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0}, id #{1} has invalid image size - {2}", index, data.Id, data.PcxSize);
            }

            if (index == 0 && data.CopyLastPalette)
            {
                Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "First sprite data it set to copy previous, non-existant palette");
            }

            if (data.SharedIndex < 0 || data.SharedIndex >= Count)
            {
                data.IsValid = false;
                Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0}, id #{1} referencing invalid sprite data index", index, data.Id);
            }
        }
Exemple #2
0
        Boolean TryGetSpriteData(SpriteId id, out SpriteFileData data, out Int32 dataindex)
        {
            data      = null;
            dataindex = Int32.MinValue;

            if (id == SpriteId.Invalid)
            {
                return(false);
            }

            Int32 index = m_collection.GetIndex(id);

            if (index == Int32.MinValue)
            {
                return(false);
            }

            SpriteFileData sfd = m_collection.GetData(index);

            if (sfd == null)
            {
                return(false);
            }

            data      = sfd;
            dataindex = index;
            return(true);
        }
Exemple #3
0
        private bool TryGetSpriteData(SpriteId id, out SpriteFileData data, out int dataindex)
        {
            data      = null;
            dataindex = int.MinValue;

            if (id == SpriteId.Invalid)
            {
                return(false);
            }

            var index = m_collection.GetIndex(id);

            if (index == int.MinValue)
            {
                return(false);
            }

            var sfd = m_collection.GetData(index);

            if (sfd == null)
            {
                return(false);
            }

            data      = sfd;
            dataindex = index;
            return(true);
        }
		void SanityCheck(SpriteFileData data, Int32 index)
		{
			if (data == null) throw new ArgumentNullException("data");

			if (data.Id.Group < 0 || data.Id.Image < 0)
			{
				data.IsValid = false;
				Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0} has invalid SpriteId #{1}", index, data.Id);
			}

			if (data.PcxSize < 0)
			{
				data.IsValid = false;
				Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0}, id #{1} has invalid image size - {2}", index, data.Id, data.PcxSize);
			}

			if (index == 0 && data.CopyLastPalette == true)
			{
				Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "First sprite data it set to copy previous, non-existant palette");
			}

			if (data.SharedIndex < 0 || data.SharedIndex >= Count)
			{
				data.IsValid = false;
				Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Sprite data #{0}, id #{1} referencing invalid sprite data index", index, data.Id);
			}
		}
Exemple #5
0
        private SpriteFile CreateSpriteFile(string filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException(nameof(filepath));
            }

            var file = GetSubSystem <IO.FileSystem>().OpenFile(filepath);

            var header = new IO.FileHeaders.SpriteFileHeader(file);

            var datalist = new List <SpriteFileData>(header.NumberOfImages);

            var subheaderOffset = header.SubheaderOffset;

            for (file.SeekFromBeginning(subheaderOffset); file.ReadPosition != file.FileLength; file.SeekFromBeginning(subheaderOffset))
            {
                var subheader = new IO.FileHeaders.SpriteFileSubHeader(file);

                var data = new SpriteFileData((int)file.ReadPosition + 13, subheader.ImageSize, subheader.Axis, subheader.Id, subheader.SharedIndex, subheader.CopyLastPalette);
                datalist.Add(data);

                subheaderOffset = subheader.NextOffset;
            }

            return(new SpriteFile(this, file, header.Version, datalist, header.SharedPalette));
        }
        public SpriteFileDataCollection(List <SpriteFileData> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            m_indexeddata = data;
            m_indexcache  = new Dictionary <SpriteId, Int32>();

            for (Int32 i = 0; i != Count; ++i)
            {
                SpriteFileData sfd = m_indexeddata[i];

                if (sfd == null)
                {
                    continue;
                }
                if (m_indexcache.ContainsKey(sfd.Id) == true)
                {
                    continue;
                }

                m_indexcache.Add(sfd.Id, i);
            }
        }
Exemple #7
0
        public void LoadAllSprites()
        {
            for (Int32 i = 0; i != m_collection.Count; ++i)
            {
                SpriteFileData data = m_collection.GetData(i);
                if (data == null)
                {
                    continue;
                }

                GetSprite(data.Id);
            }
        }
Exemple #8
0
		Boolean TryGetSpriteData(SpriteId id, out SpriteFileData data, out Int32 dataindex)
		{
			data = null;
			dataindex = Int32.MinValue;

			if (id == SpriteId.Invalid) return false;

			Int32 index = m_collection.GetIndex(id);
			if (index == Int32.MinValue) return false;

			SpriteFileData sfd = m_collection.GetData(index);
			if (sfd == null) return false;

			data = sfd;
			dataindex = index;
			return true;
		}
        public SpriteFileData GetData(Int32 index)
        {
            if (index < 0 || index >= Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            SpriteFileData data = m_indexeddata[index];

            if (data.IsValid == null)
            {
                data.IsValid = true;
                SanityCheck(data, index);
            }

            return((data.IsValid == true) ? data : null);
        }
Exemple #10
0
        public Texture2D GetFirstPalette()
        {
            if (m_collection.Count == 0)
            {
                return(null);
            }

            SpriteFileData data = m_collection.GetData(0);

            if (data == null)
            {
                return(null);
            }

            Sprite sprite = GetSprite(data.Id);

            if (sprite == null)
            {
                return(null);
            }

            return(sprite.Palette);
        }
Exemple #11
0
        public Sprite GetSprite(SpriteId id)
        {
            if (id == SpriteId.Invalid)
            {
                return(null);
            }

            if (m_cachedsprites.ContainsKey(id) == true)
            {
                return(m_cachedsprites[id]);
            }

            SpriteFileData data;
            Int32          dataindex;

            if (TryGetSpriteData(id, out data, out dataindex) == false)
            {
                return(null);
            }

            Point     size;
            Texture2D pixels;
            Texture2D palette;
            Boolean   paletteoverride = false;
            Boolean   ownpixels       = true;
            Boolean   ownpalette      = true;

            if (data.PcxSize > 0)
            {
                m_file.SeekFromBeginning(data.FileOffset);
                if (m_spritesystem.LoadImage(m_file, data.PcxSize, out size, out pixels, out palette) == false)
                {
                    Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Cannot load PCX image data from '{0}' for sprite #{1}", Filepath, id);

                    data.IsValid = false;
                    return(null);
                }
            }
            else
            {
                SpriteFileData shareddata = m_collection.GetData(data.SharedIndex);
                if (shareddata == null || shareddata.Id == id)
                {
                    return(null);
                }

                Sprite shared_sprite = GetSprite(shareddata.Id);
                if (shared_sprite == null)
                {
                    return(null);
                }

                size            = shared_sprite.Size;
                paletteoverride = shared_sprite.PaletteOverride;
                pixels          = shared_sprite.Pixels;
                palette         = shared_sprite.Palette;
                ownpixels       = false;
                ownpalette      = false;
            }

            if (data.CopyLastPalette == true && dataindex != 0)
            {
                SpriteFileData previousdata = m_collection.GetData(dataindex - 1);
                if (previousdata != null && previousdata.Id != id)
                {
                    Sprite previoussprite = GetSprite(previousdata.Id);
                    if (previoussprite != null)
                    {
                        paletteoverride = previoussprite.PaletteOverride;
                        ownpalette      = false;

                        palette = previoussprite.Palette;
                    }
                }
            }

            if (id == new SpriteId(0, 0) || id == SpriteId.SmallPortrait)
            {
                paletteoverride = true;
            }

            Sprite sprite = new Sprite(size, data.Axis, ownpixels, pixels, ownpalette, palette, paletteoverride);

            m_cachedsprites.Add(id, sprite);

            return(sprite);
        }
Exemple #12
0
		SpriteFile CreateSpriteFile(String filepath)
		{
			if (filepath == null) throw new ArgumentNullException("filepath");

			IO.File file = GetSubSystem<IO.FileSystem>().OpenFile(filepath);

			IO.FileHeaders.SpriteFileHeader header = new IO.FileHeaders.SpriteFileHeader(file);

			List<SpriteFileData> datalist = new List<SpriteFileData>(header.NumberOfImages);

			Int32 subheader_offset = header.SubheaderOffset;
			for (file.SeekFromBeginning(subheader_offset); file.ReadPosition != file.FileLength; file.SeekFromBeginning(subheader_offset))
			{
				IO.FileHeaders.SpriteFileSubHeader subheader = new IO.FileHeaders.SpriteFileSubHeader(file);

				SpriteFileData data = new SpriteFileData((Int32)file.ReadPosition + 13, subheader.ImageSize, subheader.Axis, subheader.Id, subheader.SharedIndex, subheader.CopyLastPalette);
				datalist.Add(data);

				subheader_offset = subheader.NextOffset;
			}

			return new SpriteFile(this, file, header.Version, datalist, header.SharedPalette);
		}