public static Table Solve(string address)
        {
            string[] values = address.Split(':');

            if (values.Length != 2)
            {
                RuntimeConsole.LogError("Malformed address '" + address + "'");
            }

            Table root = loadedTables[values[0]].root;

            string[] tables       = values[1].Split('/');
            Table    desiredTable = root;

            for (int i = 0; i < tables.Length; i++)
            {
                desiredTable = desiredTable[tables[i]];
            }

            if (desiredTable == null)
            {
                RuntimeConsole.LogError("Invalid table address '" + values[1] + "'");
            }

            return(desiredTable);
        }
        private static UnityEngine.Object LoadAndIncreaseCounter(string resourceName)
        {
            UnityEngine.Object obj;

            if (!resources.ContainsKey(resourceName))
            {
                obj = Resources.Load(resourceName);
                resources.Add(resourceName, new Resource()
                {
                    obj = obj, instanceCounter = 1
                });
            }
            else
            {
                Resource resource = resources[resourceName];
                resource.instanceCounter++;

                obj = resource.obj;
            }

            if (obj == null)
            {
                RuntimeConsole.LogError("The Resource '" + resourceName + "' does not exist.", alsoLogOnUnity: true);
            }

            return(obj);
        }
        //Utils
        private static void LogParseError(string msg)
        {
            while (curSourceIndex >= source.Length || source[curSourceIndex] == '\n')
            {
                curSourceIndex--;
            }

            RuntimeConsole.LogError("File: " + filePath + " - Current Line: " + (source.Substring(0, curSourceIndex).Count(h => h == '\n') + 1) + " - Error: " + msg);

            errorCount++;
        }
Example #4
0
        public void Awake()
        {
            if (instance)
            {
                Destroy(gameObject);

                return;
            }

            instance = this;

            RegisterCommand("?", Question, "command");
            RegisterCommand("help", Help);
            RegisterCommand("log_level", SetLogLevel, "level");
            RegisterCommand("unload_resources", UnloadResources);
            RegisterCommand("path", Path);
        }
        public static UnityEngine.Object Load(string resourceName)
        {
            UnityEngine.Object obj;

            if (!resources.ContainsKey(resourceName))
            {
                obj = Resources.Load(resourceName);
                resources.Add(resourceName, new Resource()
                {
                    obj = obj
                });
            }
            else
            {
                obj = resources[resourceName].obj;
            }

            if (obj == null)
            {
                RuntimeConsole.LogError("The Resoruce '" + resourceName + "' does not exist.", alsoLogOnUnity: true);
            }

            return(obj);
        }
        public static Table Load(string filePath, bool hotReload = false)
        {
            TableHandler.filePath = filePath;

            TableInfo tableInfo;
            bool      isAlreadyLoaded = loadedTables.ContainsKey(filePath);

            if (isAlreadyLoaded)
            {
                tableInfo = loadedTables[filePath];

                if (!hotReload)
                {
                    return(tableInfo.root);
                }
            }
            else
            {
                tableInfo = new TableInfo();
            }

            TableInfo newTableInfo;

            if (File.Exists(filePath))
            {
                newTableInfo = new TableInfo(File.ReadAllText(filePath), false, File.GetLastWriteTime(filePath));
            }
            else
            {
                string fullPath = DevelopmentEnvironment.fullTablePath + filePath + ".table.txt";

                if (File.Exists(fullPath))
                {
                    newTableInfo = new TableInfo(File.ReadAllText(fullPath), false, File.GetLastWriteTime(fullPath));
                }
                else
                {
                    TextAsset textAsset = (TextAsset)Resources.Load(filePath + ".table", typeof(TextAsset));

                    if (textAsset == null)
                    {
                        RuntimeConsole.LogError("Could not find file '" + filePath + "'");

                        return(null);
                    }

                    newTableInfo = new TableInfo(textAsset.text, true, new DateTime());
                }
            }

            if (isAlreadyLoaded && hotReload && newTableInfo.version > tableInfo.version)
            {
                Unload(filePath);
            }

            tableInfo = newTableInfo;

            if (Parse(ref tableInfo))
            {
                loadedTables.Add(filePath, tableInfo);

                RuntimeConsole.Log("Table '" + filePath + "' has been loaded.");

                return(tableInfo.root);
            }

            RuntimeConsole.LogError("Could not parse file '" + filePath + "'.");

            return(null);
        }
        private static string ReadNextWord(string str, ref int curStrPos, ref int curIndentationCount, bool countIndentations)
        {
            string word = "";

            curIndentationCount = 0;

            while (curStrPos < str.Length)
            {
                if (!StringContainsCharMatch(invalidCharacters, str[curStrPos]))
                {
                    break;
                }
                else if (countIndentations && (str[curStrPos] == '\t' || str[curStrPos] == ' ') && (curStrPos == 0 || str[curStrPos - 1] == '\n'))
                {
                    curStrPos++;
                    curIndentationCount++;

                    while (curStrPos < str.Length)
                    {
                        if (str[curStrPos] == '\t' || str[curStrPos] == ' ')
                        {
                            curStrPos++;
                            curIndentationCount++;
                        }
                        else if (str[curStrPos] == ' ')
                        {
                            curStrPos++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    curStrPos++;
                }
            }

            while (curStrPos < str.Length)
            {
                if (!StringContainsCharMatch(invalidCharacters, str[curStrPos]))
                {
                    if ((str[curStrPos] >= 97 && str[curStrPos] <= 122) || (str[curStrPos] >= 65 && str[curStrPos] <= 90) || (str[curStrPos] >= 48 && str[curStrPos] <= 57) || str[curStrPos] == '_' || str[curStrPos] == '.' || (str[curStrPos] == '-' && curStrPos + 1 < str.Length && (str[curStrPos + 1] >= 48 && str[curStrPos + 1] <= 57)))
                    {
                        word += str[curStrPos];

                        curStrPos++;
                    }
                    else
                    {
                        if (word.Length != 0)
                        {
                            return(word);
                        }

                        bool ignoreNewLine = false;

                        if (str[curStrPos] == '&' && Peek(str, curStrPos + 1) == '\"')
                        {
                            ignoreNewLine = true;
                            curStrPos++;
                        }

                        word += str[curStrPos];

                        if (str[curStrPos] == '\"')
                        {
                            curStrPos++;

                            while (curStrPos < str.Length)
                            {
                                if (str[curStrPos] == '\\')
                                {
                                    if (Peek(str, curStrPos + 1) == '\"')
                                    {
                                        word      += "\"";
                                        curStrPos += 2;
                                    }
                                    else if (Peek(str, curStrPos + 1) == '\'')
                                    {
                                        word      += "\'";
                                        curStrPos += 2;
                                    }
                                    else if (Peek(str, curStrPos + 1) == 'n')
                                    {
                                        word      += "\n";
                                        curStrPos += 2;
                                    }
                                }
                                else if (str[curStrPos] == '\"')
                                {
                                    word += str[curStrPos];
                                    curStrPos++;

                                    return(word);
                                }
                                else if (str[curStrPos] == '\n' && ignoreNewLine)
                                {
                                    curStrPos++;
                                }
                                else
                                {
                                    word += str[curStrPos];
                                    curStrPos++;
                                }
                            }

                            RuntimeConsole.LogError("Broken string: " + word);

                            return(null);
                        }
                        else if (str[curStrPos] == '/' && Peek(str, curStrPos + 1) == '/')
                        {
                            if (word.Length > 0 && word[0] != '/')
                            {
                                return(word);
                            }

                            curStrPos += 2;

                            while (curStrPos < str.Length)
                            {
                                if (str[curStrPos] == '\n')
                                {
                                    curStrPos++;

                                    break;
                                }

                                curStrPos++;
                            }

                            return("\n");
                        }
                        else
                        {
                            curStrPos++;

                            return(word);
                        }
                    }
                }
                else
                {
                    curStrPos++;

                    return(word);
                }

                //curTextIndex++;
            }

            if (word.Length != 0)
            {
                return(word);
            }

            curStrPos++;

            return(null);
        }