Пример #1
0
        public void Load()
        {
            // do we already have a saved object?
            BuyableDto dto = SaveManager.Get(SaveKeys.BuyableDataKey, new BuyableDto()) as BuyableDto;

            if (dto == null)
            {
                return;
            }

            // no save data yet, initialize default
            if ((dto.BuyableData == null) || (dto.BuyableData.Count == 0))
            {
                foreach (ShopCategory category in _setup.Categories)
                {
                    foreach (BaseBuyable baseBuyable in category.ItemsInCategory)
                    {
                        baseBuyable.Bought   = false;
                        baseBuyable.Selected = false;
                    }
                }

                return;
            }

            // save data found - need to loop through all categories and see if we have save data for an object and if yes load the corresponding data
            foreach (ShopCategory category in _setup.Categories)
            {
                foreach (BaseBuyable baseBuyable in category.ItemsInCategory)
                {
                    // searches for the buyable data stored in the save game that has the same name as the current buyable from the category
                    BuyableData firstOrDefault = dto.BuyableData.FirstOrDefault(b => b.Name.Equals(baseBuyable.name));
                    // buyable found, assign its values from save
                    if (firstOrDefault != null)
                    {
                        baseBuyable.Bought   = firstOrDefault.Bought;
                        baseBuyable.Selected = firstOrDefault.Selected;
                    }
                    // new buyable that is not yet saved, assign default values
                    else
                    {
                        baseBuyable.Bought   = false;
                        baseBuyable.Selected = false;
                    }
                }
            }
        }
Пример #2
0
        public void Save()
        {
            BuyableDto         dto  = new BuyableDto();
            List <BuyableData> data = new List <BuyableData>();

            // Loop over all buyable items in the shop and store their current values (name, did buy, is selected) in a data object
            foreach (ShopCategory category in _setup.Categories)
            {
                foreach (BaseBuyable baseBuyable in category.ItemsInCategory)
                {
                    data.Add(new BuyableData(
                                 baseBuyable.name,
                                 baseBuyable.Bought,
                                 baseBuyable.Selected)
                             );
                }
            }

            // save data object to save manager
            dto.BuyableData = data;
            SaveManager.Put(SaveKeys.BuyableDataKey, dto);
        }