示例#1
0
        /// <summary>
        /// Mod functionality.
        /// Calls Python functions.
        /// </summary>
        private void Update()
        {
            // Initialize block handlers
            if (Game.IsSimulating && !BlockHandlerController.Initialised)
            {
                BlockHandlerController.InitializeBlockHandlers();
            }

            // Initialize block identifiers
            if (!Game.IsSimulating && rebuildIDs)
            {
                rebuildIDs = false;
                BlockHandlerController.InitializeBuildingBlockIDs();
            }

            // Execute code on first call
            if (Game.IsSimulating && PythonEnvironment.Loaded && enableScript && (scriptFile != null || scriptCode != null))
            {
                LoadScript();
                scriptFile = null;
                scriptCode = null;
            }

            // Toggle watchlist visibility
            if (PythonEnvironment.Loaded && Keybindings.Get("Watchlist").Pressed())
            {
                Watchlist.Instance.Visible = !Watchlist.Instance.Visible;
            }

            // Toggle options visibility
            if (PythonEnvironment.Loaded && Keybindings.Get("Script Options").Pressed())
            {
                ScriptOptions.Instance.Visible = !ScriptOptions.Instance.Visible;
            }

            if (!Game.IsSimulating)
            {
                // Show block identifiers
                if (PythonEnvironment.Loaded && Keybindings.Get("Show Block ID").IsDown())
                {
                    ShowBlockIdentifiers();
                }
            }

            if (!Game.IsSimulating)
            {
                return;
            }

            // Call script update.
            try
            {
                if (!runtime_error)
                {
                    PythonEnvironment.ScripterEnvironment?.CallUpdate();
                }
            }
            catch (Exception e)
            {
                runtime_error = true;
                if (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                ScriptOptions.Instance.ErrorMessage = "Runtime error.\nSee console (Ctrl+K) for more info.";
                Debug.Log("<b><color=#FF0000>Python error: " + e.Message + "</color></b>\n" + PythonEnvironment.FormatException(e));
            }
        }