Example #1
0
    void Step()
    {
        Active = false;
        try
        {
            if (compiler == null)
            {
                compiler = Parser.Parse(Input).GetEnumerator();
                tracer   = new LineTracer();
            }

            if (compiler.MoveNext())
            {
                int    pc      = compiler.Current;
                String command = Input[pc].ToString();
                if (!autoStep)
                {
                    Output = SourceWithPc(pc);
                }
                if (tracer.Step(command, sbStep.Value, Math.PI * sbAng.Value / 180))
                {
                    DrawPath();
                }
            }
            else
            {
                Reset();
            }
        }
        catch (Parser.SyntaxException exception)
        {
            Reset(exception.Message + "\n" + SourceWithPc(exception.Pc));
        }
    }
Example #2
0
 void Reset(String message = "Ready")
 {
     autoStep = false;
     compiler = null;
     Output   = message;
     Active   = true;
     tracer   = null;
 }
Example #3
0
        /// <summary>
        /// Compile the map instance.
        /// </summary>
        /// <param name="fileName">Output file name</param>
        /// <param name="header">Map header to be included</param>
        public void Compile(string fileName, MapHeader header)
        {
            FOCommon.Utils.Log("Compiling " + fileName + " using preset '" + Config.CurrentPreset + "'.");
            Preset p = PresetsManager.GetPreset(Config.CurrentPreset);

            if (p == null)
            {
                FOCommon.Utils.Log("Error: preset '" + Config.CurrentPreset + "' not found.");
                throw new CompilerException("internal: preset '" + Config.CurrentPreset + "' not found");
            }

            FOMap m = new FOMap();

            m.Header = header;

            header.MaxHexX  = (ushort)(2 * Config.BigTileEdgeSize * Width);
            header.MaxHexY  = (ushort)(2 * Config.BigTileEdgeSize * Height);
            header.Version  = 4;
            header.WorkHexX = (ushort)(header.MaxHexX / 2);
            header.WorkHexY = (ushort)(header.MaxHexY / 2);

            // tiles
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    compileTile(m, p, x, y);
                }
            }

            // scrollblockers
            if (scrollBlockers.Count > 3)
            {
                for (int i = 2; i < scrollBlockers.Count; i++)
                {
                    Pair <int, int> from = scrollBlockers[i - 1];
                    Pair <int, int> to   = scrollBlockers[i];
                    LineTracer.TraceHex(new ScrollblockersPlacer(from, to, this, m));
                }
                LineTracer.TraceHex(new ScrollblockersPlacer(scrollBlockers[scrollBlockers.Count - 1], scrollBlockers[1], this, m));
            }

            FOMapParser parser = new FOMapParser(fileName);

            parser.Map = m;
            parser.Save();
            FOCommon.Utils.Log("Compilation successful.");
        }