FromFile() public static method

public static FromFile ( string filename ) : TdfParser,
filename string
return TdfParser,
Exemplo n.º 1
0
        public void LoadSm3(string filename)
        {
            terrain.tdfparser = TdfParser.FromFile(filename);
            TdfParser.Section terrainsection = terrain.tdfparser.RootSection.SubSection("map/terrain");
            string            tdfdirectory   = Path.GetDirectoryName(Path.GetDirectoryName(filename));

            LoadTextureStages(tdfdirectory, terrainsection);
            LoadHeightMap(tdfdirectory, terrainsection);
            terrain.OnTerrainModified();
            MainUI.GetInstance().uiwindow.InfoMessage("SM3 load completed");
        }
Exemplo n.º 2
0
        public bool LoadMod(string modfile)
        {
            this.modfilename = modfile;
            TdfParser parser1 = TdfParser.FromFile(modfile);

            if (parser1 != null)
            {
                TdfParser.Section section1 = parser1.RootSection.SubSection(@"AI\VALUES");
                if (section1 != null)
                {
                    foreach (string text1 in section1.Values.Keys)
                    {
                        string text2 = text1;
                        text2 = text2.ToLower();
                        text2 = text2.Trim();
                        this.units.Add(text2);
                        this.values[text2] = section1.GetDoubleValue(text1);
                    }
                }
                section1 = parser1.RootSection.SubSection(@"AI\NAMES");
                if (section1 != null)
                {
                    foreach (string text3 in section1.Values.Keys)
                    {
                        string text4 = text3;
                        text4 = text4.ToLower();
                        text4 = text4.Trim();
                        this.human_names[text4] = section1.GetStringValue(text3);
                    }
                }
                section1 = parser1.RootSection.SubSection(@"AI\DESCRIPTIONS");
                if (section1 != null)
                {
                    foreach (string text5 in section1.Values.Keys)
                    {
                        string text6 = text5;
                        text6 = text6.ToLower();
                        text6 = text6.Trim();
                        this.descriptions[text6] = section1.GetStringValue(text5);
                    }
                }
                this.units.Sort();
            }
            return(false);
        }
Exemplo n.º 3
0
        public void LoadFeatures(string featurelistfilename, string featuredatafilename)
        {
            LogFile.GetInstance().WriteLine("LoadFeatures()");
            TdfParser tdfparser = TdfParser.FromFile(featurelistfilename);
            Terrain   terrain   = Terrain.GetInstance();

            terrain.FeatureMap = new Unit[terrain.MapWidth, terrain.MapHeight];
            Dictionary <int, string> featurenamebynumber = new Dictionary <int, string>();
            int numfeaturetypes = tdfparser.RootSection.GetIntValue("map/featuretypes/numtypes");

            LogFile.GetInstance().WriteLine("Num types: " + numfeaturetypes);
            for (int i = 0; i < numfeaturetypes; i++)
            {
                string featurename = tdfparser.RootSection.GetStringValue("map/featuretypes/type" + i);
                if (!File.Exists(Path.Combine("objects3d", featurename + ".s3o")))
                {
                    MainUI.GetInstance().uiwindow.WarningMessage("Warning: objects3d/" + featurename + ".s3o not found");
                }
                else
                {
                    LogFile.GetInstance().WriteLine("Feature type " + i + " " + featurename.ToLower());
                    featurenamebynumber.Add(i, featurename.ToLower());
                }
            }

            List <Sm3Feature> features = new List <Sm3Feature>();

            // from FeaturePlacer Form1.cs by Jelmer Cnossen
            FileStream fs = new FileStream(featuredatafilename, FileMode.Open);

            if (fs != null)
            {
                BinaryReader br = new BinaryReader(fs);
                if (br.ReadByte() != 0)
                {
                    MainUI.GetInstance().uiwindow.WarningMessage("The featuredata you are trying to load was saved using a different version.");
                    return;
                }

                int numFeatures = br.ReadInt32();
                features.Clear();
                for (int a = 0; a < numFeatures; a++)
                {
                    Sm3Feature f = new Sm3Feature();
                    features.Add(f);
                    f.type     = br.ReadInt32();
                    f.x        = br.ReadSingle();
                    f.y        = br.ReadSingle();
                    f.z        = br.ReadSingle();
                    f.rotation = br.ReadSingle();
                }
            }

            foreach (Sm3Feature sm3feature in features)
            {
                if (featurenamebynumber.ContainsKey(sm3feature.type))
                {
                    string featurename = featurenamebynumber[sm3feature.type].ToLower();
                    if (!UnitCache.GetInstance().UnitsByName.ContainsKey(featurename))
                    {
                        LogFile.GetInstance().WriteLine("Loading unit " + Path.Combine("objects3d", featurename + ".s3o") + " ... ");
                        Unit unit = new S3oLoader().LoadS3o(Path.Combine("objects3d", featurename + ".s3o"));
                        UnitCache.GetInstance().UnitsByName.Add(featurename, unit);
                    }
                    LogFile.GetInstance().WriteLine("Adding " + featurename + " at " + (int)(sm3feature.x / Terrain.SquareSize) + " " + (int)(sm3feature.y / Terrain.SquareSize));
                    terrain.FeatureMap[(int)(sm3feature.x / Terrain.SquareSize), (int)(sm3feature.y / Terrain.SquareSize)] = UnitCache.GetInstance().UnitsByName[featurename];
                }
            }

            terrain.OnTerrainModified();
        }