Example #1
0
 private WebJSON.Comport GetComportJSON(BrainComponent.Comport c, bool includeScriptContents = false)
 {
     return(new WebJSON.Comport()
     {
         Offset = c.Offset,
         Name = c.Name,
         Scripts = c.Scripts.Select(s => GetScriptJSON(s, includeScriptContents: includeScriptContents)).ToArray(),
         FirstScript = GetScriptJSON(c.FirstScript, includeScriptContents: includeScriptContents)
     });
 }
Example #2
0
    private void ParseRequestJSON(WebJSON.Request msg)
    {
        switch (msg.Type)
        {
        case WebJSON.RequestType.Script:
            BaseScriptComponent s = GetScriptFromRequest(msg);
            if (s != null)
            {
                Send(new WebJSON.Message()
                {
                    Type   = WebJSON.MessageType.Script,
                    Script = GetScriptJSON(s, true)
                });
            }
            break;

        case WebJSON.RequestType.Comport:
            BrainComponent.Comport c = GetComportFromRequest(msg);
            if (c != null)
            {
                Send(new WebJSON.Message()
                {
                    Type    = WebJSON.MessageType.Comport,
                    Comport = GetComportJSON(c, includeScriptContents: true)
                });
            }
            break;

        case WebJSON.RequestType.Macro:
            BrainComponent.Macro m = GetMacroFromRequest(msg);
            if (m != null)
            {
                Send(new WebJSON.Message()
                {
                    Type  = WebJSON.MessageType.Macro,
                    Macro = GetMacroJSON(m, includeScriptContents: true)
                });
            }
            break;

        case WebJSON.RequestType.TransitionExport:
            if (selectedPerso_ != null && selectedPerso_ is PersoBehaviour)
            {
                MindComponent mc = selectedPerso_.GetComponent <MindComponent>();
                if (mc != null)
                {
                    try {
                        var export = mc.TransitionExport;
                        if (export != null)
                        {
                            Send(new WebJSON.Message()
                            {
                                Type             = WebJSON.MessageType.TransitionExport,
                                TransitionExport = export
                            });
                        }
                    } catch (Exception) { }
                }
            }
            break;

        case WebJSON.RequestType.Screenshot:
            TakeScreenshot(msg.Screenshot).Forget();                     // Start the async task for taking a screenshot
            break;
        }
    }
Example #3
0
        public void CreateGameObjects(OpenSpace.AI.Behavior.BehaviorType type, BrainComponent brain, Perso perso)
        {
            if (this.comports.Value == null)
            {
                return;
            }

            string ruleOrReflex = type.ToString();

            GameObject intelParent = new GameObject(ruleOrReflex + " behaviours");

            intelParent.transform.parent = brain.gameObject.transform;

            Reference <Comport>[] behaviors = this.comports.Value.comports;
            int iter = 0;

            foreach (var behaviorRef in behaviors)
            {
                Comport behavior = behaviorRef.Value;

                if (behavior == null)
                {
                    continue;
                }

                BrainComponent.Comport c           = new BrainComponent.Comport();
                GameObject             behaviorGao = new GameObject(ruleOrReflex + " #" + iter);
                behaviorGao.transform.parent = intelParent.transform;
                if (behavior.scripts?.Value?.scripts != null)
                {
                    foreach (Reference <OpenSpace.ROM.Script> scriptRef in behavior.scripts?.Value?.scripts)
                    {
                        OpenSpace.ROM.Script script    = scriptRef.Value;
                        GameObject           scriptGao = new GameObject("Script");
                        scriptGao.transform.parent = behaviorGao.transform;
                        ROMScriptComponent scriptComponent = scriptGao.AddComponent <ROMScriptComponent>();
                        scriptComponent.SetScript(script, perso);
                        c.Scripts.Add(scriptComponent);
                    }
                }
                if (behavior.firstScript.Value != null)
                {
                    ROMScriptComponent scriptComponent = behaviorGao.AddComponent <ROMScriptComponent>();
                    scriptComponent.SetScript(behavior.firstScript.Value, perso);
                    c.FirstScript = scriptComponent;
                }
                if (iter == 0)
                {
                    behaviorGao.name += " (Init)";
                }
                if ((behavior.scripts?.Value == null || behavior.scripts?.Value.length == 0) && behavior.firstScript?.Value == null)
                {
                    behaviorGao.name += " (Empty)";
                }
                c.Offset  = behavior.Offset;
                c.GaoName = behaviorGao.name;
                c.Name    = behavior.IndexString;
                switch (type)
                {
                case AI.Behavior.BehaviorType.Intelligence: brain.Intelligence.Add(c); break;

                case AI.Behavior.BehaviorType.Reflex: brain.Reflex.Add(c); break;
                }
                iter++;
            }
        }