Пример #1
0
    public void LoadConditionalUnlocks()
    {
        string      path     = Paths.GetUnlocksFile();
        XmlDocument timeFile = new XmlDocument();

        try {
            timeFile.Load(path);
        }
        catch (FileNotFoundException e) {
            Logger.Throw("Could not access timeline file at path " + path + ". Error : " + e.ToString());
            return;
        }

        XmlNodeList nodeList = timeFile.SelectNodes("unlocks")[0].ChildNodes;

        foreach (XmlNode xUnlock in nodeList)
        {
            // Garbage node
            if (xUnlock.Name != "building")
            {
                continue;
            }

            int           id         = System.Convert.ToInt32(xUnlock.Attributes["id"].Value);
            List <string> conditions = new List <string>();

            foreach (XmlNode xCondition in xUnlock.ChildNodes)
            {
                if (!ScriptInterpreter.CheckSyntax(xCondition.InnerText))
                {
                    Logger.Error("Skipped wrong syntax in code " + xCondition.InnerText + " in building unlock " + id);
                    continue;
                }
                conditions.Add(xCondition.InnerText);
            }

            unlocks.Add(new Unlock(id, conditions));
        }
    }