Exemplo n.º 1
0
		public override void Execute() {
			Map map = EditorEngine.Instance.CurrentMap;
			Tileset tileset = map.Tilesets[tilesetindex].Tileset;

			if (source.Width > 0 && source.Height > 0) {
				int sx = 0;
				int sy = 0;

				for (int x = 0; x < target.Width; x++) {
					if (x % source.Width == 0) {
						sx = 0;
					}
					for (int y = 0; y < target.Height; y++) {
						if (y % source.Height == 0) {
							sy = 0;
						}

						int xt = target.X + x;
						int yt = target.Y + y;
						int zt = EditorEngine.Instance.SelectedLayer;

						MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, zt);

						if (t != null) {
							SetTileAction ta = new SetTileAction(target.X + x, target.Y + y, zt, tilesetindex, tileset.Texture.GetIndex(source.X + sx, source.Y + sy));
							Actions.Add(ta);
							sy++;
						}
					}
					sx++;
				}
			}

			base.Execute();
		}
Exemplo n.º 2
0
		private void onMouseMove(object sender, MouseEventArgs e) {
			if (e.Button == MouseButtons.Left) {
				if (this.action == null) {
					this.action = new MultiAction("Eraser");
				}

				int xt = (int) ((e.X - EditorEngine.Instance.xCam) / EditorEngine.Instance.World.Camera.Scale / 16);
				int yt = (int) ((e.Y - EditorEngine.Instance.yCam) / EditorEngine.Instance.World.Camera.Scale / 16);

				if (xt != lxt || yt != lyt) {
					int tilesetIndex = TileEditorState.Instance.SelectedTileset;

					MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, EditorEngine.Instance.SelectedLayer);

					if (t != null) {
						SetTileAction tileAction = new SetTileAction(xt, yt, EditorEngine.Instance.SelectedLayer, tilesetIndex, -1);
						tileAction.Execute();

						action.Actions.Add(tileAction);
					}
				}

				lxt = xt;
				lyt = yt;
			}
		}
Exemplo n.º 3
0
		private void onMouseMove(object sender, MouseEventArgs e) {
			if (e.Button != MouseButtons.Left) return;
			if (action == null) action = new MultiAction("Tile Update");

			int xt = (int) ((e.X - EditorEngine.Instance.xCam) / EditorEngine.Instance.World.Camera.Scale / 16);
			int yt = (int) ((e.Y - EditorEngine.Instance.yCam) / EditorEngine.Instance.World.Camera.Scale / 16);

			if (xt != lxt || yt != lyt) {
				if (TileEditorState.Instance.SelectedRegion != Rectangle.Empty) {
					MultiAction multiAction = new MultiAction("Tile Update");
					Rectangle selection = TileEditorState.Instance.SelectedRegion;

					for (int x = 0; x < selection.Width; x++) {
						for (int y = 0; y < selection.Height; y++) {
							int currentX = selection.X + x;
							int currentY = selection.Y + y;

							int tilesetIndex = TileEditorState.Instance.SelectedTileset;

							Tileset tilesheet = EditorEngine.Instance.CurrentMap.Tilesets[tilesetIndex].Tileset;
							int tileIndex = tilesheet.Texture.GetIndex(currentX, currentY);

							int zt = EditorEngine.Instance.SelectedLayer;
							MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt + x, yt + y, zt);

							if (t == null) continue;

							SetTileAction tileAction = new SetTileAction(
								xt + x, yt + y,
								zt,
								tilesetIndex,
								tileIndex);
							multiAction.Actions.Add(tileAction);
						}
					}

					multiAction.Execute();
					action.Actions.Add(multiAction);
				}
			}

			lxt = xt;
			lyt = yt;
		}
Exemplo n.º 4
0
        public override void Execute()
        {
            Map     map     = EditorEngine.Instance.CurrentMap;
            Tileset tileset = map.Tilesets[tilesetindex].Tileset;

            if (source.Width > 0 && source.Height > 0)
            {
                int sx = 0;
                int sy = 0;

                for (int x = 0; x < target.Width; x++)
                {
                    if (x % source.Width == 0)
                    {
                        sx = 0;
                    }
                    for (int y = 0; y < target.Height; y++)
                    {
                        if (y % source.Height == 0)
                        {
                            sy = 0;
                        }

                        int xt = target.X + x;
                        int yt = target.Y + y;
                        int zt = EditorEngine.Instance.SelectedLayer;

                        MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, zt);

                        if (t != null)
                        {
                            SetTileAction ta = new SetTileAction(target.X + x, target.Y + y, zt, tilesetindex, tileset.Texture.GetIndex(source.X + sx, source.Y + sy));
                            Actions.Add(ta);
                            sy++;
                        }
                    }
                    sx++;
                }
            }

            base.Execute();
        }
Exemplo n.º 5
0
		public SetTileAction Evaluate(int x, int y) {
			try {
				MockupTile tu = EditorEngine.Instance.CurrentMap.GetTile(x, y - 1, EditorEngine.Instance.SelectedLayer);
				MockupTile td = EditorEngine.Instance.CurrentMap.GetTile(x, y + 1, EditorEngine.Instance.SelectedLayer);
				MockupTile tl = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y, EditorEngine.Instance.SelectedLayer);
				MockupTile tr = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y, EditorEngine.Instance.SelectedLayer);
				MockupTile tul = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y - 1, EditorEngine.Instance.SelectedLayer);
				MockupTile tur = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y - 1, EditorEngine.Instance.SelectedLayer);
				MockupTile tdl = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y + 1, EditorEngine.Instance.SelectedLayer);
				MockupTile tdr = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y + 1, EditorEngine.Instance.SelectedLayer);

				bool u = isSameType(tu);
				bool d = isSameType(td);
				bool l = isSameType(tl);
				bool r = isSameType(tr);
				bool ul = isSameType(tul);
				bool ur = isSameType(tur);
				bool dl = isSameType(tdl);
				bool dr = isSameType(tdr);

				LogicEvalInfo _info = new LogicEvalInfo("", 0);
				script.Invoke("Eval", this, _info, u, d, l, r, ul, ur, dl, dr);

				int zt = EditorEngine.Instance.SelectedLayer;
				MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(x, y, zt);
				if (t == null) return null;

				SetTileAction act = new SetTileAction(x, y, zt, EditorEngine.Instance.World.TilesetContainer.IndexOf(EditorEngine.Instance.GetTilesetByName(_info.s1)), _info.s2);

				return act;
			} catch (Exception e) {
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("-- Error (" + e.GetType() + "): " + e.Message);
				//GameConsole.WriteLine("Info: " + e.Value.Value);
				Console.WriteLine("\r\n\r\n");
				Console.ResetColor();
			}
			return null;
		}
Exemplo n.º 6
0
		public override void Execute() {
			Map map = EditorEngine.Instance.CurrentMap;

			if (x >= 0 && x < map.Width && y >= 0 && y < map.Height) {
				int currentIndex = map.GetTile(x, y, EditorEngine.Instance.SelectedLayer).tileIndex;
				int currentTilesetIndex = map.GetTile(x, y, EditorEngine.Instance.SelectedLayer).tilesetIndex;

				Stack<Vector2> pp = new Stack<Vector2>();
				List<Vector2> hpp = new List<Vector2>();

				pp.Push(new Vector2(x, y));

				while (pp.Count > 0) {
					Vector2 cp = pp.Pop();

					if (!hpp.Contains(cp)) {
						int cx = (int)cp.X;
						int cy = (int)cp.Y;

						MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(cx, cy, EditorEngine.Instance.SelectedLayer);
						SetTileAction ta = new SetTileAction(cx, cy, EditorEngine.Instance.SelectedLayer, tilesetindex, tileindex);

						Actions.Add(ta);

						if (map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx + 1 < map.Width && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx + 1, cy));
						if (map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx - 1 >= 0 && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx - 1, cy));
						if (map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer) != null && cy + 1 < map.Width && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx, cy + 1));
						if (map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer) != null && cy - 1 < map.Width && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx, cy - 1));

						hpp.Add(cp);
					}
				}
			}
			base.Execute();
		}