Esempio n. 1
0
        // Helpers
        void doDisplay()
        {
            for (int i = 0; i < displays.Count; i++)
            {
                displays[i].WriteText(echoBuilder.ToString());
            }
            for (int i = 0; i < surfaceProviders.Count; i++)
            {
                ((IMyTextSurfaceProvider)surfaceProviders[i]).GetSurface(surfaceIndices[i]).WriteText(echoBuilder.ToString());
            }

            base.Echo(echoBuilder.ToString());
        }
Esempio n. 2
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (commandLine.TryParse(argument))
            {
                Action commandAction;

                string command = commandLine.Argument(0);
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    echoBuilder.AppendLine($"Unknown command {command}");
                }
            }
            else
            {
                echoBuilder.Clear();
                echoBuilder.Append(setupBuilder.ToString());

                Action updateAction;
                if (updates.TryGetValue(currentState, out updateAction))
                {
                    updateAction();
                }

                doDisplay();
            }
        }
Esempio n. 3
0
        public void Save()
        {
            mySerializeBuilder.Clear();
            mySerializeBuilder.AppendLine(displays.Count.ToString());

            for (int i = 0; i < displays.Count; i++)
            {
                mySerializeBuilder.AppendLine(displays[i].EntityId.ToString());
            }

            mySerializeBuilder.AppendLine(surfaceProviders.Count.ToString());

            for (int i = 0; i < surfaceProviders.Count; i++)
            {
                mySerializeBuilder.AppendLine($"{surfaceProviders[i].EntityId.ToString()} {surfaceIndices[i]}");
            }

            MySave(mySerializeBuilder);

            Me.GetSurface(1).WriteText(mySerializeBuilder.ToString());
        }
Esempio n. 4
0
            public string Serialize()
            {
                SRKStringBuilder builder = new SRKStringBuilder();

                builder.Append($"{name}{{");
                for (int i = 0; i < subMenues.Count; i++)
                {
                    string v = subMenues[i].Serialize();
                    builder.Append($"{{{v.Length.ToString()}}}{v}");
                }
                builder.Append($"}}{remoteCommand}");
                return(builder.ToString());
            }
        public string JoinArguments(SRKStringBuilder builder, int start, int end)
        {
            builder.Clear();
            int termination = Math.Max(ArgumentCount - 1, end);

            for (int i = start; i <= termination; ++i)
            {
                builder.Append(myCommandLine.Items[i]);
                if (i != termination)
                {
                    builder.Append(' ');
                }
            }
            return(builder.ToString());
        }
Esempio n. 6
0
            public string GetStatus()
            {
                statusBuilder.Clear();

                statusBuilder.Append("CON: ");
                statusBuilder.Append(connector != null ? "AOK" : "LST");
                statusBuilder.Append(" | EXT: ");
                statusBuilder.Append(extender != null ? "AOK" : "LST");
                statusBuilder.Append(" | ROT: ");
                statusBuilder.Append(rotor != null ? "AOK" : "LST");
                statusBuilder.Append(" | GTS: ");
                statusBuilder.Append(gates.Count.ToString());

                statusBuilder.AppendLine();

                statusBuilder.AppendLine($"State: {state.ToString()}");

                statusBuilder.AppendLine($"Rotor: {rotor.Angle}");
                statusBuilder.AppendLine($"Target: {getWorldBoxTargetAngle()}");

                /*
                 * if (connector.Status == MyShipConnectorStatus.Connected)
                 * {
                 *  var dockedShipBoundingBox = connector.OtherConnector.CubeGrid.WorldAABB;
                 *  var dockedShipCenterDirection = dockedShipBoundingBox.Center - rotor.Top.WorldMatrix.Translation;
                 *  var myDir = Vector3D.TransformNormal(dockedShipCenterDirection, MatrixD.Transpose(rotor.Top.WorldMatrix));
                 *  myDir.Y = 0;
                 *  myDir.Normalize();
                 *  statusBuilder.AppendLine($"Debug: {myDir.X}");
                 *  statusBuilder.AppendLine($"Debug: {myDir.Z}");
                 *
                 *  statusBuilder.AppendLine();
                 *
                 *  var dirVector = new Vector3D(1, 0, 0);
                 *  var worldDirVector = Vector3D.TransformNormal(dirVector, connector.OtherConnector.WorldMatrix);
                 *  myDir = Vector3D.TransformNormal(worldDirVector, MatrixD.Transpose(rotor.Top.WorldMatrix));
                 *  statusBuilder.AppendLine($"Debug: {myDir.X}");
                 *  statusBuilder.AppendLine($"Debug: {myDir.Z}");
                 *  statusBuilder.AppendLine($"Target 2: {getWorldBoxTargetAngle()}");
                 * }*/

                return(statusBuilder.ToString());
            }
        public string SerializeManager()
        {
            SRKStringBuilder saveBuilder = new SRKStringBuilder();

            // Save my settings here

            // Save subsystem settings here
            saveBuilder.AppendLine(Subsystems.Count().ToString());
            foreach (KeyValuePair <string, ISubsystem> kvp in Subsystems)
            {
                string subsystemSave = kvp.Value.SerializeSubsystem();
                int    lns           = subsystemSave.Split(
                    new[] { "\r\n", "\r", "\n" },
                    StringSplitOptions.None
                    ).Count();

                saveBuilder.AppendLine($"{kvp.Key} {lns.ToString()}");
                saveBuilder.AppendLine(subsystemSave);
            }

            return(saveBuilder.ToString());
        }
        public string GetStatus()
        {
            StatusBuilder.Clear();
            StatusBuilder.AppendLine($"OUTPUT MODE: {(int)OutputMode}");
            if (OutputMode == OutputMode.Profile)
            {
                profiler.StartSectionWatch("Profiler");
                profiler.PrintPerformance(StatusBuilder);
                StatusBuilder.AppendLine("============");
                profiler.PrintSectionBreakdown(StatusBuilder);
                profiler.StopSectionWatch("Profiler");
            }
            else if (OutputMode == OutputMode.Debug)
            {
                StatusBuilder.AppendLine(ExceptionBuilder.ToString());

                StatusBuilder.AppendLine("=====");

                StatusBuilder.Append("Cycle ").AppendLine(Context.Frame.ToString());
                StatusBuilder.Append(Subsystems.Count.ToString()).AppendLine("systems connected");

                foreach (KeyValuePair <string, ISubsystem> kvp in Subsystems)
                {
                    StatusBuilder.AppendLine("[" + kvp.Key + "]");
                    StatusBuilder.AppendLine(kvp.Value.GetStatus());
                }

                Context.Log.GetOutput(DebugBuilder);
                StatusBuilder.AppendLine(DebugBuilder.ToString());
                DebugBuilder.Clear();
            }
            else
            {
                return(string.Empty);
            }

            return(StatusBuilder.ToString());
        }
        public void DeserializeManager(string serialized)
        {
            try
            {
                var loadBuilder = new SRKStringBuilder();
                var reader      = new MyStringReader(serialized);

                loadBuilder.Clear();

                // Load subsystem settings here
                int numSubsystems = int.Parse(reader.NextLine());


                for (int i = 0; i < numSubsystems; i++)
                {
                    string[] header = reader.NextLine().Split(' ');
                    string   name   = header[0];

                    int numLines = int.Parse(header[1]);

                    for (int j = 0; j < numLines; j++)
                    {
                        loadBuilder.AppendLine(reader.NextLine());
                    }

                    if (Subsystems.ContainsKey(name))
                    {
                        Subsystems[name].DeserializeSubsystem(loadBuilder.ToString());
                    }

                    loadBuilder.Clear();
                }
            }
            catch (Exception exc)
            {
                ExceptionBuilder.AppendLine(exc.StackTrace);
            }
        }
Esempio n. 10
0
 public string GetStatus()
 {
     return(statusBuilder.ToString());
 }