Beispiel #1
0
        public void LoadStaticobjects()
        {
            string fileName = Path.Combine(this.BaseDir, "staticobjects.con");
            var    lines    = File.ReadAllLines(fileName);
            var    text     = File.ReadAllText(fileName);

            Regex newObjectRx = new Regex(@"^\s*Object.(create)\s+(?<Name>.*)$", RegexOptions.IgnoreCase);
            Regex editorRx    = new Regex(@"^\s*if v_arg1 == BF2Editor$", RegexOptions.IgnoreCase);
            Regex endIfRx     = new Regex(@"^\s*endIf$", RegexOptions.IgnoreCase);

            BF2Object activeSafe;
            bool      skip = false;

            foreach (string line in lines)
            {
                if (line == "")
                {
                    continue;
                }
                if (line.StartsWith("rem "))
                {
                    continue;
                }
                if (line.StartsWith("beginrem "))
                {
                    skip = true; continue;
                }
                if (line.StartsWith("endrem "))
                {
                    skip = false; continue;
                }

                // comments and skips first
                var editorMatch = editorRx.Match(line);
                if (editorMatch.Success)
                {
                    skip = true;
                    continue;
                }
                var endIfMatch = endIfRx.Match(line);
                if (endIfMatch.Success)
                {
                    skip = false;
                    continue;
                }

                if (skip)
                {
                    continue;
                }
                // new objects, changing activeSafe
                var newMatch = newObjectRx.Match(line);
                if (newMatch.Success)
                {
                    string    objectName = newMatch.Groups["Name"].Value.Trim();
                    BF2Object newObject  = null;

                    // DEBUG
                    if (Mod.ObjectTemplates.ContainsKey(objectName) && this.LevelMod.ObjectTemplates.ContainsKey(objectName))
                    {
                        throw new NotImplementedException();
                    }
                    if (!Mod.ObjectTemplates.ContainsKey(objectName) && !this.LevelMod.ObjectTemplates.ContainsKey(objectName))
                    {
                        throw new NotImplementedException();
                    }

                    //
                    BF2Mod sourceMod;
                    if (this.LevelMod.ObjectTemplates.ContainsKey(objectName))
                    {
                        sourceMod = this.LevelMod;
                    }
                    else if (this.Mod.ObjectTemplates.ContainsKey(objectName))
                    {
                        sourceMod = this.Mod;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    BF2ObjectTemplate objectTemplate = sourceMod.ObjectTemplates[objectName];
                    newObject = objectTemplate.CreateObject();
                    if (objectTemplate.geometry != null)                           // object template has visible mesh
                    {
                        if (!this.Geometries.ContainsKey(objectTemplate.geometry)) // check if we dont have geometry loaded already
                        {
                            var loadedGeometry = newObject.LoadGeometry(sourceMod.GeometryTemplates[objectTemplate.geometry]);
                            this.Geometries.Add(objectTemplate.geometry, loadedGeometry);
                        }
                        else // otherwise assign already loaded mesh to object
                        {
                            newObject.Geometry = this.Geometries[objectTemplate.geometry];
                        }
                    }

                    this.StaticObjects.Add(newObject);
                    activeSafe = newObject;
                }
            }
        }
Beispiel #2
0
        public ConFile ParseConFile(string fileName)
        {
            this.FileName = fileName;

            Regex newObjectTemplateRx   = new Regex(@"^\s*ObjectTemplate.(create|activeSafe)\s+(?<Type>.*?)\s+(?<Name>.*)$", RegexOptions.IgnoreCase);
            Regex newGeometryTemplateRx = new Regex(@"^\s*GeometryTemplate.(create)\s+(?<Type>.*?)\s+(?<Name>.*)$", RegexOptions.IgnoreCase);
            Regex propertyRx            = new Regex(@"^\s*ObjectTemplate\.(?<Property>.*?)\s+(?<Value>.*)$", RegexOptions.IgnoreCase);
            Regex includeRx             = new Regex(@"^\s*(include|run)\s+(?<Path>.*)$", RegexOptions.IgnoreCase);

            var lines = File.ReadAllLines(fileName);
            BF2ObjectTemplate activeSafe = null;
            bool          skip;
            List <string> missingFields = new List <string>();

            foreach (string line in lines)
            {
                if (line == "")
                {
                    continue;
                }
                if (line.StartsWith("rem "))
                {
                    continue;
                }
                if (line.StartsWith("beginrem "))
                {
                    skip = true; continue;
                }
                if (line.StartsWith("endrem "))
                {
                    skip = false; continue;
                }

                // matches
                var newObjectTemplateMatch   = newObjectTemplateRx.Match(line);
                var newGeometryTemplateMatch = newGeometryTemplateRx.Match(line);
                var propMatch = propertyRx.Match(line);
                var inclMatch = includeRx.Match(line);

                if (newObjectTemplateMatch.Success)
                {
                    string objectName = newObjectTemplateMatch.Groups["Name"].Value.Trim();
                    if (!this._ObjectTemplates.ContainsKey(objectName))
                    {
                        this._ObjectTemplates.Add(objectName, new BF2ObjectTemplate(objectName));
                    }
                    activeSafe = this._ObjectTemplates[objectName];
                    continue;
                }

                if (newGeometryTemplateMatch.Success)
                {
                    string   geometryType = newGeometryTemplateMatch.Groups["Type"].Value.Trim();
                    MeshType meshType;
                    bool     meshTypeParsed = Enum.TryParse(geometryType, true, out meshType);
                    if (!meshTypeParsed)
                    {
                        throw new NotImplementedException();
                    }
                    string geometryName = newGeometryTemplateMatch.Groups["Name"].Value.Trim();
                    if (!this._GeometryTemplates.ContainsKey(geometryName))
                    {
                        string meshFileName = Path.Combine(
                            Path.GetDirectoryName(fileName),
                            "meshes",
                            geometryName);
                        var geometryTemplate = new BF2GeometryTemplate(meshFileName, meshType);
                        if (geometryTemplate.FileName != null)
                        {
                            this._GeometryTemplates.Add(geometryName, geometryTemplate);
                        }
                    }
                    continue;
                }

                if (propMatch.Success)
                {
                    var property = propMatch.Groups["Property"].Value.Trim();
                    var value    = propMatch.Groups["Value"].Value.Trim();

                    FieldInfo field = activeSafe.GetType().GetField(property);
                    if (field == null)
                    {
                        missingFields.Add(property);
                    }
                    else
                    {
                        field.SetValue(activeSafe, Convert.ChangeType(value, field.FieldType));
                    }
                }
            }

            return(this);
        }
Beispiel #3
0
 public BF2Object(BF2ObjectTemplate objectTemplate)
 {
     this.ObjectTemplate = objectTemplate;
 }