Esempio n. 1
0
        //public List<ScriptParameter> Parameters { get; set; }

        public XmlNode ToXmlNode()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<actionScript><scriptText /></actionScript>");
            //xdoc.DocumentElement.SetAttributeValue("id", Id);
            xdoc.DocumentElement.SetAttributeValue("name", Name);
            xdoc.DocumentElement.SetAttributeValue("type", ScriptType.ToString());
            xdoc.DocumentElement.SetAttributeValue("description", Description);
            xdoc.DocumentElement.SetAttributeValue("windowStyle", WindowSizeStyle.ToString());
            xdoc.DocumentElement.SetAttributeValue("adminMode", RunAdminMode);
            xdoc.DocumentElement.SetAttributeValue("correctiveErrorScript", IsErrorCorrectiveScript);
            xdoc.DocumentElement.SetAttributeValue("correctiveWarningScript", IsWarningCorrectiveScript);
            xdoc.DocumentElement.SetAttributeValue("restorationScript", IsRestorationScript);
            XmlNode scriptTextNode = xdoc.DocumentElement.SelectSingleNode("scriptText");

            scriptTextNode.InnerText = Script;
            //XmlNode parametersNode = xdoc.DocumentElement.SelectSingleNode("parameters");
            //foreach (ScriptParameter parameter in Parameters)
            //{
            //    XmlNode parameterNode = xdoc.ImportNode(parameter.ToXmlNode(), true);
            //    parametersNode.AppendChild(parameterNode);
            //}

            return(xdoc.DocumentElement);
        }
Esempio n. 2
0
 public static string FileExtension(this ScriptType scriptType)
 {
     return(typeof(ScriptType).GetField(scriptType.ToString())
            .GetCustomAttributes(typeof(FileExtensionAttribute), false)
            .Select(attr => ((FileExtensionAttribute)attr).Extension)
            .FirstOrDefault());
 }
        public static void CreateScript(ScriptType scriptType, string pathFolder, string fileName, string name, string nameNamespace, string baseClass, string customEditor, AccessModifier access, MessageUnity[] messages, ItemEnum[] itemsEnum)
        {
            string nameTemplate = "";

            switch (scriptType)
            {
            case ScriptType.Empty:
                CreateScript(pathFolder, fileName, "");
                return;

            case ScriptType.Class:
            case ScriptType.Interface:
            case ScriptType.Struct:
                nameTemplate = "Script";
                break;

            case ScriptType.MonoBehaviour: nameTemplate = "MonoBehaviour"; break;

            case ScriptType.Editor: nameTemplate = "Editor"; break;

            case ScriptType.Window: nameTemplate = "EditorWindow"; break;

            case ScriptType.Enum: nameTemplate = "Enum"; break;
            }

            StringBuilder template = new StringBuilder(CheckNamespace(ReadScriptTemplate(nameTemplate), nameNamespace));

            //Namespace
            template.Replace(templateNamespace, nameNamespace);
            //Name(class,struct,interface,enum,editor,window)
            template.Replace(templateNameClass, name);
            //LevelAccess
            template.Replace(templateAccess, AccessToString(access));

            //CustomEditor
            if (scriptType == ScriptType.Editor)
            {
                template.Replace(templateCustomEditor, customEditor);
            }

            //Base and scriptType
            if (scriptType == ScriptType.Class || scriptType == ScriptType.Interface || scriptType == ScriptType.Struct)
            {
                template.Replace(templateNameBaseClass, string.IsNullOrEmpty(baseClass) ? "" : ": " + baseClass);
                template.Replace(templateTypeScript, scriptType.ToString().ToLower());
            }

            //ItemsEnum
            if (scriptType == ScriptType.Enum)
            {
                template.Replace(templateItems, CreateItemsEnumCode(itemsEnum));
            }
            else//MessagesUnity
            {
                template.Replace(templateMethods, CreateMessagesCode(messages));
            }

            CreateScript(pathFolder, fileName, template.ToString());
        }
Esempio n. 4
0
        private void Restore(ScriptType type)
        {
            var path = Path.Combine(storePath, type.ToString());

            if (Directory.Exists(path))
            {
                var scripts = Directory.GetFiles(path, "*.sql", SearchOption.TopDirectoryOnly);
                foreach (var script in scripts)
                {
                    ExecuteFile(script, out string message);
                    File.Delete(script);
                    Watch?.AddValue(-2);
                }
            }
        }
Esempio n. 5
0
        public string ToXml()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<script />");
            xdoc.DocumentElement.SetAttributeValue("name", Name);
            xdoc.DocumentElement.SetAttributeValue("type", ScriptType.ToString());
            xdoc.DocumentElement.SetAttributeValue("description", Description);
            xdoc.DocumentElement.SetAttributeValue("windowStyle", WindowSizeStyle.ToString());
            xdoc.DocumentElement.SetAttributeValue("adminMode", RunAdminMode);

            xdoc.DocumentElement.InnerText = Script;

            return(xdoc.DocumentElement.OuterXml);
        }
Esempio n. 6
0
        void Start()
        {
            // Should we enable the compiler for our domain
            // This is requried if we want to load C# scripts as opposed to assemblies
            bool initCompiler = true;

            // Create our domain
            domain = ScriptDomain.CreateDomain("ModDomain", initCompiler);

            // Load the source code into our domain
            // The code must be compiled before it can be loaded
            ScriptType type = domain.CompileAndLoadScriptSource(sourceCode);

            // Print the type to the console
            Debug.Log(type.ToString());
        }
        private void OnGUIGeneral()
        {
            //name class
            EditorGUI.BeginDisabledGroup(_type == ScriptType.MonoBehaviour);
            _name = EditorGUILayout.TextField(_contents[string.Format("name{0}", _type.ToString())], _name);
            EditorGUI.EndDisabledGroup();

            //namespace
            _namespace = EditorGUILayout.TextField(_contents["namespace"], _namespace);

            //access
            _access = (AccessModifier)EditorGUILayout.EnumPopup(_contents["access"], _access);

            //base class
            EditorGUI.BeginDisabledGroup(!(_type == ScriptType.Class || _type == ScriptType.Struct));
            _base = EditorGUILayout.TextField(_contents["base"], _base);
            EditorGUI.EndDisabledGroup();
        }
Esempio n. 8
0
        /// <summary>
        /// Create a startup script.
        /// </summary>
        /// <param name="name">Name of the newly created startup script.</param>
        /// <param name="script">Startup script contents.</param>
        /// <param name="type">Type of startup script. Default is 'boot'.</param>
        /// <returns>StartupScript element with only SCRIPTID.</returns>
        public StartupScriptCreateResult CreateStartupScript(
            string name, string script, ScriptType type = ScriptType.boot)
        {
            var args = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>("name", name),
                new KeyValuePair <string, object>("script", script),
                new KeyValuePair <string, object>("type", type.ToString())
            };

            var response = ApiExecute <StartupScript>(
                "startupscript/create", ApiKey, args, ApiMethod.POST);

            return(new StartupScriptCreateResult()
            {
                ApiResponse = response.Item1,
                StartupScript = response.Item2
            });
        }
Esempio n. 9
0
        public static CompilerResults CompileScript(ScriptType type, string pSource)
        {
            try
            {
                if (_compiler == null)
                {
                    _compiler       = CodeDomProvider.CreateProvider("CSharp");
                    _compilerParams = new CompilerParameters();

                    _compilerParams.CompilerOptions         = "/optimize";
                    _compilerParams.GenerateInMemory        = true;
                    _compilerParams.GenerateExecutable      = false;
                    _compilerParams.IncludeDebugInformation = false;

                    foreach (AssemblyName reference in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
                    {
                        _compilerParams.ReferencedAssemblies.Add(reference.Name + ".dll");
                    }

                    _compilerParams.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
                }

                _compilerParams.OutputAssembly = "..\\DataSvr\\Script\\" + type.ToString() + "\\Compiled\\" + System.IO.Path.GetFileNameWithoutExtension(pSource) + ".compiled";
                var result = _compiler.CompileAssemblyFromFile(_compilerParams, pSource);

                if (System.IO.File.Exists(_compilerParams.OutputAssembly))
                {
                    System.IO.File.SetLastWriteTime(_compilerParams.OutputAssembly, System.IO.File.GetLastWriteTime(pSource));
                }

                _compiler.Dispose();

                return(result);
            }
            catch (Exception e)
            {
                MainForm.Instance.Log(e.ToString());
                return(null);
            }
        }
Esempio n. 10
0
 private static string getCommand(ScriptType s)
 {
     return(s.ToString() + ".exe");
 }
        unsafe void Parse(SR1_Reader reader, Event scriptEvent, ScriptType type, SR1_PrimativeArray <short> scriptData)
        {
            if ((reader.File._ImportFlags & SR1_File.ImportFlags.LogScripts) != 0)
            {
                try
                {
                    string script = "";

                    short[] opCodes = new short[scriptData.Count];
                    int     c       = 0;
                    foreach (short code in scriptData)
                    {
                        opCodes[c] = code;
                        c++;
                    }

                    List <VarType> stack = new List <VarType>();

                    fixed(short *codeStreamStart = opCodes)
                    {
                        short *codeStream = codeStreamStart;

                        c = 0;
                        while (c < opCodes.Length)
                        {
                            PCode opcode          = (PCode)(*codeStream - 1);
                            int   mathOp          = _PCodes[(int)opcode].mathOp;
                            int   additionalBytes = 0;

                            script += "\t\t";

                            if (mathOp > -1)
                            {
                                Operation operation = GetCompareOperationFromID(stack[stack.Count - 1], _PCodes[(int)opcode].mathOp, stack, codeStream);

                                VarType param0VarType = stack[stack.Count - 2];
                                string  param0        = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2);
                                VarType param1VarType = stack[stack.Count - 1];
                                string  param1        = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1);
                                string  result        = "(" + _VarTypes[(int)operation.t] + ")";

                                script += "object var" + stack.Count + " = " + result + operation.n + "(" + param0 + ", " + param1 + ")";
                                stack.Add(operation.t);
                            }
                            else if (opcode == PCode.AddObjectToStack)
                            {
                                int             param = *(codeStream + 1);
                                EventBaseObject scriptEventInstance = (EventBaseObject)scriptEvent.instances[param];

                                VarType param0Type = GetVarType_AddObjectToStack(scriptEventInstance, stack, codeStream);
                                string  param0     = "(" + _VarTypes[(int)param0Type] + ")instances[" + param.ToString() + "]";

                                script += "object var" + stack.Count + " = " + param0;
                                stack.Add(param0Type);
                            }
                            else if (opcode == PCode.AddPlayerObjectToStack)
                            {
                                int param = *(codeStream + 1);

                                VarType param0Type = VarType.InstanceObject;
                                string  param0     = "(" + _VarTypes[(int)param0Type] + ")gameTrackerX.playerInstance";

                                script += "object var" + stack.Count + " = " + param0;
                                stack.Add(param0Type);
                            }
                            else if (opcode == PCode.ModifyObjectToStackWithAttribute)
                            {
                                int       param     = *(codeStream + 1);
                                Operation operation = GetTranformOperationFromID(stack[stack.Count - 1], param, stack, codeStream);

                                VarType param0VarType = stack[stack.Count - 1];
                                string  param0        = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 1);
                                string  result        = "(" + _VarTypes[(int)operation.t] + ")";

                                if (operation.t != VarType.None)
                                {
                                    script += "var" + (stack.Count - 1) + " = " + result;
                                }

                                if (param0VarType == VarType.EventObject)
                                {
                                    // SavedEvent and SavedEventSmallVars both inherit from SavedBasic.
                                    // Hopefully the opcodes don't care where these come from and behave the same as local events.
                                    if (operation.p == 1)
                                    {
                                        string param1 = (*(codeStream + 2)).ToString();
                                        script += operation.n + "(" + param0 + ", " + param1 + ")";
                                        additionalBytes++;
                                    }
                                    else
                                    {
                                        script += operation.n + "(" + param0 + ")";
                                    }
                                }
                                else
                                {
                                    script += operation.n + "(" + param0 + ")";
                                }

                                if (operation.t != VarType.None)
                                {
                                    stack[stack.Count - 1] = operation.t;
                                }
                            }
                            else if (opcode == PCode.AddNumberToStack)
                            {
                                int param = *(codeStream + 1);

                                VarType param0Type = VarType.Number;
                                string  param0     = "(" + _VarTypes[(int)param0Type] + ")" + param.ToString();
                                script += "object var" + stack.Count + " = " + param0;
                                stack.Add(VarType.Number);
                            }
                            else if (opcode == PCode.DoStackOperationEquals)
                            {
                                VarType param0VarType = stack[stack.Count - 2];
                                string  param0        = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2);
                                VarType param1VarType = stack[stack.Count - 1];
                                string  param1        = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1);

                                script += _PCodes[*codeStream - 1].n + "(" + param0 + ", " + param1 + ")";
                            }
                            else if (opcode == PCode.Execute)
                            {
                                script += _PCodes[*codeStream - 1].n + "()";
                                stack.Clear();
                            }
                            else
                            {
                                script += _PCodes[*codeStream - 1].n + "()";
                            }

                            script += ";\r\n";

                            codeStream += _PCodes[*codeStream - 1].l;
                            codeStream += additionalBytes;
                            c          += _PCodes[opCodes[c] - 1].l;
                            c          += additionalBytes;

                            if (c < opCodes.Length &&
                                (opcode == PCode.Execute ||
                                 opcode == PCode.EndConditional || opcode == PCode.EndAction || opcode == PCode.EndOfLine2))
                            {
                                script += "\r\n";
                            }
                        }

                        reader.LogScript(script);
                    }
                }
                catch
                {
                    reader.LogScript("\t\t// Error reading " + type.ToString() + " script.\r\n");
                }
            }
        }
Esempio n. 12
0
        public static void Devman(this Panel p, Vessel v)
        {
            // avoid corner-case when this is called in a lambda after scene changes
            v = FlightGlobals.FindVessel(v.id);

            // if vessel doesn't exist anymore, leave the panel empty
            if (v == null)
            {
                return;
            }

            // get info from the cache
            Vessel_info vi = Cache.VesselInfo(v);

            // if not a valid vessel, leave the panel empty
            if (!vi.is_valid)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), " <color=#cccccc>" + Localizer.Format("#KERBALISM_UI_devman") + "</color>"));
            p.Width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.scripts;

            // time-out simulation
            if (!Lib.IsControlUnit(v) && p.Timeout(vi))
            {
                return;
            }

            // get devices
            Dictionary <uint, Device> devices = Computer.Boot(v);
            int deviceCount = 0;

            // direct control
            if (script_index == 0)
            {
                // draw section title and desc
                p.AddSection
                (
                    Localizer.Format("#KERBALISM_UI_devices"),
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last),
                    true
                );

                // for each device
                foreach (var pair in devices)
                {
                    // render device entry
                    Device dev = pair.Value;
                    if (!dev.IsVisible())
                    {
                        continue;
                    }
                    p.AddContent(dev.Name(), dev.Info(), string.Empty, dev.Toggle, () => Highlighter.Set(dev.Part(), Color.cyan));
                    deviceCount++;
                }
            }
            // script editor
            else
            {
                // get script
                ScriptType script_type = (ScriptType)script_index;
                string     script_name = script_type.ToString().Replace('_', ' ').ToUpper();
                Script     script      = DB.Vessel(v).computer.Get(script_type);

                // draw section title and desc
                p.AddSection
                (
                    script_name,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last),
                    true
                );

                // for each device
                foreach (var pair in devices)
                {
                    Device dev = pair.Value;
                    if (!dev.IsVisible())
                    {
                        continue;
                    }

                    // determine tribool state
                    int state = !script.states.ContainsKey(pair.Key)
                                          ? -1
                                          : !script.states[pair.Key]
                                          ? 0
                                          : 1;

                    // render device entry
                    p.AddContent
                    (
                        dev.Name(),
                        state == -1 ? "<color=#999999>" + Localizer.Format("#KERBALISM_UI_dontcare") + " </color>" : state == 0 ? "<color=red>" + Localizer.Format("#KERBALISM_Generic_OFF") + "</color>" : "<color=cyan>" + Localizer.Format("#KERBALISM_Generic_ON") + "</color>",
                        string.Empty,
                        () =>
                    {
                        switch (state)
                        {
                        case -1: script.Set(dev, true); break;

                        case 0: script.Set(dev, null); break;

                        case 1: script.Set(dev, false); break;
                        }
                    },
                        () => Highlighter.Set(dev.Part(), Color.cyan)
                    );
                    deviceCount++;
                }
            }

            // no devices case
            if (deviceCount == 0)
            {
                p.AddContent("<i>no devices</i>");
            }
        }
Esempio n. 13
0
        public static void Devman(this Panel p, Vessel v)
        {
            // avoid corner-case when this is called in a lambda after scene changes
            v = FlightGlobals.FindVessel(v.id);

            // if vessel doesn't exist anymore, leave the panel empty
            if (v == null)
            {
                return;
            }

            // get data
            VesselData vd = v.KerbalismData();

            // if not a valid vessel, leave the panel empty
            if (!vd.IsSimulated)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), Lib.Color("#KERBALISM_UI_devman", Lib.Kolor.LightGrey)));
            p.Width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.scripts;

            // time-out simulation
            if (!Lib.IsControlUnit(v) && p.Timeout(vd))
            {
                return;
            }

            // get devices
            List <Device> devices     = Computer.GetModuleDevices(v);
            int           deviceCount = 0;

            // direct control
            if (script_index == 0)
            {
                // draw section title and desc
                p.AddSection
                (
                    Localizer.Format("#KERBALISM_UI_devices"),
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last),
                    false
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection("VESSEL DEVICES");
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection("MODULE DEVICES");
                            hasModuleDeviceSection = true;
                        }
                    }

                    if (dev.PartId != 0u)
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle, () => Highlighter.Set(dev.PartId, Color.cyan));
                    }
                    else
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle);
                    }

                    if (dev.Icon != null)
                    {
                        p.SetLeftIcon(dev.Icon.texture, dev.Icon.tooltip, dev.Icon.onClick);
                    }

                    deviceCount++;
                }
            }
            // script editor
            else
            {
                // get script
                ScriptType script_type = (ScriptType)script_index;
                string     script_name = script_type.ToString().Replace('_', ' ').ToUpper();
                Script     script      = v.KerbalismData().computer.Get(script_type);

                // draw section title and desc
                p.AddSection
                (
                    script_name,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last)
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // determine tribool state
                    int state = !script.states.ContainsKey(dev.Id)
                                          ? -1
                                          : !script.states[dev.Id]
                                          ? 0
                                          : 1;

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection("VESSEL DEVICES");
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection("MODULE DEVICES");
                            hasModuleDeviceSection = true;
                        }
                    }

                    // render device entry
                    p.AddContent
                    (
                        dev.DisplayName,
                        state == -1 ? Lib.Color(Localizer.Format("#KERBALISM_UI_dontcare"), Lib.Kolor.DarkGrey) : Lib.Color(state == 0, Localizer.Format("#KERBALISM_Generic_OFF"), Lib.Kolor.Yellow, Localizer.Format("#KERBALISM_Generic_ON"), Lib.Kolor.Green),
                        string.Empty,
                        () =>
                    {
                        switch (state)
                        {
                        case -1: script.Set(dev, true); break;

                        case 0: script.Set(dev, null); break;

                        case 1: script.Set(dev, false); break;
                        }
                    },
                        () => Highlighter.Set(dev.PartId, Color.cyan)
                    );
                    deviceCount++;
                }
            }

            // no devices case
            if (deviceCount == 0)
            {
                p.AddContent("<i>no devices</i>");
            }
        }
 private static string CreateKey(ScriptType type)
 {
     return "__sm__{0}".ToFormat(type.ToString());
 }
Esempio n. 15
0
 private static string GetScriptTypeString(ScriptType scriptType)
 {
     return(scriptType.ToString().ToLower());
 }
Esempio n. 16
0
        public static void CompileScripts(ScriptType type)
        {
            Dictionary <string, Type>     usableScripts   = new Dictionary <string, Type>();
            Dictionary <string, DateTime> compiledScripts = new Dictionary <string, DateTime>();

            foreach (var script in System.IO.Directory.GetFiles("..\\DataSvr\\Script\\" + type.ToString() + "\\Compiled\\", "*.compiled"))
            {
                compiledScripts.Add(System.IO.Path.GetFileNameWithoutExtension(script), System.IO.File.GetLastWriteTime(script));
            }

            List <string> needCompliation = new List <string>();

            foreach (var script in System.IO.Directory.GetFiles("..\\DataSvr\\Script\\" + type.ToString() + "\\", "*.cs"))
            {
                var shortname = System.IO.Path.GetFileNameWithoutExtension(script);
                if (!compiledScripts.ContainsKey(shortname) || compiledScripts[shortname] < System.IO.File.GetLastWriteTime(script))
                {
                    needCompliation.Add(script);
                }
            }

            foreach (var script in needCompliation)
            {
                var shortName = Path.GetFileNameWithoutExtension(script);

                if (usableScripts.ContainsKey(shortName))
                {
                    usableScripts.Remove(shortName);
                }

                CompilerResults results = ScriptingFactory.CompileScript(type, script);

                if (results.Errors.Count > 0)
                {
                    MainForm.Instance.Log("");
                    MainForm.Instance.Log("Error compiling " + type.ToString() + " Script '{0}'.", shortName);
                    MainForm.Instance.Log("");

                    foreach (CompilerError error in results.Errors)
                    {
                        MainForm.Instance.Log("");
                        MainForm.Instance.Log("Line '{0}', Column '{1}': {2}", error.Line, error.Column, error.ErrorText);
                    }
                }
                else
                {
                    MainForm.Instance.Log("Compiled " + type.ToString() + " '{0}'.", shortName);
                }
            }

            foreach (var script in System.IO.Directory.GetFiles("..\\DataSvr\\Script\\" + type.ToString() + "\\Compiled\\", "*.compiled"))
            {
                var shortName = System.IO.Path.GetFileNameWithoutExtension(script);

                if (!usableScripts.ContainsKey(shortName))
                {
                    Assembly assembly = Assembly.Load(File.ReadAllBytes(Environment.CurrentDirectory + "\\" + script));
                    Type[]   types    = assembly.GetTypes();

                    foreach (Type assemblyType in types)
                    {
                        if (type == ScriptType.Npc)
                        {
                            if (!assemblyType.IsSubclassOf(typeof(NpcScript)))
                            {
                                continue;
                            }
                        }
                        else if (type == ScriptType.Portal)
                        {
                            if (!assemblyType.IsSubclassOf(typeof(PortalScript)))
                            {
                                continue;
                            }
                        }

                        AddScript(type, assemblyType, shortName);
                    }
                }
            }
        }
Esempio n. 17
0
        public static void devman(this Panel p, Vessel v)
        {
            // avoid corner-case when this is called in a lambda after scene changes
            v = FlightGlobals.FindVessel(v.id);

            // if vessel doesn't exist anymore, leave the panel empty
            if (v == null)
            {
                return;
            }

            // get info from the cache
            vessel_info vi = Cache.VesselInfo(v);

            // if not a valid vessel, leave the panel empty
            if (!vi.is_valid)
            {
                return;
            }

            // set metadata
            p.title(Lib.BuildString(Lib.Ellipsis(v.vesselName, 24), " <color=#cccccc>DEV MANAGER</color>"));

            // time-out simulation
            if (p.timeout(vi))
            {
                return;
            }

            // get devices
            Dictionary <uint, Device> devices = Computer.boot(v);

            // direct control
            if (script_index == 0)
            {
                // draw section title and desc
                p.section
                (
                    "DEVICES",
                    description(),
                    () => p.prev(ref script_index, (int)ScriptType.last),
                    () => p.next(ref script_index, (int)ScriptType.last)
                );

                // for each device
                foreach (var pair in devices)
                {
                    // render device entry
                    Device dev = pair.Value;
                    p.content(dev.name(), dev.info(), string.Empty, dev.toggle, () => Highlighter.set(dev.part(), Color.cyan));
                }
            }
            // script editor
            else
            {
                // get script
                ScriptType script_type = (ScriptType)script_index;
                string     script_name = script_type.ToString().Replace('_', ' ').ToUpper();
                Script     script      = DB.Vessel(v).computer.get(script_type);

                // draw section title and desc
                p.section
                (
                    script_name,
                    description(),
                    () => p.prev(ref script_index, (int)ScriptType.last),
                    () => p.next(ref script_index, (int)ScriptType.last)
                );

                // for each device
                foreach (var pair in devices)
                {
                    // determine tribool state
                    int state = !script.states.ContainsKey(pair.Key)
          ? -1
          : !script.states[pair.Key]
          ? 0
          : 1;

                    // render device entry
                    Device dev = pair.Value;
                    p.content
                    (
                        dev.name(),
                        state == -1 ? "<color=#999999>don't care</color>" : state == 0 ? "<color=red>off</color>" : "<color=cyan>on</color>",
                        string.Empty,
                        () =>
                    {
                        switch (state)
                        {
                        case -1: script.set(dev, true);  break;

                        case  0: script.set(dev, null);  break;

                        case  1: script.set(dev, false); break;
                        }
                    },
                        () => Highlighter.set(dev.part(), Color.cyan)
                    );
                }
            }

            // no devices case
            if (devices.Count == 0)
            {
                p.content("<i>no devices</i>");
            }
        }
Esempio n. 18
0
 protected ScriptBase(ScriptType type, string name, Character character, bool useThread)
     : base(string.Format(Application.ExecutablePath + @"..\..\scripts\{0}\{1}.lua", type.ToString().ToLower(), name), useThread)
 {
     mCharacter = character;
 }