コード例 #1
0
ファイル: SystemPart.cs プロジェクト: youndoldman/Librelancer
        protected override bool parentEntry(Entry e)
        {
            if (base.parentEntry(e))
            {
                return(true);
            }
            else
            {
                switch (e.Name.ToLowerInvariant())
                {
                case "ids_name":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (IdsName != 0)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    IdsName = e[0].ToInt32();
                    break;

                case "ids_info":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (IdsInfo == null)
                    {
                        IdsInfo = new List <int>();
                    }
                    IdsInfo.Add(e[0].ToInt32());
                    break;

                case "size":
                    if (e.Count < 1 || e.Count > 3)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Size != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Vector3 size = new Vector3(e[0].ToSingle());
                    if (e.Count > 1)
                    {
                        size.Y = e[1].ToSingle();
                    }
                    if (e.Count > 2)
                    {
                        size.Z = e[2].ToSingle();
                    }
                    Size = size;
                    break;

                case "spin":
                    if (e.Count > 3)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Spin != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    float x = 0f, y = 0f, z = 0f;
                    if (e.Count > 0)
                    {
                        x = e [0].ToSingle();
                    }
                    if (e.Count > 1)
                    {
                        y = e [1].ToSingle();
                    }
                    if (e.Count > 2)
                    {
                        z = e [2].ToSingle();
                    }
                    Spin = new Vector3(x, y, z);
                    break;

                case "reputation":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    //if (Reputation != null) throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    Reputation = e[0].ToString();                     //TODO: are multiple reputation entries valid?
                    break;

                case "visit":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Visit != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Visit = e[0].ToInt32();
                    break;

                default: return(false);
                }

                return(true);
            }
        }
コード例 #2
0
ファイル: Archetype.cs プロジェクト: gp-alex/Librelancer
        protected virtual bool parentEntry(Entry e)
        {
            switch (e.Name.ToLowerInvariant())
            {
            case "nickname":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (Nickname != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                Nickname = e[0].ToString();
                break;

            case "ids_name":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (IdsName != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                IdsName = FLData.Infocards.GetStringResource(e[0].ToInt32());
                break;

            case "ids_info":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                IdsInfo.Add(FLData.Infocards.GetXmlResource(e[0].ToInt32()));
                break;

            case "hit_pts":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                Hitpoints = e [0].ToSingle();
                break;

            case "phantom_physics":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                PhantomPhysics = e [0].ToBoolean();
                break;

            case "type":
                break;

            case "material_library":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                string path = e[0].ToString();
                switch (Path.GetExtension(path))
                {
                case ".mat":
                    MaterialPaths.Add(VFS.GetPath(FLData.Freelancer.DataPath + path));
                    break;

                case ".txm":
                    TexturePaths.Add(VFS.GetPath(FLData.Freelancer.DataPath + path));
                    break;

                default:
                    throw new Exception("Invalid value in " + section.Name + " Entry " + e.Name + ": " + path);
                }
                break;

            case "mass":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                //if (Mass != null) throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); //Hack around discovery errors
                Mass = e[0].ToSingle();
                break;

            case "shape_name":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (ShapeName != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                ShapeName = e[0].ToString();
                break;

            case "solar_radius":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (SolarRadius != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                SolarRadius = e[0].ToSingle();
                break;

            case "da_archetype":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (DaArchetypeName != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                DaArchetypeName = VFS.GetPath(FLData.Freelancer.DataPath + e [0].ToString());
                break;

            case "loadout":
                if (e.Count != 1)
                {
                    throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                }
                if (LoadoutName != null)
                {
                    throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                }
                LoadoutName = e[0].ToString();
                break;

            case "docking_sphere":
                string scr = e.Count == 4 ? e[3].ToString() : null;
                DockingSpheres.Add(new DockSphere()
                {
                    Name = e[0].ToString(), Hardpoint = e[1].ToString(), Radius = e[2].ToInt32(), Script = scr
                });
                break;

            case "open_anim":
                OpenAnim = e[0].ToString();
                break;

            case "lodranges":
                LODRanges = new float[e.Count];
                for (int i = 0; i < e.Count; i++)
                {
                    LODRanges[i] = e[i].ToSingle();
                }
                break;

            default: return(false);
            }

            return(true);
        }