Ejemplo n.º 1
0
        private static void ListBlocks(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("listblocks", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);


            Log.Write("TypeName/SubtypeName \"Name\" [IntityId]");
            Log.WriteLine();
            foreach (var block in blocks)
            {
                Log.WriteFormat("{0}/{1} \"{2}\" [{3}]", new object[] {
                    block.GetType().Name,
                    block.BlockDefinition.SubtypeName,
                    block.CustomName,
                    block.EntityId
                });
            }
        }
Ejemplo n.º 2
0
        private Field GetNextField(int[,] matrix, int[,] costMatrix, MatchingType matchingType, Field startField)
        {
            Field nextField = null;

            if (startField.x == 0)
            {
                nextField = startField;
                nextField.y--;
            }
            else if (startField.y == 0)
            {
                nextField = startField;
                nextField.x--;
            }
            else
            {
                int     value = matrix[startField.x, startField.y];
                int     nextValue;
                int     bestNextValue;
                Compare compare;

                switch (matchingType)
                {
                case MatchingType.Maximal:
                    bestNextValue = int.MinValue;
                    compare       = delegate(int a, int b) { return(a > b); };
                    break;

                case MatchingType.Minimal:
                default:
                    bestNextValue = int.MaxValue;
                    compare       = delegate(int a, int b) { return(a < b); };
                    break;
                }

                Field field = new Field(startField.x - 1, startField.y - 1);
                nextValue = matrix[field.x, field.y];
                if (costMatrix[u[field.x], w[field.y]] + nextValue == value && compare(nextValue, bestNextValue))     // check if the step is legal
                {
                    bestNextValue = nextValue;
                    nextField     = field.Clone();
                }
                field     = new Field(startField.x, startField.y - 1);
                nextValue = matrix[field.x, field.y];
                if (costMatrix[DNAToByte('_'), w[field.y]] + nextValue == value && compare(nextValue, bestNextValue))
                {
                    bestNextValue = nextValue;
                    nextField     = field.Clone();
                }
                field     = new Field(startField.x - 1, startField.y);
                nextValue = matrix[field.x, field.y];
                if (costMatrix[u[field.x], DNAToByte('_')] + nextValue == value && compare(nextValue, bestNextValue))
                {
                    bestNextValue = nextValue;
                    nextField     = field;
                }
            }

            return(nextField);
        }
Ejemplo n.º 3
0
    private void OnMatchStateChange(MatchingType type, bool isShow)
    {
        string btnName = "";

        switch (type)
        {
        case MatchingType.Gold:
        case MatchingType.Trial:
            btnName = "Entrance-Trial";
            break;

        case MatchingType.PVP:
            btnName = "Entrance-Match";
            break;
        }
        for (int index = 0; index < buttons.Length; ++index)
        {
            if (buttons[index] != null && buttons[index].name == btnName)
            {
                MatchStateChange item = buttons[index].GetComponent <MatchStateChange>();
                if (item != null)
                {
                    item.SetState(isShow);
                    break;
                }
            }
        }
    }
Ejemplo n.º 4
0
        internal static void ListActions(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("listactions", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);

            List <ITerminalAction> actions = new List <ITerminalAction>();

            foreach (var block in blocks)
            {
                Log.WriteFormat("block \"{0}\" of type \"{1}\" have actions:", new object[] { block.CustomName, block.GetType().Name });
                actions.Clear();
                block.GetActions(actions);

                foreach (var action in actions)
                {
                    Log.WriteFormat("\"{0}\": {1}", new object[] { action.Id, action.Name });
                }
                Log.WriteLine();
            }
        }
Ejemplo n.º 5
0
        internal static void Test3(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("test3", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];
            //           string prop = (string)args[2];

            var blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);

            Log.Write("TypeName/SubtypeName \"Name\" [IntityId]");
            Log.WriteLine();
            foreach (var block in blocks)
            {
                var propDef = block.GetProperty("FontColor");

                Log.WriteFormat("name as sb {0}", propDef.As <Color>());
                Log.WriteFormat("name as int {0}", propDef.As <int>());
                Log.WriteFormat("existing prop {0}", block.GetProperty("FontColor"));
                Log.WriteFormat("unexisting prop {0}", block.GetProperty("someunexistingproperty"));
            }
        }
Ejemplo n.º 6
0
        public void OnStart()
        {
            matchingType = PhotonNetwork.lobby.Equals(LobbyManager.LeagueLobby) ? MatchingType.League : MatchingType.Club;

            var playerName        = PhotonNetwork.playerName;
            var playerFightRecord = new FightRecord(0, 0);
            var player            = new WaitingPlayer(playerName, playerFightRecord, 1000);

            playerPanel.Set(player);
            inPlayerPanel();

            if (PhotonNetwork.otherPlayers.Length > 0)
            {
                var otherPlayer         = PhotonNetwork.otherPlayers[0];
                var opponentName        = otherPlayer.NickName;
                var opponentFightRecord = new FightRecord(0, 0);
                var opponent            = new WaitingPlayer(opponentName, opponentFightRecord, 1000);
                opponentPanel.Set(opponent);
                inOpponentPanel();
                startModeSelect();
            }
            else
            {
                inWaitingWindow();
            }
        }
Ejemplo n.º 7
0
        public static void Action(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("action", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];
            string       action = (string)args[2];

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);


            foreach (var block in blocks)
            {
                if (block.HasAction(action))
                {
                    block.ApplyAction(action);
                }
                else
                {
                    Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "block \"{0}\" does not support action \"{1}\", ignoring", block.CustomName, action);
                }
            }
        }
Ejemplo n.º 8
0
        private string[] GetMatching(int[,] matrix, int[,] costMatrix, MatchingType matchingType, bool stopAtNonPositive = false, Field startField = null)
        {
            Field field     = startField ?? new Field(n, m);
            Field lastField = field.Clone();

            StringBuilder outSequence1 = new StringBuilder();
            StringBuilder outSequence2 = new StringBuilder();

            while ((field.x != 0 || field.y != 0) && (!stopAtNonPositive || matrix[field.x, field.y] > 0))
            {
                field = GetNextField(matrix, costMatrix, matchingType, field);

                if (field.x == lastField.x)
                {
                    outSequence1.Insert(0, '_');
                    outSequence2.Insert(0, ByteToDNA(w[field.y]));    // z nierówności trójkąta będzie działać
                }
                else if (field.y == lastField.y)
                {
                    outSequence1.Insert(0, ByteToDNA(u[field.x]));
                    outSequence2.Insert(0, '_');
                }
                else
                {
                    outSequence1.Insert(0, ByteToDNA(u[field.x]));
                    outSequence2.Insert(0, ByteToDNA(w[field.y]));
                }

                lastField.Copy(field);
            }

            return(new string[] { outSequence1.ToString(), outSequence2.ToString() });
        }
Ejemplo n.º 9
0
    private void OnMatchStateChange(MatchingType type, bool isShow)
    {
        string name = "";

        switch (type)
        {
        case MatchingType.Trial:
            name = NAME_TRIAL;
            break;

        case MatchingType.Gold:
            name = NAME_GOLD;
            break;
        }
        for (int i = 0; i < buttons.Count; i++)
        {
            string btnName = buttons[i].name;
            btnName = btnName.TrimStart("1234567890".ToCharArray());
            if (btnName == name)
            {
                MatchStateChange item = buttons[i].GetComponent <MatchStateChange>();
                if (item != null)
                {
                    item.SetState(isShow);
                    break;
                }
            }
        }
    }
Ejemplo n.º 10
0
        public static void GetBlocksOfTypeWithQuery <T>(MatchingType selectionMode, string query, List <T> blocks) where T : class
        {
            switch (selectionMode)
            {
            case MatchingType.Match:
            {
                Program.Current.GridTerminalSystem.GetBlocksOfType(blocks, x => (x as IMyTerminalBlock)?.CustomName?.Equals(query) ?? false);
                return;
            }

            case MatchingType.Contains:
            {
                Program.Current.GridTerminalSystem.GetBlocksOfType(blocks, x => (x as IMyTerminalBlock)?.CustomName?.Contains(query) ?? false);
                return;
            }

            case MatchingType.Head:
            {
                Program.Current.GridTerminalSystem.GetBlocksOfType(blocks, x => (x as IMyTerminalBlock)?.CustomName?.StartsWith(query) ?? false);
                return;
            }

            case MatchingType.Group:
            {
                IMyBlockGroup group = Program.Current.GridTerminalSystem.GetBlockGroupWithName(query);
                blocks.Clear();
                if (group != null)
                {
                    group.GetBlocksOfType <T>(blocks);
                }
                return;
            }

            case MatchingType.Type:
            {
                string[] parts = query.Split("|/:, ".ToCharArray()).Select(x => x.Trim()).ToArray();

                bool   allTypes = parts[0] == "" || parts[0] == "*";
                string type     = "My" + parts[0];

                bool   allSubtypes = true;
                string subtype     = "";

                if (parts.Length > 1)
                {
                    allSubtypes = parts[1] == "*";
                    subtype     = parts[1];
                }

                Program.Current.GridTerminalSystem.GetBlocksOfType(blocks, block =>
                    {
                        return((allTypes || block.GetType().Name == type) &&
                               (allSubtypes || (block as IMyTerminalBlock)?.BlockDefinition.SubtypeName == subtype));
                    });

                return;
            }
            }
        }
Ejemplo n.º 11
0
        internal void Mark(MatchingType matchingType, PropertyInfo pi)
        {
            MatchingType |= matchingType;

            if (matchingType == MatchingType.Left)
            {
                LeftSideItem = new PropertyMatchingMemberItem <T1>(pi);
            }
            else if (matchingType == MatchingType.Right)
            {
                RightSideItem = new PropertyMatchingMemberItem <T2>(pi);
            }
        }
Ejemplo n.º 12
0
        internal void Mark(MatchingType matchingType, FieldInfo fi)
        {
            MatchingType |= matchingType;

            if (matchingType == MatchingType.Left)
            {
                LeftSideItem = new FieldMatchingMemberItem <T1>(fi);
            }
            else if (matchingType == MatchingType.Right)
            {
                RightSideItem = new FieldMatchingMemberItem <T2>(fi);
            }
        }
Ejemplo n.º 13
0
        private void AddField(Dictionary <string, MatchingMemberInfo <T1, T2> > members,
                              FieldInfo fi,
                              MatchingType matchingType)
        {
            if (!members.ContainsKey(fi.Name))
            {
                members.Add(fi.Name, new MatchingMemberInfo <T1, T2>(fi.Name));
            }

            if (ShouldBeCompared(fi))
            {
                members[fi.Name].Mark(matchingType, fi);
            }
        }
Ejemplo n.º 14
0
                static string MatchingTypeToString(MatchingType matchingType)
                {
                    switch (matchingType)
                    {
                    case MatchingType.Equal:
                        return(string.Empty);

                    case MatchingType.GreaterOrEqual:
                        return(GreaterOrEqual.ToString());

                    default:
                        throw new ArgumentOutOfRangeException(nameof(matchingType), matchingType, null);
                    }
                }
Ejemplo n.º 15
0
        public static void Run(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("run", args);

            MatchingType type     = (MatchingType)args[0];
            string       filter   = (string)args[1];
            string       argument = (string)args[2];

            List <IMyProgrammableBlock> blocks = new List <IMyProgrammableBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);

            foreach (var block in blocks)
            {
                block.TryRun(argument);
            }
        }
Ejemplo n.º 16
0
        private void AddProperty(Dictionary <string, MatchingMemberInfo <T1, T2> > members,
                                 PropertyInfo pi,
                                 MatchingType matchingType)
        {
            if (pi.GetIndexParameters().Length > 0) //skip indexed property
            {
                return;
            }

            if (!members.ContainsKey(pi.Name))
            {
                members.Add(pi.Name, new MatchingMemberInfo <T1, T2>(pi.Name));
            }

            if (ShouldBeCompared(pi))
            {
                members[pi.Name].Mark(matchingType, pi);
            }
        }
Ejemplo n.º 17
0
                static string ToStringInternal(int?number, MatchingType matchingType)
                {
                    if (number.HasValue == false)
                    {
                        return(Wildcard);
                    }

                    switch (matchingType)
                    {
                    case MatchingType.Equal:
                        return(number.ToString());

                    case MatchingType.GreaterOrEqual:
                        return($"{number}{GreaterOrEqual}");

                    default:
                        throw new ArgumentOutOfRangeException(nameof(matchingType), matchingType, null);
                    }
                }
Ejemplo n.º 18
0
        private string[] GetMatching(int[,] matrix, int[,] costMatrix, MatchingType matchingType, Sequence uSequence, Sequence wSequence, bool stopAtNonPositive = false, Field startField = null)
        {
            Field field     = startField ?? new Field(uSequence.data.Length, wSequence.data.Length);
            Field lastField = field.Clone();

            int stopSeq1 = (field.x + uSequence.index) * 3; // 3 chars for amino
            int stopSeq2 = (field.y + wSequence.index) * 3;


            StringBuilder outSequence1 = new StringBuilder();
            StringBuilder outSequence2 = new StringBuilder();

            while ((field.x != 0 || field.y != 0) && (!stopAtNonPositive || matrix[field.x, field.y] > 0))
            {
                field = GetNextField(matrix, costMatrix, matchingType, field, uSequence.data, wSequence.data);

                if (field.x == lastField.x)
                {
                    stopSeq2 -= 3;
                    outSequence1.Insert(0, "___");
                    outSequence2.Insert(0, RNASequence2.Substring(stopSeq2, 3));
                }
                else if (field.y == lastField.y)
                {
                    stopSeq1 -= 3;
                    outSequence1.Insert(0, RNASequence1.Substring(stopSeq1, 3));
                    outSequence2.Insert(0, "___");
                }
                else
                {
                    stopSeq1 -= 3;
                    stopSeq2 -= 3;
                    outSequence1.Insert(0, RNASequence1.Substring(stopSeq1, 3));
                    outSequence2.Insert(0, RNASequence2.Substring(stopSeq2, 3));
                }

                lastField.Copy(field);
            }

            return(new string[] { outSequence1.ToString(), outSequence2.ToString() });
        }
Ejemplo n.º 19
0
        public ENFA_Controller(ParserType parserType)
        {
            _parserType = parserType;
            switch (_parserType)
            {
            case ParserType.Regex:
                _factory   = new ENFA_Regex_Factory(this);
                _tokenizer = Factory.GetTokenizer();
                _parser    = Factory.GetParser();
                break;

            case ParserType.Grammar:
                _factory   = new ENFA_Grammar_Factory(this);
                _tokenizer = Factory.GetTokenizer();
                _parser    = Factory.GetParser();
                break;
            }
            _patternStart = new ENFA_PatternStart(this);
            _matchingType = MatchingType.LazyMatching;
            _inDebugMode  = false;
        }
Ejemplo n.º 20
0
        public Node goToMatchingNode(String query, MatchingType type)
        {
            if (query.Count() > 0)
            {
                Node child = this.findChild(query.ToString()[0]);
                if (child == null)
                {
                    return(null);
                }
                // filter wrong nodes
                if (!query.StartsWith(child.getSymbol(), this.stringComparison))
                {
                    if (type == MatchingType.MATCH_EXACT || type == MatchingType.MATCH_INSERT)
                    {
                        return(null);
                    }
                    else
                    {
                        return(child);
                    }
                }
                query = query.Substring(child.getSymbol().Count());
                Node nextChild = child.goToMatchingNode(query, type);

                //this is the case when there is either no matching translation in the trie, or we found a translation
                if (nextChild == null)
                {
                    if (type == MatchingType.MATCH_EXACT && query.Length != 0)
                    {
                        return(null);
                    }
                    return(child);
                }
                else
                {
                    return(nextChild);
                }
            }
            return(null);
        }
Ejemplo n.º 21
0
        //        static blocks

        internal static void Test1(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("test1", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];

            List <IMyTextSurfaceProvider> blocks = new List <IMyTextSurfaceProvider>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);


            Log.Write("TypeName/SubtypeName \"Name\" [IntityId]");
            Log.WriteLine();
            foreach (var lcd in blocks)
            {
                var block = lcd as IMyTerminalBlock;
                Log.Write($"{block.GetType().Name}/{block.BlockDefinition.SubtypeName} \"{block.CustomName}\" [{block.EntityId}]");
                Log.WriteFormat("surfaces count: {0}", lcd.SurfaceCount);
            }
        }
Ejemplo n.º 22
0
        public static void Text(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("text", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];
            int          index  = (int)(double)args[2];
            bool         append = (bool)args[3];
            string       text   = (string)args[4];

            var blocks = new List <IMyTextSurfaceProvider>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);

            foreach (var block in blocks)
            {
                IMyTextSurface surface;
                if (block is IMyTextPanel && index == 0)
                {
                    surface = block as IMyTextSurface;
                }
                else
                {
                    surface = block.GetSurface(index);
                }

                if (surface != null)
                {
                    surface?.WriteText(text, append);
                }
                else
                {
                    Log.Write(ImplLogger.LOG_CAT, LogLevel.Verbose, "surface index out of range");
                }
            }
        }
Ejemplo n.º 23
0
            private void Set(int i, string valueAsString, int?value, MatchingType matchingType)
            {
                switch (i)
                {
                case 0:
                    AssertMatchingType(nameof(Major), valueAsString, MatchingType.Equal, matchingType);
                    Major = value;
                    break;

                case 1:
                    AssertMatchingType(nameof(Minor), valueAsString, MatchingType.Equal, matchingType);
                    Minor = value;
                    break;

                case 2:
                    AssertMatchingType(nameof(Patch), valueAsString, expectedMatchingType: null, matchingType);
                    Patch             = value;
                    PatchMatchingType = matchingType;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(i));
                }

                void AssertMatchingType(string fieldName, string valueAsString, MatchingType?expectedMatchingType, MatchingType matchingType)
                {
                    if (Suffix != null && matchingType != MatchingType.Equal)
                    {
                        throw new InvalidOperationException($"Cannot set '{fieldName}' with value '{valueAsString}' because '{MatchingTypeToString(matchingType)}' is not allowed when Suffix ('{Suffix}') is set.");
                    }

                    if (expectedMatchingType.HasValue && expectedMatchingType != matchingType)
                    {
                        throw new InvalidOperationException($"Cannot set '{fieldName}' with value '{valueAsString}' because '{MatchingTypeToString(matchingType)}' is not allowed.");
                    }
                }
Ejemplo n.º 24
0
 public ConsoleOutputSourceAttribute(string memberName, MatchingType matchingType = MatchingType.Standard, Type declaredType = null)
 {
     MemberName   = memberName;
     MatchingType = matchingType;
     DeclaredType = declaredType;
 }
Ejemplo n.º 25
0
 public ConsoleOutCommand(TestCommand innerCommand, string expectedMessage, MatchingType matchingType) : base(innerCommand)
 {
     _expectedMessage = expectedMessage; _matchingType = matchingType;
 }
Ejemplo n.º 26
0
 public MatchingTagConditional(string tagToMatch, MatchingType type)
 {
     this.tagToMatch = tagToMatch;
     this.type       = type;
 }
Ejemplo n.º 27
0
        public static void Transmit(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("transmit", args);

            MatchingType matchingType = (MatchingType)args[0];
            string       filter       = (string)args[1];
            string       targetString = (string)args[2];
            string       message      = (string)args[3];

            List <IMyTerminalBlock> antennas = new List <IMyTerminalBlock>();

            List <IMyRadioAntenna> radioAntennas = new List <IMyRadioAntenna>();

            BlockSelector.GetBlocksOfTypeWithQuery(matchingType, filter, radioAntennas);
            ImplLogger.LogBlocks(antennas);

            //get most powerful radio antenna
            IMyRadioAntenna mostPowerfulAntenna = null;

            //get radio antenna with longest radius that's enabled and broadcasting
            foreach (IMyRadioAntenna antenna in radioAntennas)
            {
                if (antenna.Enabled && antenna.GetValueBool("EnableBroadCast") &&
                    (mostPowerfulAntenna == null || antenna.Radius > mostPowerfulAntenna.Radius))
                {
                    mostPowerfulAntenna = antenna;
                }
            }

            if (mostPowerfulAntenna != null)
            {
                antennas.Add(mostPowerfulAntenna);
            }

            //--------get all laser antennas
            List <IMyLaserAntenna> laserAntennas = new List <IMyLaserAntenna>();

            BlockSelector.GetBlocksOfTypeWithQuery(matchingType, filter, laserAntennas);
            Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Verbose, "{0} block(s) found", laserAntennas.Count);

            foreach (IMyLaserAntenna antenna in laserAntennas)
            {
                if (antenna.Status == MyLaserAntennaStatus.Connected)
                {
                    antennas.Add(antenna);
                }
            }

            //-----check whether at least one valid antenna was found
            if (antennas.Count != 0)
            {
                var transmitter = new Transmitter(antennas);
                transmitter.Transmit(message, targetString);
            }
            else
            {
                string warning;
                switch (matchingType)
                {
                default:
                case MatchingType.Match:
                    warning = string.Format("No antennas called \"{0}\" are currently able to transmit.", filter);
                    break;

                case MatchingType.Contains:
                    warning = string.Format("No antennas containing \"{0}\" are currently able to transmit.", filter);
                    break;

                case MatchingType.Head:
                    warning = string.Format("No antennas starting with \"{0}\" are currently able to transmit.", filter);
                    break;

                case MatchingType.Group:
                    warning = string.Format("No antennas in group \"{0}\" are currently able to transmit.", filter);
                    break;

                case MatchingType.Type:
                    warning = string.Format("No antennas of type \"{0}\" are currently able to transmit.", filter);
                    break;
                }

                Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, warning);
            }
        }
Ejemplo n.º 28
0
        public static void Set(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("set", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];
            string       prop   = (string)args[2];
            string       value  = (string)args[3];

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);


            // Boolean
            // StringBuilder
            // Single
            // Int64
            // Color

            foreach (var block in blocks)
            {
                // todo: redo
                var propDef = block.GetProperty(prop);

                PropType propType;

                if (propDef != null && Enum.TryParse(propDef.TypeName, out propType))
                {
                    switch (propType)
                    {
                    case PropType.Boolean:
                    {
                        bool b;
                        if (bool.TryParse(value, out b))
                        {
                            block.SetValue(prop, b);
                        }
                        break;
                    }

                    case PropType.StringBuilder:
                    {
                        block.SetValue(prop, new StringBuilder(value));
                        break;
                    }

                    case PropType.String:
                    {
                        block.SetValue(prop, value);
                        break;
                    }

                    case PropType.Single:
                    {
                        float s;
                        if (float.TryParse(value, System.Globalization.NumberStyles.Number, C.I, out s))
                        {
                            block.SetValue(prop, s);
                        }
                    }
                    break;

                    case PropType.Int64:
                    {
                        long i;

                        if (ListConverter.ResolveListProperty(prop, value, out i))
                        {
                            block.SetValue(prop, i);
                        }
                    }
                    break;

                    case PropType.Color:
                    {
                        Color c;

                        if (ColorConverter.TryParseColor(value, out c))
                        {
                            block.SetValueColor(prop, c);
                        }
                        else
                        {
                            Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "\"{0}\" is not a valid color", value);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "block \"{0}\" does not have property \"{1}\", ignoring", block.CustomName, prop);
                }
            }
        }
Ejemplo n.º 29
0
        private void CheckQuantifiers(StreamReader reader, out int minRepetitions, out int maxRepetitions, out MatchingType matchingType)
        {
            char matchedChar;

            minRepetitions = 0;
            maxRepetitions = -1;
            /* Run digits until comma or curly barce end */
            string firstDigit  = GetStringUntilChar(reader, new char[] { Constants.Comma, Constants.RightCurlyBracket }, out matchedChar);
            string secondDigit = null;

            if (matchedChar == Constants.RightCurlyBracket && firstDigit == String.Empty)
            {
                ThrowBuildException(ErrorText.EmptyCurlyBraces);
            }
            if (firstDigit != String.Empty && !int.TryParse(firstDigit, out minRepetitions))
            {
                ThrowBuildException(ErrorText.CouldNotParseMinRepetitions);
            }
            else if (matchedChar == Constants.RightCurlyBracket)
            {
                maxRepetitions = minRepetitions;
            }
            if (matchedChar == Constants.Comma)
            {
                /* if comma is found then check digits until curly barce end */
                secondDigit = GetStringUntilChar(reader, new char[] { Constants.RightCurlyBracket }, out matchedChar);
                if (secondDigit == String.Empty)
                {
                    maxRepetitions = -1;
                }
                else if (!int.TryParse(secondDigit, out maxRepetitions))
                {
                    ThrowBuildException(ErrorText.CouldNotParseMaxRepetitions);
                }
            }
            /* Check for additional matching type */
            if (PeekNextChar(reader) == Constants.QuestionMark)
            {
                /* Consume Quention Mark */
                ConsumeNextChar(reader);
                /* Lazy matching overwriting default */
                matchingType = MatchingType.LazyMatching;
            }
            else if (PeekNextChar(reader) == Constants.GreaterThanSign)
            {
                /* Consume Greater Than Sign */
                ConsumeNextChar(reader);
                /* Greedy matching overwriting default */
                matchingType = MatchingType.GreedyMatching;
            }
            else
            {
                /* Use default matching */
                matchingType = Controller.DefaultMatchType;
            }
        }
Ejemplo n.º 30
0
        internal static void ListProps(IList args, IMethodContext context)
        {
            ImplLogger.LogImpl("listprops", args);

            MatchingType type   = (MatchingType)args[0];
            string       filter = (string)args[1];

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks);
            ImplLogger.LogBlocks(blocks);

            List <ITerminalProperty> props = new List <ITerminalProperty>();

            foreach (var block in blocks)
            {
                Log.WriteFormat("Block \"{0}\" of type \"{1}\" contains properties:", new object[] { block.CustomName, block.GetType().Name });
                props.Clear();
                block.GetProperties(props);


                var allProps = new HashSet <string>();
                var badProps = new HashSet <string>(); // Termimal Properties can have same ids, which makes them unaccessible

                foreach (var prop in props)
                {
                    if (allProps.Contains(prop.Id))
                    {
                        badProps.Add(prop.Id);
                    }
                    else
                    {
                        allProps.Add(prop.Id);
                    }
                }

                foreach (var prop in props)
                {
                    // block.GetValue<object>(prop.Id) - Property is not of Type object <...>
                    object value = null;
                    try
                    {
                        PropType propType;
                        if (!badProps.Contains(prop.Id) && Enum.TryParse(prop.TypeName, out propType))
                        {
                            switch (propType)
                            {
                            case PropType.Boolean:
                                value = block.GetValueBool(prop.Id);
                                break;

                            case PropType.Single:
                                value = block.GetValueFloat(prop.Id);
                                break;

                            case PropType.Color:
                                value = block.GetValueColor(prop.Id);
                                break;

                            case PropType.StringBuilder:
                                value = block.GetValue <StringBuilder>(prop.Id);
                                break;

                            case PropType.String:
                                value = block.GetValue <string>(prop.Id);
                                break;

                            case PropType.Int64:
                                value = block.GetValue <long>(prop.Id);
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // Looks like some game mod is broken, which is bad. Game breaking bad.
                        Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, $"Error reading property \"{prop.Id}\"");
                    }
                    Log.WriteFormat("\"{0}\" ({1}) = \"{2}\"", new object[] { prop.Id, prop.TypeName, value });
                }
                Log.WriteLine();
            }
        }