Beispiel #1
0
        /// <summary>
        /// Populates the Commodity Registry with data from the eddb json string
        /// </summary>
        /// <param name="json">Json string of EDDB commodities.json data</param>
        private void _ParseCommodities(string json)
        {
            AerDebug.Log("Loading Commodities...");
            Stopwatch timer = new Stopwatch();

            timer.Start();
            JArray ja = JArray.Parse(json);

            foreach (JObject jo in ja)
            {
                EliteCommodity ec = new EliteCommodity();
                ec.Name = jo["name"].ToString();
                try
                {
                    ec.AveragePrice = int.Parse(jo["average_price"].ToString());
                }
                catch (FormatException e)
                {
                    AerDebug.LogError(@"Error formatting Average Price for " + ec.Name + ", " + e.Message);
                    ec.AveragePrice = -1;
                }

                ec.id = int.Parse(jo["id"].ToString());
                _CommodityRegistry.Add(ec.id, ec);
                _CommodityNameRegistry.Add(ec.Name.ToLower(), ec.id);
            }

            timer.Stop();
        }
Beispiel #2
0
        /// <summary>
        /// Loads the grammar in to the recognition engine.
        /// </summary>
        protected virtual void LoadGrammar(string pathToGrammar, AerHandler handler)
        {
            AerDebug.Log("Loading Grammar...");
            Grammar grammar = new Grammar(pathToGrammar + @"Default.xml");

            RecognitionEngine.LoadGrammarCompleted += handler.ReadyToSpeak_Handler;
            RecognitionEngine.LoadGrammarAsync(grammar);
        }
Beispiel #3
0
        /// <summary>
        /// Loads the grammar in to the recognition engine.
        /// </summary>
        protected virtual void LoadGrammar(string pathToGrammar, EventHandler <LoadGrammarCompletedEventArgs> GrammarLoaded)
        {
            AerDebug.Log("Loading Grammar...");
            Grammar grammar = new Grammar(pathToGrammar + @"Default.xml");

            RecognitionEngine.LoadGrammarCompleted += GrammarLoaded;
            RecognitionEngine.LoadGrammarAsync(grammar);
        }
Beispiel #4
0
//This is getting out of hand for the AerDB file, perhaps a static AerJSON should be created
// As a container for all of these darn utility methods
//TODO: Make AerEddb or AerJSON and create an interface between AerDB and it. -SingularTier
//WARNING: THE CODE IN THE JSON PARSING REGION WILL MAKE YOU VOMIT.
        #region JSON Parsing
        /// <summary>
        /// Populates the System Registry with data from the eddb json string
        /// </summary>
        /// <param name="json">Json string of EDDB systems.json data</param>
        private void _ParseSystems(string json)
        {
            AerDebug.Log("Loading Systems...");
            Stopwatch timer = new Stopwatch();

            timer.Start();
            JArray ja = JArray.Parse(json);

            foreach (JObject jo in ja)
            {
                try
                {
                    EliteSystem es = new EliteSystem();
                    es.Name           = jo["name"].ToString();
                    es.id             = int.Parse(jo["id"].ToString());
                    es.x              = float.Parse(jo["x"].ToString());
                    es.y              = float.Parse(jo["y"].ToString());
                    es.z              = float.Parse(jo["z"].ToString());
                    es.Faction        = jo["faction"].ToString();
                    es.Population     = jo["population"].ToString();
                    es.Government     = jo["government"].ToString();
                    es.Allegiance     = jo["allegiance"].ToString();
                    es.State          = jo["state"].ToString();
                    es.Security       = jo["security"].ToString();
                    es.PrimaryEconomy = jo["primary_economy"].ToString();

                    string permit = jo["needs_permit"].ToString();
                    es.PermitRequired = permit.Equals("1");

                    _SystemRegistry.Add(es.id, es);
                    _SystemNameRegistry.Add(es.Name.ToLower(), es.id);
                }
                catch (FormatException e)
                {
                    AerDebug.LogError("Malformed/Unexpected System JSON data, " + e.Message);
                }
            }
            timer.Stop();
        }
Beispiel #5
0
        //This creates grammar rules out of our data
        public void DBG_CompileGrammars()
        {
            Dictionary <string, bool> stationAdded = new Dictionary <string, bool>();

            System.IO.StreamWriter file;
            AerDebug.Log("Compiling grammars...");
            AerDebug.Log("Compiling grammars for systems...");

            file = new System.IO.StreamWriter(@"systemsGrammar.xml");
            foreach (EliteSystem system in _SystemRegistry.Values)
            {
                file.WriteLine(@"<item> " + stripForXML(system.Name) + " <tag> out.id=" + system.id + "; out.Name=\"" + stripForXML(system.Name) + "\"; </tag></item>");
            }
            file.Close();

            AerDebug.Log("Compiling grammars for commodities...");
            file = new System.IO.StreamWriter(@"commoditiesGrammar.xml");
            foreach (EliteCommodity commodity in _CommodityRegistry.Values)
            {
                file.WriteLine(@"<item> " + stripForXML(commodity.Name) + " <tag> out.id=" + commodity.id + "; </tag></item>");
            }
            file.Close();

            AerDebug.Log("Compiling grammars for stations...");
            file = new System.IO.StreamWriter(@"stationsGrammar.xml");
            foreach (EliteSystem system in _SystemRegistry.Values)
            {
                foreach (EliteStation station in system.Stations)
                {
                    if (!stationAdded.ContainsKey(station.Name))
                    {
                        file.WriteLine(@"<item> " + stripForXML(station.Name) + " <tag> out.Name=\"" + stripForXML(station.Name) + "\";</tag></item>");
                        stationAdded.Add(station.Name, true);
                    }
                }
            }
            file.Close();
        }
Beispiel #6
0
 internal void ReadyToSpeak_Handler(object sender, LoadGrammarCompletedEventArgs e)
 {
     _Talk.SayReady();
     AerDebug.Log("Initialization Complete.");
 }
Beispiel #7
0
 /// <summary>
 /// An ugly mess. This is used by AerInput spaghetti code to notify the user when the grammar is loaded.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void GrammarLoaded_Handler(object sender, LoadGrammarCompletedEventArgs e)
 {
     _Talk.SayReady();
     AerDebug.Log("Initialization Complete.");
 }