コード例 #1
0
 public bool TryAdd(string subtypename, RailDefinition definition)
 {
     if (def.ContainsKey(subtypename))
     {
         return(false);
     }
     def.Add(subtypename, definition);
     return(true);
 }
コード例 #2
0
 public bool TryGetDef(string subtypename, out RailDefinition definition)
 {
     return(def.TryGetValue(subtypename, out definition));
 }
コード例 #3
0
ファイル: Rail.cs プロジェクト: Blue64/Space_Engineers
        private void initBlockSettings()
        {
            if (CoreMagRails.instance == null)
            {
                return;
            }
            try
            {
                initDirty = false;

                if (CoreMagRails.instance.Definitions.TryGetDef(gear.BlockDefinition.SubtypeName, out def))
                {
                    return;
                }
                def      = new RailDefinition();
                def.type = RailType.straight;
                MyCubeBlockDefinition blockDefinition = null;
                if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(gear.BlockDefinition, out blockDefinition))
                {
                    var descriptionStr = blockDefinition.DescriptionString;
                    def.size     = blockDefinition.Size;
                    def.sizeenum = (blockDefinition.CubeSize == MyCubeSize.Large ? 2.5 : 0.5);
                    Regex reg    = new Regex("maglift{(.*?)}");
                    Regex regcom = new Regex(";");
                    Regex regeq  = new Regex("=");
                    if (descriptionStr == null || descriptionStr.Length == 0)
                    {
                        return;
                    }
                    var res = reg.Split(descriptionStr);
                    if (res.Length > 1)
                    {
                        var search = regcom.Split(res[1]);
                        if (search == null)
                        {
                            return;
                        }
                        foreach (string parts in search)
                        {
                            var dataeq = regeq.Split(parts);
                            if (dataeq.Length == 0)
                            {
                                continue;
                            }
                            switch (dataeq[0].ToLower())
                            {
                            case "rail":
                                if (dataeq[1].ToLowerInvariant() == "yes")
                                {
                                    def.valid = true;
                                }
                                if (dataeq[1].ToLowerInvariant() == "true")
                                {
                                    def.valid = true;
                                }
                                break;

                            case "curve":
                                if (dataeq[1].ToLowerInvariant() == "yes")
                                {
                                    def.type = RailType.curve;
                                }
                                if (dataeq[1].ToLowerInvariant() == "true")
                                {
                                    def.type = RailType.curve;
                                }
                                break;

                            case "cross":
                                if (dataeq[1].ToLowerInvariant() == "yes")
                                {
                                    def.type = RailType.cross;
                                }
                                if (dataeq[1].ToLowerInvariant() == "true")
                                {
                                    def.type = RailType.cross;
                                }
                                break;

                            case "straight":
                                if (dataeq[1].ToLowerInvariant() == "yes")
                                {
                                    def.type = RailType.straight;
                                }
                                if (dataeq[1].ToLowerInvariant() == "true")
                                {
                                    def.type = RailType.straight;
                                }
                                break;

                            case "slant":
                                if (dataeq[1].ToLowerInvariant() == "yes")
                                {
                                    def.type = RailType.slant;
                                }
                                if (dataeq[1].ToLowerInvariant() == "true")
                                {
                                    def.type = RailType.slant;
                                }
                                break;

                            case "ymin":
                                var minvec = def.min;
                                minvec.Y = Convert.ToDouble(dataeq[1], new CultureInfo("en-US"));
                                def.min  = minvec;
                                break;

                            case "x":
                                def.X = Convert.ToDouble(dataeq[1], new CultureInfo("en-US"));
                                break;

                            case "y":
                                def.Y = Convert.ToDouble(dataeq[1], new CultureInfo("en-US"));
                                break;

                            case "z":
                                def.Z = Convert.ToDouble(dataeq[1], new CultureInfo("en-US"));
                                break;

                            case "radius":
                                def.radius = Convert.ToDouble(dataeq[1], new CultureInfo("en-US"));
                                break;
                            }
                        }
                    }
                    if (def.valid)
                    {
                        if (CoreMagRails.instance.Definitions.TryAdd(gear.BlockDefinition.SubtypeName, def))
                        {
                        }
                        else
                        {
                            //fail
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                initDirty = true;
                Log.DebugWrite(DebugLevel.Error, "ERROR in definition, could not init check definition description for correct format. " + ex.ToString());
            }
        }