Exemplo n.º 1
0
        public static JassFunctionDeclarationSyntax InitGlobals(MapTriggers mapTriggers)
        {
            const string LocalIndexVariableName = "i";

            var statements = new List <IStatementSyntax>();

            if (mapTriggers.Variables.Any(variable => variable.IsArray))
            {
                statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, LocalIndexVariableName, SyntaxFactory.LiteralExpression(0)));
            }

            if (mapTriggers is not null)
            {
                foreach (var variable in mapTriggers.Variables)
                {
                    if (variable.IsArray)
                    {
                        statements.Add(SyntaxFactory.SetStatement(LocalIndexVariableName, SyntaxFactory.LiteralExpression(0)));
                        statements.Add(SyntaxFactory.LoopStatement(
                                           new JassExitStatementSyntax(new JassParenthesizedExpressionSyntax(SyntaxFactory.BinaryGreaterThanExpression(
                                                                                                                 SyntaxFactory.VariableReferenceExpression(LocalIndexVariableName),
                                                                                                                 SyntaxFactory.LiteralExpression(variable.ArraySize)))),
                                           SyntaxFactory.SetStatement(variable.GetVariableName(), SyntaxFactory.VariableReferenceExpression(LocalIndexVariableName), variable.GetInitialValueExpression()),
                                           SyntaxFactory.SetStatement(LocalIndexVariableName, SyntaxFactory.BinaryAdditionExpression(SyntaxFactory.VariableReferenceExpression(LocalIndexVariableName), SyntaxFactory.LiteralExpression(1)))));
                    }
                }
            }

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitGlobals)), statements));
        }
Exemplo n.º 2
0
 public static GamePatch GetMinimumPatch(this MapTriggers mapTriggers)
 {
     return(mapTriggers.SubVersion.HasValue
         ? GamePatch.v1_31_0
         : mapTriggers.FormatVersion == MapTriggersFormatVersion.Tft
             ? GamePatch.v1_07
             : GamePatch.v1_00);
 }
Exemplo n.º 3
0
        private static void TestParseMapTriggers(string mapTriggersFilePath)
        {
            using var original  = FileProvider.GetFile(mapTriggersFilePath);
            using var recreated = new MemoryStream();

            MapTriggers.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
Exemplo n.º 4
0
 public static void DowngradeOnce(this MapTriggers mapTriggers)
 {
     if (mapTriggers.SubVersion.HasValue)
     {
         mapTriggers.SubVersion = null;
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemplo n.º 5
0
        public static bool TryDowngrade(this MapTriggers mapTriggers, GamePatch targetPatch)
        {
            try
            {
                while (mapTriggers.GetMinimumPatch() > targetPatch)
                {
                    mapTriggers.DowngradeOnce();
                }

                return(true);
            }
            catch (NotSupportedException)
            {
                return(false);
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 6
0
 public static void Write(this BinaryWriter writer, MapTriggers mapTriggers) => mapTriggers.WriteTo(writer);