Ejemplo n.º 1
0
        public override void OnEnable()
        {
            base.OnEnable();

            if (config is null)
            {
                config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>();
            }
            ScriptAsset = assetTarget as Script;
            scriptText  = File.ReadAllText(AssetDatabase.GetAssetPath(ScriptAsset));

            if (config.EnableVisualEditor)
            {
                VisualEditor = new ScriptView(config, ApplyRevertHackGUI, ApplyAndImportChecked);
                VisualEditor.GenerateForScript(scriptText, ScriptAsset);

                ScriptAssetPostprocessor.OnModified += HandleScriptModified;
                return;
            }

            previewContent = scriptText;
            if (previewContent.Length > previewLengthLimit)
            {
                previewContent  = previewContent.Substring(0, previewLengthLimit);
                previewContent += $"{System.Environment.NewLine}<...>";
            }

            labelTags = ScriptAsset.Lines.OfType <LabelScriptLine>().Select(l => new GUIContent($"# {l.LabelText}")).ToArray();
            gotoTags  = ScriptAsset.ExtractCommands().OfType <Commands.Goto>()
                        .Where(c => !string.IsNullOrEmpty(c.Path.Name))
                        .Select(c => new GUIContent($"@goto {c.Path.ToString().Replace(".null", "")}")).ToArray();
        }
Ejemplo n.º 2
0
        public ScriptView(ScriptsConfiguration config, Action drawHackGuiAction, Action saveAssetAction)
        {
            ScriptModified       = false;
            this.config          = config;
            this.saveAssetAction = saveAssetAction;
            CustomStyleSheet     = config.CustomStyleSheet;
            ViewRange            = new IntRange(0, config.VisualEditorPageLength - 1);
            styleSheets.Add(StyleSheet);
            if (CustomStyleSheet != null)
            {
                styleSheets.Add(CustomStyleSheet);
            }
            Add(new IMGUIContainer(drawHackGuiAction));
            Add(new IMGUIContainer(() => MonitorKeys(null)));
            RegisterCallback <KeyDownEvent>(MonitorKeys);

            linesContainer = new VisualElement();
            Add(linesContainer);

            paginationView = new PaginationView(SelectNextPage, SelectPreviousPage);
            paginationView.style.display = DisplayStyle.None;
            Add(paginationView);

            infoLabel      = new Label("Loading, please wait...");
            infoLabel.name = "InfoLabel";
            Add(infoLabel);

            new ContextualMenuManipulator(ContextMenu).target = this;
        }
Ejemplo n.º 3
0
 public ScriptManager(ScriptsConfiguration config, IResourceProviderManager providerManager, ILocalizationManager localizationManager)
 {
     Configuration            = config;
     this.providerManager     = providerManager;
     this.localizationManager = localizationManager;
     localizationScripts      = new Dictionary <string, Script>();
 }
Ejemplo n.º 4
0
        public override void OnEnable()
        {
            base.OnEnable();

            if (config is null)
            {
                config = Configuration.LoadOrDefault <ScriptsConfiguration>();
            }
            scriptAsset = assetTarget as ScriptAsset;

            if (config.EnableVisualEditor)
            {
                visualEditor = new ScriptView(config, ApplyRevertHackGUI, ApplyAndImport);
                visualEditor.GenerateForScript(scriptAsset);

                ScriptImporter.OnModified += visualEditor.GenerateForScript;
                return;
            }

            previewContent = scriptAsset.ScriptText;
            if (previewContent.Length > previewLengthLimit)
            {
                previewContent  = previewContent.Substring(0, previewLengthLimit);
                previewContent += $"{System.Environment.NewLine}<...>";
            }

            var script = new Script(scriptAsset.name, scriptAsset.ScriptText, ignoreErrors: true);

            labelTags = script.LabelLines.Select(l => new GUIContent($"# {l.LabelText}")).ToArray();
            gotoTags  = script.CommandLines
                        .Where(c => c.CommandName.EqualsFastIgnoreCase("goto") && c.CommandParameters.TryGetValue(string.Empty, out var path) && !path.StartsWithFast("."))
                        .Select(c => new GUIContent($"@goto {c.CommandParameters[string.Empty]}")).ToArray();
        }
Ejemplo n.º 5
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (BuildProcessor.Building)
            {
                return;
            }

            var modifiedResources = false;

            foreach (string assetPath in importedAssets)
            {
                if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(Script))
                {
                    continue;
                }

                if (configuration is null)
                {
                    configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>();
                }
                if (editorResources is null)
                {
                    editorResources = EditorResources.LoadOrDefault();
                }

                HandleAutoAdd(assetPath, ref modifiedResources);
            }

            if (modifiedResources)
            {
                EditorUtility.SetDirty(editorResources);
                AssetDatabase.SaveAssets();
            }
        }
Ejemplo n.º 6
0
        private static void HandleEngineInitialized()
        {
            if (!(Engine.Behaviour is RuntimeBehaviour))
            {
                return;
            }

            if (configuration is null)
            {
                configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>();
            }
            if (editorResources is null)
            {
                editorResources = EditorResources.LoadOrDefault();
            }

            if (!configuration.HotReloadScripts)
            {
                return;
            }

            scriptManager  = Engine.GetService <IScriptManager>();
            player         = Engine.GetService <IScriptPlayer>();
            stateManager   = Engine.GetService <IStateManager>();
            player.OnPlay += HandleStartPlaying;
        }
Ejemplo n.º 7
0
        public ScriptGraphNode(ScriptsConfiguration config, Script script, List <Script> availableScripts)
        {
            this.config           = config;
            this.availableScripts = availableScripts;
            title    = script.Name;
            expanded = true;
            m_CollapseButton.Clear();
            m_CollapseButton.SetEnabled(false);
            capabilities = Capabilities.Ascendable | Capabilities.Selectable | Capabilities.Movable;
            Script       = script;

            RegisterCallback <MouseDownEvent>(OnNodeMouseDown);

            // Add synopsis.
            if (config.ShowSynopsis)
            {
                var synopsis = CreateSynopsis(script);
                mainContainer.Insert(1, synopsis);
            }

            // Add input port.
            InputPorts[string.Empty] = AddPort(Direction.Input, startLabel);

            // Add out ports.
            foreach (var line in script.Lines)
            {
                if (line is LabelScriptLine labelLine)
                {
                    InputPorts[labelLine.LabelText] = AddPort(Direction.Input, $"{Lexing.Constants.LabelLineId}{labelLine.LabelText}");
                    continue;
                }

                if (line is CommandScriptLine commandLine)
                {
                    if (commandLine.Command is Goto @goto)
                    {
                        AddOutPort(@goto, @goto.Path.Name ?? @goto.PlaybackSpot.ScriptName, @goto.Path.NamedValue, $"goto {@goto.Path}");
                    }
                    if (commandLine.Command is Gosub gosub)
                    {
                        AddOutPort(gosub, gosub.Path.Name ?? gosub.PlaybackSpot.ScriptName, gosub.Path.NamedValue, $"gosub {gosub.Path}");
                    }
                    if (commandLine.Command is AddChoice choice && Command.Assigned(choice.GotoPath))
                    {
                        AddOutPort(choice, choice.GotoPath.Name ?? choice.PlaybackSpot.ScriptName, choice.GotoPath.NamedValue, $"choice goto:{choice.GotoPath}");
                    }
                    continue;
                }
            }

            void AddOutPort(Command command, string gotoScript, string gotoLabel, string portLabel)
            {
                portLabel = $"{Lexing.Constants.CommandLineId}{portLabel}";
                var port     = AddPort(Direction.Output, portLabel, command.ConditionalExpression);
                var label    = string.IsNullOrEmpty(gotoLabel) ? string.Empty : gotoLabel;
                var portData = new ScriptGraphOutputPort(gotoScript, label, port);

                OutputPorts.Add(portData);
            }
        }
Ejemplo n.º 8
0
        public ScriptView(ScriptsConfiguration config, Action drawHackGuiAction, Action saveAssetAction)
        {
            ScriptModified = false;

            this.config          = config;
            this.saveAssetAction = saveAssetAction;
            editorResources      = EditorResources.LoadOrDefault();
            ViewRange            = new IntRange(0, config.EditorPageLength - 1);

            styleSheets.Add(StyleSheet);
            if (EditorGUIUtility.isProSkin)
            {
                styleSheets.Add(DarkStyleSheet);
            }
            CustomStyleSheet = config.EditorCustomStyleSheet;
            if (CustomStyleSheet)
            {
                styleSheets.Add(CustomStyleSheet);
            }

            var commentItem     = new SearcherItem("Comment");
            var labelItem       = new SearcherItem("Label");
            var genericTextItem = new SearcherItem("Generic Text", config.InsertLineKey != KeyCode.None
                ? $"{(config.InsertLineModifier != EventModifiers.None ? $"{config.InsertLineModifier}+" : string.Empty)}{config.InsertLineKey}"
                : null);
            var commandsItem = new SearcherItem("Commands");

            foreach (var commandId in Command.CommandTypes.Keys.OrderBy(k => k))
            {
                commandsItem.AddChild(new SearcherItem(char.ToLowerInvariant(commandId[0]) + commandId.Substring(1)));
            }
            searchItems = new List <SearcherItem> {
                commandsItem, genericTextItem, labelItem, commentItem
            };

            Add(new IMGUIContainer(drawHackGuiAction));
            Add(new IMGUIContainer(() => HandleKeyDownEvent(null)));

            linesContainer = new VisualElement();
            Add(linesContainer);

            paginationView = new PaginationView(SelectNextPage, SelectPreviousPage);
            paginationView.style.display = DisplayStyle.None;
            Add(paginationView);

            infoLabel      = new Label("Loading, please wait...");
            infoLabel.name = "InfoLabel";
            ColorUtility.TryParseHtmlString(EditorGUIUtility.isProSkin ? "#cccccc" : "#555555", out var color);
            infoLabel.style.color = color;
            Add(infoLabel);

            RegisterCallback <KeyDownEvent>(HandleKeyDownEvent, TrickleDown.TrickleDown);
            RegisterCallback <MouseDownEvent>(HandleMouseDownEvent, TrickleDown.TrickleDown);

            new ContextualMenuManipulator(ContextMenu).target = this;
        }
Ejemplo n.º 9
0
        public ScriptGraphView(ScriptsConfiguration config, ScriptGraphState state, List <Script> scripts)
        {
            this.config  = config;
            this.scripts = scripts;
            this.state   = state;

            CustomStyleSheet = config.GraphCustomStyleSheet;
            styleSheets.Add(StyleSheet);
            if (CustomStyleSheet != null)
            {
                styleSheets.Add(CustomStyleSheet);
            }

            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());

            var grid = new GridBackground();

            Insert(0, grid);
            grid.StretchToParentSize();

            var minimap = new MiniMap();

            minimap.anchored = true;
            minimap.SetPosition(new Rect(10, 30, 200, 140));
            minimap.visible = false;
            Add(minimap);

            var toolbar = new Toolbar();

            Add(toolbar);
            var rebuildButton = new Button(HandleRebuildButtonClicked);

            rebuildButton.text = "Rebuild Graph";
            toolbar.Add(rebuildButton);
            var alignButton = new Button(AutoAlign);

            alignButton.text = "Auto Align";
            toolbar.Add(alignButton);
            var minimapToggle = new Toggle();

            minimapToggle.label = "Show Minimap";
            minimapToggle.RegisterValueChangedCallback(evt => minimap.visible = evt.newValue);
            toolbar.Add(minimapToggle);
            var saveButton = new Button(SerializeState);

            saveButton.text = "Save";
            toolbar.Add(saveButton);

            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);

            RebuildGraph();
        }
        public ScriptGraphNode(ScriptsConfiguration config, Script script, List <Script> availableScripts)
        {
            this.config           = config;
            this.availableScripts = availableScripts;
            title    = script.Name;
            expanded = true;
            m_CollapseButton.Clear();
            m_CollapseButton.SetEnabled(false);
            capabilities = Capabilities.Ascendable | Capabilities.Selectable | Capabilities.Movable;
            Script       = script;

            RegisterCallback <MouseDownEvent>(OnNodeMouseDown);

            InputPorts[string.Empty] = AddPort(Direction.Input, startLabel);

            foreach (var line in script.Lines)
            {
                if (line is LabelScriptLine labelLine)
                {
                    InputPorts[labelLine.LabelText] = AddPort(Direction.Input, $"{LabelScriptLine.IdentifierLiteral}{labelLine.LabelText}");
                    continue;
                }

                if (line is CommandScriptLine commandLine)
                {
                    if (commandLine.Command is Goto gotoCommand)
                    {
                        AddOutPort(gotoCommand, gotoCommand.Path.Name ?? line.ScriptName, gotoCommand.Path.NamedValue,
                                   $"goto {gotoCommand.Path}".Replace(".null", string.Empty).Replace("null", string.Empty));
                    }
                    if (commandLine.Command is Gosub gosubCommand)
                    {
                        AddOutPort(gosubCommand, gosubCommand.Path.Name ?? line.ScriptName, gosubCommand.Path.NamedValue,
                                   $"gosub {gosubCommand.Path}".Replace(".null", string.Empty).Replace("null", string.Empty));
                    }
                    continue;
                }
            }

            void AddOutPort(Command command, string gotoScript, string gotoLabel, string portLabel)
            {
                portLabel = $"{CommandScriptLine.IdentifierLiteral}{portLabel}";
                var portData = new OutputPortData {
                    ScriptName = gotoScript,
                    Label      = string.IsNullOrEmpty(gotoLabel) ? string.Empty : gotoLabel,
                    Port       = AddPort(Direction.Output, portLabel, command.ConditionalExpression)
                };

                OutputPorts.Add(portData);
            }
        }
Ejemplo n.º 11
0
        private static void Initialize()
        {
            ScriptAssetPostprocessor.OnModified += HandleScriptModifiedAsync;
            Engine.OnInitializationFinished     += HandleEngineInitialized;

            void HandleEngineInitialized()
            {
                if (!(Engine.Behaviour is RuntimeBehaviour))
                {
                    return;
                }

                if (configuration is null)
                {
                    configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>();
                }

                scriptManager  = Engine.GetService <IScriptManager>();
                player         = Engine.GetService <IScriptPlayer>();
                stateManager   = Engine.GetService <IStateManager>();
                player.OnPlay += HandleStartPlaying;
            }
        }
Ejemplo n.º 12
0
 public ScriptManager(ScriptsConfiguration config, ResourceProviderManager providersManager, LocalizationManager localizationManager)
 {
     this.config              = config;
     this.providersManager    = providersManager;
     this.localizationManager = localizationManager;
 }