Пример #1
0
        private static int AddTexture(string baseDirectory, string filePath, Dictionary <string, int> textureLookup, TexturePack texturePack, float scale)
        {
            if (!textureLookup.TryGetValue(filePath, out var textureId))
            {
                var fileExists = true;
                var path       = filePath;

                if (!File.Exists(path))
                {
                    // Assume it's a relative path
                    path = Path.Combine(baseDirectory, path);
                    if (!File.Exists(path))
                    {
                        fileExists = false;
                    }
                }

                var bitmap = fileExists ? TextureImportHelper.ImportBitmap(path) : new Bitmap(32, 32);
                if (scale != 1)
                {
                    bitmap = new Bitmap(bitmap, new Size(( int )(bitmap.Width / scale), ( int )(bitmap.Height / scale)));
                }
                var name    = Path.GetFileNameWithoutExtension(path);
                var texture = new Texture(bitmap, PS2.GS.GSPixelFormat.PSMT8, name);
                textureId = texturePack.Count;
                texturePack.Add(texture);
                textureLookup[filePath] = textureId;
            }

            return(textureId);
        }
Пример #2
0
        public void CanMapRectangle()
        {
            // ARRANGE
            var texturePack = new TexturePack(2000, 1000);
            var region      = texturePack
                              .Add(500, 500, 100, 100)
                              .Get(1);

            // ACT
            var uv = region.Map(new Vector2(0.5f, 0.5f));

            Assert.IsTrue(Math.Abs(0.275 - uv.x) < Precision);
            Assert.IsTrue(Math.Abs(0.55 - uv.y) < Precision);
        }