Ejemplo n.º 1
0
    void InitSounds()
    {
        s_sounds = new Sounds();
        string       soundFolder = "/"; // This gets all sounds. Should I change it?
        HFTWebFileDB db          = HFTWebFileDB.GetInstance();

        AddSoundFiles(soundFolder, db.GetFiles(soundFolder, "*.mp3"));
        AddSoundFiles(soundFolder, db.GetFiles(soundFolder, "*.wav"));
        AddJSFXSounds(db.GetFiles(soundFolder, "*.jsfx.txt"));
    }
Ejemplo n.º 2
0
    void AddJSFXSounds(string[] filenames)
    {
        foreach (string filename in filenames)
        {
            byte[] bytes = null;
            if (!HFTWebFileDB.GetInstance().GetFile(filename, out bytes))
            {
                Debug.LogError("no such file: " + filename);
            }
            string   content = System.Text.Encoding.UTF8.GetString(bytes);
            string[] lines   = content.Split(s_lineDelims, System.StringSplitOptions.None);
            int      lineNo  = 0;
            foreach (string lineStr in lines)
            {
                ++lineNo;
                string line = lineStr.Split('#')[0].Split('/')[0].Split(';')[0].Trim();
                if (line.Length == 0)
                {
                    continue;
                }

                // TODO remove comments
                Match m = s_jsfxRE.Match(line);
                if (!m.Success)
                {
                    Debug.LogError(filename + " line: " + lineNo + " could not parse line");
                    continue;
                }
                string   name          = m.Groups[1].Value;
                string   generator     = m.Groups[2].Value;
                string   numbersString = m.Groups[3].Value;
                string[] numberStrings = numbersString.Split(',');
                if (numberStrings.Length != 27)
                {
                    Debug.LogError(filename + " line:" + lineNo + " expected 27 values found " + numberStrings.Length);
                    continue;
                }

                float[] parameters = new float[27];
                int     i          = 0;
                bool    error      = false;
                foreach (string numstr in numberStrings)
                {
                    try
                    {
                        parameters[i] = float.Parse(numstr, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                    }
                    catch (System.Exception)
                    {
                        Debug.LogError(filename + " line:" + lineNo + " could not parse number " + numstr);
                        error = true;
                    }
                    ++i;
                }

                if (error)
                {
                    continue;
                }
                s_sounds[name] = new SoundJSFX(generator, parameters);
            }
        }
    }