Exemplo n.º 1
0
 public void Load(HapticDefinitionFile other)
 {
     this.root_effect            = other.root_effect;
     this.pattern_definitions    = other.pattern_definitions;
     this.sequence_definitions   = other.sequence_definitions;
     this.experience_definitions = other.experience_definitions;
 }
Exemplo n.º 2
0
        public static IDictionary <string, object> encodeDefinitionsDict <TAtomType>(DefDictionary <TAtomType> dict)
            where TAtomType : IJsonSerializable, new()
        {
            IDictionary <string, object> returnDict = new Dictionary <string, object>();

#if !UNITY_EDITOR
            Console.WriteLine("Encode dict count: " + dict.Count + "   " + dict.GetType().ToString());
#endif

            foreach (var item in dict)
            {
                IList <object> atoms = new List <object>();
                //Console.WriteLine("Item list count: " + item.Value.Count);
                for (int i = 0; i < item.Value.Count; i++)
                {
#if !UNITY_EDITOR
                    Console.WriteLine("\t\t " + item.Key + "  -  " + item.Value[i].ToString());
#endif
                    atoms.Add(item.Value[i].Serialize());
                }

                returnDict.Add(item.Key, atoms);
            }

            return(returnDict);
        }
Exemplo n.º 3
0
 public HapticDefinitionFile(RootEffect root)
 {
     this.root_effect            = root;
     this.sequence_definitions   = new DefDictionary <JsonEffectAtom>();
     this.pattern_definitions    = new DefDictionary <JsonSequenceAtom>();
     this.experience_definitions = new DefDictionary <JsonPatternAtom>();
 }
Exemplo n.º 4
0
 public string getDefPath(string id)
 {
     if (DefDictionary.ContainsKey(id) && DefDictionary[id].internalId != null)
     {
         return(DefDictionary[id].defPath);
     }
     return(null);
 }
Exemplo n.º 5
0
 public string getDefPath(string id)
 {
     if (DefDictionary.ContainsKey(id) && DefDictionary[id].calibrationlId != null)
     {
         return(DefDictionary[id].filePath);
     }
     return(null);
 }
Exemplo n.º 6
0
 public Definition getDef(string id)
 {
     if (DefDictionary.ContainsKey(id) && DefDictionary[id].internalId != null)
     {
         DefDictionary[id].Populate();
         return(DefDictionary[id]);
     }
     return(null);
 }
Exemplo n.º 7
0
 public ECUMetaData getDef(string id)
 {
     if (DefDictionary.ContainsKey(id) && DefDictionary[id].calibrationlId != null)
     {
         DefDictionary[id].Populate();
         return(DefDictionary[id]);
     }
     return(null);
 }
Exemplo n.º 8
0
        public void Populate(string xmldir)
        {
            DefDictionary.Clear();
            DeviceCount = 0;
            IdentList.Clear();
            try
            {
                //wtf is this TODO
                List <string> ts = ResourceUtil.directorySearchRecursiveDir(xmldir, null);
                if (!GetDevices(ts[0]))
                {
                    Trace.WriteLine("XML initialize failed");
                    DialogResult deferr = MessageBox.Show(
                        "Error initializing definitions! Please download the appropriate definitions and point the settings to the git repo base directory!" + Environment.NewLine +
                        "Would you like to download the latest definitions??",
                        "Error loading definitions",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1,
                        0);

                    if (deferr == DialogResult.Yes)
                    {
                        Process.Start(Settings.Default.GitHelpUrl);
                    }
                }
                else
                {
                    //MessageBox.Show("finished populating available devices");
                    Trace.WriteLine("Successfully loaded " + DeviceCount + "XML definitions!");
                }
            }
            catch (System.Exception excpt)
            {
                Trace.WriteLine("Error reading ECUFlash definitions!!");
                Trace.WriteLine(excpt.Message);
            }

            //Read RomRaider definitions
            try
            {
            }catch (Exception crap)
            {
                Trace.WriteLine("Error reading RomRaider definitions!!");
                Trace.WriteLine(crap.Message);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Parse a json object into a list of atoms (smallest unit that describes a sequence, pattern, or experience)
        /// </summary>
        /// <typeparam name="T">The json atom type</typeparam>
        /// <param name="dict">The raw json object</param>
        /// <returns>A dictionary representing the list of haptic effect IDs and their associated atoms</returns>
        public static DefDictionary <TAtomType> parseDefinitionsDict <TAtomType>(IDictionary <string, object> dict)
            where TAtomType : IJsonDeserializable, new()
        {
            //setup a dictionary from string -> list of atoms for our result
            DefDictionary <TAtomType> resultDict = new DefDictionary <TAtomType>();

            foreach (var kvp in dict)
            {
                IList <object> atoms = kvp.Value as IList <object>;
                //make sure to instantiate the list for this key
                resultDict.Add(kvp.Key, new List <TAtomType>());

                foreach (var atom in atoms)
                {
                    TAtomType a = new TAtomType();
                    a.Deserialize(atom as IDictionary <string, object>);
                    resultDict[kvp.Key].Add(a);
                }
            }

            return(resultDict);
        }
Exemplo n.º 10
0
        public bool GetDevices(string directory)
        {
            try
            {
                string[] files = Directory.GetFiles(directory);
                Parallel.ForEach(
                    files, f =>
                {
                    try
                    {
                        Definition d = new Definition(f);
                        if (d.isBase)
                        {
                            d.LoadRomId();
                        }
                        lock (DefDictionary)
                        {
                            if (DefDictionary.ContainsKey(d.internalId))
                            {
                                Trace.WriteLine("Duplicate definition found for: " + d.internalId + " in file: " + f + " Check the definitions!!");
                                Trace.WriteLine("Definition was previously found in file: " + DefDictionary[d.internalId].defPath);
                            }
                            else
                            {
                                DefDictionary.Add(d.internalId, d);

                                lock (IdentList)
                                {
                                    IdentList.Add(d.internalId);
                                    DeviceCount++;
                                }
                            }
                        }
                    }
                    catch (System.Exception excpt)
                    {
                        Trace.WriteLine("Error reading XML file " + f);
                        Trace.WriteLine(excpt.Message);
                    }
                });

                List <string> directories = Directory.GetDirectories(directory).ToList();

                Parallel.ForEach(
                    directories, d =>
                {
                    if (!GetDevices(d))
                    {
                        return;
                    }
                });

                return(true);
            }
            catch (System.Exception excpt)
            {
                Trace.WriteLine(excpt.Message);
            }

            return(false);
        }
Exemplo n.º 11
0
        public void Deserialize(IDictionary <string, object> dict)
        {
            try
            {
                root_effect.Deserialize(dict["root_effect"] as IDictionary <string, object>);

                //Generics = worthless at this point. Thanks unity!
                //Should probably redesign a better native format for unity, parsed from the hdf

                try
                {
                    pattern_definitions = parseDefinitionsDict <JsonSequenceAtom>(
                        dict["pattern_definitions"] as IDictionary <string, object>
                        );
                }
                catch (KeyNotFoundException e)
                {
#if UNITY_EDITOR
                    UnityEngine.Debug.LogException("In pats: " + e.Message + "\n");
#else
                    Console.WriteLine("[Error] Exception from pattern parsing: " + e.Message + "\n");
#endif
                }

                try
                {
                    sequence_definitions = parseDefinitionsDict <JsonEffectAtom>(
                        dict["sequence_definitions"] as IDictionary <string, object>
                        );
                }
                catch (KeyNotFoundException e)
                {
#if UNITY_EDITOR
                    UnityEngine.Debug.LogException("[Error] Exception from pattern parsing: " + e.Message + "\n");
#else
                    Console.WriteLine("[Error] Exception from pattern parsing: " + e.Message + "\n");
#endif
                }
                try
                {
                    experience_definitions = parseDefinitionsDict <JsonPatternAtom>(
                        dict["experience_definitions"] as IDictionary <string, object>
                        );
                }
                catch (KeyNotFoundException e)
                {
#if UNITY_EDITOR
                    UnityEngine.Debug.LogException("[Error] Exception from experience parsing: " + e.Message + "\n");
#else
                    Console.WriteLine("[Error] Exception from experience parsing: " + e.Message + "\n");
#endif
                }
            }
            catch (Exception e)
            {
                var exep = new HapticsAssetException("Couldn't parse the haptic asset", e);


#if UNITY_EDITOR
                Debug.LogException(exep);
#else
                Console.WriteLine(exep.Message);
#endif
            }
        }
Exemplo n.º 12
0
        public bool GetDevices(string directory)
        {
            try
            {
                string[] files = Directory.GetFiles(directory);
                //Parallel.ForEach(
                //  files, f =>
                foreach (var f in files)
                {
                    try
                    {
                        ECUMetaData d = new ECUMetaData(this, f);
                        if (d.isBase)
                        {
                            d.Populate();
                        }
                        lock (DefDictionary)
                        {
                            if (DefDictionary.ContainsKey(d.calibrationlId))
                            {
                                Trace.WriteLine("Duplicate definition found for: " + d.calibrationlId + " in file: " + f + " Check the definitions!!");
                                Trace.WriteLine("Definition was previously found in file: " + DefDictionary[d.calibrationlId].filePath);
                            }
                            else
                            {
                                DefDictionary.Add(d.calibrationlId, d);

                                lock (IdentList)
                                {
                                    IdentList.Add(d.calibrationlId);
                                    DeviceCount++;
                                }
                            }
                        }
                    }
                    catch (System.Exception excpt)
                    {
                        Trace.WriteLine("Error reading XML file " + f);
                        Trace.WriteLine(excpt.Message);
                    }
                }
                //});

                List <string> directories = Directory.GetDirectories(directory).ToList();

                //Parallel.ForEach(
                //   directories, d =>
                foreach (var d in directories)
                {
                    if (!GetDevices(d))
                    {
                        return(false);
                    }
                }  // });

                return(true);
            }
            catch (System.Exception excpt)
            {
                Trace.WriteLine(excpt.Message);
            }

            return(false);
        }