Exemplo n.º 1
0
        public AllLevels GetLevels(ISaver saver, Preset[] levelPresets)
        {
            int lastID = -1;

            LevelParameters[]         param = new LevelParameters[levelPresets.Length];
            SavingParametersContainer spc;
            bool hasData = saver != null && saver.HasData();

            if (hasData)
            {
                spc = saver.Load();
            }
            else
            {
                spc = new SavingParametersContainer();
                spc.SavingParameters = new SavingParameters[0];
            }

            bool find = false;

            for (int i = 0; i < param.Length; ++i)
            {
                param[i]        = new LevelParameters();
                param[i].Preset = levelPresets[i];
                find            = false;
                for (int j = 0; j < spc.SavingParameters.Length; ++j)
                {
                    if (spc.SavingParameters[j].ID == param[i].Preset.ID)
                    {
                        param[i].SavedParameters = spc.SavingParameters[j];
                        find = true;
                        break;
                    }
                }
                if (!find)
                {
                    param[i].SavedParameters = GenerateLevel(param[i].Preset.ID);
                }
                if (lastID < param[i].Preset.ID)
                {
                    lastID = param[i].Preset.ID;
                }
            }
            if (!hasData)
            {
                SetFirstOpen(param);
            }
            return(new AllLevels(param, lastID));
        }