Beispiel #1
0
 public void GetArgs(out BlockDef envelope, out Size size, out string dir, out string inputFilename)
 {
     envelope      = new BlockDef(_blockName, ucGeoRangeControl1.MinX, ucGeoRangeControl1.MinY, ucGeoRangeControl1.MaxX, ucGeoRangeControl1.MaxY);
     size          = new Size((int)txtWidth.Value, (int)txtHeight.Value);
     dir           = txtOutFile.Text;
     inputFilename = txtInputFile.Text;
 }
        private void UpdateCursorBlocks()
        {
            _isHit = WorldRaycaster.Raycast(_camera.position, _camera.forward);

            if (_isHit)
            {
                // ====== Update Place Block cursor ======

                var placeBlockPosition = WorldRaycaster.LastPosition;

                // don't show place block cursor if it collides with the player
                _collidesWithPlayer = PhysicsWorld.CheckBodyOnGlobalXyz(_playerBody, placeBlockPosition.x, placeBlockPosition.y, placeBlockPosition.z);

                _placeBlockCursor.Transform.position = placeBlockPosition;

                // ====== Update Mining cursor / position / time ======

                var hitPosition = WorldRaycaster.HitPosition;
                if (WorldRaycaster.HitPosition != _lastMinePosition)
                {
                    _mineBlockCursor.Transform.position = WorldRaycaster.HitPosition;

                    //position changed => reset mining timer
                    _miningStartedTime = Time.time;

                    _minedBlockType   = BlockDefs.GetDefinitionById((BlockTypeId)WorldModel.GetVoxel(hitPosition.x, hitPosition.y, hitPosition.z));
                    _lastMinePosition = hitPosition;
                }
            }

            UpdateCursorsVisibility();
        }
Beispiel #3
0
    public static Chunk NewFilledChunk(World world, Position chunkPos, int blockID)
    {
        BlockDef definition     = BlockDefManager.GetBlockDef(blockID);
        Chunk    chunk          = new Chunk(world, chunkPos);
        Position globalChunkPos = chunkPos.MultAll(CHUNK_SIZE);

        int x, y, z;

        for (x = 0; x < CHUNK_SIZE; x++)
        {
            for (y = 0; y < CHUNK_SIZE; y++)
            {
                for (z = 0; z < CHUNK_SIZE; z++)
                {
                    chunk.Blocks[x, y, z] = new Block(definition, globalChunkPos.Add(x, y, z), chunk);
                }
            }
        }

        if (definition.BlockType == BlockDef.TYPE_FLUID)
        {
            for (x = 0; x < CHUNK_SIZE; x++)
            {
                for (y = 0; y < CHUNK_SIZE; y++)
                {
                    for (z = 0; z < CHUNK_SIZE; z++)
                    {
                        chunk.fluids.Add(new Fluid(chunk.Blocks[x, y, z]));
                    }
                }
            }
        }

        return(chunk);
    }
Beispiel #4
0
    /// <summary>
    /// Remplace le bloc présent aux coordonées indiquées.
    /// </summary>
    public bool SetLocalBlock(int id, Position localBlockPos)
    {
        if (!IsValid(localBlockPos))
        {
            return(false);
        }

        BlockDef definition = BlockDefManager.GetBlockDef(id);

        if (definition == null)
        {
            return(false);
        }

        Block block = Blocks[localBlockPos.X, localBlockPos.Y, localBlockPos.Z];

        if (block.Definition.BlockType == BlockDef.TYPE_FLUID)
        {
            RemoveFluid(block);
        }

        block.Definition = definition;

        if (definition.BlockType == BlockDef.TYPE_FLUID)
        {
            fluids.Add(new Fluid(block));
        }

        altered = true;
        RecalculateMesh();

        return(true);
    }
Beispiel #5
0
    private static void SetBlockOreGen(Chunk chunk)
    {
        for (int x = 0; x < CHUNK_SIZE; x++)
        {
            for (int y = 0; y < CHUNK_SIZE; y++)
            {
                for (int z = 0; z < CHUNK_SIZE; z++)
                {
                    if (chunk.Blocks[x, y, z].ID != Block.AIR_BLOCK_ID)
                    {
                        if (Utils.rand.Next(1, 100) < 35)
                        {
                            return;
                        }

                        BlockDef ore = BlockDefManager.RandomBlock(BlockDef.TYPE_ORE);
                        chunk.Blocks[x, y, z].Definition = ore;

                        int gen = 50;

                        //down
                        SetBlockWithProbability(chunk, new Position(x + 1, y - 1, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y - 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y - 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y - 1, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y - 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y - 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y - 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y - 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y - 1, z + 1), ore, gen);

                        //up
                        SetBlockWithProbability(chunk, new Position(x + 1, y + 1, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y + 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y + 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y + 1, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y + 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y + 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y + 1, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y + 1, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y + 1, z + 1), ore, gen);

                        //sides
                        SetBlockWithProbability(chunk, new Position(x + 1, y, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y, z + 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x - 1, y, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x + 1, y, z), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y, z - 1), ore, gen);
                        SetBlockWithProbability(chunk, new Position(x, y, z + 1), ore, gen);
                    }
                }
            }
        }
    }
Beispiel #6
0
        private void t()
        {
            string fname            = "E:\\masData\\Mas二期投影结果展示\\FY3A_VIRRX_GBAL_L1_20110322_0525_1000M_MS.ldf";
            IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider;

            BlockDef[]          blocks = new BlockDef[] { new BlockDef("DXX", 74.0, 33.0, 10.0) };
            RasterClipProcesser s      = new RasterClipProcesser();

            IRasterDataProvider[] outs = s.Clip(prd, blocks, 50, "LDF", "E:\\masData\\Clip", null);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the translated code for the grammar structure.
        /// </summary>
        /// <returns>The translated code for the grammar structure.</returns>
        public ScriptTuple Translate(TranslationContext context)
        {
            BlockDef definition = new BlockDef
            {
                Spec   = GetInternalName(),
                Atomic = Atomic
            };

            // Add parameters
            foreach (ParamDeclaration paramDeclaration in Params)
            {
                definition.InputNames.Add(paramDeclaration.Name);
                definition.DefaultValues.Add(paramDeclaration.Type.GetDefault());
            }

            // Add hidden stack parameters
            definition.InputNames.Add(Settings.StackRefParam);
            definition.DefaultValues.Add(0);
            definition.InputNames.Add(Settings.StackOffsetParam);
            definition.DefaultValues.Add(0);

            // Create script tuple
            ScriptTuple script = new ScriptTuple();

            script.Blocks.Add(definition);

            // Create translation context
            Scope scope = new Scope(this, Unsafe);
            TranslationContext newContext = new TranslationContext(scope, context);

            // Translate blocks
            foreach (IStatement statement in Statements)
            {
                foreach (Block block in statement.Translate(newContext))
                {
                    script.Blocks.Add(block);
                }
            }

            // Clean up scope (if necessary)
            IStatement lastStatement = Statements.LastOrDefault();

            if (!(lastStatement is ReturnStmt || lastStatement is ForeverLoop))
            {
                foreach (Block block in scope.CreateCleanUp())
                {
                    script.Blocks.Add(block);
                }
            }

            return(script);
        }
Beispiel #8
0
    /// <summary>
    /// Ajoute un nouveau bloc au registre des définitions.
    /// </summary>
    public static bool AddBlockDef(BlockDef definition)
    {
        if (blockDefs.ContainsKey(definition.Id))
        {
            return(false);
        }
        else
        {
            blockDefs.Add(definition.Id, definition);
        }

        return(true);
    }
Beispiel #9
0
    private static void SetBlockWithProbability(Chunk chunk, Position position, BlockDef definition, int percent)
    {
        if (!IsValid(position))
        {
            return;
        }

        if (chunk.Blocks[position.X, position.Y, position.Z].ID != Block.AIR_BLOCK_ID)
        {
            if (Utils.rand.Next(1, 100) > percent)
            {
                chunk.Blocks[position.X, position.Y, position.Z].Definition = definition;
            }
        }
    }
Beispiel #10
0
    /// <summary>
    /// Remplace les blocs présents entre les deux coordonées locales indiquées.
    /// </summary>
    public bool SetLocalBlockBatch(int id, Position first, Position second)
    {
        if (!IsValid(first, second))
        {
            return(false);
        }

        BlockDef newDef = BlockDefManager.GetBlockDef(id);

        if (newDef == null)
        {
            return(false);
        }

        Position.Smooth(first, second);

        for (int x = first.X; x <= second.X; x++)
        {
            for (int y = first.Y; y <= second.Y; y++)
            {
                for (int z = first.Z; z <= second.Z; z++)
                {
                    Block block = Blocks[x, y, z];
                    if (block.Definition.BlockType == BlockDef.TYPE_FLUID)
                    {
                        RemoveFluid(block);
                    }

                    block.Definition = newDef;
                    if (newDef.BlockType == BlockDef.TYPE_FLUID)
                    {
                        fluids.Add(new Fluid(block));
                    }
                }
            }
        }

        altered = true;
        RecalculateMesh();

        return(true);
    }
Beispiel #11
0
 public override void Execute()
 {
     try
     {
         base.Execute();
         RasterClip s = new RasterClip();
         BlockDef[] envelopes;
         string     inputFilename = TryGetInfoFromActiveView(out envelopes);
         string     outdir        = Path.GetDirectoryName(inputFilename);
         if (string.IsNullOrWhiteSpace(inputFilename) || envelopes == null || envelopes.Length == 0 || envelopes.Length == 1)
         {
             frmImageClip frm = new frmImageClip(_smartSession);
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 BlockDef outEnvelope;
                 Size     size;
                 frm.GetArgs(out outEnvelope, out size, out outdir, out inputFilename);
                 envelopes = new BlockDef[] { outEnvelope };
             }
             else
             {
                 return;
             }
         }
         List <BlockDef> blockList = new List <BlockDef>();
         for (int i = 0; i < envelopes.Length; i++)
         {
             blockList.Add(envelopes[i]);
         }
         string[] put = s.RasterClipT(inputFilename, blockList.ToArray(), outdir, _smartSession.ProgressMonitorManager.DefaultProgressMonitor, "Clip");
         for (int i = 0; i < put.Length; i++)
         {
             OpenFileToWindows(put[i]);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Beispiel #12
0
    /// <summary>
    /// Construit une face d'un block du chunk.
    /// </summary>
    private void BuildFace(BlockDef definition, Vector3 corner, Vector3 up, Vector3 right, bool reversed, List <Vector3> verts, List <Vector2> uvs, List <int> tris, bool applyScale = false)
    {
        int index = verts.Count;

        if (applyScale)
        {
            up *= definition.Scale;
        }

        verts.Add(corner);
        verts.Add(corner + up);
        verts.Add(corner + up + right);
        verts.Add(corner + right);

        Rect rect = definition.UvRect;

        uvs.Add(new Vector2(rect.xMin, rect.yMin));
        uvs.Add(new Vector2(rect.xMin, rect.yMax));
        uvs.Add(new Vector2(rect.xMax, rect.yMax));
        uvs.Add(new Vector2(rect.xMax, rect.yMin));

        if (reversed)
        {
            tris.Add(index + 0);
            tris.Add(index + 1);
            tris.Add(index + 2);
            tris.Add(index + 2);
            tris.Add(index + 3);
            tris.Add(index + 0);
        }
        else
        {
            tris.Add(index + 1);
            tris.Add(index + 0);
            tris.Add(index + 2);
            tris.Add(index + 3);
            tris.Add(index + 2);
            tris.Add(index + 0);
        }
    }
Beispiel #13
0
 public void SetBlockDef(BlockDef blockDef)
 {
     BlockDef = blockDef;
     SpriteRenderer.sprite = blockDef.Sprite;
 }
Beispiel #14
0
 public Block(BlockDef definition, Position globalPosition, Chunk parent)
 {
     Definition  = definition;
     ParentChunk = parent;
     Position    = globalPosition;
 }
Beispiel #15
0
    public static Chunk LoadChunk(World world, Position chunkPos)
    {
        if (!Directory.Exists(world.SaveDir))
        {
            return(null);
        }

        string filePath = world.SaveDir + "[" + chunkPos.X + "." + chunkPos.Y + "." + chunkPos.Z + "].chunk";

        if (!File.Exists(filePath))
        {
            return(CreateChunk(world, chunkPos));
        }

        Chunk    newChunk       = new Chunk(world, chunkPos);
        Position globalChunkPos = chunkPos.MultAll(CHUNK_SIZE);

        using (var reader = new BinaryReader(File.Open(filePath, FileMode.Open)))
        {
            int  x = 0, y = 0, z = 0, len;
            bool filled = false;
            while (!filled)
            {
                len = reader.ReadInt32();
                BlockDef definition = BlockDefManager.GetBlockDef(reader.ReadInt32());

                while (len-- > 0)
                {
                    newChunk.Blocks[x, y, z] = new Block(definition, globalChunkPos.Add(x, y, z), newChunk);

                    if (definition.BlockType == BlockDef.TYPE_FLUID)
                    {
                        newChunk.fluids.Add(new Fluid(newChunk.Blocks[x, y, z]));
                    }

                    if (z >= 15)
                    {
                        z = 0;
                        if (y >= 15)
                        {
                            y = 0;
                            if (x >= 15)
                            {
                                filled = true;
                                break;
                            }
                            ++x;
                        }
                        else
                        {
                            ++y;
                        }
                    }
                    else
                    {
                        ++z;
                    }
                }
            }
        }

        newChunk.altered = false;
        return(newChunk);
    }
Beispiel #16
0
 public virtual void CreateBlock(BlockDef block)
 {
 }
Beispiel #17
0
        public void Do(string xmlArg)
        {
            BlockArg inArg = BlockArg.ParseXml(xmlArg);

            string outDir = inArg.OutputDir;
            IRasterDataProvider inRaster = null;
            OutputArg           outArg   = new OutputArg();

            try
            {
                CheckArg(inArg);
                BlockDef[] blocks = GenericBlock(inArg);
                inRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider;
                DataIdentify dataIdentify = inRaster.DataIdentify;
                outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                outArg.Satellite          = dataIdentify.Satellite;
                outArg.Sensor             = dataIdentify.Sensor;
                outArg.Level              = "L1";
                outArg.ProjectionIdentify = ParseProjectionIdentify(Path.GetFileName(inArg.InputFilename));
                outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                List <FileArg> fileArgs   = new List <FileArg>();
                string         retMessage = "";
                for (int blockIndex = 0; blockIndex < blocks.Length; blockIndex++)
                {
                    BlockDef blockDef = blocks[blockIndex];
                    if (blocks == null)
                    {
                        continue;
                    }
                    CoordEnvelope       oEnvelope       = inRaster.CoordEnvelope;
                    CoordEnvelope       tEnvelope       = blockDef.ToEnvelope();
                    IRasterDataProvider outBlockRasters = null;
                    try
                    {
                        if (!IsInteractived(oEnvelope, tEnvelope))
                        {
                            continue;
                        }
                        double validPercent = 0;
                        outBlockRasters = _rasterClipProcess.Clip(inRaster, blockDef, 100, "LDF", outDir, new Action <int, string>(OnProgress), out validPercent);
                        if (outBlockRasters == null)
                        {
                            continue;
                        }
                        if (validPercent == 0)
                        {
                            string filename = outBlockRasters.fileName;
                            outBlockRasters.Dispose();
                            outBlockRasters = null;
                            TryDeleteLdfFiles(filename);
                            continue;
                        }
                        IRasterDataProvider outfileRaster = outBlockRasters;
                        string        overViewFilename    = OverViewHelper.OverView(outfileRaster, _blockPngSize);
                        FileArg       fileArg             = new FileArg();
                        CoordEnvelope env = null;
                        float         resolutionX;
                        float         resolutionY;
                        env                    = outfileRaster.CoordEnvelope;
                        resolutionX            = outfileRaster.ResolutionX;
                        resolutionY            = outfileRaster.ResolutionY;
                        fileArg.OutputFilename = Path.GetFileName(outfileRaster.fileName);
                        fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                        fileArg.ExtendFiles    = Path.ChangeExtension(Path.GetFileName(outfileRaster.fileName), "hdr");
                        fileArg.Envelope       = new PrjEnvelopeItem(blockDef.Name, env == null ? null : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY));
                        fileArg.ResolutionX    = resolutionX.ToString();
                        fileArg.ResolutionY    = resolutionY.ToString();
                        fileArg.Length         = new FileInfo(outfileRaster.fileName).Length;
                        fileArgs.Add(fileArg);
                    }
                    catch (Exception ex)
                    {
                        retMessage += (ex.Message + " Block:" + blockDef.Name + tEnvelope == null ? "" : tEnvelope.ToString());
                    }
                    finally
                    {
                        if (outBlockRasters != null)
                        {
                            if (outBlockRasters != null)
                            {
                                outBlockRasters.Dispose();
                            }
                        }
                    }
                }
                outArg.OutputFiles = fileArgs.ToArray();
                outArg.LogLevel    = "info";
                if (string.IsNullOrWhiteSpace(retMessage))
                {
                    outArg.LogInfo = "分幅成功";
                }
                else
                {
                    outArg.LogInfo = retMessage;
                }
            }
            catch (Exception ex)
            {
                LogFactory.WriteLine(ex);
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
                if (inRaster != null)
                {
                    inRaster.Dispose();
                }
            }
        }
Beispiel #18
0
 public static int AddBlockDef(BlockDef def)
 {
     BlockDefs.Add(def);
     return(BlockDefs.Count - 1);
 }
Beispiel #19
0
    private void DrawBlock(int x, int y, int z, int block)
    {
        Vector3 point   = new Vector3(x, y, z);
        Vector3 right   = new Vector3(1, 0, 0);
        Vector3 left    = new Vector3(-1, 0, 0);
        Vector3 forward = new Vector3(0, 0, 1);
        Vector3 back    = new Vector3(0, 0, -1);
        Vector3 up      = new Vector3(0, 1, 0);
        Vector3 down    = new Vector3(0, -1, 0);

        Color    color    = c_dark;
        BlockDef blockDef = World.currentWorld.blockDefs[block];

        int      matIndex = blockDef.materialIndex;
        Material mat      = World.currentWorld.materials[matIndex];

        if (materials.IndexOf(mat) == -1)
        {
            materials.Add(mat);
        }

        matIndex = materials.IndexOf(mat);

        var bottomBlock = GetBlockAt(x, y - 1, z);
        var topBlock    = GetBlockAt(x, y + 1, z);
        var leftBlock   = GetBlockAt(x - 1, y, z);
        var rightBlock  = GetBlockAt(x + 1, y, z);
        var frontBlock  = GetBlockAt(x, y, z + 1);
        var backBlock   = GetBlockAt(x, y, z - 1);

        if (IsAirBlock(point + down) || (World.currentWorld.blockDefs[bottomBlock].isTransparent && block != bottomBlock))
        {
            DrawFace(point + right, left, back, block, 0, color, matIndex); // bottom
        }
        if (IsAirBlock(point + up) || (World.currentWorld.blockDefs[topBlock].isTransparent && block != topBlock))
        {
            if (block == World.waterDef && topBlock != -1 && topBlock != World.waterDef)                   // is water
            {
                DrawFace(point + new Vector3(0.0f, 0.875f, 0.0f), right, back, block, 1, color, matIndex); // top
            }
            else
            {
                DrawFace(point + up, right, back, block, 1, color, matIndex); // top
            }
        }
        if (IsAirBlock(point + right) || (World.currentWorld.blockDefs[rightBlock].isTransparent && block != rightBlock))
        {
            if (block == World.waterDef && rightBlock != -1 && rightBlock != World.waterDef)               // is water
            {
                DrawFace(point + right, back, new Vector3(0.0f, 0.875f, 0.0f), block, 2, color, matIndex); // right
            }
            else
            {
                DrawFace(point + right, back, up, block, 2, color, matIndex); // right
            }
        }
        if (IsAirBlock(point + left) || (World.currentWorld.blockDefs[leftBlock].isTransparent && block != leftBlock))
        {
            if (block == World.waterDef && leftBlock != -1 && leftBlock != World.waterDef)                   // is water
            {
                DrawFace(point + back, forward, new Vector3(0.0f, 0.875f, 0.0f), block, 3, color, matIndex); // left
            }
            else
            {
                DrawFace(point + back, forward, up, block, 3, color, matIndex); // left
            }
        }
        if (IsAirBlock(point + forward) || (World.currentWorld.blockDefs[frontBlock].isTransparent && block != frontBlock))
        {
            if (block == World.waterDef && frontBlock != -1 && frontBlock != World.waterDef)        // is water
            {
                DrawFace(point, right, new Vector3(0.0f, 0.875f, 0.0f), block, 4, color, matIndex); // front
            }
            else
            {
                DrawFace(point, right, up, block, 4, color, matIndex); // front
            }
        }
        if (IsAirBlock(point + back) || (World.currentWorld.blockDefs[backBlock].isTransparent && block != backBlock))
        {
            if (block == World.waterDef && backBlock != -1 && backBlock != World.waterDef)                        // is water
            {
                DrawFace(point + right + back, left, new Vector3(0.0f, 0.875f, 0.0f), block, 5, color, matIndex); // back
            }
            else
            {
                DrawFace(point + right + back, left, up, block, 5, color, matIndex); // back
            }
        }
    }
Beispiel #20
0
        /// <summary>
        /// Gets the translated code for the grammar structure.
        /// </summary>
        /// <returns>The translated code for the grammar structure.</returns>
        public ScriptTuple[] Translate(TranslationContext context)
        {
            // Create event scope
            Scope newScope = new Scope(this, Unsafe);

            string internalName = $"{newScope.ID}: {Name} %n %n"; // Internal name used for custom block

            ScriptTuple eventHandler = new ScriptTuple();

            switch (Name)
            {
            case "GreenFlag":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenGreenFlagClicked));
                break;

            case "KeyPressed":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenKeyPressed, Parameter.Translate(context)));
                break;

            case "Clicked":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenSpriteClicked));
                break;

            case "BackdropChanged":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenBackdropSwitchesTo, Parameter.Translate(context)));
                break;

            case "MessageReceived":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenIReceive, Parameter.Translate(context)));
                break;

            case "Cloned":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenSpriteCloned));
                break;

            case "TimerGreaterThan":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenSensorGreaterThan, "timer",
                                                  Parameter.Translate(context)));
                break;

            case "LoudnessGreaterThan":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenSensorGreaterThan, "loudness",
                                                  Parameter.Translate(context)));
                break;

            case "VideoMotionGreaterThan":
                eventHandler.Blocks.Add(new Block(BlockSpecs.WhenSensorGreaterThan, "video motion",
                                                  Parameter.Translate(context)));
                break;

            default:
                context.ErrorList.Add(new CompilerError($"Event '{Name}' is not supported", ErrorType.NotDefined, ErrorToken, FileName));
                return(new ScriptTuple[2]);
            }

            // Increment CurrentStack
            eventHandler.Blocks.Add(new Block(BlockSpecs.ChangeVarBy, Settings.CurrentStackVar, 1));
            // Clear (or create) stack
            eventHandler.Blocks.Add(new Block(BlockSpecs.DeleteItemOfList, "all",
                                              new Block(BlockSpecs.GetVariable, Settings.CurrentStackVar)));
            // Call internal method
            eventHandler.Blocks.Add(new Block(BlockSpecs.CustomMethodCall, internalName,
                                              new Block(BlockSpecs.GetVariable, Settings.CurrentStackVar), 0));
            // Decrement CurrentStack
            eventHandler.Blocks.Add(new Block(BlockSpecs.ChangeVarBy, Settings.CurrentStackVar, -1));

            // Create internal method
            ScriptTuple internalMethod = new ScriptTuple();

            BlockDef definition = new BlockDef
            {
                Spec   = internalName,
                Atomic = Atomic
            };

            definition.InputNames.Add(Settings.StackRefParam);
            definition.DefaultValues.Add(DataType.Number.GetDefault());
            definition.InputNames.Add(Settings.StackOffsetParam);
            definition.DefaultValues.Add(DataType.Number.GetDefault());

            internalMethod.Blocks.Add(definition);

            // Translate event code
            TranslationContext newContext = new TranslationContext(newScope, context);

            foreach (IStatement statement in Statements)
            {
                foreach (Block block in statement.Translate(newContext))
                {
                    internalMethod.Blocks.Add(block);
                }
            }

            // Clean up scope (if necessary)
            IStatement lastStatement = Statements.LastOrDefault();

            if (!(lastStatement is ReturnStmt || lastStatement is ForeverLoop))
            {
                foreach (Block block in newScope.CreateCleanUp())
                {
                    internalMethod.Blocks.Add(block);
                }
            }

            // Return results
            return(new[]
            {
                eventHandler,
                internalMethod
            });
        }