Пример #1
0
 public Animation(World world, string name, Func <WAngle> facingFunc, Func <bool> paused)
 {
     sequenceProvider = world.Map.Rules.Sequences;
     Name             = name.ToLowerInvariant();
     this.facingFunc  = facingFunc;
     this.paused      = paused;
 }
Пример #2
0
 public Animation(World world, string name, Func<int> facingFunc, Func<bool> paused)
 {
     sequenceProvider = world.Map.Rules.Sequences;
     Name = name.ToLowerInvariant();
     this.facingFunc = facingFunc;
     this.paused = paused;
 }
Пример #3
0
 public Animation(SequenceProvider sequenceProvider, string name, Func <int> facingFunc)
 {
     this.sequenceProvider = sequenceProvider;
     this.name             = name.ToLowerInvariant();
     this.tickFunc         = () => {};
     this.facingFunc       = facingFunc;
 }
Пример #4
0
 public Animation(SequenceProvider sequenceProvider, string name, Func<int> facingFunc)
 {
     this.sequenceProvider = sequenceProvider;
     this.name = name.ToLowerInvariant();
     this.tickFunc = () => {};
     this.facingFunc = facingFunc;
 }
Пример #5
0
 public void PlayFetchIndex(string sequenceName, Func <int> func)
 {
     backwards       = false;
     tickAlways      = true;
     CurrentSequence = SequenceProvider.GetSequence(name, sequenceName);
     frame           = func();
     tickFunc        = () => frame = func();
 }
Пример #6
0
        public bool ReplaceAnim(string sequenceName)
        {
            if (!HasSequence(sequenceName))
            {
                return(false);
            }

            CurrentSequence = SequenceProvider.GetSequence(name, sequenceName);
            frame          %= CurrentSequence.Length;
            return(true);
        }
Пример #7
0
		public string GetImage(ActorInfo actor, SequenceProvider sequenceProvider, string faction)
		{
			if (FactionImages != null && !string.IsNullOrEmpty(faction))
			{
				string factionImage = null;
				if (FactionImages.TryGetValue(faction, out factionImage) && sequenceProvider.HasSequence(factionImage))
					return factionImage;
			}

			return (Image ?? actor.Name).ToLowerInvariant();
		}
Пример #8
0
 public void PlayRepeating(string sequenceName)
 {
     backwards       = false;
     tickAlways      = false;
     CurrentSequence = SequenceProvider.GetSequence(name, sequenceName);
     frame           = 0;
     tickFunc        = () =>
     {
         ++frame;
         if (frame >= CurrentSequence.Length)
         {
             frame = 0;
         }
     };
 }
Пример #9
0
        public static ActorTemplate RenderActor(ActorInfo info, SequenceProvider sequenceProvider, TileSet tileset, IPalette p, string race)
        {
            var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info, sequenceProvider, race);
            image = ResolveFilename(image, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                var shp = new ShpTDSprite(s);
                var bitmap = RenderShp(shp, p);

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
Пример #10
0
 public void PlayThen(string sequenceName, Action after)
 {
     backwards       = false;
     tickAlways      = false;
     CurrentSequence = SequenceProvider.GetSequence(name, sequenceName);
     frame           = 0;
     tickFunc        = () =>
     {
         ++frame;
         if (frame >= CurrentSequence.Length)
         {
             frame    = CurrentSequence.Length - 1;
             tickFunc = () => { };
             if (after != null)
             {
                 after();
             }
         }
     };
 }
Пример #11
0
        public string GetImage(ActorInfo actor, SequenceProvider sequenceProvider, string race)
        {
            if (RaceImages != null)
            {
                string raceImage = null;
                if (RaceImages.TryGetValue(race, out raceImage) && sequenceProvider.HasSequence(raceImage))
                    return raceImage;
            }

            return (Image ?? actor.Name).ToLowerInvariant();
        }
Пример #12
0
 public string EditorImage(ActorInfo actor, SequenceProvider sequenceProvider, string race)
 {
     return GetImage(actor, sequenceProvider, race);
 }
Пример #13
0
 public Sequence GetSequence(string sequenceName)
 {
     return(SequenceProvider.GetSequence(name, sequenceName));
 }
Пример #14
0
 public bool HasSequence(string seq)
 {
     return(SequenceProvider.HasSequence(name, seq));
 }
Пример #15
0
        public static Sprite GetImage(string collectionName, string imageName)
        {
            if (imageName == "harktitle")
            {
            }
            if (string.IsNullOrEmpty(collectionName))
            {
                return(null);
            }

            // Cached sprite
            Dictionary <string, Sprite> cachedCollection;
            Sprite sprite;

            if (collectionName == "dropdown")
            {
            }
            if (cachedSprites.TryGetValue(collectionName, out cachedCollection) && cachedCollection.TryGetValue(imageName, out sprite))
            {
                return(sprite);                //нашли в кешах, возвращаем Sprite
            }
            Collection collection;

            if (!collections.TryGetValue(collectionName, out collection))
            {
                Log.Write("debug", "Could not find collection '{0}'", collectionName);
                return(null);
            }

            MappedImage mi;

            if (!collection.Regions.TryGetValue(imageName, out mi))
            {
                return(null);
            }
            if (World == null)
            {
            }
            else
            {
                seqprov = World.Map.Rules.Sequences;
            }
            // по идее, можно написать в chrome.yaml разные ресурсы игры cps и т.п. , они будут загружаться , только при обращении в этот метод.
            // при обращении за cps , переменная wolrd уже будет заполнена.
            bool switch2Seq = false;

            if (seqprov != null)
            {
                if (seqprov.HasSequence(mi.Src))
                {
                    switch2Seq = true;
                }
            }
            Sprite     image = null, image2 = null;
            SheetCache sheet2d;

            if (switch2Seq)
            {
                if (cachedSheets2d.ContainsKey(mi.Src))                 //mi.Src это имя png файла.
                {
                    sheet2d = cachedSheets2d[mi.Src];
                }
                else
                {
                    sheet2d       = new SheetCache();
                    sheet2d.sheet = seqprov.GetSequence(mi.Src, "idle").GetSprite(0).Sheet2D;
                    cachedSheets2d.Add(mi.Src, sheet2d);
                }
                image2 = seqprov.GetSequence(mi.Src, "idle").GetSprite(0);
                int2 offset = new int2(image2.Bounds.Location.X, image2.Bounds.Location.Y);                                                                      //основная часть текстуры
                image = new Sprite(sheet2d.sheet, new Rectangle(mi.rect.X + offset.X, mi.rect.Y + offset.Y, mi.rect.Width, mi.rect.Height), TextureChannel.Red); //смещение в основной части текстуры

                if (mi.Rotate > 0)
                {
                    // передаем данные о повороте, если больше 0
                    image.Rotate = mi.Rotate;
                }
                if (mi.Stretched)
                {
                    image.Stretched = true;
                }
                image.SpriteType = 3;                 // для Utils.FastCreateQuad для алгоритма Fill rect with

                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }
                cachedCollection.Add(imageName, image);
                return(image);
            }

            if (!switch2Seq)
            {
                // Cached sheet
                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }


                if (cachedSheets2d.ContainsKey(mi.Src))                 //mi.Src это имя png файла. Каждый png будет в своем индексе у 2д текстуры
                {
                    sheet2d = cachedSheets2d[mi.Src];
                }
                else
                {
                    using (var stream = fileSystem.Open(mi.Src))
                    {
                        //currentPngSprite = seqprov.SpriteCache.SheetBuilder2D.Add(new Png(stream));
                        currentPngSprite = Game.SheetBuilder2D.Add(new Png(stream));
                        //sheet2d = new Sheet2D(SheetType.BGRA, stream);
                    }

                    sheet2d         = new SheetCache();
                    sheet2d.sheet   = Game.SheetBuilder2D.Current;
                    sheet2d.OffsetX = currentPngSprite.Bounds.Location.X;                     //так как теперь png внутри большой текстуры, то теперь нужно запоминать ее смещение и прибавлять к коориданатам в chrome.yaml
                    sheet2d.OffsetY = currentPngSprite.Bounds.Location.Y;
                    cachedSheets2d.Add(mi.Src, sheet2d);
                }
                //collection.OffsetLeft = sheet2d.OffsetX;
                //collection.OffsetTop = sheet2d.OffsetY;
                // Cache the sprite

                mi.OffsetTop  = sheet2d.OffsetY;
                mi.OffsetLeft = sheet2d.OffsetX;
                image         = mi.GetImage(sheet2d.sheet);
                cachedCollection.Add(imageName, image);
            }
            return(image);
        }
Пример #16
0
        public static Sprite GetImageOld(string collectionName, string imageName)
        {
            if (imageName == "harktitle")
            {
            }
            if (string.IsNullOrEmpty(collectionName))
            {
                return(null);
            }

            // Cached sprite
            Dictionary <string, Sprite> cachedCollection;
            Sprite sprite;

            if (cachedSprites.TryGetValue(collectionName, out cachedCollection) && cachedCollection.TryGetValue(imageName, out sprite))
            {
                return(sprite);
            }

            Collection collection;

            if (!collections.TryGetValue(collectionName, out collection))
            {
                Log.Write("debug", "Could not find collection '{0}'", collectionName);
                return(null);
            }

            MappedImage mi;

            if (!collection.Regions.TryGetValue(imageName, out mi))
            {
                return(null);
            }

            SequenceProvider seqprov;

            seqprov = World.Map.Rules.Sequences;
            // по идее, можно написать в chrome.yaml разные ресурсы игры cps и т.п. , они будут загружаться , только при обращении в этот метод.
            // при обращении за cps , переменная wolrd уже будет заполнена.
            bool switch2Seq = false;

            if (seqprov != null)
            {
                if (seqprov.HasSequence(mi.Src))
                {
                    switch2Seq = true;
                }
            }
            Sprite image = null, image2 = null;
            Sheet  sheet;

            if (switch2Seq)
            {
                if (cachedSheets.ContainsKey(mi.Src))                 //mi.Src это имя png файла.
                {
                    sheet = cachedSheets[mi.Src];
                }
                else
                {
                    sheet = seqprov.GetSequence(mi.Src, "idle").GetSprite(0).Sheet;
                    cachedSheets.Add(mi.Src, sheet);
                }
                image2 = seqprov.GetSequence(mi.Src, "idle").GetSprite(0);
                int2 offset = new int2(image2.Bounds.Location.X, image2.Bounds.Location.Y);                                                              //основная часть текстуры
                image = new Sprite(sheet, new Rectangle(mi.rect.X + offset.X, mi.rect.Y + offset.Y, mi.rect.Width, mi.rect.Height), TextureChannel.Red); //смещение в основной части текстуры

                if (mi.Rotate > 0)
                {
                    // передаем данные о повороте, если больше 0
                    image.Rotate = mi.Rotate;
                }
                if (mi.Stretched)
                {
                    image.Stretched = true;
                }
                image.SpriteType = 3;                 // для Utils.FastCreateQuad для алгоритма Fill rect with

                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }
                cachedCollection.Add(imageName, image);
                return(image);
            }

            if (!switch2Seq)
            {
                // Cached sheet
                if (cachedSheets.ContainsKey(mi.Src))                 //mi.Src это имя png файла. То есть Sheet создается под каждый файл png.
                {
                    sheet = cachedSheets[mi.Src];
                }
                else
                {
                    using (var stream = fileSystem.Open(mi.Src))
                        sheet = new Sheet(SheetType.BGRA, stream);

                    cachedSheets.Add(mi.Src, sheet);
                }

                // Cache the sprite
                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }

                image = mi.GetImage(sheet);
                cachedCollection.Add(imageName, image);
            }
            return(image);
        }