public AnimationSource(MekaItem _item) { if (_item.Contains("Sprites")) { foreach (MekaItem frame in _item["Sprites"].Children) { this.Sprites.Add(GameBase.LoadImageSource(frame.Data)); this.Offsets.Add(frame.Contains("Offset") ? frame["Offset"].To <Vector>() : 0); } } else { ImageSource src = GameBase.LoadImageSource(_item["Spriteset"].Children[0].Data); this.Sprites.Add(src.Split(_item["Spriteset"]["Count"].To <int>())); for (int i = 0; i < this.Sprites.Count; i++) { this.Offsets.Add(0); } } if (_item.Contains("Offset")) { Vector offset = _item["Offset"].To <Vector>(); for (int i = 0; i < this.Sprites.Count; i++) { this.Offsets[i] = offset; } } this.Speed = _item["Speed"].To <int>(); this.Repeated = _item.Contains("Repeated"); }
internal SaveFile(GameBase _game, string _path) : this(_game) { MekaItem file = MekaItem.LoadFromFile(_path); this.PlayTime = file["Play Time"].Content.To <int>(); int[] ds = file["Last Played"].Content.Split('.').ToArray().Select(item => item.To <int>()).ToArray(); this.LastPlayed = new DateTime(ds[2], ds[1], ds[0]); this._PositionRegion = file["Position Region"].Content; this._PositionEntrance = file["Position Entrance"].Content; foreach (MekaItem level in file["Levels"].Children) { this._Levels[level.Name] = new Bunch <SavedEntity>(); foreach (MekaItem entity in level.Children) { this._Levels[level.Name].Add(new SavedEntity(entity)); } } foreach (MekaItem achievement in file["Achievements"].Children) { this.Achievements[achievement.Name] = achievement.Children[0]; } this.CustomInfo = file["Custom Info"]; string n = File.GetName(_path); n = n.Substring(n.IndexOf('#') + 1); this._Id = n.To <int>(); }
//public static Rect GetRect(this Bunch<Collider> @this) //{ // return @this.Select(item => item.Rect).GetRect(); //} public static MekaItem Convert(this MekaItem @this) { if (@this.HasChildren) { MekaItem @out = new MekaItem(@this.Name, new List <MekaItem>()); foreach (MekaItem child in @this.Children) { if (child.Name[0] == '#') { foreach (MekaItem c in child.Convert().Children) { @out.Children.Add(c); } } else { @out.Children.Add(child.Convert()); } } return(@out); } else { return(@this); } }
//internal void _CollectData() //{ // byte[] @out = new byte[this._Client.Available]; // this._Client.Client.Receive(@out); // this._CollectedData.Add(@out); //} private void _SendLoop() { while (this.IsConnected) { //if (!this._WantingToSend) //{ // this._Sending = true; if (this._Messages.Count > 0) { MekaItem msg = this._Messages[0]; byte[] bs = msg.ToBytes(); DateTime start = DateTime.Now; this._Client.Client.Send(bs); TimeSpan dif = DateTime.Now - start; if (dif.TotalMilliseconds != 0) { this._Speed = bs.Length / 1000.0 / dif.TotalSeconds; } //this._Messages.RemoveAt(0); Interlocked.Exchange <Bunch <MekaItem> >(ref this._Messages, this._Messages.SubBunch(1)); } //this._Sending = false; //} } }
public override void OnInitialization() { this.Children.Add(this.Editor = new AreasetEditorHidden()); this.Children.Remove(this.Editor); this.Children.Add(this.AlignmentButtons = new Alignment ( new Label("Areaset:"), new Button("Add", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("png"); if (f != null) { this.Editor.TilesetSource = GameBase.LoadImageSource(f.Bytes); this.EditorShown = true; } }), new Button("Open", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("meka"); if (f != null) { this.Editor.Load(MekaItem.FromBytesEncrypted(f.Bytes)); this.EditorShown = true; } }) ) { Spacing = 3 }); }
internal void _Send(MekaItem _item) { foreach (User u in this.Users.Where(item => item._Started)) { u.Send(_item); } }
public void Load(byte[] _bytes) { if (this.LevelProperties != null) { MekaItem file = MekaItem.FromBytesEncrypted(_bytes); this.Properties = PropertySaver.Load(PropertyReflector.GetPropertyTypes(this.LevelProperties), file["Properties"].Children /*file.Contains("Info") ? file["Info"].Children : new List<MekaItem>()*/); } }
public void Send(MekaItem _item) { //this._WantingToSend = true; //while (this._Sending) // await Task.Delay(1); //this._Messages.Add(_item); //this._WantingToSend = false; Interlocked.Exchange <Bunch <MekaItem> >(ref this._Messages, this._Messages + _item); }
internal MekaItem _Export() { MekaItem @out = new MekaItem(this.Type, new List <MekaItem>()); @out.Children.Add(new MekaItem("X", this.X.ToString())); @out.Children.Add(new MekaItem("Y", this.Y.ToString())); @out.Children.Add(new MekaItem("Z", this.Z.ToString())); @out.Children.Add(new MekaItem("Properties", this.Properties.Select(item => new MekaItem(item.Key, item.Value)).ToList())); return(@out); }
internal void _CheckRegions() { foreach (File f in File.GetAllFiles(this._Game.Path + "\\" + this._Game.LevelFolder)) { if (f.Name == "_Region") { this._Regions[f.Path] = MekaItem.LoadFromFile(f.Path).Children.Select(item => File.GetFolder(f.Path) + "\\" + item.Name).ToBunch(); } } }
public MekaItem Export() { MekaItem @out = new MekaItem(this.Type.Name, new List <MekaItem>()); @out.Children.Add(new MekaItem("X", this.Position.X.ToString())); @out.Children.Add(new MekaItem("Y", this.Position.Y.ToString())); @out.Children.Add(new MekaItem("Z", this.EntityZ.ToString())); @out.Children.Add(new MekaItem("Properties", this.Properties.Select(item => new MekaItem(item.Name, item.Value)).ToList())); return(@out); }
public void Send(MekaItem _item) { if (this.IsServer) { this.Server._Send(_item); } else { this.Client._Send(_item); } }
public void Load(byte[] _bytes) { MekaItem info = MekaItem.FromBytesEncrypted(_bytes)["Info"]; this.BoxTitle.Content = info["Title"].Content; this.BoxAuthor.Content = info["Author"].Content; this.BoxWidth.Value = info["Width"].Content.To <int>(); this.BoxHeight.Value = info["Height"].Content.To <int>(); this.BoxOnLoad.Content = info["OnLoad"].Content; this.BoxOnEnter.Content = info["OnEnter"].Content; this.BoxOnExit.Content = info["OnExit"].Content; }
public MekaItem Export() { MekaItem @out = new MekaItem("Areaset", new List <MekaItem>()); @out.Children.Add(new MekaItem("Info", new List <MekaItem>() { new MekaItem("Tilesize", this.Parent.TileSize.ToString()), new MekaItem("Colsize", this.Parent.TileCollisionResolution.ToString()) })); @out.Children.Add(new MekaItem("Tileset", this.TilesetSource.Bytes)); @out.Children.Add(new MekaItem("Colset", this.GetColset().Bytes)); return(@out); }
public EntityInstance(MekaItem _item) { this.Type = _item.Name; this.X = _item["X"].To <double>(); this.Y = _item["Y"].To <double>(); this.Z = _item["Z"].To <int>(); foreach (MekaItem s in _item["Properties"].Children) { this.Properties[s.Name] = s.Content; } }
public Areaset(string _path, Point _tilesize, Point _tilecollisionresolution) : this(MekaItem.LoadFromFile(_path + "\\Areaset.meka"), _tilesize, _tilecollisionresolution) { this.Name = _path.Substring(_path.LastIndexOf('\\') + 1); if (File.Exists(_path + "\\Decorations")) { foreach (File f in File.GetAllFiles(_path + "\\Decorations")) { this.Decorations[f.Name] = GameBase.LoadImageSource(f.Bytes); } } }
public void LoadFromItem(MekaItem _item) { this.Position = new Vector(_item["X"].To <double>(), _item["Y"].To <double>()); this.EntityZ = _item["Z"].To <int>(); foreach (MekaItem property in _item["Properties"].Children) { if (this.Properties.Any(item => item.Name == property.Name)) { this.Properties.First(item => item.Name == property.Name).Value = property.Content; } } }
public MekaItem Export() { MekaItem @out = new MekaItem("Info", new List <MekaItem>()); @out.Children.Add(new MekaItem("Title", this.BoxTitle.Content)); @out.Children.Add(new MekaItem("Author", this.BoxAuthor.Content)); @out.Children.Add(new MekaItem("Width", this.BoxWidth.Value.ToString())); @out.Children.Add(new MekaItem("Height", this.BoxHeight.Value.ToString())); @out.Children.Add(new MekaItem("OnLoad", this.BoxOnLoad.Content)); @out.Children.Add(new MekaItem("OnEnter", this.BoxOnEnter.Content)); @out.Children.Add(new MekaItem("OnExit", this.BoxOnExit.Content)); return(@out); }
public PixelFont(string _path) { MekaItem file = MekaItem.LoadFromFile(_path); MekaItem chars = file["Characters"].Children[0]; ImageSource src = new ImageSource(chars.Data); ImageSource[,] cs = src.Split(chars["Count"].To <Point>()); foreach (ImageSource c in cs) { for (int x = 0; x < c.Width; x++) { for (int y = 0; y < c.Height; y++) { if (c[x, y].A > 0 && c[x, y] != Color.White) { c[x, y] = Color.White; } } } } { int y = 0; foreach (MekaItem line in file["Characters"].Children.Where(item => item.Name == "Line")) { for (int x = 0; x < line.Content.Length; x++) { this.Chars[line.Content[x]] = cs[x, y]; } y++; } } if (file.Contains("Character Size")) { this.CharSize = file["Character Size"].To <Point>(); } else { this.CharSize = this.Chars.ToArray()[0].Value.Size; } if (file.Contains("Default")) { this._DefaultChar = file["Default"].Content[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); }
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); } } }
public void Test(string _entrance) { File f = this.Parent.Save(this._Export(), "meka"); if (f != null) { this.Parent._TestStarted = true; this.Parent.FixedResolution = this.StartFixedResolution; //this.Parent.IgnoreMouseWithoutFocus = this.StartIgnoreMouseWithoutFocus; this.Parent.MouseLimitedToScreen = this.StartMouseLimitedToScreen; this.Parent.ScaleMode = this.StartScaleMode; this.Parent.UseMultipleRenderers = this.StartUseMultipleRenderers; this.Parent.Entities.Remove(this); this.Parent.StartTest(new LevelSource(this.Parent, MekaItem.FromBytesEncrypted(this._Export())), this.Parent.SavePath, _entrance); } }
public MekaItem GetAnimationFile() { MekaItem @out = new MekaItem("Animation", new List <MekaItem>()); MekaItem spriteset = new MekaItem("Spriteset", new List <MekaItem>()); spriteset.Children.Add(new MekaItem("Spritesheet", "png", this.SpritesheetSource.Bytes)); spriteset.Children.Add(new MekaItem("Count", this.AnimSprites.ToString())); @out.Children.Add(spriteset); @out.Children.Add(new MekaItem("Speed", this.AnimSpeed.ToString())); if (this.AnimRepeated) { @out.Children.Add(new MekaItem("Repeated")); } return(@out); }
public LayerSource(MekaItem _item, Bunch <string> _areasets) { this.Main = _item.Contains("Main"); ImageSource img = GameBase.LoadImageSource(_item["Tiles"].Data); Color[,] px = img.Pixels; this.Tiles = new Tuple <string, int> [img.Width, img.Height]; for (int x = 0; x < img.Width; x++) { for (int y = 0; y < img.Height; y++) { this.Tiles[x, y] = new Tuple <string, int>(_areasets[(int)Beth.FromEndian(px[x, y].Bytes.Sub(0, 2))], (int)Beth.FromEndian(px[x, y].Bytes.Sub(2, 2))); } } foreach (MekaItem entity in _item["Entities"].Children) { this.Entities.Add(new EntityInstance(entity)); } }
internal MekaItem _Export(Bunch <string> _areasets) { MekaItem @out = new MekaItem("Layer", new List <MekaItem>()); ImageSource src = new ImageSource(this.Tiles.GetLength(0), this.Tiles.GetLength(1)); for (int x = 0; x < this.Tiles.GetLength(0); x++) { for (int y = 0; y < this.Tiles.GetLength(1); y++) { Bunch <byte> bs = Beth.ToEndian(_areasets.IndexOf(this.Tiles[x, y].Item1), 2); bs.Add(Beth.ToEndian(this.Tiles[x, y].Item2, 2)); src[x, y] = new Color(bs); } } @out.Children.Add(new MekaItem("Tiles", src.Bytes)); @out.Children.Add(new MekaItem("Entities", this.Entities.Select(item => item._Export()).ToList())); return(@out); }
public void Load(MekaItem _file) { Areaset a = new Areaset(_file, this.Parent.TileSize, this.Parent.TileCollisionResolution); this.TilesetSource = GameBase.LoadImageSource(_file["Tileset"].Data); this.Colset = new byte[this.TileCount.X * this.Parent.TileCollisionResolution.X, this.TileCount.Y * this.Parent.TileCollisionResolution.Y][, ]; for (int i = 0; i < a.Cols.Count; i++) { Point p = new Point(i % this.TileCount.X, Meth.Down(i / this.TileCount.X)); this.Colset[p.X, p.Y] = a.Cols[i].Select(item => (byte)(item ? 1 : 0)); for (int cx = 0; cx < this.Parent.TileCollisionResolution.X; cx++) { for (int cy = 0; cy < this.Parent.TileCollisionResolution.Y; cy++) { this.ColPreviewSource[p.X * this.Parent.TileCollisionResolution.X + cx, p.Y *this.Parent.TileCollisionResolution.Y + cy] = (this.Colset[p.X, p.Y][cx, cy] == 1) ? Color.White : Color.Transparent; } } } }
internal void _Save() { string path = this._Game.Path + "\\Internal\\Saves\\Save File #" + this._Id.ToString() + ".meka"; MekaItem file = new MekaItem("Save File #" + this._Id.ToString(), new Bunch <MekaItem>()); file.Children.Add(new MekaItem("Play Time", this.PlayTime.ToString())); file.Children.Add(new MekaItem("Last Played", DateTime.Now.Day.ToString() + "." + DateTime.Now.Month.ToString() + "." + DateTime.Now.Year.ToString())); file.Children.Add(new MekaItem("Position Region", this.PositionRegion)); file.Children.Add(new MekaItem("Position Entrance", this.PositionEntrance)); MekaItem levels = new MekaItem("Levels", new List <MekaItem>()); foreach (KeyValuePair <string, Bunch <SavedEntity> > level in this._Levels) { MekaItem l = new MekaItem(level.Key, new List <MekaItem>()); foreach (SavedEntity e in level.Value) { l.Children.Add(new MekaItem(e.Identifier, e.Properties)); } levels.Children.Add(l); } file.Children.Add(levels); MekaItem achievements = new MekaItem("Achievements", new List <MekaItem>()); foreach (KeyValuePair <string, MekaItem> achievement in this.Achievements) { achievements.Children.Add(new MekaItem(achievement.Key, new List <MekaItem>() { achievement.Value })); } file.Children.Add(achievements); file.Children.Add(new MekaItem("Custom Info", this.CustomInfo)); file.SaveToFile(path); }
public override void OnInitialization() { this.Children.Add(this.Editor = new AnimationEditorHidden()); this.Children.Remove(this.Editor); this.Children.Add(this.AlignmentButtons = new Alignment ( new Label("Animation:"), new Button("Add", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("png"); if (f != null) { this.Editor.SpritesheetSource = GameBase.LoadImageSource(f.Bytes); this.AnimationShown = true; } }), new Button("Open", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("meka"); if (f != null) { MekaItem file = MekaItem.FromBytesEncrypted(f.Bytes); this.Editor.SpritesheetSource = GameBase.LoadImageSource(file["Spriteset"].Children[0].Data); this.Editor.BoxSprites.Value = file["Spriteset"]["Count"].To <int>(); this.Editor.BoxSpeed.Value = file["Speed"].To <int>(); this.Editor.BoxRepeated.Checked = file.Contains("Repeated"); this.AnimationShown = true; } }) ) { Spacing = 3 }); }
internal byte[] _Export() { Bunch <string> _areasets = new Bunch <string>(); foreach (Layer l in this.TileEditor.Layers) { foreach (string areaset in l.GetAreasets()) { if (!_areasets.Contains(areaset)) { _areasets.Add(areaset); } } } MekaItem file = new MekaItem("File", new List <MekaItem>()); file.Children.Add(this.LevelInfoEditor.Export()); file.Children.Add(this.LevelPropertiesEditor.Export()); file.Children.Add(new MekaItem("Areasets", _areasets.Select(item => new MekaItem("Areaset", item)))); MekaItem layers = new MekaItem("Layers", new List <MekaItem>()); foreach (Layer l in this.TileEditor.Layers) { MekaItem item = l._Export(_areasets); if (this.TileEditor.MainLayer == l) { item.Children.Add(new MekaItem("Main")); } layers.Children.Add(item); } file.Children.Add(layers); return(file.ToBytesEncrypted()); }
internal void _Load(byte[] _bytes) { foreach (Entity c in this.Children) { c.Kill(); } MekaItem level = MekaItem.FromBytesEncrypted(_bytes); this.Layers = new Bunch <Layer>(); Bunch <string> areasets = level["Areasets"].Children.Select(item => item.Content).ToBunch(); foreach (MekaItem layer in level["Layers"].Children) { Layer l = new Layer(this.Areasets, this.Parent.TileSize, this.DefaultTile) { SizeChangedLayer = true }; l.LoadFromImage(GameBase.LoadImageSource(layer["Tiles"].Data), areasets); foreach (MekaItem entity in layer["Entities"].Children) { EntityIcon i = new EntityIcon(l, Editor.EntityTypes.First(item => item.Name == entity.Name), _dragged: false) { LoadInfo = entity }; //i.LoadFromItem(entity); l.Entities.Add(i); this.Children.Add(i); } this.Layers.Add(l); if (layer.Contains("Main")) { this.MainLayer = l; } } this.SwitchToLayer(this.Layers.IndexOf(this.MainLayer)); this.Editor.LayerList.NeedsUpdate = true; this.Editor.LevelPreview.NeedsUpdate = true; this.UpdateFrame(); //ImageSource tiles = new ImageSource(level["Tiles"].Data); //this.Size = tiles.Size; //for (int x = 0; x < tiles.Size.X; x++) //{ // for (int y = 0; y < tiles.Size.Y; y++) // //this.Draw(new Point(x, y), Beth.FromEndian(tiles[x, y].Bytes.Sub(0, 3))); // this.Layer[x, y] = Beth.FromEndian(tiles[x, y].Bytes.Sub(0, 3)); //} //this.Editor.EntityEditor.Select(null); //foreach (MekaItem entity in level["Entities"].Children) //{ // EntityIcon e = new EntityIcon(Editor.EntityTypes.First(item => item.Name == entity.Name), _dragged: false); // e.Position = entity["Settings"]["Position"].To<Vector>(); // foreach (MekaItem property in entity["Properties"].Children) // e.Properties.First(item => item.Name == property.Name).Value = property.Content; // this.Children.Add(e); //} }