Example #1
0
        public async Task <IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
                                                                         IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            animationConfig = animationConfig ?? new AGSAnimationConfiguration();
            string    filePath = spriteSheet.Path;
            IResource resource = await Task.Run(() => _resources.LoadResource(filePath));

            if (resource == null)
            {
                throw new InvalidOperationException("Failed to load sprite sheet from " + filePath);
            }
            IBitmap bitmap = await Task.Run(() => _bitmapLoader.Load(resource.Stream));

            int cellsGrabbed = 0;

            getSpriteSheetData(bitmap, spriteSheet, animationConfig, out int cellsInRow, out int cellsInCol,
                               out int _, out int cellX, out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep,
                               out AGSAnimation animation);
            for (int currentCell = 0; cellsGrabbed < cellsToGrab; currentCell++)
            {
                if (currentCell >= spriteSheet.StartFromCell)
                {
                    getImageInfo(bitmap, cellX, cellY, spriteSheet, loadConfig, filePath, out Rectangle _, out IBitmap clone, out string path, out ITexture tex);
                    IImage image = _loadImage(tex, clone, path, loadConfig, spriteSheet);
                    _addAnimationFrame(image, animation);
                    cellsGrabbed++;
                }

                nextCell(mainStep, secondStep, cellsInRow, cellsInCol, ref cellX, ref cellY);
            }
            animation.Setup();
            return(animation);
        }
		public async Task<IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			animationConfig = animationConfig ?? new AGSAnimationConfiguration ();
			string filePath = spriteSheet.Path;
			IResource resource = await Task.Run(() =>_resources.LoadResource (filePath));
			if (resource == null) {
				throw new InvalidOperationException ("Failed to load sprite sheet from " + filePath);
			}
			IBitmap bitmap = await Task.Run(() => _bitmapLoader.Load (resource.Stream));
			int cellsInRow, cellsInCol, cellsTotal, cellX, cellY, cellsToGrab, cellsGrabbed = 0;
			Point mainStep, secondStep;
			AGSAnimation animation;
			getSpriteSheetData (bitmap, spriteSheet, animationConfig, out cellsInRow, out cellsInCol,
								out cellsTotal, out cellX, out cellY, out cellsToGrab, out mainStep, out secondStep,
								out animation);
			for (int currentCell = 0; cellsGrabbed < cellsToGrab; currentCell++) 
			{
				if (currentCell >= spriteSheet.StartFromCell) 
				{
                    Rectangle rect; IBitmap clone; string path; ITexture tex;
                    getImageInfo (bitmap, cellX, cellY, spriteSheet, loadConfig, filePath, out rect, out clone, out path, out tex);
                    IImage image = _loadImage (tex, clone, path, loadConfig, spriteSheet);
					_addAnimationFrame (image, animation);
					cellsGrabbed++;
				}

				nextCell (mainStep, secondStep, cellsInRow, cellsInCol, ref cellX, ref cellY);
			}
			animation.Setup ();
			return animation;
		}
Example #3
0
 public IAnimation LoadAnimationFromFiles(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string[] files)
 {
     if (files.Length == 0)
     {
         throw new InvalidOperationException("No files given to LoadAnimationFromFiles");
     }
     return(loadAnimationFromResources(files[0], _resources.LoadResources(files), animationConfig, loadConfig));
 }
Example #4
0
 public async Task <IAnimation> LoadAnimationFromFilesAsync(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string [] files)
 {
     if (files.Length == 0)
     {
         throw new InvalidOperationException("No files given to LoadAnimationFromFilesAsync");
     }
     return(await loadAnimationFromResourcesAsync(files[0], await Task.Run(() => _resources.LoadResources(files)),
                                                  animationConfig, loadConfig));
 }
Example #5
0
        private AGSAnimation getAnimation(string samplePath, IAnimationConfiguration animationConfig, int resourcesCount)
        {
            if (resourcesCount == 0 && samplePath != null)
            {
                throw new InvalidOperationException($"Failed to load animation from: {samplePath}");
            }
            animationConfig = animationConfig ?? new AGSAnimationConfiguration();
            AGSAnimationState state     = new AGSAnimationState();
            AGSAnimation      animation = new AGSAnimation(animationConfig, state, resourcesCount);

            return(animation);
        }
Example #6
0
        private IAnimation loadAnimationFromResources(string samplePath, List <IResource> resources,
                                                      IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            AGSAnimation animation = getAnimation(samplePath, animationConfig, resources.Count);

            foreach (IResource resource in resources)
            {
                var image = loadImage(resource, loadConfig);
                addAnimationFrame(image, animation);
            }
            animation.Setup();
            return(animation);
        }
Example #7
0
        private void getSpriteSheetData(IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig,
                                        out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX,
                                        out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep,
                                        out AGSAnimation animation)
        {
            cellsInRow = bitmap.Width / spriteSheet.CellWidth;
            cellsInCol = bitmap.Height / spriteSheet.CellHeight;
            cellsTotal = cellsInRow * cellsInCol;

            int startRow, startCol;

            getOrder(spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep);

            cellX       = startCol;
            cellY       = startRow;
            cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min(spriteSheet.CellsToGrab, cellsTotal);
            animation   = new AGSAnimation(animationConfig, new AGSAnimationState(), cellsToGrab);
        }
Example #8
0
		public async Task<IOutfit> LoadOutfitFromFoldersAsync(string baseFolder, string walkLeftFolder = null, string walkRightFolder = null,
			string walkDownFolder = null, string walkUpFolder = null, string idleLeftFolder = null, string idleRightFolder = null,
			string idleDownFolder = null, string idleUpFolder = null, string speakLeftFolder = null, string speakRightFolder = null,
			string speakDownFolder = null, string speakUpFolder = null,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			IOutfit outfit = _resolver.Resolve<IOutfit> ();

            outfit[AGSOutfit.Idle] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, idleLeftFolder, idleRightFolder,
				idleDownFolder, idleUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Walk] = await _graphics.LoadDirectionalAnimationFromFoldersAsync (baseFolder, walkLeftFolder, walkRightFolder,
				walkDownFolder, walkUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Speak] = await _graphics.LoadDirectionalAnimationFromFoldersAsync (baseFolder, speakLeftFolder, speakRightFolder,
				speakDownFolder, speakUpFolder, animationConfig, loadConfig);

			return outfit;
		}
Example #9
0
        public async Task <IOutfit> LoadOutfitFromFoldersAsync(string baseFolder, string walkLeftFolder = null, string walkRightFolder = null,
                                                               string walkDownFolder  = null, string walkUpFolder  = null, string idleLeftFolder  = null, string idleRightFolder  = null,
                                                               string idleDownFolder  = null, string idleUpFolder  = null, string speakLeftFolder = null, string speakRightFolder = null,
                                                               string speakDownFolder = null, string speakUpFolder = null,
                                                               IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            IOutfit outfit = _resolver.Resolve <IOutfit> ();

            outfit[AGSOutfit.Idle] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, idleLeftFolder, idleRightFolder,
                                                                                              idleDownFolder, idleUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Walk] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, walkLeftFolder, walkRightFolder,
                                                                                              walkDownFolder, walkUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Speak] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, speakLeftFolder, speakRightFolder,
                                                                                               speakDownFolder, speakUpFolder, animationConfig, loadConfig);

            return(outfit);
        }
Example #10
0
        public IDirectionalAnimation LoadDirectionalAnimationFromFolders(string baseFolder, string leftFolder = null,
                                                                         string rightFolder = null, string downFolder = null, string upFolder = null,
                                                                         IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            if (leftFolder == null && rightFolder == null && downFolder == null && upFolder == null)
            {
                return(null);
            }

            AGSDirectionalAnimation dirAnimation = new AGSDirectionalAnimation();

            if (leftFolder != null)
            {
                dirAnimation.Left = LoadAnimationFromFolder(baseFolder + leftFolder, animationConfig, loadConfig);
            }
            if (rightFolder != null)
            {
                dirAnimation.Right = LoadAnimationFromFolder(baseFolder + rightFolder, animationConfig, loadConfig);
            }
            if (downFolder != null)
            {
                dirAnimation.Down = LoadAnimationFromFolder(baseFolder + downFolder, animationConfig, loadConfig);
            }
            if (upFolder != null)
            {
                dirAnimation.Up = LoadAnimationFromFolder(baseFolder + upFolder, animationConfig, loadConfig);
            }

            if (dirAnimation.Left != null && dirAnimation.Right == null)
            {
                dirAnimation.Right = createLeftRightAnimation(dirAnimation.Left);
            }

            if (dirAnimation.Right != null && dirAnimation.Left == null)
            {
                dirAnimation.Left = createLeftRightAnimation(dirAnimation.Right);
            }

            return(dirAnimation);
        }
Example #11
0
		public async Task<IDirectionalAnimation> LoadDirectionalAnimationFromFoldersAsync(string baseFolder, string leftFolder = null,
			string rightFolder = null, string downFolder = null, string upFolder = null,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			if (leftFolder == null && rightFolder == null && downFolder == null && upFolder == null) return null;

			AGSDirectionalAnimation dirAnimation = new AGSDirectionalAnimation ();
			if (leftFolder != null) dirAnimation.Left = await LoadAnimationFromFolderAsync(baseFolder + leftFolder, animationConfig, loadConfig);
			if (rightFolder != null) dirAnimation.Right = await LoadAnimationFromFolderAsync(baseFolder + rightFolder, animationConfig, loadConfig);
			if (downFolder != null) dirAnimation.Down = await LoadAnimationFromFolderAsync(baseFolder + downFolder, animationConfig, loadConfig);
			if (upFolder != null) dirAnimation.Up = await LoadAnimationFromFolderAsync(baseFolder + upFolder, animationConfig, loadConfig);

			if (dirAnimation.Left != null && dirAnimation.Right == null) {
				dirAnimation.Right = createLeftRightAnimation (dirAnimation.Left);
			}

			if (dirAnimation.Right != null && dirAnimation.Left == null) {
				dirAnimation.Left = createLeftRightAnimation (dirAnimation.Right);
			}

			return dirAnimation;
		}
Example #12
0
		public IAnimation LoadAnimationFromSpriteSheet (ISpriteSheet spriteSheet, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return _spriteSheetLoader.LoadAnimationFromSpriteSheet (spriteSheet, animationConfig, loadConfig);
		}
Example #13
0
 public async Task <IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
                                                                  IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(await _spriteSheetLoader.LoadAnimationFromSpriteSheetAsync(spriteSheet, animationConfig, loadConfig));
 }
Example #14
0
 public IAnimation LoadAnimationFromSpriteSheet(ISpriteSheet spriteSheet,
                                                IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(_spriteSheetLoader.LoadAnimationFromSpriteSheet(spriteSheet, animationConfig, loadConfig));
 }
Example #15
0
		private void getSpriteSheetData (IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig,
		                                out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX,
		                                 out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep, 
		                                 out AGSAnimation animation)
		{
			cellsInRow = bitmap.Width / spriteSheet.CellWidth;
			cellsInCol = bitmap.Height / spriteSheet.CellHeight;
			cellsTotal = cellsInRow * cellsInCol;

			int startRow, startCol;
			getOrder (spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep);

			cellX = startCol;
			cellY = startRow;
			cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min (spriteSheet.CellsToGrab, cellsTotal);
			animation = new AGSAnimation (animationConfig, new AGSAnimationState (), cellsToGrab);
		}
Example #16
0
		public async Task<IAnimation> LoadAnimationFromSpriteSheetAsync (ISpriteSheet spriteSheet, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return await _spriteSheetLoader.LoadAnimationFromSpriteSheetAsync (spriteSheet, animationConfig, loadConfig);
		}
Example #17
0
		private async Task<IAnimation> loadAnimationFromResourcesAsync (List<IResource> resources,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			AGSAnimation animation = getAnimation (animationConfig, resources.Count);

			foreach (IResource resource in resources) 
			{
				var image = await loadImageAsync (resource, loadConfig);
				addAnimationFrame (image, animation);
			}
			animation.Setup ();
			return animation;
		}
Example #18
0
		public async Task<IAnimation> LoadAnimationFromFolderAsync (string folderPath,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return await loadAnimationFromResourcesAsync (await Task.Run(() => _resources.LoadResources (folderPath)), 
			                                   animationConfig, loadConfig);
		}
Example #19
0
		public IAnimation LoadAnimationFromFolder (string folderPath, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return loadAnimationFromResources(_resources.LoadResources(folderPath), animationConfig, loadConfig);
		}
Example #20
0
		public async Task<IAnimation> LoadAnimationFromFilesAsync(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string [] files)
		{
			return await loadAnimationFromResourcesAsync(await Task.Run(() => _resources.LoadResources (files)), 
			                                             animationConfig, loadConfig);
		}
Example #21
0
		public IAnimation LoadAnimationFromFiles(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string[] files)
		{
			return loadAnimationFromResources(_resources.LoadResources(files), animationConfig, loadConfig);
		}
Example #22
0
 public AGSAnimation(IAnimationConfiguration configuration, IAnimationState state, int estimatedNumberOfFrames = 8)
 {
     Configuration = configuration;
     State         = state;
     Frames        = new List <IAnimationFrame> (estimatedNumberOfFrames);
 }
Example #23
0
 public IAnimation LoadAnimationFromFolder(string folderPath,
                                           IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(loadAnimationFromResources(folderPath, _resources.LoadResources(folderPath), animationConfig, loadConfig));
 }
Example #24
0
 public async Task <IAnimation> LoadAnimationFromFolderAsync(string folderPath,
                                                             IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(await loadAnimationFromResourcesAsync(folderPath, await Task.Run(() => _resources.LoadResources(folderPath)),
                                                  animationConfig, loadConfig));
 }
Example #25
0
		public AGSAnimation (IAnimationConfiguration configuration, IAnimationState state, int estimatedNumberOfFrames = 8)
		{
			Configuration = configuration;
			State = state;
			Frames = new List<IAnimationFrame> (estimatedNumberOfFrames);
		}
Example #26
0
		private AGSAnimation getAnimation (IAnimationConfiguration animationConfig, int resourcesCount)
		{
			animationConfig = animationConfig ?? new AGSAnimationConfiguration ();
			AGSAnimationState state = new AGSAnimationState ();
			AGSAnimation animation = new AGSAnimation (animationConfig, state, resourcesCount);
			return animation;
		}