Ejemplo n.º 1
0
        public void UserInput(string argument)
        {
            var command = argument.Split(' ');

            if (command.Length < 2)
            {
                return;
            }

            if (command[0] != "RESET")
            {
                return;
            }

            ConfigHolder.Set(PriorityConfigKey, $"{GridTerminalSystem.GetBlocks().Count()}");
            ConfigHolder.Set(NameConfigKey, Me.CubeGrid.CustomName);

            switch (command[1])
            {
            case "SAFE":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "false");
                ConfigHolder.Set(IgnorePriorityConfigKey, "true");
                ConfigHolder.Set(IgnoreNameConfigKey, "true");
                break;
            }

            case "NORMAL":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "true");
                ConfigHolder.Set(IgnorePriorityConfigKey, "false");
                ConfigHolder.Set(IgnoreNameConfigKey, "false");
                break;
            }

            case "OBSTINATE":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "true");
                ConfigHolder.Set(IgnorePriorityConfigKey, "true");
                ConfigHolder.Set(IgnoreNameConfigKey, "false");
                break;
            }

            default:
            {
                EchoManager.Print($"Template {command[1]} does not exist");
                return;
            }
            }

            EchoManager.Print($"Reset configuration to the template {command[1]}");
            ConfigHolder.Save();
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            UpdateFromConfig();

            EchoManager.AddStatusLine("NIN.NAME.STATUS", () => _status);
            EchoManager.AddStatusLine("NIN.NAME.BROADCAST", () => $"Broadcast tag: {_broadcastTag}");
            EchoManager.Print("Monitoring grid for name changes...");
            EchoManager.Print("The name is configured inside the custom data of this block.");
            EchoManager.Print("Or run one of the following commands for a default configuration:");
            EchoManager.Print("'RESET SAFE' Makes sure the name wont cause the grid to be cleaned up but otherwise does nothing.");
            EchoManager.Print("'RESET NORMAL' Sets the grid name to the stored name unless another script is on the same grid with a higher priority.");
            EchoManager.Print("'RESET OBSTINATE' Sets the grid name to the stored name. Ignores priority and has max priority.");
            EchoManager.Print("Default priority is the logic block count of the grid.");
            EchoManager.Print("Default name is whatever the grid name was on configuration reset.");
        }
Ejemplo n.º 3
0
        private IEnumerable <IMyBroadcastListener> UpdateBroadcast()
        {
            var broadcastTag = $"{Me.CubeGrid.EntityId}.NIN.NAME";

            if (_broadcastTag != broadcastTag)
            {
                IGC.UnregisterBroadcastListener(_broadcastTag);
                _broadcastTag = broadcastTag;
            }
            var broadcastListener = IGC.RegisterBroadcastListener(broadcastTag);

            yield return(null);

            IGC.SendBroadcastMessage(broadcastTag, _priority);

            yield return(null);

            while (broadcastListener.HasPendingMessage)
            {
                var message          = broadcastListener.AcceptMessage();
                var priorityReceived = -1;
                try
                {
                    priorityReceived = (int)message.Data;
                }
                catch
                {
                    EchoManager.Print($"Received an invalid message in broadcast channel: {message.Data}");
                }

                if (!_ignorePriority && priorityReceived > _priority)
                {
                    Disable();
                }

                yield return(null);
            }

            EnableIfReady();

            yield return(broadcastListener);
        }
Ejemplo n.º 4
0
 private void UpdateName()
 {
     EchoManager.Print($"Changing grid name from: '{Me.CubeGrid.CustomName}' to: '{_savedName}'");
     Me.CubeGrid.CustomName = _savedName;
 }