Beispiel #1
0
    public Vector3 LoadVector3Line(string key, MISS_OPT opt = MISS_OPT.SKIP, Vector3 def = default(Vector3))
    {
        Vector3 val = default(Vector3);

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                LoadKey(sr, key);
                SkipSpaces(sr);
                SkipCharacter(sr, '(');
                val.x = float.Parse(GetWord(sr));
                val.y = float.Parse(GetWord(sr));
                val.z = float.Parse(GetWord(sr));
                SkipCharacter(sr, ')');
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                val = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }
        return(val);
    }
Beispiel #2
0
    public T LoadValueLine <T>(string key, MISS_OPT opt = MISS_OPT.SKIP, T def = default(T))
    {
        T val = default(T);

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                val = _LoadValue <T>(sr, key);
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                val = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }
        return(val);
    }
Beispiel #3
0
    public string LoadStrLine(string key, MISS_OPT opt = MISS_OPT.SKIP, string def = "")
    {
        string val = "";

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                LoadKey(sr, key);
                SkipSpaces(sr);

                // check first quotation
                int read = sr.Read();
                if (read < 0 || (char)read != '"')
                {
                    throw new Exception("LoadStrLine " + key + "Exception");
                }
                read = sr.Read();
                while (read >= 0)
                {
                    // read to next quotation
                    char ch = (char)read;
                    if (ch == '"')
                    {
                        break;
                    }
                    val += ch;
                    read = sr.Read();
                }
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                val = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }

        return(val);
    }
Beispiel #4
0
    public List <T> LoadValueListLine <T>(string key, MISS_OPT opt = MISS_OPT.SKIP, List <T> def = null)
    {
        List <T> val = new List <T>();

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                LoadKey(sr, key);
                SkipSpaces(sr);
                if (!SkipCharacter(sr, '{'))
                {
                    throw new Exception(string.Format("LoadValueListLine {0} exception", key));
                }
                string word = GetWord(sr);
                while (!string.IsNullOrEmpty(word))
                {
                    val.Add(_ParseValue <T>(word));
                }
                SkipSpaces(sr);
                if (!SkipCharacter(sr, '}'))
                {
                    throw new Exception(string.Format("LoadValueListLine {0} exception", key));
                }
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                val = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }
        return(val);
    }
Beispiel #5
0
    public DateTime LoadDateLine(string key, MISS_OPT opt = MISS_OPT.SKIP, DateTime def = default(DateTime))
    {
        DateTime dt = default(DateTime);

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                LoadKey(sr, key);
                SkipSpaces(sr);
                int year   = int.Parse(GetWord(sr));
                int month  = int.Parse(GetWord(sr));
                int day    = int.Parse(GetWord(sr));
                int hour   = int.Parse(GetWord(sr));
                int minute = int.Parse(GetWord(sr));
                int second = int.Parse(GetWord(sr));
                dt = new DateTime(year, month, day, hour, minute, second);
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                dt = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }
        return(dt);
    }
Beispiel #6
0
    public Color LoadColoerLine(string key, MISS_OPT opt = MISS_OPT.SKIP, Color def = default(Color))
    {
        Color col = default(Color);

        try
        {
            using (StreamReader sr = BuildCurLineReader())
            {
                LoadKey(sr, key);
                SkipSpaces(sr);
                SkipCharacter(sr, '(');
                col.r = float.Parse(GetWord(sr));
                col.g = float.Parse(GetWord(sr));
                col.b = float.Parse(GetWord(sr));
                col.a = float.Parse(GetWord(sr));
                SkipCharacter(sr, ')');
            }
            ClearLineCache();
        }
        catch (Exception)
        {
            if (opt == MISS_OPT.THROW)
            {
                throw;
            }
            else if (opt == MISS_OPT.SETDEFAULT)
            {
                col = def;
            }
            else if (opt == MISS_OPT.CLEAR_LINE)
            {
                ClearLineCache();
            }
        }
        return(col);
    }