private static TravelStationDefinition GetTravelStationDefinition( InfoDictionary<DownloadableContentDefinition> downloadableContents, KeyValuePair<string, Raw.TravelStationDefinition> kv) { DownloadableContentDefinition dlcExpansion = null; if (string.IsNullOrEmpty(kv.Value.DLCExpansion) == false) { if (downloadableContents.ContainsKey(kv.Value.DLCExpansion) == false) { throw new KeyNotFoundException("could not find downloadable content '" + kv.Value.DLCExpansion + "'"); } dlcExpansion = downloadableContents[kv.Value.DLCExpansion]; } if (kv.Value is Raw.FastTravelStationDefinition) { return GetFastTravelStationDefinition(dlcExpansion, kv); } if (kv.Value is Raw.LevelTravelStationDefinition) { return GetLevelTravelStationDefinition(dlcExpansion, kv); } throw new InvalidOperationException(); }
private static CustomizationDefinition GetCustomizationDefinition( InfoDictionary <DownloadableContentDefinition> downloadableContents, KeyValuePair <string, Raw.CustomizationDefinition> kv) { DownloadableContentDefinition content = null; if (string.IsNullOrEmpty(kv.Value.DLC) == false) { if (downloadableContents.ContainsKey(kv.Value.DLC) == false) { throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLC); } content = downloadableContents[kv.Value.DLC]; } return(new CustomizationDefinition() { ResourcePath = kv.Key, Name = kv.Value.Name, Type = kv.Value.Type, Usage = kv.Value.Usage, DataName = kv.Value.DataName, PrimarySort = kv.Value.PrimarySort, SecondarySort = kv.Value.SecondarySort, DLC = content, }); }
private static WeaponBalancePartCollection GetWeaponBalancePartCollection( InfoDictionary <WeaponTypeDefinition> weaponTypes, Raw.WeaponBalancePartCollection raw) { if (raw == null) { return(null); } WeaponTypeDefinition type = null; if (string.IsNullOrEmpty(raw.Type) == false) { if (weaponTypes.ContainsKey(raw.Type) == false) { throw ResourceNotFoundException.Create("weapon type", raw.Type); } type = weaponTypes[raw.Type]; } return(new WeaponBalancePartCollection() { Type = type, Mode = raw.Mode, BodyParts = raw.BodyParts, GripParts = raw.GripParts, BarrelParts = raw.BarrelParts, SightParts = raw.SightParts, StockParts = raw.StockParts, ElementalParts = raw.ElementalParts, Accessory1Parts = raw.Accessory1Parts, Accessory2Parts = raw.Accessory2Parts, MaterialParts = raw.MaterialParts, }); }
private static TravelStationDefinition GetTravelStationDefinition( InfoDictionary <DownloadableContentDefinition> downloadableContents, KeyValuePair <string, Raw.TravelStationDefinition> kv) { DownloadableContentDefinition dlcExpansion = null; if (string.IsNullOrEmpty(kv.Value.DLCExpansion) == false) { if (downloadableContents.ContainsKey(kv.Value.DLCExpansion) == false) { throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLCExpansion); } dlcExpansion = downloadableContents[kv.Value.DLCExpansion]; } if (kv.Value is Raw.FastTravelStationDefinition) { return(GetFastTravelStationDefinition(dlcExpansion, kv)); } if (kv.Value is Raw.LevelTravelStationDefinition) { return(GetLevelTravelStationDefinition(dlcExpansion, kv)); } throw new InvalidOperationException(); }
public static InfoDictionary <TravelStationDefinition> Load( InfoDictionary <DownloadableContentDefinition> downloadableContents) { try { var raws = LoaderHelper .DeserializeJson <Dictionary <string, Raw.TravelStationDefinition> >("Travel Stations"); var defs = new InfoDictionary <TravelStationDefinition>( raws.ToDictionary(kv => kv.Key, kv => GetTravelStationDefinition(downloadableContents, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.PreviousStation) == false)) { if (defs.ContainsKey(kv.Value.PreviousStation) == false) { throw new KeyNotFoundException("could not find travel station '" + kv.Value.PreviousStation + "'"); } defs[kv.Key].PreviousStation = defs[kv.Value.PreviousStation]; } return(defs); } catch (Exception e) { throw new InfoLoadException("failed to load travel stations", e); } }
public static InfoDictionary<TravelStationDefinition> Load( InfoDictionary<DownloadableContentDefinition> downloadableContents) { try { var raws = LoaderHelper .DeserializeJson<Dictionary<string, Raw.TravelStationDefinition>>("Travel Stations"); var defs = new InfoDictionary<TravelStationDefinition>( raws.ToDictionary(kv => kv.Key, kv => GetTravelStationDefinition(downloadableContents, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.PreviousStation) == false)) { if (defs.ContainsKey(kv.Value.PreviousStation) == false) { throw new KeyNotFoundException("could not find travel station '" + kv.Value.PreviousStation + "'"); } defs[kv.Key].PreviousStation = defs[kv.Value.PreviousStation]; } return defs; } catch (Exception e) { throw new InfoLoadException("failed to load travel stations", e); } }
private static ItemBalancePartCollection GetItemBalancePartCollection( InfoDictionary <ItemTypeDefinition> itemTypes, Raw.ItemBalancePartCollection raw) { if (raw == null) { return(null); } ItemTypeDefinition type = null; if (string.IsNullOrEmpty(raw.Type) == false) { if (itemTypes.ContainsKey(raw.Type) == false) { throw ResourceNotFoundException.Create("item type", raw.Type); } type = itemTypes[raw.Type]; } return(new ItemBalancePartCollection() { Type = type, Mode = raw.Mode, AlphaParts = raw.AlphaParts, BetaParts = raw.BetaParts, GammaParts = raw.GammaParts, DeltaParts = raw.DeltaParts, EpsilonParts = raw.EpsilonParts, ZetaParts = raw.ZetaParts, EtaParts = raw.EtaParts, ThetaParts = raw.ThetaParts, MaterialParts = raw.MaterialParts, }); }
public static InfoDictionary <ItemBalanceDefinition> Load(InfoDictionary <ItemTypeDefinition> itemTypes) { try { var raws = LoaderHelper.DeserializeJson <Dictionary <string, Raw.ItemBalanceDefinition> >("Item Balance"); var defs = new InfoDictionary <ItemBalanceDefinition>(raws.ToDictionary(kv => kv.Key, kv => GetItemBalanceDefinition(itemTypes, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.Base) == false)) { if (defs.ContainsKey(kv.Value.Base) == false) { throw new KeyNotFoundException("could not find item balance '" + kv.Value.Base + "'"); } defs[kv.Key].Base = defs[kv.Value.Base]; } return(defs); } catch (Exception e) { throw new InfoLoadException("failed to load item balance", e); } }
public static InfoDictionary<WeaponBalanceDefinition> Load(InfoDictionary<WeaponTypeDefinition> weaponTypes) { try { var raws = LoaderHelper.DeserializeJson<Dictionary<string, Raw.WeaponBalanceDefinition>>("Weapon Balance"); var defs = new InfoDictionary<WeaponBalanceDefinition>(raws.ToDictionary(kv => kv.Key, kv => GetWeaponBalanceDefinition( weaponTypes, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.Base) == false)) { if (defs.ContainsKey(kv.Value.Base) == false) { throw new KeyNotFoundException("could not find weapon balance '" + kv.Value.Base + "'"); } defs[kv.Key].Base = defs[kv.Value.Base]; } return defs; } catch (Exception e) { throw new InfoLoadException("failed to load weapon balance", e); } }
public static InfoDictionary <TravelStationDefinition> Load( InfoDictionary <DownloadableContentDefinition> downloadableContents) { try { var raws = LoaderHelper.DeserializeDump <Dictionary <string, Raw.TravelStationDefinition> >( "Travel Stations"); var defs = new InfoDictionary <TravelStationDefinition>( raws.ToDictionary(kv => kv.Key, kv => GetTravelStationDefinition(downloadableContents, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.PreviousStation) == false)) { if (defs.ContainsKey(kv.Value.PreviousStation) == false) { throw ResourceNotFoundException.Create("travel station", kv.Value.PreviousStation); } defs[kv.Key].PreviousStation = defs[kv.Value.PreviousStation]; } foreach (var kv in raws .Where( kv => (kv.Value is Raw.LevelTravelStationDefinition) && string.IsNullOrEmpty(((Raw.LevelTravelStationDefinition)kv.Value).DestinationStation) == false)) { var rawLevelTravelStation = (Raw.LevelTravelStationDefinition)kv.Value; if (defs.ContainsKey(rawLevelTravelStation.DestinationStation) == false) { throw ResourceNotFoundException.Create( "level travel station", rawLevelTravelStation.DestinationStation); } var levelTravelStation = (LevelTravelStationDefinition)defs[kv.Key]; levelTravelStation.DestinationStation = (LevelTravelStationDefinition)defs[rawLevelTravelStation.DestinationStation]; } return(defs); } catch (Exception e) { throw new InfoLoadException("failed to load travel stations", e); } }
private static ItemTypeDefinition GetItemType(InfoDictionary <ItemTypeDefinition> itemTypes, string type) { if (string.IsNullOrEmpty(type) == true) { return(null); } if (itemTypes.ContainsKey(type) == false) { throw ResourceNotFoundException.Create("item type", type); } return(itemTypes[type]); }
private static ItemTypeDefinition GetItemType(InfoDictionary <ItemTypeDefinition> itemTypes, string type) { if (string.IsNullOrEmpty(type) == true) { return(null); } if (itemTypes.ContainsKey(type) == false) { throw new KeyNotFoundException("could not find item type '" + type + "'"); } return(itemTypes[type]); }
private static WeaponTypeDefinition GetWeaponType(InfoDictionary<WeaponTypeDefinition> weaponTypes, string type) { if (string.IsNullOrEmpty(type) == true) { return null; } if (weaponTypes.ContainsKey(type) == false) { throw new KeyNotFoundException("could not find weapon type '" + type + "'"); } return weaponTypes[type]; }
private static List <ItemTypeDefinition> GetTypes(InfoDictionary <ItemTypeDefinition> itemTypes, IEnumerable <string> types) { if (types == null) { return(null); } return(types.Select(t => { if (itemTypes.ContainsKey(t) == false) { throw ResourceNotFoundException.Create("item type", t); } return itemTypes[t]; }).ToList()); }
private static List <ItemTypeDefinition> GetTypes(InfoDictionary <ItemTypeDefinition> itemTypes, List <string> types) { if (types == null) { return(null); } return(types.Select(t => { if (itemTypes.ContainsKey(t) == false) { throw new KeyNotFoundException("could not find item type '" + t + "'"); } return itemTypes[t]; }).ToList()); }
private static DownloadableContentDefinition GetDownloadableContent( InfoDictionary<DownloadablePackageDefinition> downloadablePackages, KeyValuePair<string, Raw.DownloadableContentDefinition> kv) { DownloadablePackageDefinition package = null; if (string.IsNullOrEmpty(kv.Value.Package) == false) { if (downloadablePackages.ContainsKey(kv.Value.Package) == false) { throw new KeyNotFoundException("could not find downloadable package " + kv.Value.Package); } package = downloadablePackages[kv.Value.Package]; } return new DownloadableContentDefinition() { ResourcePath = kv.Key, Id = kv.Value.Id, Name = kv.Value.Name, Package = package, Type = kv.Value.Type, }; }
private static FastTravelStationOrdering GetFastTravelStationOrdering( InfoDictionary <TravelStationDefinition> travelStations, InfoDictionary <DownloadableContentDefinition> downloadableContents, KeyValuePair <string, Raw.FastTravelStationOrdering> kv) { DownloadableContentDefinition dlcExpansion = null; if (string.IsNullOrEmpty(kv.Value.DLCExpansion) == false) { if (downloadableContents.ContainsKey(kv.Value.DLCExpansion) == false) { throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLCExpansion); } dlcExpansion = downloadableContents[kv.Value.DLCExpansion]; } return(new FastTravelStationOrdering() { ResourcePath = kv.Key, Stations = GetStations(travelStations, kv.Value.Stations), DLCExpansion = dlcExpansion, }); }
private static List <FastTravelStationDefinition> GetStations( InfoDictionary <TravelStationDefinition> travelStations, IEnumerable <string> raws) { if (raws == null) { return(null); } return(raws.Select(raw => { if (travelStations.ContainsKey(raw) == false) { throw ResourceNotFoundException.Create("fast travel station", raw); } var travelStation = travelStations[raw]; if (travelStation is FastTravelStationDefinition fastTravelStation) { return fastTravelStation; } throw new InvalidOperationException($"'{raw}' is not a FastTravelStationDefinition"); }).ToList()); }
private static PlayerClassDefinition GetPlayerClassDefinition( InfoDictionary<DownloadableContentDefinition> downloadableContents, KeyValuePair<string, Raw.PlayerClassDefinition> kv) { DownloadableContentDefinition content = null; if (string.IsNullOrEmpty(kv.Value.DLC) == false) { if (downloadableContents.ContainsKey(kv.Value.DLC) == false) { throw new KeyNotFoundException("could not find downloadable content " + kv.Value.DLC); } content = downloadableContents[kv.Value.DLC]; } return new PlayerClassDefinition() { ResourcePath = kv.Key, Name = kv.Value.Name, Class = kv.Value.Class, SortOrder = kv.Value.SortOrder, DLC = content, }; }
private static CustomizationDefinition GetCustomizationDefinition( InfoDictionary<DownloadableContentDefinition> downloadableContents, KeyValuePair<string, Raw.CustomizationDefinition> kv) { DownloadableContentDefinition content = null; if (string.IsNullOrEmpty(kv.Value.DLC) == false) { if (downloadableContents.ContainsKey(kv.Value.DLC) == false) { throw new KeyNotFoundException("could not find downloadable content " + kv.Value.DLC); } content = downloadableContents[kv.Value.DLC]; } return new CustomizationDefinition() { ResourcePath = kv.Key, Name = kv.Value.Name, Type = kv.Value.Type, Usage = kv.Value.Usage, DLC = content, }; }
public static InfoDictionary <WeaponBalanceDefinition> Load(InfoDictionary <WeaponTypeDefinition> weaponTypes) { try { var raws = LoaderHelper.DeserializeDump <Dictionary <string, Raw.WeaponBalanceDefinition> >( "Weapon Balance"); var defs = new InfoDictionary <WeaponBalanceDefinition>( raws.ToDictionary(kv => kv.Key, kv => GetWeaponBalanceDefinition(weaponTypes, kv))); foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.Base) == false)) { if (defs.ContainsKey(kv.Value.Base) == false) { throw ResourceNotFoundException.Create("weapon balance", kv.Value.Base); } defs[kv.Key].Base = defs[kv.Value.Base]; } return(defs); } catch (Exception e) { throw new InfoLoadException("failed to load weapon balance", e); } }
private static DownloadableContentDefinition GetDownloadableContent( InfoDictionary <DownloadablePackageDefinition> downloadablePackages, KeyValuePair <string, Raw.DownloadableContentDefinition> kv) { DownloadablePackageDefinition package = null; if (string.IsNullOrEmpty(kv.Value.Package) == false) { if (downloadablePackages.ContainsKey(kv.Value.Package) == false) { throw ResourceNotFoundException.Create("downloadable package", kv.Value.Package); } package = downloadablePackages[kv.Value.Package]; } return(new DownloadableContentDefinition() { ResourcePath = kv.Key, Id = kv.Value.Id, Name = kv.Value.Name, Package = package, Type = kv.Value.Type, }); }
private static PlayerClassDefinition GetPlayerClassDefinition( InfoDictionary <DownloadableContentDefinition> downloadableContents, KeyValuePair <string, Raw.PlayerClassDefinition> kv) { DownloadableContentDefinition content = null; if (string.IsNullOrEmpty(kv.Value.DLC) == false) { if (downloadableContents.ContainsKey(kv.Value.DLC) == false) { throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLC); } content = downloadableContents[kv.Value.DLC]; } return(new PlayerClassDefinition() { ResourcePath = kv.Key, Name = kv.Value.Name, Class = kv.Value.Class, SortOrder = kv.Value.SortOrder, DLC = content, }); }
private static CustomizationDefinition GetCustomizationDefinition( InfoDictionary <DownloadableContentDefinition> downloadableContents, KeyValuePair <string, Raw.CustomizationDefinition> kv) { DownloadableContentDefinition content = null; if (string.IsNullOrEmpty(kv.Value.DLC) == false) { if (downloadableContents.ContainsKey(kv.Value.DLC) == false) { throw new KeyNotFoundException("could not find downloadable content " + kv.Value.DLC); } content = downloadableContents[kv.Value.DLC]; } return(new CustomizationDefinition() { ResourcePath = kv.Key, Name = kv.Value.Name, Type = kv.Value.Type, Usage = kv.Value.Usage, DLC = content, }); }
private static ItemBalancePartCollection GetItemBalancePartCollection( InfoDictionary<ItemTypeDefinition> itemTypes, Raw.ItemBalancePartCollection raw) { if (raw == null) { return null; } ItemTypeDefinition type = null; if (string.IsNullOrEmpty(raw.Type) == false) { if (itemTypes.ContainsKey(raw.Type) == false) { throw new KeyNotFoundException("could not find item type " + raw.Type); } type = itemTypes[raw.Type]; } return new ItemBalancePartCollection() { Type = type, Mode = raw.Mode, AlphaParts = raw.AlphaParts, BetaParts = raw.BetaParts, GammaParts = raw.GammaParts, DeltaParts = raw.DeltaParts, EpsilonParts = raw.EpsilonParts, ZetaParts = raw.ZetaParts, EtaParts = raw.EtaParts, ThetaParts = raw.ThetaParts, MaterialParts = raw.MaterialParts, }; }
private static List<ItemTypeDefinition> GetTypes(InfoDictionary<ItemTypeDefinition> itemTypes, List<string> types) { if (types == null) { return null; } return types.Select(t => { if (itemTypes.ContainsKey(t) == false) { throw new KeyNotFoundException("could not find item type '" + t + "'"); } return itemTypes[t]; }).ToList(); }
private static WeaponBalancePartCollection GetWeaponBalancePartCollection( InfoDictionary<WeaponTypeDefinition> weaponTypes, Raw.WeaponBalancePartCollection raw) { if (raw == null) { return null; } WeaponTypeDefinition type = null; if (string.IsNullOrEmpty(raw.Type) == false) { if (weaponTypes.ContainsKey(raw.Type) == false) { throw new KeyNotFoundException("could not find weapon type '" + raw.Type + "'"); } type = weaponTypes[raw.Type]; } return new WeaponBalancePartCollection() { Type = type, Mode = raw.Mode, BodyParts = raw.BodyParts, GripParts = raw.GripParts, BarrelParts = raw.BarrelParts, SightParts = raw.SightParts, StockParts = raw.StockParts, ElementalParts = raw.ElementalParts, Accessory1Parts = raw.Accessory1Parts, Accessory2Parts = raw.Accessory2Parts, MaterialParts = raw.MaterialParts, }; }
protected override Expression VisitMember(MemberExpression node) { if (node.NodeType == ExpressionType.Constant) { return(base.VisitMember(node)); } string sourcePath; var parameterExpression = node.GetParameterExpression(); if (parameterExpression == null) { return(base.VisitMember(node)); } InfoDictionary.Add(parameterExpression, TypeMappings); var sType = parameterExpression.Type; if (InfoDictionary.ContainsKey(parameterExpression) && node.IsMemberExpression()) { sourcePath = node.GetPropertyFullName(); } else { return(base.VisitMember(node)); } var propertyMapInfoList = new List <PropertyMapInfo>(); FindDestinationFullName(sType, InfoDictionary[parameterExpression].DestType, sourcePath, propertyMapInfoList); string fullName; if (propertyMapInfoList.Any(x => x.CustomExpression != null)) { var last = propertyMapInfoList.Last(x => x.CustomExpression != null); var beforeCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) => { if (propertyMapInfoList.IndexOf(next) < propertyMapInfoList.IndexOf(last)) { list.Add(next); } return(list); }); var afterCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) => { if (propertyMapInfoList.IndexOf(next) > propertyMapInfoList.IndexOf(last)) { list.Add(next); } return(list); }); fullName = BuildFullName(beforeCustExpression); var visitor = new PrependParentNameVisitor(last.CustomExpression.Parameters[0].Type /*Parent type of current property*/, fullName, InfoDictionary[parameterExpression].NewParameter); var ex = propertyMapInfoList[propertyMapInfoList.Count - 1] != last ? visitor.Visit(last.CustomExpression.Body.AddExpressions(afterCustExpression)) : visitor.Visit(last.CustomExpression.Body); return(ex); } fullName = BuildFullName(propertyMapInfoList); var me = InfoDictionary[parameterExpression].NewParameter.BuildExpression(fullName); return(me); }
protected override Expression VisitMember(MemberExpression node) { string sourcePath; var parameterExpression = node.GetParameterExpression(); if (parameterExpression == null) { return(base.VisitMember(node)); } InfoDictionary.Add(parameterExpression, TypeMappings); var sType = parameterExpression.Type; if (sType != null && InfoDictionary.ContainsKey(parameterExpression) && node.IsMemberExpression()) { sourcePath = node.GetPropertyFullName(); } else { return(base.VisitMember(node)); } var propertyMapInfoList = new List <PropertyMapInfo>(); FindDestinationFullName(sType, InfoDictionary[parameterExpression].DestType, sourcePath, propertyMapInfoList); string fullName; if (propertyMapInfoList.Any(x => x.CustomExpression != null))//CustomExpression takes precedence over DestinationPropertyInfo { var last = propertyMapInfoList.Last(x => x.CustomExpression != null); var beforeCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) => { if (propertyMapInfoList.IndexOf(next) < propertyMapInfoList.IndexOf(last)) { list.Add(next); } return(list); }); var afterCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) => { if (propertyMapInfoList.IndexOf(next) > propertyMapInfoList.IndexOf(last)) { list.Add(next); } return(list); }); fullName = BuildFullName(beforeCustExpression); var visitor = new PrependParentNameVisitor(last.CustomExpression.Parameters[0].Type /*Parent type of current property*/, fullName, InfoDictionary[parameterExpression].NewParameter); var ex = propertyMapInfoList[propertyMapInfoList.Count - 1] != last ? visitor.Visit(last.CustomExpression.Body.MemberAccesses(afterCustExpression)) : visitor.Visit(last.CustomExpression.Body); var v = new FindMemberExpressionsVisitor(InfoDictionary[parameterExpression].NewParameter); v.Visit(ex); return(v.Result); } fullName = BuildFullName(propertyMapInfoList); var me = ExpressionFactory.MemberAccesses(fullName, InfoDictionary[parameterExpression].NewParameter); if (me.Expression.NodeType == ExpressionType.MemberAccess && (me.Type == typeof(string) || me.Type.GetTypeInfo().IsValueType || (me.Type.GetTypeInfo().IsGenericType && me.Type.GetGenericTypeDefinition() == typeof(Nullable <>) && Nullable.GetUnderlyingType(me.Type).GetTypeInfo().IsValueType))) { return(me.Expression); } return(me); }