Exemplo n.º 1
0
        public PropTemplate MakePropTemplate(ComplexLS template_script)
        {
            var    sprtscript = template_script.Read <ComplexLS>("SPRITE");
            Sprite sprt;

            if (sprtscript != null)
            {
                sprt = LevelContext.Context.Content.MakeSprite(template_script.Read <ComplexLS>("SPRITE"));
            }
            else
            {
                sprt = LevelContext.Context.Content.MakeAnimation(template_script.Read <ComplexLS>("ANIMATION"));
            }
            var    name_s     = template_script.Read <TokenLS <string> >("NAME");
            string name       = name_s != null ? name_s.Value : "UNKNOWN";
            var    desc_s     = template_script.Read <TokenLS <string> >("DESC");
            string desc       = desc_s != null ? desc_s.Value : "";
            float  mass       = (float)template_script.Read <TokenLS <double> >("MASS");
            bool   canmove    = template_script.ReadAll <LScript>("CANMOVE").Any();
            bool   collides   = template_script.ReadAll <LScript>("COLLIDES").Any();
            float  friction   = 1.0f;
            var    s_friction = template_script.Read <TokenLS <double> >("FRICTION");

            if (s_friction != null)
            {
                friction = (float)s_friction.Value;
            }
            var width  = template_script.Read <TokenLS <Pixels> >("WIDTH");
            var height = template_script.Read <TokenLS <Pixels> >("HEIGHT");

            if (width != null && height != null)
            {
                return(new PropTemplate(sprt, name, desc, mass, friction, collides, canmove,
                                        width.Value / Sprite.TileSize, height.Value / Sprite.TileSize));
            }
            else
            {
                return(new PropTemplate(sprt, name, desc, mass, friction, collides, canmove));
            }
        }
Exemplo n.º 2
0
        public Sprite MakeAnimation(ComplexLS script)
        {
            string filename = script.Read <TokenLS <string> >("FILENAME");

            if (ActiveTextures.TryGetValue(filename, out Sprite texture))
            {
                return(texture);
            }
            var seqs = new List <AnimationSequence>();
            int handle, w, h;

            handle = Sprite.LoadHandle(filename, out w, out h);
            foreach (var scriptsequence in script.ReadAll <ComplexLS>("SEQUENCE"))
            {
                string name = scriptsequence.ReadToken <string>("NAME");
                var    dirs = AnimationDirections.None;
                foreach (var scriptdir in scriptsequence.Read <ComplexLS>("DIRECTIONS").SubRunes)
                {
                    if (Enum.TryParse <AnimationDirections>(scriptdir.Word, true, out var fnddir))
                    {
                        dirs |= fnddir;
                    }
                }
                var locs = new List <(int X, int Y)>();
                foreach (var scriptloc in scriptsequence.ReadAll <ComplexLS>("STEP"))
                {
                    locs.Add((scriptloc.ReadToken <Pixels>("X"), scriptloc.ReadToken <Pixels>("Y")));
                }
                var scriptoffset = scriptsequence.Read <ComplexLS>("OFFSET");
                var offset_x     = scriptoffset != null?scriptoffset.Read <TokenLS <Pixels> >("X") : null;

                var offset_y = scriptoffset != null?scriptoffset.Read <TokenLS <Pixels> >("Y") : null;

                seqs.Add(Sprite.MakeSteps(name,
                                          locs,
                                          (scriptsequence.ReadToken <Pixels>("WIDTH"), scriptsequence.ReadToken <Pixels>("HEIGHT")),
                                          (offset_x != null ?offset_x.Value : 0, offset_y != null ? offset_y.Value : 0),
                                          (w, h), dirs));
            }
            var animation = new Animation(seqs.ToArray(), handle);

            return(ActiveTextures[filename] = animation);
        }