static public MapDataManager GetInstance()
 {
     if (_instance == null)
     {
         _instance = new MapDataManager();
     }
     return(_instance);
 }
        public bool LoadLevelDataForMap(string mapKey)
        {
            m_customers.Clear();
            m_foods.Clear();

            var mapData = MapDataManager.GetInstance().GetMapData(mapKey);

            var sqlCnn = new SQLiteConnection();

            sqlCnn.ConnectionString = string.Format("Data Source={0};Version = 3", m_dbPath);
            sqlCnn.Open();

            var cmd = sqlCnn.CreateCommand();

            List <LevelData> levels = new List <LevelData>();

            for (int i = mapData.start_level; i <= mapData.end_level; i++)
            {
                cmd.CommandText = string.Format("SELECT " +
                                                "level,type,total,star_score,orders,special_orders,new_foods,guide_orders," +
                                                "anyfood_orders,max_order,order_interval,first_arrival,waiting_time_decay,secret_customers," +
                                                "mucky_interval,broken_interval,rain_interval,requirement,organic_materials,required_kitchenware,unlock,rewards " +
                                                "FROM Level " +
                                                "WHERE level={0}", i);
                SQLiteDataReader reader = cmd.ExecuteReader();
                if (reader == null)
                {
                    Generic.MyDebug.WriteLine(string.Format("Level={0} is not found", i));
                    return(false);
                }

                while (reader.Read())
                {
                    LevelData lvData = new LevelData();
                    int       column = 0;

                    Func <string> getNextString = () =>
                    {
                        return(reader.GetStringSafe(column++));
                    };

                    Func <int> getNextInt32 = () =>
                    {
                        return(reader.GetInt32Safe(column++));
                    };

                    Func <float> getNextFloat = () =>
                    {
                        return(reader.GetFloatSafe(column++));
                    };

                    lvData.id    = getNextInt32();
                    lvData.type  = LevelTypeDict[getNextString()];
                    lvData.total = getNextInt32();
                    string strScoreList = getNextString();
                    if (strScoreList.Length > 0)
                    {
                        var scoreList = strScoreList.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string score in scoreList)
                        {
                            lvData.scoreList = new List <string>(scoreList);
                        }
                    }
                    lvData.orders        = ParseOrders(getNextString());
                    lvData.specialOrders = ParseSpecialOrders(getNextString());
                    string newfood     = getNextString();
                    string guideOrders = getNextString();
                    lvData.anyfoodOrders = ParseAnyfoodOrders(getNextString());
                    lvData.max_order     = getNextInt32();
                    string[] orderIntervals = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    lvData.order_interval.set(orderIntervals[0].ToFloat(), orderIntervals[1].ToFloat());
                    string[] first_arrivals = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    foreach (string arrTime in first_arrivals)
                    {
                        lvData.first_arrivals.Add(arrTime.ToFloat());
                    }
                    string[] decayInfo = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    if (decayInfo.Length >= 2)
                    {
                        lvData.waiting_decay.set(decayInfo[0].ToFloat(), decayInfo[1].ToFloat());
                    }

                    string secretStr = getNextString();
                    lvData.parseSecretCustomer(secretStr);

                    var litter_interval = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    if (litter_interval.Length > 0)
                    {
                        lvData.litter_interval.set(litter_interval[0].ToInt32(), litter_interval[1].ToInt32());
                    }

                    var broken_interval = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    if (broken_interval.Length > 0)
                    {
                        lvData.broken_interval.set(broken_interval[0].ToInt32(), broken_interval[1].ToInt32());
                    }

                    var rain_interval = getNextString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);;
                    if (rain_interval.Length > 0)
                    {
                        lvData.rain_interval.set(rain_interval[0].ToInt32(), rain_interval[1].ToInt32());
                    }

                    string requirementStr = getNextString();
                    lvData.parseRequirement(requirementStr);

                    string[] organics = getNextString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (organics.Length > 0)
                    {
                        lvData.organicMaterials = new List <string>(organics);
                    }

                    int requireKitchenware = getNextInt32();

                    string[] unlockItems = getNextString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (unlockItems.Length > 0)
                    {
                        foreach (string itemId in unlockItems)
                        {
                            lvData.unlock_items.Add(itemId.ToInt32());
                        }
                    }

                    lvData.parseRewards(getNextString());

                    levels.Add(lvData);
                }
                reader.Close();
            }
            sqlCnn.Close();
            sqlCnn.Dispose();

            SetMapLevelDatas(mapKey, levels);

            return(true);
        }