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(); }
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); }