コード例 #1
0
        static void Prefix(GameObject LoadedObject, SavedCustomObject save)
        {
            var handler     = LoadedObject.GetComponent <UpdateHandler>();
            var handlerType = handler.GetType();

            Action <object> setValue = null;

            foreach (var item in save.CustomData.Skip(2))
            {
                if (item is string str && str.StartsWith("::"))
                {
                    string name = str.Substring(2);

                    var field = handlerType.GetField(name);
                    if (field == null)
                    {
                        var prop = handlerType.GetProperty(name);

                        if (prop == null)
                        {
                            MDebug.WriteLine("ERROR: INVALID DATA FIELD!");
                        }
                        else
                        {
                            setValue = o => prop.SetValue(handler, Convert.ChangeType(o, prop.PropertyType), null);
                        }
                    }
                    else
                    {
                        setValue = o => field.SetValue(handler, o);
                    }
                }
コード例 #2
0
        /// <summary>
        /// Log a message to the console (can be multi-line)
        /// </summary>
        /// <param name="type">Type of log <see cref="LogType"/></param>
        /// <param name="msg">Message to log</param>
        public static void Log(LogType type, object msg)
        {
            if (msg == null)
            {
                return;
            }

            if (!Initialized)
            {
                EntryQueue.Enqueue(new KeyValuePair <LogType, object>(type, msg));
                return;
            }

            string m = WordWrap(msg.ToString(), (int)(Screen.width / Style.CalcSize(new GUIContent("A")).x));

            foreach (string line in m.Split('\n'))
            {
                var logEntry = new LogEntry(type, line);

                CmdLog.Push(logEntry);
            }

#if DEBUG
            var stack   = new StackTrace();
            var calling = stack.GetFrame(1).GetMethod();

            if (calling.DeclaringType == typeof(IGConsole))
            {
                calling = stack.GetFrame(2).GetMethod();
            }

            MDebug.WriteLine($"[IGCONSOLE] {calling}: {msg}");
#endif
        }
コード例 #3
0
        public static void Prefix(SavedCustomObject save, ObjectInfo CreateFromThis)
        {
            /*
             *    CustomData structure:
             *    - CustomComponent.UniqueName
             *    - Outputs.On[]
             *    - Fields[]
             */

            List <object> saveData = new List <object>();

            var customComponent = CreateFromThis.GetComponent <UpdateHandler>();

            CircuitOutput[] outputs = CreateFromThis.GetComponentsInChildren <CircuitOutput>();

            if (customComponent.Component == null)
            {
                MDebug.WriteLine("!!customComponent.Component IS NULL!! NAME: " + customComponent.ComponentName);

                if (customComponent.ComponentName != null)
                {
                    if (ComponentRegistry.Registry.TryGetValue(customComponent.ComponentName, out var comp))
                    {
                        customComponent.Component = comp;
                    }
                    else
                    {
                        MDebug.WriteLine("!!MISING COMPONENT: " + customComponent.ComponentName);
                    }
                }
                else
                {
                    MDebug.WriteLine("!!customComponent.ComponentName IS ALSO NULL!! ALLOW ME TO JUMP OFF A CLIFF");

                    return;
                }
            }

            saveData.Add(customComponent.ComponentName);
            saveData.Add(outputs.Select(o => o.On).ToArray());
            saveData.AddRange(GetSaveThisFields(customComponent));

            save.CustomData = saveData.ToArray();
        }
コード例 #4
0
        public static ConfigurationFile Load(Mod mod)
        {
            string fileName = mod == null ? "pitung" : mod.PackageName;
            string filePath = Path.Combine(Application.persistentDataPath, Path.Combine("config", fileName + ".json"));

            string dir = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            ConfigurationFile configFile;

            if (!File.Exists(filePath))
            {
                configFile = new ConfigurationFile {
                    FilePath = filePath
                };
                configFile.Save();
            }
            else
            {
                string file = File.ReadAllText(filePath);

                try
                {
                    configFile = JSON.ToObject <ConfigurationFile>(file, Parameters);
                }
                catch (Exception ex)
                {
                    MDebug.WriteLine($"ERROR: COULDN'T LOAD CONFIGURATION FILE AT '{filePath}'. DETAILS:");
                    MDebug.WriteLine(ex);

                    configFile = new ConfigurationFile();
                }
            }

            configFile.FilePath = filePath;
            return(configFile);
        }
コード例 #5
0
        static void Postfix(ref GameObject __result, SavedCustomObject save)
        {
            if (save.CustomData.Length == 0)
            {
                MDebug.WriteLine("ERROR: INVALID CUSTOM COMPONENT LOADED!");
                __result = GetDefaultObject("");
                return;
            }

            string name = save.CustomData[0] as string;

            if (ComponentRegistry.Registry.TryGetValue(name, out var item))
            {
                __result = item.Instantiate();
                __result.transform.parent = NextParent;
            }
            else
            {
                MDebug.WriteLine("ERROR: CUSTOM COMPONENT NOT FOUND!");
                __result = GetDefaultObject(name);
            }
        }
コード例 #6
0
ファイル: Shell.cs プロジェクト: NeatWolf/PiTUNG
        /// <summary>
        /// Called when the user presses enter
        /// </summary>
        /// <param name="cmd">The full command line</param>
        internal static void ExecuteCommand(string cmd)
        {
            if (cmd.Length == 0)
            {
                return;
            }

            string verb, error;

            string[] args;

            if (!CmdParser.TryParseCmdLine(cmd, out verb, out args, out error))
            {
                Log(LogType.ERROR, "Invalid command: " + error);
                return;
            }

            args = ReplaceVariables(args).ToArray();

            Command command = Registry.Values.SingleOrDefault(o => o.Aliases != null && o.Aliases.Contains(verb));

            if (command != null || Registry.TryGetValue(verb, out command))
            {
                try
                {
                    command.Execute(args);
                }
                catch (Exception e)
                {
                    Log(LogType.ERROR, "An internal error occurred while executing the command.");
                    MDebug.WriteLine("Command exception: '" + cmd + "'");
                    MDebug.WriteLine(e);
                }
            }
            else if (!TryParseVariables(cmd.Trim()))
            {
                Log(LogType.ERROR, $"Unrecognized command: {verb}");
            }
        }
コード例 #7
0
ファイル: InternalCommands.cs プロジェクト: NeatWolf/PiTUNG
        public override bool Execute(IEnumerable <string> arguments)
        {
            var scene = SceneManager.GetActiveScene();

            foreach (var obj in scene.GetRootGameObjects())
            {
                Recurse(obj);
            }

            return(true);

            void Recurse(GameObject parent, int level = 0)
            {
                string compStr = string.Join(", ", parent.GetComponents <Component>().Select(o => o.GetType().Name).ToArray());

                MDebug.WriteLine(new string(' ', level * 4) + $"{parent.name} [{parent.tag}] ({compStr})");

                foreach (Transform item in parent.transform)
                {
                    Recurse(item.gameObject, level + 1);
                }
            }
        }
コード例 #8
0
 public void Save()
 {
     MDebug.WriteLine("SAVE CONFIG TO " + FilePath);
     File.WriteAllText(FilePath, JSON.ToNiceJSON(this, Parameters));
 }