public string DisplayValue(GameData gd) { var cls = gd.Classes.FirstOrDefault(x => x.Name == Class); var prop = cls == null ? null : cls.Properties.FirstOrDefault(x => x.Name == OriginalKey && x.VariableType == VariableType.Choices); var opt = prop == null ? null : prop.Options.FirstOrDefault(x => x.Key == Value); return opt == null ? Value : opt.Description; }
public Document(string mapFile, Map map, Game game) { MapFile = mapFile; Map = map; Game = game; MapFileName = mapFile == null ? DocumentManager.GetUntitledDocumentName() : Path.GetFileName(mapFile); _subscriptions = new DocumentSubscriptions(this); _memory = new DocumentMemory(); var cam = Map.GetActiveCamera(); if (cam != null) _memory.SetCamera(cam.EyePosition, cam.LookPosition); Selection = new SelectionManager(this); History = new HistoryManager(this); if (Map.GridSpacing <= 0) { Map.GridSpacing = Grid.DefaultSize; } try { GameData = GameDataProvider.GetGameDataFromFiles(game.Fgds.Select(f => f.Path)); } catch(ProviderException) { // TODO: Error logging GameData = new GameData(); } TextureCollection = TextureProvider.CreateCollection(game.Wads.Select(x => x.Path).Distinct()); var texList = Map.GetAllTextures(); var items = TextureCollection.GetItems(texList); TextureCollection.LoadTextureItems(items); Map.PostLoadProcess(GameData, GetTexture, SettingsManager.GetSpecialTextureOpacity); HelperManager = new HelperManager(this); Renderer = new RenderManager(this); if (MapFile != null) Mediator.Publish(EditorMediator.FileOpened, MapFile); // Autosaving if (Game.Autosave) { var at = Math.Max(1, Game.AutosaveTime); Scheduler.Schedule(this, Autosave, TimeSpan.FromMinutes(at)); } }
public static List<TableValue> Create(GameData gd, string className, List<Property> props) { var list = new List<TableValue>(); var cls = gd.Classes.FirstOrDefault(x => x.Name == className); var gameDataProps = cls != null ? cls.Properties : new List<DataStructures.GameData.Property>(); foreach (var gdProps in gameDataProps.Where(x => x.Name != "spawnflags").GroupBy(x => x.Name)) { var gdProp = gdProps.First(); var vals = props.Where(x => x.Key == gdProp.Name).Select(x => x.Value).Distinct().ToList(); var value = vals.Count == 0 ? gdProp.DefaultValue : (vals.Count == 1 ? vals.First() : "<multiple values>" + String.Join(", ", vals)); list.Add(new TableValue { Class = className, OriginalKey = gdProp.Name, NewKey = gdProp.Name, Value = value}); } foreach (var group in props.Where(x => gameDataProps.All(y => x.Key != y.Name)).GroupBy(x => x.Key)) { var vals = @group.Select(x => x.Value).Distinct().ToList(); var value = vals.Count == 1 ? vals.First() : "<multiple values> - " + String.Join(", ", vals); list.Add(new TableValue { Class = className, OriginalKey = @group.Key, NewKey = @group.Key, Value = value }); } return list; }
public string DisplayText(GameData gd) { var cls = gd.Classes.FirstOrDefault(x => x.Name == Class); var prop = cls == null ? null : cls.Properties.FirstOrDefault(x => x.Name == NewKey); return prop == null ? NewKey : prop.DisplayText(); }
/// <summary> /// Should be called when a map is loaded. Sets up visgroups, object ids, gamedata, and textures. /// </summary> public void PostLoadProcess(GameData.GameData gameData, Func<string, ITexture> textureAccessor, Func<string, float> textureOpacity) { PartialPostLoadProcess(gameData, textureAccessor, textureOpacity); var all = WorldSpawn.FindAll(); // Set maximum ids var maxObjectId = all.Max(x => x.ID); var faces = all.OfType<Solid>().SelectMany(x => x.Faces).ToList(); var maxFaceId = faces.Any() ? faces.Max(x => x.ID) : 0; IDGenerator.Reset(maxObjectId, maxFaceId); // todo visgroups // WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true); // Auto visgroup var auto = AutoVisgroup.GetDefaultAutoVisgroup(); var quickHide = new AutoVisgroup {ID = int.MinValue, IsHidden = true, Name = "Autohide", Parent = auto, Visible = false}; auto.Children.Add(quickHide); Visgroups.Add(auto); UpdateAutoVisgroups(all, false); // Purge empty groups foreach (var emptyGroup in WorldSpawn.Find(x => x is Group && !x.HasChildren)) { emptyGroup.SetParent(null); } }
public void PartialPostLoadProcess(GameData.GameData gameData, Func<string, ITexture> textureAccessor, Func<string, float> textureOpacity) { var objects = WorldSpawn.FindAll(); Parallel.ForEach(objects, obj => { if (obj is Entity) { var ent = (Entity) obj; if (ent.GameData == null || !String.Equals(ent.GameData.Name, ent.EntityData.Name, StringComparison.InvariantCultureIgnoreCase)) { var gd = gameData.Classes.FirstOrDefault( x => String.Equals(x.Name, ent.EntityData.Name, StringComparison.CurrentCultureIgnoreCase) && x.ClassType != ClassType.Base); ent.GameData = gd; ent.UpdateBoundingBox(); } } else if (obj is Solid) { var s = ((Solid) obj); var disp = HideDisplacementSolids && s.Faces.Any(x => x is Displacement); s.Faces.ForEach(f => { if (f.Texture.Texture == null) { f.Texture.Texture = textureAccessor(f.Texture.Name.ToLowerInvariant()); f.CalculateTextureCoordinates(true); } if (disp && !(f is Displacement)) { f.Opacity = 0; } else if (f.Texture.Texture != null) { f.Opacity = textureOpacity(f.Texture.Name.ToLowerInvariant()); if (!HideNullTextures && f.Opacity < 0.1) f.Opacity = 1; } }); } }); }
private void SetEntityData(Entity ent, EntityData data, GameData gameData) { ent.EntityData = data; ent.GameData = gameData.Classes.FirstOrDefault(x => String.Equals(x.Name, data.Name, StringComparison.CurrentCultureIgnoreCase) && x.ClassType != ClassType.Base); }
private void SetEntityData(Entity ent, EntityData data, GameData gameData) { ent.EntityData = data; ent.GameData = gameData.Classes.FirstOrDefault(x => x.Name.ToLower() == data.Name.ToLower()); }