Esempio n. 1
0
        public void ExecuteScript(Script _script, bool _includeentities, params Variable[] _vars)
        {
            Bunch <Variable> vars = new Bunch <Variable>(this._WrappedThis, Misc.Mekanik);

            vars.Add(_vars);

            if (_includeentities)
            {
                foreach (Entity e in this.Parent.RealEntities.Where(item => item.Identifier != null))
                {
                    vars.Add(new Variable(new string(e.Identifier.Select(item => (item == ' ') ? '_' : item).ToArray()), e._WrappedThis.Value));
                }
            }

            Program p = new Program(_script)
            {
                OnCrash = cr =>
                {
                    if (cr.Error.ErrorCode != Error.Execution.AbortedByUser.ErrorCode)
                    {
                        throw cr.Error;
                    }
                }
            };

            p.Start(new Permissions(Permission.DllUsage), vars);
            this._Programs.Add(p);
        }
Esempio n. 2
0
        public ImageSource GetColset()
        {
            int         pixelcount = Meth.Up(this.Parent.TileCollisionResolution.X * this.Parent.TileCollisionResolution.Y / 4.0);
            ImageSource @out       = new ImageSource(this.TileCount.X * pixelcount, this.TileCount.Y);

            for (int x = 0; x < this.TileCount.X; x++)
            {
                for (int y = 0; y < this.TileCount.Y; y++)
                {
                    Bunch <byte> bs = new Bunch <byte>();
                    for (int ty = 0; ty < this.Parent.TileCollisionResolution.Y; ty++)
                    {
                        for (int tx = 0; tx < this.Parent.TileCollisionResolution.X; tx++)
                        {
                            bs.Add(this.Colset[x, y][tx, ty]);
                        }
                    }
                    Bunch <Color> ps = new Bunch <Color>();
                    while (bs.Count > 0)
                    {
                        while (bs.Count < 4)
                        {
                            bs.Add(0);
                        }
                        ps.Add(new Color(bs.SubBunch(0, 4)));
                        bs = bs.SubBunch(4);
                    }
                    for (int i = 0; i < pixelcount; i++)
                    {
                        @out[x * pixelcount + i, y] = ps[i];
                    }
                }
            }
            return(@out);
        }
Esempio n. 3
0
        public static Bunch <Point> Trace(Point _start, Point _end)
        {
            Bunch <Point> @out = new Bunch <Point>();

            Point dif = _end - _start;

            if (dif.X != 0 || dif.Y != 0)
            {
                if (Meth.Abs(dif.X) > Meth.Abs(dif.Y))
                {
                    for (int x = 0; x <= Meth.Abs(dif.X); x++)
                    {
                        int nx = _start.X + x * Meth.Sign(dif.X);
                        int ny = Meth.Round(_start.Y + dif.Y * (x * Math.Sign(dif.X) / (float)dif.X));
                        @out.Add(new Point(nx, ny));
                    }
                }
                else
                {
                    for (int y = 0; y <= Meth.Abs(dif.Y); y++)
                    {
                        int nx = Meth.Round(_start.X + dif.X * (y * Meth.Sign(dif.Y) / (float)dif.Y));
                        int ny = _start.Y + y * Meth.Sign(dif.Y);
                        @out.Add(new Point(nx, ny));
                    }
                }
            }
            else
            {
                @out.Add(_start);
            }

            return(@out);
        }
Esempio n. 4
0
        public void Select(EntityIcon _entity)
        {
            if (this.Icon != _entity)
            {
                if (this.Icon != null)
                {
                    this.UpdateValues();
                    this.Icon.Selected = false;
                }

                this.Icon = _entity;
                if (this.Icon != null)
                {
                    this.Icon.Selected = true;
                }

                foreach (Entity c in this.Children)
                {
                    c.Kill();
                }
                //this.Properties = new Dictionary<string, Func<string>>();

                Bunch <Alignable> als = new Bunch <Alignable>();

                if (_entity != null)
                {
                    als.Add(new Alignment(new Label("X:"), this.XBox = new NumBox(Meth.Down(_entity.X))));
                    als.Add(new Alignment(new Label("Y:"), this.YBox = new NumBox(Meth.Down(_entity.Y))));
                    als.Add(new Alignment(new Label("Z:"), this.ZBox = new NumBox(Meth.Down(_entity.EntityZ))
                    {
                        MinValue = -9999
                    }));
                }

                if (_entity == null)
                {
                    this.PropertyEditor = new PropertyEditor(new Dictionary <string, Type>());
                }
                else if (_entity.Type.Name != "Decoration")
                {
                    als.Add(this.PropertyEditor = new PropertyEditor(this.Icon.Properties.ToDictionary(item => item.Name, item => item.Type), this.Icon.Properties.ToDictionary(item => item.Name, item => (object)item.Value)));
                }

                this.Children.Add(new Alignment(als)
                {
                    Vertical = true
                });

                if (_entity != null)
                {
                    Button b = new Button("Delete", () => this.Icon.RemoveFromLevel());
                    b.Position = new Vector(((TabList)this.Parents[2]).InnerSize.X - b.RectSize.X, 0);
                    this.Children.Add(b);
                }
            }
        }
Esempio n. 5
0
            public Rack(bool _fixedres)
            {
                double[] ls = new double[] { 15, 15, 30 };
                double[] ds = new double[] { 0.2, 0.1 };

                VertexArray lines = new VertexArray(VertexArrayType.LinesStrip)
                {
                    Color = Color.White * 0.25, /*Position = _fixedres ? 0.5 : 0, */ LockToGrid = _fixedres
                };

                lines.Add(new Vector(0, ls[2] * 7), new Vector(0, 0), new Vector(0, 0));

                for (int i = 0; i < 7; i++)
                {
                    Bunch <Vector> vs = new Bunch <Vector>();

                    vs.Add(new Vector(0, i * ls[2]));
                    //lines0.Add(new Vector(0, i * ls[2]), new Vector(0, (i + 1) * ls[2]));

                    Action <Vector> add = v =>
                    {
                        vs.Add(v);
                        lines.Add(v);
                    };

                    add(new Vector(ls[0], i * ls[2]));

                    //vs.Add(new Vector(ls[0] + ls[1], (i + 0.5) * ls[2]));
                    for (int n = 0; n <= 3; n++)
                    {
                        add(new Vector(ls[0] + Meth.Smooth(n / 3.0) * ls[1], i * ls[2] + ls[2] * ds[0] + ls[2] * ds[1] * (n / 3.0)));
                    }
                    for (int n = 0; n <= 3; n++)
                    {
                        add(new Vector(ls[0] + Meth.Smooth((3 - n) / 3.0) * ls[1], i * ls[2] + ls[2] * (1 - ds[0] - ds[1]) + ls[2] * ds[1] * (n / 3.0)));
                    }

                    add(new Vector(ls[0], (i + 1) * ls[2]));

                    vs.Add(new Vector(0, (i + 1) * ls[2]));

                    this.Graphics.Add(new VertexArray(VertexArrayType.TrianglesFan)
                    {
                        Vertices = new Vertex(new Vector(0, (i + 0.5) * ls[2]), Color.White) + vs.Select(item => (Vertex)item), Color = Color.White, LockToGrid = _fixedres
                    });
                }

                lines.Add(new Vector(0, ls[2] * 7));

                this.Graphics.Add(lines);
            }
Esempio n. 6
0
        private void _UpdateGraphics()
        {
            this.Graphics.Clear();
            this.Graphics.Add(this.CollapseArrow);

            double d = Border / 2;

            Bunch <Vector> vs = new Bunch <Vector>();

            vs.Add(0);
            vs.Add(new Vector(0, d + this.InnerSize.Y));
            vs.Add(new Vector(d, d + this.InnerSize.Y + d));
            vs.Add(new Vector(d + this.InnerSize.X, d + this.InnerSize.Y + d));
            vs.Add(new Vector(d + this.InnerSize.X + d, d + this.InnerSize.Y));
            vs.Add(new Vector(d + this.InnerSize.X + d, d));
            vs.Add(new Vector(d + this.InnerSize.X, 0));
            vs.Add(0);

            if (this.AlignRight)
            {
                vs = vs.Select(item => new Vector(this.OuterSize.X - item.X, item.Y));
            }

            this.Graphics.Add(this.Inline = new VertexArray(VertexArrayType.Polygon)
            {
                Color = Color.White, Vertices = vs.Select(item => new Vertex(item, Color.White)), Position = new Vector(0, this.TabOffset), Z = 1
            });
            this.Graphics.Add(this.Outline = new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.Black, Vertices = vs.Select(item => new Vertex(item, Color.White)), Position = new Vector(0, this.TabOffset), Z = 1
            });
        }
Esempio n. 7
0
        //public int IndexOf(T _item)
        //{
        //	for (int i = 0; i < this.Count; i++)
        //	{
        //		if (this[i].Equals(_item))
        //			return i;
        //	}
        //	return -1;
        //}

        public Bunch <T> Merge(Bunch <T> _bunch)
        {
            Bunch <T> @out = this.Clone();

            @out.Add(_bunch.Where(item => [email protected](item)));
            return(@out);
        }
Esempio n. 8
0
        //public TOut Sum<TOut>(Func<T, TOut> _func)
        //{
        //	MethodInfo plus = _func.GetType().GetMethod("op_Addition");
        //	if (plus == null)
        //		throw new Exception("The type has to have a + method!");

        //	TOut sum = default(TOut);
        //	foreach (T t in this)
        //		sum = (TOut)plus.Invoke(sum, new object[] { sum, _func(t) });

        //	return sum;
        //}

        //public static bool operator ==(Bunch<T> _one, string _two)
        //{
        //	if (typeof(T) != typeof(string))
        //		return false;

        //	string[] parts = _two.Split(',');
        //	for (int i = 1; i < parts.Length; i++)
        //	{
        //		if (parts[i][0] == ' ')
        //			parts[i] = parts[i].Substring(1);
        //	}

        //	if (_one.Count != parts.Length)
        //		return false;

        //	for (int i = 0; i < parts.Length; i++)
        //	{
        //		object o = _one[i];
        //		if (parts[i] != (string)o)
        //			return false;
        //	}

        //	return true;
        //}
        //public static bool operator !=(Bunch<T> _one, string _two) { return !(_one == _two); }

        public static Bunch <T> operator +(Bunch <T> _one, T _two)
        {
            Bunch <T> @out = _one.Clone();

            @out.Add(_two);
            return(@out);
        }
Esempio n. 9
0
            public void Tick()
            {
                Bunch <Tuple <Action, int> > adds = new Bunch <Tuple <Action, int> >();
                Dictionary <int, Bunch <Tuple <Action, int> > > ncodes = new Dictionary <int, Bunch <Tuple <Action, int> > >();

                foreach (KeyValuePair <int, Bunch <Tuple <Action, int> > > b in this._Codes)
                {
                    if (b.Key == 1)
                    {
                        foreach (Tuple <Action, int> d in b.Value)
                        {
                            d.Item1();
                            if (d.Item2 > 0)
                            {
                                adds.Add(d);
                            }
                        }
                    }
                    else
                    {
                        ncodes[b.Key - 1] = b.Value;
                    }
                }
                this._Codes = ncodes;

                foreach (Tuple <Action, int> add in adds)
                {
                    Add(add.Item2, add.Item1, add.Item2);
                }
            }
Esempio n. 10
0
        public static Bunch <File> GetAllFiles(string _path, string _relativeto = null)
        {
            Bunch <File> @out = new Bunch <File>();

            System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(_path);
            foreach (System.IO.FileInfo f in d.GetFiles())
            {
                @out.Add(new File(f.FullName, _relativeto));
            }
            foreach (System.IO.DirectoryInfo dd in d.GetDirectories())
            {
                @out.Add(GetAllFiles(dd.FullName, _relativeto));
            }

            return(@out);
        }
Esempio n. 11
0
        public override void OnInitialization()
        {
            Renderer        c  = new Renderer(this.Parent.TileSize * this.Size * 2);
            Bunch <Graphic> gs = new Bunch <Graphic>();

            for (int i = 0; i < this.Areaset.Tiles.Count; i++)
            {
                gs.Add(new Image(this.Areaset.Tiles[i])
                {
                    Position = this.Parent.TileSize * new Vector(i % this.Size.X, Meth.Down(i / (double)this.Size.X)) * 2, Scale = 2
                });
            }
            c.Draw(gs);
            this.Graphics.Add(new Image(c.ImageSource));

            this.AddMouseArea(new MouseArea(new Rectangle(0, this.Size * this.Parent.TileSize * 2))
            {
                OnClick = key =>
                {
                    Point p = this.LocalMousePosition / this.Parent.TileSize / 2;
                    int i   = p.X + p.Y * this.Size.X;
                    if (i < this.Areaset.Tiles.Count)
                    {
                        this.TileEditor.CurTile = new Tuple <string, int>(this.Areaset.Name, i);
                    }
                }
            });
        }
Esempio n. 12
0
        internal Bunch <Graphic> _GetGraphics()
        {
            if (!this.Visible)
            {
                return(new Bunch <Graphic>());
            }
            else
            {
                this._UpdateRealPosition();
                this._UpdateScale();

                foreach (Graphic g in this.Graphics)
                {
                    g._Set(this);
                }

                Bunch <Graphic> @out = this.Graphics.Where(item => item.Visible);
                Bunch <Graphic> ns   = new Bunch <Graphic>();

                foreach (Entity c in this.Children)
                {
                    @out.Add(c._GetGraphics());
                }

                foreach (Graphic g in @out)
                {
                    this._UpdateGraphic(g);
                }

                return(@out);
            }
        }
Esempio n. 13
0
        public override void OnInitialization()
        {
            this.Children.Add(this.Zooms = new Alignment(new Button("-", () => this.SetZoom(this.Zoom - 1)), new Button("+", () => this.SetZoom(this.Zoom + 1)))
            {
                Vertical = true
            });

            Bunch <Alignable> als = new Bunch <Alignable>();

            als.Add(new Alignment(new Label("Sprites:"), this.BoxSprites = new NumBox(4)
            {
                MinValue = 1, Digits = 2, MaxValue = 99
            }));
            als.Add(new Alignment(new Label("Speed:"), this.BoxSpeed = new NumBox(10)
            {
                MinValue = 1, Digits = 3, MaxValue = 999
            }));
            als.Add(new Alignment(this.BoxRepeated = new Checkbox(true)
            {
                Content = "Repeated"
            }, new Button("►", () => this.Animation.ForcePlay("Start"))));
            als.Add(new Alignment
                    (
                        new Button("Add", () => { }),
                        new Button("Export", () =>
            {
                this.Parent.ReleaseKey(Key.MouseLeft);
                File f = this.Parent.SaveFile(this.GetAnimationFile().ToBytesEncrypted(), "meka");
                if (f != null)
                {
                    ((AnimationEditor)this.Parents[0]).AnimationShown = false;
                }
            }),
                        new Button("Cancel", () => ((AnimationEditor)this.Parents[0]).AnimationShown = false)
                    )
            {
                Spacing = 3
            });
            this.Children.Add(this.Bottom = new Alignment(als)
            {
                Vertical = true
            });
        }
Esempio n. 14
0
        public static Bunch <T> ToBunch <T>(this IEnumerable <T> @this)
        {
            Bunch <T> @out = new Bunch <T>();

            foreach (T t in @this)
            {
                @out.Add(t);
            }
            return(@out);
        }
Esempio n. 15
0
        public Bunch <T> SubBunch(int _start)
        {
            Bunch <T> @out = new Bunch <T>();

            for (int i = _start; i < this.Count; i++)
            {
                @out.Add(this[i]);
            }
            return(@out);
        }
Esempio n. 16
0
        public Bunch <T> SubBunch(int _start, int _length)
        {
            Bunch <T> @out = new Bunch <T>();

            for (int i = _start; i < _start + _length; i++)
            {
                @out.Add(this[i]);
            }
            return(@out);
        }
Esempio n. 17
0
        public Bunch <T> Clone()
        {
            Bunch <T> @out = new Bunch <T>();

            foreach (T obj in this)
            {
                @out.Add(obj);
            }
            return(@out);
        }
Esempio n. 18
0
        public static Bunch <T> operator +(T _one, Bunch <T> _two)
        {
            Bunch <T> @out = new Bunch <T>()
            {
                _one
            };

            @out.Add(_two);
            return(@out);
        }
Esempio n. 19
0
        public Tab(string _content)
        {
            this.Interfacial = true;
            this.Content     = _content;

            //this.Cutoff = Font.Consolas.GetLineSpacing(14) / 4;
            this.Cutoff = FontBase.Consolas.CharSize / 4;
            this.Label  = new Label(this.Content)
            {
                Z = 0.000001, Position = new Vector(this.Cutoff * 0.5, 0)
            };

            Bunch <Vector> vs = new Bunch <Vector>();

            double w = this.Label.Width + this.Cutoff * 3;

            vs.Add(0);
            vs.Add(new Vector(0, this.Label.Height - this.Cutoff));
            vs.Add(new Vector(this.Cutoff, this.Label.Height));
            vs.Add(new Vector(w - this.Cutoff, this.Label.Height));
            vs.Add(new Vector(w, this.Label.Height - this.Cutoff));
            vs.Add(new Vector(w, 0));

            this.Graphics.Add(new VertexArray(VertexArrayType.Polygon)
            {
                Color = Color.White, Position = new Vector(-this.Cutoff, 0), Vertices = vs.Select(item => new Vertex(new Vector(item.X, this.Label.Height - item.Y), Color.White))
            });
            this.Graphics.Add(new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.Black, Position = new Vector(-this.Cutoff, 0), Vertices = vs.Select(item => new Vertex(new Vector(item.X, this.Label.Height - item.Y), Color.White))
            });
        }
Esempio n. 20
0
        public Bunch <string> GetAreasets()
        {
            Bunch <string> @out = new Bunch <string>();

            foreach (Tuple <string, int> tile in this._Tiles)
            {
                if ([email protected](tile.Item1))
                {
                    @out.Add(tile.Item1);
                }
            }
            return(@out);
        }
Esempio n. 21
0
        private void _LoadOggPages(string _path)
        {
            FileStream stream = new FileStream(_path, FileMode.Open);

            long pos = 0;
            long end = stream.Length;

            Bunch <OggPage> ps = new Bunch <OggPage>();

            while (pos < end)
            {
                byte[] header = new byte[27];
                stream.Read(header, 0, 27);

                OggPage p = new OggPage();
                p.Granule        = Beth.FromEndian(header.SubArray(6, 8));
                p.StreamId       = (int)Beth.FromEndian(header.SubArray(14, 4));
                p.StreamPosition = (int)Beth.FromEndian(header.SubArray(18, 4));

                int ss = header[26];
                p.Segments = new byte[ss];
                pos       += 27;

                int si = 0;
                while (ss > 0)
                {
                    ss--;
                    p.Segments[si] = ((byte)stream.ReadByte());
                    si++;
                    pos++;
                }

                p.SegmentsPositionInFile = pos;

                foreach (byte s in p.Segments)
                {
                    pos             += s;
                    stream.Position += s;
                }

                ps.Add(p);
            }

            stream.Close();

            byte[][] bs1 = ps[0].ReadSegments(_path);
            byte[][] bs2 = ps[1].ReadSegments(_path);

            throw new Exception();
        }
Esempio n. 22
0
        public static byte[] ToEndian(int _number, int _bytes)
        {
            byte[]       bs   = ToEndian(_number);
            Bunch <byte> @out = new Bunch <byte>()
            {
                bs
            };

            while (@out.Count < _bytes)
            {
                @out.Add(0);
            }
            return(@out.ToArray());
        }
Esempio n. 23
0
        public static byte[] ToEndian(int _number)
        {
            Bunch <byte> @out = new Bunch <byte>();

            while (_number > 0)
            {
                byte b = (byte)(_number % 256);
                @out.Add(b);
                _number -= b;
                _number /= 256;
            }

            return(@out.ToArray());
        }
Esempio n. 24
0
        internal void _SaveLevel(Level _level, string _name)
        {
            Bunch <SavedEntity> ss = new Bunch <SavedEntity>();

            foreach (Entity entity in _level.Children.Where(item => item.Identifier != "[none]"))
            {
                Bunch <FieldInfo> fs = entity.GetType().GetFields().Where(item => item.GetCustomAttributes <SavableAttribute>().ToArray().Length > 0).ToArray();
                if (fs.Count > 0)
                {
                    ss.Add(new SavedEntity(fs, entity));
                }
            }

            this._Levels[_name] = ss;
        }
Esempio n. 25
0
        public static Vector GetSingle(Bunch <Vector> _points, double _progress)
        {
            Bunch <Vector> ps = _points.Clone();

            while (ps.Count > 1)
            {
                Bunch <Vector> nps = new Bunch <Vector>();
                for (int x = 0; x < ps.Count - 1; x++)
                {
                    nps.Add(ps[x] + (ps[x + 1] - ps[x]) * _progress);
                }
                ps = nps;
            }
            return(ps[0]);
        }
Esempio n. 26
0
        internal Bunch <string> _GetAreasets()
        {
            Bunch <string> @out = new Bunch <string>();

            for (int x = 0; x < this.Tiles.GetLength(0); x++)
            {
                for (int y = 0; y < this.Tiles.GetLength(1); y++)
                {
                    if ([email protected](this.Tiles[x, y].Item1))
                    {
                        @out.Add(this.Tiles[x, y].Item1);
                    }
                }
            }
            return(@out);
        }
Esempio n. 27
0
        public void Save(string _path)
        {
            Bunch <string> _areasets = new Bunch <string>();

            foreach (LayerSource l in this.Layers)
            {
                foreach (string areaset in l._GetAreasets())
                {
                    if (!_areasets.Contains(areaset))
                    {
                        _areasets.Add(areaset);
                    }
                }
            }

            MekaItem file = new MekaItem("File", new List <MekaItem>());

            MekaItem info = new MekaItem("Info", new List <MekaItem>());

            info.Children.Add(new MekaItem("Title", this.Title));
            info.Children.Add(new MekaItem("Author", this.Author));
            info.Children.Add(new MekaItem("Width", this.Size.X.ToString()));
            info.Children.Add(new MekaItem("Height", this.Size.Y.ToString()));
            info.Children.Add(new MekaItem("OnLoad", this.OnLoad.SourceCode));
            info.Children.Add(new MekaItem("OnEnter", this.OnEnter.SourceCode));
            info.Children.Add(new MekaItem("OnExit", this.OnEnter.SourceCode));
            file.Children.Add(info);

            file.Children.Add(new MekaItem("Properties", this._Properties));

            file.Children.Add(new MekaItem("Areasets", _areasets.Select(item => new MekaItem("Areaset", item))));

            MekaItem layers = new MekaItem("Layers", new List <MekaItem>());

            foreach (LayerSource l in this.Layers)
            {
                MekaItem item = l._Export(_areasets);
                if (this.MainLayer == l)
                {
                    item.Children.Add(new MekaItem("Main"));
                }
                layers.Children.Add(item);
            }
            file.Children.Add(layers);

            file.SaveToFile(_path);
        }
Esempio n. 28
0
        public override void OnInitialization()
        {
            Bunch <Alignable> als = new Bunch <Alignable>();

            //als.Add(new Alignment(new Label("Width:"), this.WidthBox = new NumBox(this.Editor.TileEditor.Size.X) { Digits = 3, MinValue = 1 }));
            //als.Add(new Alignment(new Label("Height:"), this.HeightBox = new NumBox(this.Editor.TileEditor.Size.Y) { Digits = 3, MinValue = 1 }));

            if (this.LevelProperties != null)
            {
                als.Add(this.PropertyEditor = new PropertyEditor(this.LevelProperties));
            }

            this.Children.Add(new Alignment(als)
            {
                Vertical = true
            });
        }
Esempio n. 29
0
        public override void OnInitialization()
        {
            Bunch <Alignable> als = new Bunch <Alignable>();

            als.Add(new Alignment(new Label("Title:"), this.BoxTitle     = new TextBox("untitled")));
            als.Add(new Alignment(new Label("Author:"), this.BoxAuthor   = new TextBox("unknown")));
            als.Add(new Alignment(new Label("Width:"), this.BoxWidth     = new NumBox(this.Editor.TileEditor.Size.X)));
            als.Add(new Alignment(new Label("Height:"), this.BoxHeight   = new NumBox(this.Editor.TileEditor.Size.Y)));
            als.Add(new Alignment(new Label("OnLoad:"), this.BoxOnLoad   = new ScriptBox(Zero.Script.Store(""))));
            als.Add(new Alignment(new Label("OnEnter:"), this.BoxOnEnter = new ScriptBox(Zero.Script.Store(""))));
            als.Add(new Alignment(new Label("OnExit:"), this.BoxOnExit   = new ScriptBox(Zero.Script.Store(""))));
            this.Children.Add(new Alignment(als)
            {
                Vertical = true
            });
        }
Esempio n. 30
0
        public Areaset(MekaItem _file, Point _tilesize, Point _tilecollisionresolution)
        {
            if (_file["Info"]["Tilesize"].To <Point>() != _tilesize || _file["Info"]["Colsize"].To <Point>() != _tilecollisionresolution)
            {
                throw new Exception("Tilesize and/or Colsize don't match up with this game's.");
            }

            ImageSource tileset = GameBase.LoadImageSource(_file["Tileset"].Data);

            ImageSource[,] tiles = tileset.Split(tileset.Size / _tilesize);
            ImageSource colset = GameBase.LoadImageSource(_file["Colset"].Data);

            int pixelcount = Meth.Up(_tilecollisionresolution.X * _tilecollisionresolution.Y / 4.0);

            this.Size = new Point(tiles.GetLength(0), tiles.GetLength(1));

            for (int y = 0; y < this.Size.Y; y++)
            {
                for (int x = 0; x < this.Size.X; x++)
                {
                    this.Tiles.Add(tiles[x, y]);

                    Bunch <Color> cs = new Bunch <Color>();
                    for (int i = 0; i < pixelcount; i++)
                    {
                        cs.Add(colset[x * pixelcount + i, y]);
                    }

                    Bunch <byte> bs = new Bunch <byte>();
                    foreach (Color c in cs)
                    {
                        bs.Add(c.Bytes);
                    }

                    bs           = bs.SubBunch(0, _tilecollisionresolution.X * _tilecollisionresolution.Y);
                    bool[,] cols = new bool[_tilecollisionresolution.X, _tilecollisionresolution.Y];
                    for (int i = 0; i < bs.Count; i++)
                    {
                        cols[i % _tilecollisionresolution.X, Meth.Down(i / _tilecollisionresolution.X)] = bs[i] == 1;
                    }
                    this.Cols.Add(cols);
                }
            }
        }