public static BlocksCollection FromClipboard() { BlocksCollection blocks = BlocksCollection.FromXML(Clipboard.GetText()); blocks.ClipboardReady = true; return(blocks); }
private void ClipboardNotification_ClipboardUpdate(object sender, EventArgs e) { buttonFromClipboardPreview.Enabled = buttonFromClipboardScreenshot.Enabled = Clipboard.ContainsImage() && OpenedLevel != null; ClipboardBlocks = BlocksCollection.FromClipboard(); if (Clipboard.ContainsText() && Clipboard.GetText() != "") { UpdateBlockCount(); } }
private void buttonRotateBlocks_Click(object sender, EventArgs e) { BlocksSource src = GetBlocksSource(sender); BlocksCollection blocks = GetRightBlocks(src); blocks.Rotate(comboBoxRotation.SelectedIndex + 1); Status("{0} blocks were rotated by {1}.", src, comboBoxRotation.Text); SaveButtonUpdate(src == BlocksSource.Puzzle); }
private void buttonShiftBlocks_Click(object sender, EventArgs e) { BlocksSource src = GetBlocksSource(sender); BlocksCollection blocks = GetRightBlocks(src); Vec vec = new Vec((int)numericUpDownXShift.Value, (int)numericUpDownYShift.Value, (int)numericUpDownZShift.Value); blocks.Shift(vec); Status("{0} blocks were shifted by {1} vector.", src, vec); SaveButtonUpdate(src == BlocksSource.Puzzle); }
private void buttonFlipBlocks_Click(object sender, EventArgs e) { MessageBox.Show("This feature doesn't really flip the level entirely: while blocks positions will flip, their orientation won't change accordingly.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); BlocksSource src = GetBlocksSource(sender); BlocksCollection blocks = GetRightBlocks(src); blocks.Flip((Axis)comboBoxFlipping.SelectedIndex, BlockInfosManager); Status("{0} blocks were flipped along the {1}.", src, comboBoxFlipping.Text); SaveButtonUpdate(src == BlocksSource.Puzzle); }
private void buttonReplaceBlocks_Click(object sender, EventArgs e) { BlocksSource src = GetBlocksSource(sender); BlocksCollection blocks = GetRightBlocks(src); int what = (int)numericUpDownReplaceWhat.Value; int with = (int)numericUpDownReplaceWith.Value; string msg = "There is no block " + with + " in the Block Reference. Do you want to continue with the replacement?"; if (BlockInfosManager.BlockInfosList.Any(i => !i.Decal && i.Type == with) || MessageBox.Show(msg, "Replace blocks?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { blocks.Replace(what, with); Status("{0} blocks {1} were replaced with blocks {2}.", src, what, with); SaveButtonUpdate(src == BlocksSource.Puzzle); } }
public int CountOverlaps(BlocksCollection b) { List <Vec> aOcc = OccupiedCoordinates.ToList(); List <Vec> bOcc = b.OccupiedCoordinates.ToList(); if (aOcc.Count() > bOcc.Count()) { List <Vec> cOcc = aOcc; aOcc = bOcc; bOcc = cOcc; } HashSet <Vec> aSet = new HashSet <Vec>(aOcc); return(bOcc.Count(i => aSet.Contains(i))); }
private void buttonConvertToClipboard_Click(object sender, EventArgs e) { BlocksCollection blocks = new BlocksCollection(); for (int y = 0; y < pictureBoxReduced.Image.Height; y++) { for (int x = 0; x < pictureBoxReduced.Image.Width; x++) { Vec pos = new Vec(-pictureBoxReduced.Image.Width / 2 + x, 100 - y, 180); blocks[pos] = new Block( colorTranslation[((Bitmap)pictureBoxReduced.Image).GetPixel(x, y)].Type, Direction.NegZ ); } } blocks.ToClipboard(); }
public static BlocksCollection FromBase64(string inputs, string outputs, string world) { BlocksCollection blocks = new BlocksCollection(); blocks.AddFromBase64(world, Block.Roles.World, 0); int group = 1; foreach (string input in inputs.Split('#')) { blocks.AddFromBase64(input, Block.Roles.In, group++); } foreach (string output in outputs.Split('#')) { blocks.AddFromBase64(output, Block.Roles.Out, group++); } return(blocks); }
public void AddBlocks(BlocksCollection b2, bool overide = false) { foreach (var pair in b2.blocksDict) { if (blocksDict.ContainsKey(pair.Key)) { if (overide) { blocksDict[pair.Key] = pair.Value; } } else { blocksDict.Add(pair.Key, pair.Value); } } if (ClipboardReady) { ToClipboard(); } }
public static BlocksCollection FromXML(string source) { BlocksCollection blocks = new BlocksCollection(); try { XDocument xml = XDocument.Parse(source); blocks.AddFromXML(xml.Root.Element("World"), Block.Roles.World); foreach (XElement input in xml.Root.Elements("Input")) { blocks.AddFromXML(input, Block.Roles.In); } foreach (XElement output in xml.Root.Elements("Output")) { blocks.AddFromXML(output, Block.Roles.Out); } } catch { blocks.Valid = false; } return(blocks); }
public BlocksCollection(BlocksCollection old) { Valid = old.Valid; blocksDict = new Dictionary <Vec, Block>(old.blocksDict); Version = old.Version; }
private void Run() { BlocksCollection ClipboardBlocks = ((FormMain)Owner).ClipboardBlocks; BlocksCollection PuzzleBlocks = ((FormMain)Owner).OpenedLevel == null ? null : ((FormMain)Owner).OpenedLevel.Blocks; string res = ""; try { Lua state = new Lua(); state.LoadCLRPackage(); state.DoString(@" import ('InfiniEditor', 'InfiniEditor')"); state.DoString(@"import = function () end"); state["Clipboard"] = ClipboardBlocks; state["Puzzle"] = PuzzleBlocks; state.DoString(@"enumDict = function(dict) local e = dict:GetEnumerator() return function() if e:MoveNext() then return e.Current.Key, e.Current.Value end end end"); BlockInfosManager bim = new BlockInfosManager(); state.RegisterFunction("BlockInfo", bim, typeof(BlockInfosManager).GetMethod("BlockInfo")); state.RegisterFunction("DecalInfo", bim, typeof(BlockInfosManager).GetMethod("DecalInfo")); state["BIM"] = bim; state.DoString(@"dictToTable = function (dict) table = {} for k, v in enumDict(dict) do table[k]=v end return table end"); state.DoString(@"BlockInfos = function(cond) return dictToTable(BIM:BlockInfos(cond)) end"); state.DoString(@"DecalInfos = function(cond) return dictToTable(BIM:DecalInfos(cond)) end"); state["World"] = Block.Roles.World; state["Input"] = Block.Roles.In; state["Output"] = Block.Roles.Out; state["NegX"] = Direction.NegX; state["PosX"] = Direction.PosX; state["NegZ"] = Direction.NegZ; state["PosZ"] = Direction.PosZ; state["PosY"] = Direction.PosY; state["NegY"] = Direction.NegY; state.DoString(@"Directions = {PosX, NegX, PosY, NegY, PosZ, NegZ}"); state.DoString(@"BlockDirections = {PosX, NegX, PosZ, NegZ}"); state.DoString(@"Blocks = function(x) return enumDict(x.blocksDict) end"); state.DoString(@"Decals = function(x) return enumDict(x.Decals) end"); state.RegisterFunction("print", this, typeof(FormScripting).GetMethod("LogConsole")); state.DoString(richTextBoxCode.Text); ClipboardBlocks.ToClipboard(); res = "Code ran successfully."; ((FormMain)Owner).SaveButtonUpdate(true); ((FormMain)Owner).UpdateBlockCount(); } catch (NLua.Exceptions.LuaScriptException ex) { res = "There was an error executing the code. " + ex.Message.Replace("[string \"chunk\"]:", "line "); } ((FormMain)Owner).Status(res); LogConsole(res); }