Exemple #1
0
    static ControlFlowGraph SeverEdge(ControlFlowGraph graph, int start, int end)
    {
        var labelName = ScriptConstants.BuildDummyLabel(Guid.NewGuid());
        var gotoNode  = Emit.Goto(labelName);

        if (graph == null)
        {
            throw new ArgumentNullException(nameof(graph));
        }
        if (gotoNode == null)
        {
            throw new ArgumentNullException(nameof(gotoNode));
        }
        var label = graph.GetEdgeLabel(start, end);

        graph = graph
                .RemoveEdge(start, end)
                .AddNode(gotoNode, out var sourceNodeIndex)
                .AddEdge(start, sourceNodeIndex, label)
                .AddEdge(sourceNodeIndex, graph.ExitIndex, CfgEdge.True);

        if (labelName != null)
        {
            graph = graph.ReplaceNode(end,
                                      new ControlFlowGraph(0, 1,
                                                           new[] { Emit.Label(labelName), graph.Nodes[end] },
                                                           new[] { (0, 1, CfgEdge.True) }));
        public void TestParseCueToken()
        {
            string cueLine = "PHASE";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("PHASE", cueToken);
            Assert.AreEqual(null, postCueLine);
        }
        public void TestParseCueTokenOtherOptions()
        {
            string cueLine = "WOUND_GLASS, 5";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("WOUND_GLASS", cueToken);
            Assert.AreEqual("5", postCueLine);
        }
        public void TestParseCueTokenWithOptions()
        {
            string cueLine = "PHASE: chest_shirt_01";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("PHASE", cueToken);
            Assert.AreEqual("chest_shirt_01", postCueLine);
        }
Exemple #5
0
    public static void LoadObjectGroups(AssetInfo info,
                                        Map map,
                                        int tileWidth,
                                        int tileHeight,
                                        EventLayout eventLayout,
                                        List <TriggerInfo> triggers,
                                        List <MapNpc> npcs,
                                        List <MapEventZone> zones,
                                        List <AutomapInfo> markers,
                                        List <byte> markerTiles)
    {
        ushort ResolveEntryPoint(string name)
        {
            var(isChain, id) = ScriptConstants.ParseEntryPoint(name);
            return(isChain ? eventLayout.Chains[id] : id);
        }

        var mapObjects = map.ObjectGroups.SelectMany(x => x.Objects);
        var pathParser = NpcPathBuilder.BuildParser(mapObjects, tileWidth, tileHeight);

        foreach (var objectGroup in map.ObjectGroups)
        {
            foreach (var obj in objectGroup.Objects)
            {
                if (TypeName.Trigger.Equals(obj.Type, StringComparison.OrdinalIgnoreCase))
                {
                    triggers.Add(TriggerMapping.ParseTrigger(obj, tileWidth, tileHeight, ResolveEntryPoint));
                }

                if (TypeName.Npc.Equals(obj.Type, StringComparison.OrdinalIgnoreCase))
                {
                    npcs.Add(NpcMapping.ParseNpc(obj, tileWidth, tileHeight, ResolveEntryPoint, pathParser));
                }

                if (TypeName.Marker.Equals(obj.Type, StringComparison.OrdinalIgnoreCase))
                {
                    var(marker, tile) = AutomapMapping.ParseMarker(obj, tileWidth, tileHeight);
                    markers.Add(marker);
                    markerTiles.Add(tile);
                }
            }
        }

        TriggerMapping.LoadZones(zones, info.AssetId, triggers, map);
    }
Exemple #6
0
        private static List <TokenNode> GenerateTokens(IEnumerable <LineMeta> lines)
        {
            var capturedTokens = new Stack <TokenNode>();

            foreach (LineMeta meta in lines)
            {
                string line = meta.Line;
                // ZLog.Info($"[PASS 1] {line}, tokens: {capturedTokens.Count}");

                if (!line.StartsWith(ParseTokens.CUE_CHAR, out string cueLine))
                {
                    TokenNode node;
                    if (line == "")
                    {
                        node = new TokenNode
                        {
                            Type       = TokenType.BREAK,
                            LineNumber = meta.LineNumber,
                        };
                    }
                    else
                    {
                        node = new TokenNode
                        {
                            Type       = TokenType.MISC,
                            LineNumber = meta.LineNumber,
                            Content    = line
                        };
                    }

                    capturedTokens.Push(node);
                    // TokenNode previousNode = capturedTokens.Peek();
                    //
                    // if (previousNode.Content == null)
                    // {
                    //     previousNode.Content = line;
                    // }
                    // else
                    // {
                    //     previousNode.Content += $"{Environment.NewLine}{line}";
                    // }
                }
                else
                {
                    string cueToken = ScriptConstants.ParseCueToken(cueLine, out string cueData);
                    // ZLog.Info($"[TOKEN] {cueToken}");

                    if (cueToken.StartsWith(ParseTokens.CUE_END_TOKEN, out string endCueToken))
                    {
                        // ZLog.Info($"Found end token: {cueToken}");

                        if (capturedTokens.Count == 0)
                        {
                            throw new InvalidOperationException($"No captured items for token group: {endCueToken}, line: {meta.LineNumber}");
                        }

                        List <TokenNode> nodes = new List <TokenNode>();
                        TokenNode        captureGroup;
                        while ((captureGroup = capturedTokens.Pop()) != null)
                        {
                            if (captureGroup.Keyword == endCueToken)
                            {
                                if (captureGroup.Children == null)
                                {
                                    // found matching start token, has empty children
                                    break;
                                }
                            }

                            // ZLog.Info($"{captureGroup.Keyword} part of capture group, remaining: {capturedTokens.Count}");
                            nodes.Add(captureGroup);

                            if (capturedTokens.Count == 0)
                            {
                                throw new InvalidOperationException(
                                          $"No start token to capture group found: {endCueToken}, line: {meta.LineNumber}");
                            }
                        }

                        nodes.Reverse();

                        captureGroup.Children = nodes;

                        capturedTokens.Push(captureGroup);


                        continue;
                    }

                    TokenNode node = new TokenNode
                    {
                        Type       = TokenType.KEYWORD,
                        LineNumber = meta.LineNumber,
                        Keyword    = cueToken,
                        Data       = cueData
                    };

                    capturedTokens.Push(node);
                    //
                    // ZLog.Info($"[NODE] {node}");
                }
            }

            // since this is built up in reverse, we have to reverse it again to negate the effect
            var result = capturedTokens.ToList();

            result.Reverse();
            return(result);
        }