public static void ImportItems(this OGLContext context) { if (context == null || context.Config == null) { return; } context.Items.Clear(); context.ItemLists.Clear(); context.ItemsSimple.Clear(); var files = SourceManager.EnumerateFiles(context, context.Config.Items_Directory); foreach (var f in files) { try { Uri source = new Uri(SourceManager.GetDirectory(f.Value, context.Config.Items_Directory).FullName); Uri target = new Uri(f.Key.DirectoryName); using (TextReader reader = new StreamReader(f.Key.FullName)) { Item s = (Item)Item.Serializer.Deserialize(reader); s.Category = Make(context, source.MakeRelativeUri(target)); s.Source = f.Value; s.Register(context, f.Key.FullName); } } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } } }
private void NewItemCat_Click(object sender, EventArgs e) { if (ItemCat.SelectedItem == null) { return; } string cat = Interaction.InputBox("New category name", "New Sub Category"); cat = string.Join("_", cat.Split(Path.GetInvalidFileNameChars())); SourceManager.GetDirectory(Program.Context.Config.DefaultSource, Path.Combine((string)ItemCat.SelectedItem, cat)); if (TabControls.SelectedTab == itemTab) { tabControl1_SelectedIndexChanged(null, null); } else { TabControls.SelectedTab = itemTab; } }
public static void ImportMagic(this OGLContext context) { if (context == null || context.Config == null) { return; } context.Magic.Clear(); context.MagicCategories.Clear(); context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0)); context.MagicSimple.Clear(); var files = SourceManager.EnumerateFiles(context, context.Config.Magic_Directory, SearchOption.AllDirectories); foreach (var f in files) { try { Uri source = new Uri(SourceManager.GetDirectory(f.Value, context.Config.Magic_Directory).FullName); Uri target = new Uri(f.Key.DirectoryName); string cat = MagicPropertyCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString())); if (!context.MagicCategories.ContainsKey(cat)) { context.MagicCategories.Add(cat, MakeMagicCategory(cat)); } String parent = Path.GetDirectoryName(cat); while (parent.IsSubPathOf(context.Config.Magic_Directory) && !context.MagicCategories.ContainsKey(parent)) { context.MagicCategories.Add(parent, MakeMagicCategory(parent)); parent = Path.GetDirectoryName(parent); } using (TextReader reader = new StreamReader(f.Key.FullName)) { MagicProperty mp = ((MagicProperty)MagicProperty.Serializer.Deserialize(reader)); mp.FileName = f.Key.FullName; mp.Source = f.Value; foreach (Feature fea in mp.AttunementFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.CarryFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.OnUseFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.EquipFeatures) { fea.Source = f.Value; } mp.Category = cat; context.MagicCategories[cat].Contents.Add(mp); if (context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source)) { throw new Exception("Duplicate Magic Property: " + mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source); } if (context.MagicSimple.ContainsKey(mp.Name)) { context.MagicSimple[mp.Name].ShowSource = true; mp.ShowSource = true; } context.Magic.Add(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source, mp); context.MagicSimple[mp.Name] = mp; } } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } //Collections[].AddRange(feats); } }
public static void ImportStandaloneFeatures(this OGLContext context) { if (context == null || context.Config == null) { return; } context.FeatureCollections.Clear(); context.FeatureContainers.Clear(); context.FeatureCategories.Clear(); context.Boons.Clear(); context.Features.Clear(); context.BoonsSimple.Clear(); var files = SourceManager.EnumerateFiles(context, context.Config.Features_Directory); foreach (var f in files) { try { Uri source = new Uri(SourceManager.GetDirectory(f.Value, context.Config.Features_Directory).FullName); Uri target = new Uri(f.Key.DirectoryName); FeatureContainer cont = LoadFeatureContainer(f.Key.FullName); List <Feature> feats = cont.Features; string cat = FeatureCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString())); if (!context.FeatureContainers.ContainsKey(cat)) { context.FeatureContainers.Add(cat, new List <FeatureContainer>()); } cont.FileName = f.Key.FullName; cont.category = cat; cont.Name = Path.GetFileNameWithoutExtension(f.Key.FullName); cont.Source = f.Value; context.FeatureContainers[cat].Add(cont); foreach (Feature feat in feats) { feat.Source = cont.Source; foreach (Keyword kw in feat.Keywords) { kw.check(); } feat.Category = cat; if (!context.FeatureCategories.ContainsKey(cat)) { context.FeatureCategories.Add(cat, new List <Feature>()); } Feature other = context.FeatureCategories[cat].Where(ff => string.Equals(ff.Name, feat.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (other != null) { other.ShowSource = true; feat.ShowSource = true; } context.FeatureCategories[cat].Add(feat); if (cat.Equals("Feats/Boons", StringComparison.InvariantCultureIgnoreCase)) { if (context.BoonsSimple.ContainsKey(feat.Name)) { context.BoonsSimple[feat.Name].ShowSource = true; feat.ShowSource = true; } else { context.BoonsSimple.Add(feat.Name, feat); } if (context.Boons.ContainsKey(feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source)) { ConfigManager.LogError("Duplicate Boon: " + feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source); } else { context.Boons[feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source] = feat; } } } foreach (Feature feat in feats) { context.Features.Add(feat); } } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } } }