Exemplo n.º 1
0
        public IEnumerable <ITagSpan <BrightScriptTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();
                int startPos = containingLine.Start.Position;
                var line     = containingLine.GetText();

                var scanner = new ScannerColor();
                scanner.SetSource(line, 0);

                int token;

                while ((token = scanner.yylex()) != (int)TokensColor.EOF)
                {
                    if (_bsTypes.ContainsKey(token))
                    {
                        var tokenSpan = new SnapshotSpan(curSpan.Snapshot, new Span(startPos + scanner.GetPos(), scanner.yyleng));
                        if (tokenSpan.IntersectsWith(curSpan))
                        {
                            yield return(new TagSpan <BrightScriptTokenTag>(tokenSpan, new BrightScriptTokenTag(_bsTypes[token])));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
    private void Initialize()
    {
        _table = Rnd.Range(0, 8);
        _mode  = Rnd.Range(0, 2) != 0 ? ScanningMode.TopToBottom : ScanningMode.BottomToTop;

        var validCells = Enumerable.Range(0, 49).Except(new[] { 0, 6, 42, 48, 24 }).ToArray();

        _curCell      = validCells.PickRandom();
        _solutionCell = validCells.PickRandom();

        _directions = ((ButtonDirection[])Enum.GetValues(typeof(ButtonDirection))).Shuffle();
        var similarCells = validCells.Where(c => _rules.Tables[_table][c] == _rules.Tables[_table][_solutionCell]);

        _scannerColor =
            _solutionCell == similarCells.Min() ? ScannerColor.Red :
            _solutionCell == similarCells.Max() ? ScannerColor.Blue :
            _solutionCell % 7 == similarCells.Select(c => c % 7).Min() ? ScannerColor.White : ScannerColor.Yellow;

        Debug.LogFormat(@"[Not X-Ray #{0}] Buttons 1–4 go: {1}", _moduleId, _directions.Join(", "));
        Debug.LogFormat(@"[Not X-Ray #{0}] You’re in table #{1}, starting position {2}{3}.", _moduleId, _table + 1, (char)('A' + _curCell % 7), _curCell / 7 + 1);
        Debug.LogFormat(@"[Not X-Ray #{0}] Scanning {1}.", _moduleId, _mode == ScanningMode.TopToBottom ? "top to bottom" : "bottom to top");

        _isMazeStage = false;
        StartLights(new[] { _rules.Tables[_table][_curCell] }, _mode, ScannerColor.Green, 2f);
    }
Exemplo n.º 3
0
    private IEnumerator RunLights(SymbolInfo[] icons, ScanningMode mode, ScannerColor color, float delayBetweenRepeats = 0)
    {
        const int _iconWidth  = 180;
        const int _iconHeight = 180;

        const int   _ulongsPerScanline = (_iconWidth + 63) / 64;
        const float _pixelWidth        = 0.138f / _iconWidth;
        const float _secondsPerIcon    = 4f;

        foreach (var scanLight in ScanLights)
        {
            scanLight.GetComponent <MeshRenderer>().sharedMaterial = ScannerColors[(int)color];
        }

        var prevScanline = -1;

        while (true)
        {
            int curScanline;
            switch (mode)
            {
            case ScanningMode.TopToBottom:
                curScanline = Mathf.FloorToInt((Time.time % (icons.Length * _secondsPerIcon + delayBetweenRepeats)) * (_iconHeight / _secondsPerIcon));
                break;

            case ScanningMode.BottomToTop:
                curScanline = Mathf.FloorToInt((icons.Length * _secondsPerIcon - Time.time % (icons.Length * _secondsPerIcon + delayBetweenRepeats)) * (_iconHeight / _secondsPerIcon));
                break;

            default:        // alternating
                var e = Time.time % (2 * icons.Length * _secondsPerIcon + 2 * delayBetweenRepeats);
                curScanline = e > icons.Length * _secondsPerIcon
                        ? Mathf.FloorToInt((2 * icons.Length * _secondsPerIcon - e - delayBetweenRepeats) * (_iconHeight / _secondsPerIcon))
                        : Mathf.FloorToInt((e - delayBetweenRepeats) * (_iconHeight / _secondsPerIcon));
                break;
            }

            if (curScanline < icons.Length * _iconHeight && curScanline > 0 && curScanline != prevScanline)
            {
                var icon          = RawBits.Icons[icons[curScanline / _iconHeight].Index];
                var scanlineStart = (icons[curScanline / _iconHeight].Flipped ? _iconHeight - 1 - (curScanline % _iconHeight) : curScanline % _iconHeight) * _ulongsPerScanline;
                var lightIx       = 0;
                int?startX        = null;
                for (int x = 0; x <= _iconWidth; x++)
                {
                    var curBit = x < _iconWidth && (icon[scanlineStart + x / 64] & (1UL << (x % 64))) != 0;
                    if (curBit && startX == null)
                    {
                        startX = x;
                    }
                    else if (!curBit && startX != null)
                    {
                        ScanLights[lightIx].SetActive(true);
                        ScanLights[lightIx].transform.localScale    = new Vector3((x - startX.Value) * _pixelWidth, 1, 1);
                        ScanLights[lightIx].transform.localPosition = new Vector3((x + startX.Value - _iconWidth) * .5f * _pixelWidth, 0, 0);
                        lightIx++;
                        startX = null;
                    }
                }
                for (int i = lightIx; i < ScanLights.Length; i++)
                {
                    ScanLights[i].SetActive(false);
                }
            }

            prevScanline = curScanline;
            yield return(null);
        }
    }
Exemplo n.º 4
0
 protected void StartLights(SymbolInfo[] icons, ScanningMode mode, ScannerColor color, float delayBetweenRepeats = 0)
 {
     StopLights();
     _coroutine = StartCoroutine(RunLights(icons, mode, color, delayBetweenRepeats));
 }