public void Write(GenericStructure gs) { foreach (var pi in GetType().GetProperties()) { var val = pi.GetValue(this, null); gs.AddProperty(pi.Name, val == null ? "" : val.ToString()); } }
public void Write(GenericStructure gs) { gs["ID"] = ID.ToString(CultureInfo.InvariantCulture); gs["Name"] = Name; gs["EngineID"] = Engine.ToString(); gs["BuildID"] = BuildID.ToString(CultureInfo.InvariantCulture); gs["SteamInstall"] = SteamInstall.ToString(CultureInfo.InvariantCulture); gs["WonGameDir"] = WonGameDir; gs["SteamGameDir"] = SteamGameDir; gs["ModDir"] = ModDir; gs["UseHDModels"] = UseHDModels.ToString(CultureInfo.InvariantCulture); gs["BaseDir"] = BaseDir; gs["Executable"] = Executable; gs["ExecutableParameters"] = ExecutableParameters; gs["MapDir"] = MapDir; gs["Autosave"] = Autosave.ToString(CultureInfo.InvariantCulture); gs["UseCustomAutosaveDir"] = UseCustomAutosaveDir.ToString(CultureInfo.InvariantCulture); gs["AutosaveDir"] = AutosaveDir; gs["AutosaveTime"] = AutosaveTime.ToString(CultureInfo.InvariantCulture); gs["AutosaveLimit"] = AutosaveLimit.ToString(CultureInfo.InvariantCulture); gs["AutosaveOnlyOnChanged"] = AutosaveOnlyOnChanged.ToString(CultureInfo.InvariantCulture); gs["AutosaveTriggerFileChange"] = AutosaveTriggerFileSave.ToString(CultureInfo.InvariantCulture); gs["DefaultPointEntity"] = DefaultPointEntity; gs["DefaultBrushEntity"] = DefaultBrushEntity; gs["DefaultTextureScale"] = DefaultTextureScale.ToString(CultureInfo.InvariantCulture); gs["DefaultLightmapScale"] = DefaultLightmapScale.ToString(CultureInfo.InvariantCulture); gs["IncludeFgdDirectoriesInEnvironment"] = IncludeFgdDirectoriesInEnvironment.ToString(CultureInfo.InvariantCulture); gs["OverrideMapSize"] = OverrideMapSize.ToString(CultureInfo.InvariantCulture); gs["OverrideMapSizeLow"] = OverrideMapSizeLow.ToString(CultureInfo.InvariantCulture); gs["OverrideMapSizeHigh"] = OverrideMapSizeHigh.ToString(CultureInfo.InvariantCulture); var additional = new GenericStructure("AdditionalPackages"); var i = 1; foreach (var add in AdditionalPackages) { additional.AddProperty(i.ToString(CultureInfo.InvariantCulture), add); i++; } gs.Children.Add(additional); gs["PackageBlacklist"] = (PackageBlacklist ?? "").Replace("\r", "").Replace('\n', ';'); gs["PackageWhitelist"] = (PackageWhitelist ?? "").Replace("\r", "").Replace('\n', ';'); var fgds = new GenericStructure("Fgds"); i = 1; foreach (var fgd in Fgds) { fgds.AddProperty(i.ToString(CultureInfo.InvariantCulture), fgd.Path); i++; } gs.Children.Add(fgds); }
private static GenericStructure WriteEditor(MapObject obj) { var editor = new GenericStructure("editor"); editor["color"] = FormatColor(obj.Colour); foreach (var visgroup in obj.Visgroups.Except(obj.AutoVisgroups).OrderBy(x => x)) { editor.AddProperty("visgroupid", visgroup.ToString(CultureInfo.InvariantCulture)); } editor["visgroupshown"] = "1"; editor["visgroupautoshown"] = "1"; if (obj.Parent is Group) { editor["groupid"] = obj.Parent.ID.ToString(CultureInfo.InvariantCulture); } if (obj.Parent != null) { editor["parentid"] = obj.Parent.ID.ToString(CultureInfo.InvariantCulture); } return(editor); }
public static void Write() { var newSettings = Serialise.SerialiseSettings().Select(s => new Setting { Key = s.Key, Value = s.Value }); Settings.Clear(); Settings.AddRange(newSettings); var root = new GenericStructure("Sledge"); // Settings var settings = new GenericStructure("Settings"); foreach (var setting in Settings) { settings.AddProperty(setting.Key, setting.Value); } root.Children.Add(settings); // Recent Files var recents = new GenericStructure("RecentFiles"); var i = 1; foreach (var file in RecentFiles.OrderBy(x => x.Order).Select(x => x.Location).Where(File.Exists)) { recents.AddProperty(i.ToString(CultureInfo.InvariantCulture), file); i++; } root.Children.Add(recents); // Games > Fgds/Wads foreach (var game in Games) { var g = new GenericStructure("Game"); game.Write(g); root.Children.Add(g); } // Builds foreach (var build in Builds) { var b = new GenericStructure("Build"); build.Write(b); root.Children.Add(b); } // Hotkeys Hotkeys = Sledge.Settings.Hotkeys.GetHotkeys().ToList(); var hotkeys = new GenericStructure("Hotkeys"); foreach (var g in Hotkeys.GroupBy(x => x.ID)) { var count = 0; foreach (var hotkey in g) { hotkeys.AddProperty(hotkey.ID + ":" + count, hotkey.HotkeyString); count++; } } root.Children.Add(hotkeys); // Additional var additional = new GenericStructure("AdditionalSettings"); foreach (var kv in AdditionalSettings) { var child = new GenericStructure(kv.Key); child.Children.Add(kv.Value); additional.Children.Add(child); } root.Children.Add(additional); // Favourite textures var favTextures = new GenericStructure("FavouriteTextures"); favTextures.Children.Add(GenericStructure.Serialise(FavouriteTextureFolders)); root.Children.Add(favTextures); File.WriteAllText(SettingsFile, root.ToString()); }
protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { var groups = new List <Group>(); var solids = new List <Solid>(); var ents = new List <Entity>(); FlattenTree(map.WorldSpawn, solids, ents, groups); var fvi = FileVersionInfo.GetVersionInfo(typeof(VmfProvider).Assembly.Location); var versioninfo = new GenericStructure("versioninfo"); versioninfo.AddProperty("editorname", "Chisel"); versioninfo.AddProperty("editorversion", fvi.ProductMajorPart.ToString(CultureInfo.InvariantCulture) + "." + fvi.ProductMinorPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("editorbuild", fvi.ProductBuildPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("mapversion", map.Version.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("formatversion", "100"); versioninfo.AddProperty("prefab", "0"); var visgroups = new GenericStructure("visgroups"); foreach (var visgroup in map.Visgroups.OrderBy(x => x.ID).Where(x => !x.IsAutomatic)) { visgroups.Children.Add(WriteVisgroup(visgroup)); } var viewsettings = new GenericStructure("viewsettings"); viewsettings.AddProperty("bSnapToGrid", map.SnapToGrid ? "1" : "0"); viewsettings.AddProperty("bShowGrid", map.Show2DGrid ? "1" : "0"); viewsettings.AddProperty("bShow3DGrid", map.Show3DGrid ? "1" : "0"); viewsettings.AddProperty("nGridSpacing", map.GridSpacing.ToString(CultureInfo.InvariantCulture)); viewsettings.AddProperty("bIgnoreGrouping", map.IgnoreGrouping ? "1" : "0"); viewsettings.AddProperty("bHideFaceMask", map.HideFaceMask ? "1" : "0"); viewsettings.AddProperty("bHideNullTextures", map.HideNullTextures ? "1" : "0"); viewsettings.AddProperty("bTextureLock", map.TextureLock ? "1" : "0"); viewsettings.AddProperty("bTextureScalingLock", map.TextureScalingLock ? "1" : "0"); var world = WriteWorld(map, solids, groups); var entities = ents.OrderBy(x => x.ID).Select(WriteEntity).ToList(); var cameras = new GenericStructure("cameras"); cameras.AddProperty("activecamera", map.Cameras.IndexOf(map.ActiveCamera).ToString(CultureInfo.InvariantCulture)); foreach (var cam in map.Cameras) { var camera = new GenericStructure("camera"); camera.AddProperty("position", "[" + FormatCoordinate(cam.EyePosition) + "]"); camera.AddProperty("look", "[" + FormatCoordinate(cam.LookPosition) + "]"); cameras.Children.Add(camera); } var cordon = new GenericStructure("cordon"); cordon.AddProperty("mins", map.CordonBounds.Start.ToString()); cordon.AddProperty("maxs", map.CordonBounds.End.ToString()); cordon.AddProperty("active", map.Cordon ? "1" : "0"); using (var sw = new StreamWriter(stream)) { versioninfo.PrintToStream(sw); visgroups.PrintToStream(sw); viewsettings.PrintToStream(sw); world.PrintToStream(sw); entities.ForEach(e => e.PrintToStream(sw)); cameras.PrintToStream(sw); cordon.PrintToStream(sw); } }
private static GenericStructure WriteEditor(MapObject obj) { var editor = new GenericStructure("editor"); editor["color"] = FormatColor(obj.Colour); foreach (var visgroup in obj.Visgroups.OrderBy(x => x)) { editor.AddProperty("visgroupid", visgroup.ToString(CultureInfo.InvariantCulture)); } editor["visgroupshown"] = "1"; editor["visgroupautoshown"] = "1"; if (obj.Parent is Group) editor["groupid"] = obj.Parent.ID.ToString(CultureInfo.InvariantCulture); if (obj.Parent != null) editor["parentid"] = obj.Parent.ID.ToString(CultureInfo.InvariantCulture); return editor; }
protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { var groups = new List<Group>(); var solids = new List<Solid>(); var ents = new List<Entity>(); FlattenTree(map.WorldSpawn, solids, ents, groups); var fvi = FileVersionInfo.GetVersionInfo(typeof (VmfProvider).Assembly.Location); var versioninfo = new GenericStructure("versioninfo"); versioninfo.AddProperty("editorname", "Sledge"); versioninfo.AddProperty("editorversion", fvi.ProductMajorPart.ToString(CultureInfo.InvariantCulture) + "." + fvi.ProductMinorPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("editorbuild", fvi.ProductBuildPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("mapversion", map.Version.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("formatversion", "100"); versioninfo.AddProperty("prefab", "0"); var visgroups = new GenericStructure("visgroups"); foreach (var visgroup in map.Visgroups.OrderBy(x => x.ID).Where(x => !x.IsAutomatic)) { visgroups.Children.Add(WriteVisgroup(visgroup)); } var viewsettings = new GenericStructure("viewsettings"); viewsettings.AddProperty("bSnapToGrid", map.SnapToGrid ? "1" : "0"); viewsettings.AddProperty("bShowGrid", map.Show2DGrid ? "1" : "0"); viewsettings.AddProperty("bShow3DGrid", map.Show3DGrid ? "1" : "0"); viewsettings.AddProperty("nGridSpacing", map.GridSpacing.ToString(CultureInfo.InvariantCulture)); viewsettings.AddProperty("bIgnoreGrouping", map.IgnoreGrouping ? "1" : "0"); viewsettings.AddProperty("bHideFaceMask", map.HideFaceMask ? "1" : "0"); viewsettings.AddProperty("bHideNullTextures", map.HideNullTextures ? "1" : "0"); viewsettings.AddProperty("bTextureLock", map.TextureLock ? "1" : "0"); viewsettings.AddProperty("bTextureScalingLock", map.TextureScalingLock ? "1" : "0"); var world = WriteWorld(map, solids, groups); var entities = ents.OrderBy(x => x.ID).Select(WriteEntity).ToList(); var cameras = new GenericStructure("cameras"); cameras.AddProperty("activecamera", map.Cameras.IndexOf(map.ActiveCamera).ToString(CultureInfo.InvariantCulture)); foreach (var cam in map.Cameras) { var camera = new GenericStructure("camera"); camera.AddProperty("position", "[" + FormatCoordinate(cam.EyePosition) + "]"); camera.AddProperty("look", "[" + FormatCoordinate(cam.LookPosition) + "]"); cameras.Children.Add(camera); } var cordon = new GenericStructure("cordon"); cordon.AddProperty("mins", map.CordonBounds.Start.ToString()); cordon.AddProperty("maxs", map.CordonBounds.End.ToString()); cordon.AddProperty("active", map.Cordon ? "1" : "0"); using (var sw = new StreamWriter(stream)) { versioninfo.PrintToStream(sw); visgroups.PrintToStream(sw); viewsettings.PrintToStream(sw); world.PrintToStream(sw); entities.ForEach(e => e.PrintToStream(sw)); cameras.PrintToStream(sw); cordon.PrintToStream(sw); } }