public void Start(GameObject panel, GameObject rewardPanel, GameObject punishmentPanel, GameObject spammingText) { if (GlobalSettings.Gs == null) { GuiHandler.GoToMainMenu(); } else { switch (_myType) { case TaskType.Control: _taskSettings = GlobalSettings.Gs.ControlSettings; break; case TaskType.Reward: _taskSettings = GlobalSettings.Gs.RewardSettings; break; case TaskType.Punishment: _taskSettings = GlobalSettings.Gs.PunishmentSettings; break; default: throw new ArgumentOutOfRangeException(); } _spriteSettings = GlobalSettings.Gs.SpriteSettings; _threshold = GlobalSettings.Gs.Threshold; } SetPanels(panel, rewardPanel, punishmentPanel, spammingText); GetInformation(); InitValues(); }
public GlobalSettings() { const int numberOfTasks = 40; BaselineSettings = new BaselineSettings(4000, 20); ControlSettings = new TaskSettings(3000, TaskType.Control, numberOfTasks, 0.8f); RewardSettings = new TaskSettings(3000, TaskType.Reward, numberOfTasks, 0.8f); PunishmentSettings = new TaskSettings(3000, TaskType.Punishment, numberOfTasks, 0.8f); SpriteSettings = new SpriteSettings(); Threshold = 400; }
public void CreateSprite(MagickImageCollection spriteImages, ISpriteSettings spriteSettings) { using var result = spriteImages.AppendVertically(); spriteSettings.SaveSpriteAsync(result); }
public void SetSpriteSettings(ISpriteSettings newSettings) { SpriteSettings = newSettings; }
public void CreateCss(string css, ISpriteSettings spriteSettings) { spriteSettings.SaveCssAsync(css); }
/// <summary> /// Create a sprite image from a list of images and the CSS to render each image. /// </summary> /// <param name="images">The list of images to include in the sprite.</param> /// <param name="placeholderImages">The list of custom placeholder images.</param> /// <param name="spriteSettings">The settings to use when creating the sprite.</param> public void CreateSprite(IReadOnlyCollection <ISpriteImage> images, IReadOnlyCollection <ISpriteImage> placeholderImages, ISpriteSettings spriteSettings) { if (images == null) { throw new ArgumentNullException(nameof(images)); } if (images.GroupBy(x => x.Key).Any(x => x.Skip(1).Any())) { throw new ArgumentException("The list of keys must be unique.", nameof(images)); } if (placeholderImages == null || !placeholderImages.Any()) { placeholderImages = DefaultPlaceholderImages; } if (placeholderImages.GroupBy(x => x.Key).Any(x => x.Skip(1).Any())) { throw new ArgumentException("The list of keys must be unique.", nameof(placeholderImages)); } if (spriteSettings == null) { throw new ArgumentNullException(nameof(spriteSettings)); } var spritePlaceholderImages = new List <SpritePlaceholderImage>(); using var spriteImages = new MagickImageCollection(); var css = new StringBuilder(); var nextSpriteImageTop = 0; foreach (var image in images) { var hasImageBeenAddedToSprite = false; int selectedImageHeight; int selectedImageTop; int selectedImageWidth; var selectedHoverImageHeight = 0; var selectedHoverImageTop = 0; var selectedHoverImageWidth = 0; var imageForSprite = ImageToMagickImage(image); if (imageForSprite != null) { spriteImages.Add(imageForSprite); hasImageBeenAddedToSprite = true; selectedImageTop = nextSpriteImageTop; selectedImageHeight = imageForSprite.Height; selectedImageWidth = imageForSprite.Width; } else { var selectedPlaceholderImageKey = placeholderImages.Any(x => x.Key == image.PlaceholderImageKey) ? image.PlaceholderImageKey : placeholderImages.First().Key; var selectedPlaceholderImage = placeholderImages.FirstOrDefault(x => x.Key == selectedPlaceholderImageKey); imageForSprite = ImageToMagickImage(selectedPlaceholderImage); var spritePlaceholderImage = spritePlaceholderImages.FirstOrDefault(x => x.Key == selectedPlaceholderImageKey && x.Width == imageForSprite.Width && x.Height == imageForSprite.Height); if (spritePlaceholderImage == null) { spritePlaceholderImage = new SpritePlaceholderImage(selectedPlaceholderImageKey, nextSpriteImageTop, imageForSprite.Height, imageForSprite.Width); spritePlaceholderImages.Add(spritePlaceholderImage); spriteImages.Add(imageForSprite); hasImageBeenAddedToSprite = true; } selectedImageTop = spritePlaceholderImage.Top; selectedImageHeight = spritePlaceholderImage.Height; selectedImageWidth = spritePlaceholderImage.Width; } var selectedImageTopText = selectedImageTop != 0 ? $"-{selectedImageTop}px" : "0"; css.Append($"#{image.Key}{{height:{selectedImageHeight}px;width:{selectedImageWidth}px;background:url('{spriteSettings.SpriteUrl}') 0 {selectedImageTopText};}}"); if (hasImageBeenAddedToSprite) { nextSpriteImageTop += selectedImageHeight; } if (image.HoverImage != null) { var hoverImageForSprite = ImageToMagickImage(image.HoverImage, imageForSprite); if (hoverImageForSprite != null) { spriteImages.Add(hoverImageForSprite); hasImageBeenAddedToSprite = true; selectedHoverImageTop = nextSpriteImageTop; selectedHoverImageHeight = hoverImageForSprite.Height; selectedHoverImageWidth = hoverImageForSprite.Width; } var selectedHoverImageTopText = selectedHoverImageTop != 0 ? $"-{selectedHoverImageTop}px" : "0"; css.Append($"#{image.Key}:hover{{height:{selectedHoverImageHeight}px;width:{selectedHoverImageWidth}px;background:url('{spriteSettings.SpriteUrl}') 0 {selectedHoverImageTopText};}}"); if (hasImageBeenAddedToSprite) { nextSpriteImageTop += selectedHoverImageHeight; } } } _imageProcessor.CreateSprite(spriteImages, spriteSettings); _cssProcessor.CreateCss(css.ToString(), spriteSettings); }
/// <summary> /// Create a sprite image from a list of images and the CSS to render each image. /// </summary> /// <param name="images">The list of images to include in the sprite.</param> /// <param name="spriteSettings">The settings to use when creating the sprite.</param> public void CreateSprite(IReadOnlyCollection <ISpriteImage> images, ISpriteSettings spriteSettings) { CreateSprite(images, DefaultPlaceholderImages, spriteSettings); }