예제 #1
0
        public override void OnCreated(IThreading threading)
        {
            Console.Message("loading auto color monitor");
            Console.Message("initializing colors");
            RandomColor.Initialize();

            Console.Message("loading current config");
            var config = Configuration.LoadConfig();

            _colorStrategy  = SetColorStrategy(config.ColorStrategy);
            _namingStrategy = SetNamingStrategy(config.NamingStrategy);
            _usedColors     = new List <Color32>();

            Console.Message("Found color strategy of " + config.ColorStrategy);
            Console.Message("Found naming strategy of " + config.NamingStrategy);

            _initialized = true;
            base.OnCreated(threading);
        }
예제 #2
0
        public override void OnCreated(IThreading threading)
        {
            Logger.Message("===============================");
            Logger.Message("Initializing auto color monitor");
            Logger.Message("Initializing colors");
            GenericNames.Initialize();

            Logger.Message("Loading current config");
            _config         = Configuration.Instance;
            _colorStrategy  = SetColorStrategy(_config.ColorStrategy);
            _namingStrategy = SetNamingStrategy(_config.NamingStrategy);
            _usedColors     = new NullUsedColors();

            Logger.Message("Found color strategy of " + _config.ColorStrategy);
            Logger.Message("Found naming strategy of " + _config.NamingStrategy);

            _initialized = true;
            Instance     = this;

            Logger.Message("done creating");
            base.OnCreated(threading);
        }
        public override void OnCreated(IThreading threading)
        {
            logger.Message("===============================");
            logger.Message("Initializing auto color monitor");
            logger.Message("Initializing colors");
            RandomColor.Initialize();
            CategorisedColor.Initialize();
            GenericNames.Initialize();

            logger.Message("Loading current config");
            _config = Configuration.Instance;
            _colorStrategy = SetColorStrategy(_config.ColorStrategy);
            _namingStrategy = SetNamingStrategy(_config.NamingStrategy);
            _usedColors = new List<Color32>();

            logger.Message("Found color strategy of " + _config.ColorStrategy);
            logger.Message("Found naming strategy of " + _config.NamingStrategy);

            _initialized = true;

            logger.Message("done creating");
            base.OnCreated(threading);
        }
예제 #4
0
        // TODO: make this whole thing a coroutine?
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            TransportManager  theTransportManager;
            SimulationManager theSimulationManager;

            TransportLine[] lines;

            try
            {
                //Digest changes
                if (_config.UndigestedChanges)
                {
                    Logger.Message("Applying undigested changes");
                    _colorStrategy            = SetColorStrategy(_config.ColorStrategy);
                    _namingStrategy           = SetNamingStrategy(_config.NamingStrategy);
                    _config.UndigestedChanges = false;
                }

                if (_initialized == false)
                {
                    return;
                }

                // try and limit how often we are scanning for lines. this ain't that important
                if (_nextUpdateTime >= DateTimeOffset.Now)
                {
                    return;
                }

                if (!Singleton <TransportManager> .exists || !Singleton <SimulationManager> .exists)
                {
                    return;
                }

                theTransportManager  = Singleton <TransportManager> .instance;
                theSimulationManager = Singleton <SimulationManager> .instance;
                lines = theTransportManager.m_lines.m_buffer;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                return;
            }

            if (theSimulationManager.SimulationPaused)
            {
                return;
            }

            var locked = false;

            try
            {
                _nextUpdateTime = DateTimeOffset.Now.AddSeconds(Constants.UpdateIntervalSeconds);

                locked = Monitor.TryEnter(lines, SimulationManager.SYNCHRONIZE_TIMEOUT);

                if (!locked)
                {
                    return;
                }

                _usedColors = UsedColors.FromLines(lines);

                for (ushort i = 0; i < lines.Length - 1; i++)
                {
                    ProcessLine(i, lines[i], false, theSimulationManager, theTransportManager);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            finally
            {
                if (locked)
                {
                    Monitor.Exit(lines);
                }
            }
        }
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            //Digest changes
            if (_config.UndigestedChanges == true) {
                logger.Message("Applying undigested changes");
                _colorStrategy = SetColorStrategy(_config.ColorStrategy);
                _namingStrategy = SetNamingStrategy(_config.NamingStrategy);
                _config.UndigestedChanges = false;
            }

            if (_initialized == false)
                return;

            // try and limit how often we are scanning for lines. this ain't that important
            if (_nextUpdateTime >= DateTimeOffset.Now)
                return;

            var theTransportManager = Singleton<TransportManager>.instance;
            var lines = theTransportManager.m_lines.m_buffer;

            try
            {
                _nextUpdateTime = DateTimeOffset.Now.AddSeconds(10);
                _usedColors = lines.Where(l => l.IsActive()).Select(l => l.m_color).ToList();

                for (ushort i = 0; i < theTransportManager.m_lines.m_buffer.Length - 1; i++)
                {
                    var transportLine = lines[i];
                    //logger.Message(string.Format("Starting on line {0}", i));

                    if (transportLine.m_flags == TransportLine.Flags.None)
                        continue;

                    if (!transportLine.Complete)
                        continue;

                    // only worry about fully created lines
                    if (!transportLine.IsActive() || transportLine.HasCustomName() || !transportLine.m_color.IsDefaultColor())
                        continue;

                    logger.Message(string.Format("Working on line {0}", i));

                    var instanceID = new InstanceID();
                    var lineName = theTransportManager.GetLineName(i);
                    var newName = _namingStrategy.GetName(transportLine);

                    if (!transportLine.HasCustomColor() || transportLine.m_color.IsDefaultColor())
                    {
                        var color = _colorStrategy.GetColor(transportLine, _usedColors);

                        logger.Message(string.Format("About to change line color to {0}", color));
                        transportLine.m_color = color;
                        transportLine.m_flags |= TransportLine.Flags.CustomColor;
                        theTransportManager.SetLineColor(i, color);

                        logger.Message(string.Format("Changed line color. '{0}' {1} -> {2}", lineName, theTransportManager.GetLineColor(i), color));
                    }

                    if (string.IsNullOrEmpty(newName) == false &&
                        transportLine.HasCustomName() == false) {
                        logger.Message(string.Format("About to rename line to {0}", newName));

                        transportLine.m_flags |= TransportLine.Flags.CustomName;
                        theTransportManager.SetLineName(i, newName);

                        logger.Message(string.Format("Renamed Line '{0}' -> '{1}'", lineName, newName));
                    }

                    logger.Message(string.Format("Line is now {0} and {1}",
                        theTransportManager.GetLineName(i),
                        theTransportManager.GetLineColor(i)));

                    lines[i] = transportLine;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
            }
            finally
            {
                Monitor.Exit(Monitor.TryEnter(lines));
            }
        }
예제 #6
0
 public Car(IHonkingStrategy honkingStrategy, IColorStrategy colorStrategy)
 {
     _honk  = honkingStrategy;
     _color = colorStrategy;
 }