public static void Load(string path, AssetStore <string> assets) { foreach (PropertyBag artProp in PropertyBag.FromFile(path)) { string sheetName = artProp.GetOrDefault("sheet", string.Empty); Spritesheet sheet = assets.GetAsset <Spritesheet>(sheetName); string name = artProp.Name; int x = artProp.GetOrDefault("x", 0); int y = artProp.GetOrDefault("y", 0); int width = artProp.GetOrDefault("width", -1); int height = artProp.GetOrDefault("height", -1); bool exact = artProp.GetOrDefault("exact", false); Vector2?origin = DataLoader.ParseVector(artProp.GetOrDefault("origin", null)); Sprite sprite; if (!exact) { sprite = sheet.CutSprite(x, y, width, height, name, origin); } else { sprite = sheet.CutSpriteExact(x, y, width, height, name, origin); } assets.AddAsset(name, sprite); Console.WriteLine($"Loaded Sprite: {name}"); } }
public void SerializeAndDeserialize_WhenInputMappingIsNotNull() { // Arrange var inputMapping = new InputMapping(); var inputMappingAssetId = AssetId.CreateUnique(); var component = new InputComponent { InputMapping = inputMapping }; AssetStore.GetAssetId(inputMapping).Returns(inputMappingAssetId); AssetStore.GetAsset <InputMapping>(inputMappingAssetId).Returns(inputMapping); // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.InputMapping, Is.EqualTo(inputMapping)); Assert.That(actual.HardwareInput, Is.EqualTo(HardwareInput.Empty)); Assert.That(actual.ActionBindings, Is.Empty); Assert.That(actual.AxisBindings, Is.Empty); Assert.That(actual.ActionStates, Is.Empty); Assert.That(actual.AxisStates, Is.Empty); }
public void SerializeAndDeserialize_WhenSpriteIsNotNull() { // Arrange var texture = Substitute.For <ITexture>(); var sprite = new Sprite(texture, Vector2.Zero, Vector2.Zero, Vector2.Zero, 0); var spriteAssetId = AssetId.CreateUnique(); var component = new SpriteRendererComponent { Visible = false, SortingLayerName = "Some sorting layer", OrderInLayer = 2, Sprite = sprite }; AssetStore.GetAssetId(sprite).Returns(spriteAssetId); AssetStore.GetAsset <Sprite>(spriteAssetId).Returns(sprite); // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.Visible, Is.EqualTo(component.Visible)); Assert.That(actual.SortingLayerName, Is.EqualTo(component.SortingLayerName)); Assert.That(actual.OrderInLayer, Is.EqualTo(component.OrderInLayer)); Assert.That(actual.Sprite, Is.EqualTo(sprite)); }
public void SerializeAndDeserialize_WhenCurrentAnimationIsNull() { // Arrange var animation = CreateAnimation(); var animationAssetId = AssetId.CreateUnique(); var component = new SpriteAnimationComponent(); component.AddAnimation("animation", animation); component.Position = 0.7; component.PlaybackSpeed = 1.3; component.PlayInLoop = true; AssetStore.GetAssetId(animation).Returns(animationAssetId); AssetStore.GetAsset <SpriteAnimation>(animationAssetId).Returns(animation); // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.Animations, Has.Count.EqualTo(1)); Assert.That(actual.Animations.Single().Key, Is.EqualTo("animation")); Assert.That(actual.Animations.Single().Value, Is.EqualTo(animation)); Assert.That(actual.CurrentAnimation, Is.Null); Assert.That(actual.IsPlaying, Is.False); Assert.That(actual.Position, Is.EqualTo(component.Position)); Assert.That(actual.PlaybackSpeed, Is.EqualTo(component.PlaybackSpeed)); Assert.That(actual.PlayInLoop, Is.EqualTo(component.PlayInLoop)); }
public static void Load(string path, AssetStore <string> assets) { foreach (PropertyBag animProp in PropertyBag.FromFile(path)) { string name = animProp.Name; Spritesheet sheet = assets.GetAsset <Spritesheet>(animProp.GetOrDefault("sheet", string.Empty)); float frameDuration = animProp.GetOrDefault("frameDuration", 0.5f); string[] frames = animProp.GetOrDefault("frames", string.Empty).Split(','); AnimationFrame[] animationFrames = new AnimationFrame[frames.Length]; for (int i = 0; i < frames.Length; i++) { Sprite sprite = assets.GetAsset <Sprite>(frames[i].Trim()); animationFrames[i] = new AnimationFrame(sprite); } Animation animation = new Animation(frameDuration, animationFrames); assets.AddAsset(name, animation); } }
public static void Load(string path, AssetStore <string> assets) { foreach (PropertyBag raceProp in PropertyBag.FromFile(path)) { string name = raceProp.Name; int speed = raceProp.GetOrDefault("speed", Energy.NormalSpeed); int health = raceProp.GetOrDefault("health", 1); Animation animation = assets.GetAsset <Animation>(raceProp["animation"].Value); Color color = ColorParser.ParseColor(raceProp["color"].Value); Race race = new Race(name, animation, color, speed, health); assets.AddAsset(name, race); } }
public void SerializeAndDeserialize_WhenSoundIsNotNull() { // Arrange var sound = Substitute.For <ISound>(); var soundAssetId = AssetId.CreateUnique(); var component = new AudioSourceComponent { Sound = sound, IsPlaying = true }; AssetStore.GetAssetId(sound).Returns(soundAssetId); AssetStore.GetAsset <ISound>(soundAssetId).Returns(sound); // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.Sound, Is.EqualTo(sound)); Assert.That(actual.IsPlaying, Is.True); }
public static void Load(string path, AssetStore <string> assets) { foreach (PropertyBag tileProp in PropertyBag.FromFile(path)) { string name = tileProp.Name; bool isSolid = tileProp.GetOrDefault("solid", false); bool isTransparent = tileProp.GetOrDefault("transparent", true); byte id = _nextId++; string animation = tileProp.GetOrDefault("animation", null); Sprite sprite = null; if (string.IsNullOrWhiteSpace(animation)) { string spriteName = tileProp.GetOrDefault("sprite", name); sprite = assets.GetAsset <Sprite>(spriteName); } Color color = ColorParser.ParseColor(tileProp["color"].Value.ToLower().Trim()); Tile tile = new Tile(id, sprite, color, isSolid, isTransparent, animation); assets.AddAsset(name, tile); } }