/// <summary>Loads an XML file at the given absolute path.</summary>
        public override void LoadFile(string path, LanguageTextEvent onFileAvailable)
        {
            // Create a data package:
            DataPackage package = new DataPackage(path);

            // Setup load event:
            package.onload = delegate(UIEvent e){
                // Run the callback:
                onFileAvailable(package.responseText);
            };

            // Get:
            package.send();
        }
示例#2
0
        /// <summary>Loads a variable value from the language set. Note that this occurs after checking 'diverted' variables
        /// and after custom ones too - it only looks for languages. This is essentially handled by the document.languages API.</summary>
        public override void LoadLanguageVariable(string groupName, string variableName, LanguageTextEvent onResolved)
        {
            // Get the group:
            languages.current.getGroup(groupName, delegate(LanguageEvent e){
                // Load the variable and run the event:
                string variableValue = null;

                if (e.group != null)
                {
                    variableValue = e.group[variableName];
                }

                // Run the callback:
                onResolved(variableValue);
            });
        }
示例#3
0
 /// <summary>Loads a variable value from the language set. Note that this occurs after checking 'diverted' variables
 /// and after custom ones too - it only looks for languages. This is essentially handled by the document.languages API.</summary>
 public virtual void LoadLanguageVariable(string groupName, string variableName, LanguageTextEvent onResolved)
 {
     onResolved(null);
 }
        /// <summary>Resolves a variable value, calling the given function when it's done.</summary>
        public void GetValue(string variableName, Document document, LanguageTextEvent onResolved)
        {
            if (Custom != null)
            {
                // Custom variables take top priority - is it overriden?
                string value = Custom.GetValue(variableName);

                if (value != null)
                {
                    onResolved(value);
                    return;
                }
            }

            // Are we loading from a group?
            int    dotIndex  = variableName.IndexOf('.');
            string groupName = "";

            if (dotIndex != -1)
            {
                // We're loading from a specific group.

                // Get the name up to (but not including) the first dot:
                groupName = variableName.Substring(0, dotIndex);

                // Is it diverted? E.g. &items.1.name; could be handled in a custom way
                // rather than having a huge group of all items.

                GroupResolveEvent handler;
                if (Diverts != null && Diverts.TryGetValue(groupName, out handler))
                {
                    // Chop off the rest of the variable name:
                    variableName = variableName.Substring(dotIndex + 1);

                    // It's diverted! Call the handler:
                    handler(variableName, onResolved);

                    return;
                }

                // Not diverted. It might be a sub-group (&a.b.c;) so check for that:
                int lastIndex = variableName.LastIndexOf('.');

                if (lastIndex != dotIndex)
                {
                    // Sub-group; get its name again:
                    groupName = variableName.Substring(0, lastIndex);
                }

                // Chop off the rest of the variable name:
                variableName = variableName.Substring(lastIndex + 1);
            }

            // Load a var from the language set now:
            document.LoadLanguageVariable(groupName, variableName, delegate(string variableValue){
                if (variableValue == null)
                {
                    // Nope! Not found in either custom or language.

                    if (OnFind != null)
                    {
                        OnFind(variableName, onResolved);
                        return;
                    }
                }

                // Ok!
                onResolved(variableValue);
            });
        }
 /// <summary>Loads an XML file at the given path.</summary>
 /// <param name="onFileAvailable">A callback that runs when the file has been downloaded.</param>
 public virtual void LoadFile(string path, LanguageTextEvent onFileAvailable)
 {
     throw new NotImplementedException("Use a PowerUILanguageLoader.");
 }