Esempio n. 1
0
        public RenderContract[] GetRenderers()
        {
            List <RenderContract> retCtrc = new List <RenderContract>();
            bool updateEntBuf             = false;

            foreach (BaseObject b in goList)
            {
                RenderComp r = b.GetComponent <RenderComp>();
                Transform  t = b.GetComponent <Transform>();
                if (r != null && r.Enabled)
                {
                    retCtrc.Add(new RenderContract(t, r));
                    if (!entityBuffer.Contains(b))
                    {
                        if (!b.HasComponent <WorldTile>())
                        {
                            entityBuffer.Add(b);
                        }
                        if (!updateEntBuf)
                        {
                            updateEntBuf = true;
                        }
                    }
                }
            }
            if (updateEntBuf)
            {
                if (OnNewEntity != null)
                {
                    OnNewEntity.Invoke(entityBuffer.ToArray());
                }
            }

            return(retCtrc.ToArray());
        }
Esempio n. 2
0
        private void DiffUpdate(object sender, FileSystemEventArgs e)
        {
            var path = e.FullPath;

            if (!IncludeFilters.Contains(path))
            {
                _logger.LogError($"IncludeFilters: {path}");
                return;
            }

            //foreach (var item in IncludeFilters) {
            //	watcher.Filters.Add(item);
            //}

            foreach (var dir in ExcludeDirectories)
            {
                if (path.Contains(dir))
                {
                    _logger.LogWarning($"Build file: {path}");
                    return;
                }
            }

            if (!File.Exists(path))
            {
                _logger.LogWarning($"File not found: {path}");
                return;
            }

            using var data = File.Open(path, FileMode.Open);

            if (data.Length > 1_048_576)               // 1 mb
            {
                _logger.LogWarning($"File {path} is Larger than 1MB: {data.Length}");
                return;
            }

            using var reader = new StreamReader(data);
            var current = reader.ReadToEnd();

            if (string.IsNullOrWhiteSpace(current))
            {
                _logger.LogError($"Empty file: {path}");
                return;
            }

            if (_diffs.FindById(path) is CodeWatcherEntity codeWatcherEntity)
            {
                // do diff
                var diffs = _differ.diff_main(codeWatcherEntity.Latest, current);
                _differ.diff_cleanupSemantic(diffs);

                var final = diffs.Where(x => x.Operation != Operation.EQUAL)
                            .Where(x => !string.IsNullOrWhiteSpace(x.Text));

                if (!final.Any())
                {
                    return;                     // all content equal
                }

                //updates
                codeWatcherEntity.Latest = current;
                codeWatcherEntity.Diffs.AddRange(final);

                //save
                var html = _differ.diff_prettyHtml(final.ToList());
                OnNewDiff?.Invoke(this, html);
                _logger.LogInformation(html);
                _diffs.Update(codeWatcherEntity);
            }
            else
            {
                // new
                codeWatcherEntity = new CodeWatcherEntity {
                    Latest = current,
                    Path   = path
                };

                // add
                OnNewEntity?.Invoke(this, current);
                _logger.LogInformation($"Added new file for tracking: {path}");
                _diffs.Insert(codeWatcherEntity);
                _diffs.EnsureIndex(x => x.Path);
            }

            _db.Checkpoint();
        }