Beispiel #1
0
 private void NewDB_Click(object sender, RoutedEventArgs e)
 {
     lastSaveLocation = null;
     Database         = new ItemDBModel();
     Database.GetGameDirectory();
     Redraw();
     UpdateStatusBar("New Database created");
 }
Beispiel #2
0
        private void OpenDB_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = FILTER;
            ofd.InitialDirectory = Database.GameDirectory;
            if (ofd.ShowDialog() == true)
            {
                lastSaveLocation = ofd.FileName;
                Database         = ItemDBModel.Load(ofd.FileName);
            }
            Redraw();
            UpdateStatusBar("Opened Database file");
        }
Beispiel #3
0
        public static ItemDBModel Load(string path)
        {
            Cursor.Current = Cursors.WaitCursor;
            ItemDBModel      model = new ItemDBModel();
            List <ItemModel> items = new List <ItemModel>();

            model.Inventories = new List <InventoryModel>();

            string  json = File.ReadAllText(path);
            JObject jObj = JObject.Parse(json);

            model.GameDirectory = jObj["GameDirectory"]?.Value <string>();
            JArray jItems = (JArray)jObj["Items"];

            for (int i = 0; i < jItems.Count; i++)
            {
                string type  = jItems[i]["Type"].Value <string>();
                var    props = jItems[i]["Properties"].Values();
                Dictionary <string, string> propsDictionary = new Dictionary <string, string>();
                foreach (var prop in props)
                {
                    propsDictionary.Add(((JProperty)prop.Parent).Name, prop.Value <string>());
                }
                ItemModel item = new ItemModel(type, propsDictionary);
                items.Add(item);
            }

            JArray jInventories = (JArray)jObj["Inventories"];

            for (int i = 0; i < jInventories.Count; i++)
            {
                InventoryModel inventory = new InventoryModel();

                inventory.items   = new List <string>();
                inventory.m_id    = jInventories[i]["m_id"].Value <string>();
                inventory.m_owner = jInventories[i]["m_owner"].Value <string>();
                foreach (var value in jInventories[i]["items"].Values())
                {
                    inventory.items.Add(value.Value <string>());
                }
                model.Inventories.Add(inventory);
            }

            model.Items         = items;
            Cursor.Current      = Cursors.Default;
            model.GameDirectory = Path.GetDirectoryName(path);
            return(model);
        }