Esempio n. 1
0
        private TextureFlags GetFlags(GenericStructure vmt)
        {
            var flags = TextureFlags.None;
            var tp    = vmt.PropertyInteger("$translucent") + vmt.PropertyInteger("$alphatest");

            if (tp > 0)
            {
                flags |= TextureFlags.Transparent;
            }
            return(flags);
        }
Esempio n. 2
0
        public void Read(GenericStructure gs)
        {
            ID                       = gs.PropertyInteger("ID");
            Name                     = gs["Name"];
            Specification            = gs["Specification"];
            Engine                   = (Engine)Enum.Parse(typeof(Engine), gs["EngineID"]);
            DontRedirectOutput       = gs.PropertyBoolean("DontRedirectOutput");
            Path                     = gs["Path"];
            Bsp                      = gs["Bsp"];
            Csg                      = gs["Csg"];
            Vis                      = gs["Vis"];
            Rad                      = gs["Rad"];
            IncludePathInEnvironment = gs.PropertyBoolean("IncludePathInEnvironment", true);

            WorkingDirectory  = gs.PropertyEnum("WorkingDirectory", CompileWorkingDirectory.TemporaryDirectory);
            AfterCopyBsp      = gs.PropertyBoolean("AfterCopyBsp");
            AfterRunGame      = gs.PropertyBoolean("AfterRunGame");
            AfterAskBeforeRun = gs.PropertyBoolean("AfterAskBeforeRun");

            CopyBsp = gs.PropertyBoolean("CopyBsp");
            CopyRes = gs.PropertyBoolean("CopyRes");
            CopyLin = gs.PropertyBoolean("CopyLin");
            CopyMap = gs.PropertyBoolean("CopyMap");
            CopyPts = gs.PropertyBoolean("CopyPts");
            CopyLog = gs.PropertyBoolean("CopyLog");
            CopyErr = gs.PropertyBoolean("CopyErr");

            foreach (var prof in gs.GetChildren("Profile"))
            {
                var bp = new BuildProfile();
                bp.Read(prof);
                Profiles.Add(bp);
            }
        }
Esempio n. 3
0
        private static Visgroup ReadVisgroup(GenericStructure visgroup)
        {
            var v = new Visgroup {
                Name    = visgroup["name"],
                ID      = visgroup.PropertyInteger("visgroupid"),
                Colour  = visgroup.PropertyColour("color", Colour.GetRandomBrushColour()),
                Visible = true
            };

            return(v);
        }
Esempio n. 4
0
        private static Displacement ReadDisplacement(long id, GenericStructure dispinfo)
        {
            var disp = new Displacement(id);

            // power, startposition, flags, elevation, subdiv, normals{}, distances{},
            // offsets{}, offset_normals{}, alphas{}, triangle_tags{}, allowed_verts{}
            disp.SetPower(dispinfo.PropertyInteger("power", 3));
            disp.StartPosition = dispinfo.PropertyCoordinate("startposition");
            disp.Elevation     = dispinfo.PropertyDecimal("elevation");
            disp.SubDiv        = dispinfo.PropertyInteger("subdiv") > 0;
            var size          = disp.Resolution + 1;
            var normals       = dispinfo.GetChildren("normals").FirstOrDefault();
            var distances     = dispinfo.GetChildren("distances").FirstOrDefault();
            var offsets       = dispinfo.GetChildren("offsets").FirstOrDefault();
            var offsetNormals = dispinfo.GetChildren("offset_normals").FirstOrDefault();
            var alphas        = dispinfo.GetChildren("alphas").FirstOrDefault();

            //var triangleTags = dispinfo.GetChildren("triangle_tags").First();
            //var allowedVerts = dispinfo.GetChildren("allowed_verts").First();
            for (var i = 0; i < size; i++)
            {
                var row  = "row" + i;
                var norm = normals != null?normals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray();

                var dist = distances != null?distances.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();

                var offn = offsetNormals != null?offsetNormals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray();

                var offs = offsets != null?offsets.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();

                var alph = alphas != null?alphas.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();

                for (var j = 0; j < size; j++)
                {
                    disp.Points[i, j].Displacement       = new Vector(norm[j], dist[j]);
                    disp.Points[i, j].OffsetDisplacement = new Vector(offn[j], offs[j]);
                    disp.Points[i, j].Alpha = alph[j];
                }
            }
            return(disp);
        }
Esempio n. 5
0
        public static CompileTool Parse(GenericStructure gs)
        {
            var tool = new CompileTool
            {
                Name        = gs["Name"] ?? "",
                Description = gs["Description"] ?? "",
                Order       = gs.PropertyInteger("Order"),
                Enabled     = gs.PropertyBoolean("Enabled", true)
            };
            var parameters = gs.GetChildren("Parameter");

            tool.Parameters.AddRange(parameters.Select(CompileParameter.Parse));
            return(tool);
        }
Esempio n. 6
0
        public void Read(GenericStructure gs)
        {
            ID                                 = gs.PropertyInteger("ID");
            Name                               = gs["Name"];
            Engine                             = (Engine)Enum.Parse(typeof(Engine), gs["EngineID"]);
            BuildID                            = gs.PropertyInteger("BuildID");
            SteamInstall                       = gs.PropertyBoolean("SteamInstall");
            WonGameDir                         = gs["WonGameDir"];
            SteamGameDir                       = gs["SteamGameDir"];
            ModDir                             = gs["ModDir"];
            UseHDModels                        = gs.PropertyBoolean("UseHDModels", true);
            BaseDir                            = gs["BaseDir"];
            Executable                         = gs["Executable"];
            ExecutableParameters               = gs["ExecutableParameters"];
            MapDir                             = gs["MapDir"];
            Autosave                           = gs.PropertyBoolean("Autosave");
            UseCustomAutosaveDir               = gs.PropertyBoolean("UseCustomAutosaveDir");
            AutosaveDir                        = gs["AutosaveDir"];
            AutosaveTime                       = gs.PropertyInteger("AutosaveTime");
            AutosaveLimit                      = gs.PropertyInteger("AutosaveLimit");
            AutosaveOnlyOnChanged              = gs.PropertyBoolean("AutosaveOnlyOnChanged", true);
            AutosaveTriggerFileSave            = gs.PropertyBoolean("AutosaveTriggerFileChange", true);
            DefaultPointEntity                 = gs["DefaultPointEntity"];
            DefaultBrushEntity                 = gs["DefaultBrushEntity"];
            DefaultTextureScale                = gs.PropertyDecimal("DefaultTextureScale");
            DefaultLightmapScale               = gs.PropertyDecimal("DefaultLightmapScale");
            IncludeFgdDirectoriesInEnvironment = gs.PropertyBoolean("IncludeFgdDirectoriesInEnvironment", true);
            OverrideMapSize                    = gs.PropertyBoolean("OverrideMapSize");
            OverrideMapSizeLow                 = gs.PropertyInteger("OverrideMapSizeLow");
            OverrideMapSizeHigh                = gs.PropertyInteger("OverrideMapSizeHigh");

            var additional = gs.Children.FirstOrDefault(x => x.Name == "AdditionalPackages");

            if (additional != null)
            {
                foreach (var key in additional.GetPropertyKeys())
                {
                    AdditionalPackages.Add(additional[key]);
                }
            }

            PackageBlacklist = (gs["PackageBlacklist"] ?? "").Replace(";", "\r\n");
            PackageWhitelist = (gs["PackageWhitelist"] ?? "").Replace(";", "\r\n");

            var fgds = gs.Children.FirstOrDefault(x => x.Name == "Fgds");

            if (fgds != null)
            {
                foreach (var key in fgds.GetPropertyKeys())
                {
                    Fgds.Add(new Fgd {
                        Path = fgds[key]
                    });
                }
            }
        }
Esempio n. 7
0
        private static EntityData ReadEntityData(GenericStructure structure)
        {
            var ret = new EntityData();

            foreach (var key in structure.GetPropertyKeys())
            {
                if (ExcludedKeys.Contains(key.ToLower()))
                {
                    continue;
                }
                ret.SetPropertyValue(key, structure[key]);
            }
            ret.Name  = structure["classname"];
            ret.Flags = structure.PropertyInteger("spawnflags");
            return(ret);
        }
Esempio n. 8
0
        private static Face ReadFace(GenericStructure side, IDGenerator generator)
        {
            var id = side.PropertyLong("id");

            if (id == 0)
            {
                id = generator.GetNextFaceID();
            }
            var dispinfo = side.GetChildren("dispinfo").FirstOrDefault();
            var ret      = dispinfo != null?ReadDisplacement(id, dispinfo) : new Face(id);

            // id, plane, material, uaxis, vaxis, rotation, lightmapscale, smoothing_groups
            var uaxis = side.PropertyTextureAxis("uaxis");
            var vaxis = side.PropertyTextureAxis("vaxis");

            ret.Texture.Name     = side["material"];
            ret.Texture.UAxis    = uaxis.Item1;
            ret.Texture.XShift   = uaxis.Item2;
            ret.Texture.XScale   = uaxis.Item3;
            ret.Texture.VAxis    = vaxis.Item1;
            ret.Texture.YShift   = vaxis.Item2;
            ret.Texture.YScale   = vaxis.Item3;
            ret.Texture.Rotation = side.PropertyDecimal("rotation");
            ret.Plane            = side.PropertyPlane("plane");
            //NOTE(SVK) Paste RF data
            ret.Texture.Flags            = (FaceFlags)side.PropertyInteger("flags");
            ret.Texture.Translucency     = (int)side.PropertyDecimal("translucency");
            ret.Texture.Opacity          = side.PropertyDecimal("opacity");
            ret.Texture.PositionRF       = side.PropertyCoordinate("positionrf");
            ret.Texture.TransformAngleRF = side.PropertyMatrix("transformanglerf");

            var verts = side.Children.FirstOrDefault(x => x.Name == "vertex");

            if (verts != null)
            {
                var count = verts.PropertyInteger("count");
                for (var i = 0; i < count; i++)
                {
                    ret.Vertices.Add(new Vertex(verts.PropertyCoordinate("vertex" + i), ret));
                }
            }

            return(ret);
        }
Esempio n. 9
0
        public static CompileParameter Parse(GenericStructure gs)
        {
            var param = new CompileParameter
            {
                Name         = gs["Name"] ?? "",
                Flag         = gs["Flag"] ?? "",
                Description  = gs["Description"] ?? "",
                Enabled      = gs.PropertyBoolean("Enabled"),
                Value        = gs["Value"] ?? "",
                Type         = gs.PropertyEnum("Type", CompileParameterType.Checkbox),
                Min          = gs.PropertyDecimal("Min", Decimal.MinValue),
                Max          = gs.PropertyDecimal("Max", Decimal.MaxValue),
                Precision    = gs.PropertyInteger("Precision", 1),
                Options      = (gs["Options"] ?? "").Split(',').ToList(),
                OptionValues = (gs["OptionValues"] ?? "").Split(',').ToList(),
                Filter       = gs["Filter"] ?? ""
            };

            return(param);
        }
Esempio n. 10
0
        private static Solid ReadSolid(GenericStructure solid, IDGenerator generator)
        {
            var editor = solid.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor");
            var faces  = solid.GetChildren("side").Select(x => ReadFace(x, generator)).ToList();

            Solid ret;

            if (faces.All(x => x.Vertices.Count >= 3))
            {
                // Vertices were stored in the VMF
                ret = new Solid(GetObjectID(solid, generator));
                ret.Faces.AddRange(faces);
            }
            else
            {
                // Need to grab the vertices using plane intersections
                var idg = new IDGenerator(); // No need to increment the id generator if it doesn't have to be
                ret    = Solid.CreateFromIntersectingPlanes(faces.Select(x => x.Plane), idg);
                ret.ID = GetObjectID(solid, generator);

                for (var i = 0; i < ret.Faces.Count; i++)
                {
                    var face = ret.Faces[i];
                    var f    = faces.FirstOrDefault(x => x.Plane.Normal.EquivalentTo(ret.Faces[i].Plane.Normal));
                    if (f == null)
                    {
                        // TODO: Report invalid solids
                        Debug.WriteLine("Invalid solid! ID: " + solid["id"]);
                        return(null);
                    }
                    face.Texture = f.Texture;

                    var disp = f as Displacement;
                    if (disp == null)
                    {
                        continue;
                    }

                    disp.Plane    = face.Plane;
                    disp.Vertices = face.Vertices;
                    disp.Texture  = f.Texture;
                    disp.AlignTexture();
                    disp.CalculatePoints();
                    ret.Faces[i] = disp;
                }
            }

            ret.Flags  = (UInt32)solid.PropertyInteger("flags");
            ret.Colour = editor.PropertyColour("color", Colour.GetRandomBrushColour());
            ret.Visgroups.AddRange(editor.GetAllPropertyValues("visgroupid").Select(int.Parse).Where(x => x > 0));
            foreach (var face in ret.Faces)
            {
                face.Parent = ret;
                face.Colour = ret.Colour;
                face.UpdateBoundingBox();
            }

            if (ret.Faces.Any(x => x is Displacement))
            {
                ret.Faces.ForEach(x => x.IsHidden = !(x is Displacement));
            }

            ret.UpdateBoundingBox(false);

            return(ret);
        }
Esempio n. 11
0
 private TextureFlags GetFlags(GenericStructure vmt)
 {
     var flags = TextureFlags.None;
     var tp = vmt.PropertyInteger("$translucent") + vmt.PropertyInteger("$alphatest");
     if (tp > 0) flags |= TextureFlags.Transparent;
     return flags;
 }
Esempio n. 12
0
 private static Visgroup ReadVisgroup(GenericStructure visgroup)
 {
     var v = new Visgroup
                 {
                     Name = visgroup["name"],
                     ID = visgroup.PropertyInteger("visgroupid"),
                     Colour = visgroup.PropertyColour("color", Colour.GetRandomBrushColour()),
                     Visible = true
                 };
     return v;
 }
Esempio n. 13
0
 private static EntityData ReadEntityData(GenericStructure structure)
 {
     var ret = new EntityData();
     foreach (var key in structure.GetPropertyKeys())
     {
         if (ExcludedKeys.Contains(key.ToLower())) continue;
         ret.SetPropertyValue(key, structure[key]);
     }
     ret.Name = structure["classname"];
     ret.Flags = structure.PropertyInteger("spawnflags");
     return ret;
 }
Esempio n. 14
0
 private static Displacement ReadDisplacement(long id, GenericStructure dispinfo)
 {
     var disp = new Displacement(id);
     // power, startposition, flags, elevation, subdiv, normals{}, distances{},
     // offsets{}, offset_normals{}, alphas{}, triangle_tags{}, allowed_verts{}
     disp.SetPower(dispinfo.PropertyInteger("power", 3));
     disp.StartPosition = dispinfo.PropertyCoordinate("startposition");
     disp.Elevation = dispinfo.PropertyDecimal("elevation");
     disp.SubDiv = dispinfo.PropertyInteger("subdiv") > 0;
     var size = disp.Resolution + 1;
     var normals = dispinfo.GetChildren("normals").FirstOrDefault();
     var distances = dispinfo.GetChildren("distances").FirstOrDefault();
     var offsets = dispinfo.GetChildren("offsets").FirstOrDefault();
     var offsetNormals = dispinfo.GetChildren("offset_normals").FirstOrDefault();
     var alphas = dispinfo.GetChildren("alphas").FirstOrDefault();
     //var triangleTags = dispinfo.GetChildren("triangle_tags").First();
     //var allowedVerts = dispinfo.GetChildren("allowed_verts").First();
     for (var i = 0; i < size; i++)
     {
         var row = "row" + i;
         var norm = normals != null ? normals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray();
         var dist = distances != null ? distances.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();
         var offn = offsetNormals != null ? offsetNormals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray();
         var offs = offsets != null ? offsets.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();
         var alph = alphas != null ? alphas.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray();
         for (var j = 0; j < size; j++)
         {
             disp.Points[i, j].Displacement = new Vector(norm[j], dist[j]);
             disp.Points[i, j].OffsetDisplacement = new Vector(offn[j], offs[j]);
             disp.Points[i, j].Alpha = alph[j];
         }
     }
     return disp;
 }