private bool TryAdaptCallStatement(JassMapScriptAdapterContext context, JassCallStatementSyntax callStatement, [NotNullWhen(true)] out IStatementSyntax?adaptedCallStatement)
        {
            if (TryAdaptInvocation(context, callStatement, out var adaptedInvocationName, out var adaptedInvocationArguments))
            {
                if (string.IsNullOrEmpty(adaptedInvocationName))
                {
                    adaptedCallStatement = new JassCommentSyntax(callStatement.ToString());
                }
                else if (TryAdaptArgumentList(context, adaptedInvocationArguments, out var adaptedArguments))
                {
                    adaptedCallStatement = JassSyntaxFactory.CallStatement(
                        adaptedInvocationName,
                        adaptedArguments);
                }
                else
                {
                    adaptedCallStatement = JassSyntaxFactory.CallStatement(
                        adaptedInvocationName,
                        adaptedInvocationArguments);
                }

                return(true);
            }
Beispiel #2
0
        private FunctionSyntax GetMainFunctionSyntax(float left, float right, float top, float bottom, Tileset tileset, SoundEnvironment sound, params string[] initFunctions)
        {
            var statements = new List <NewStatementSyntax>()
            {
                JassSyntaxFactory.CallStatement(
                    "SetCameraBounds",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.VariableExpression("left"),
                        JassSyntaxFactory.VariableExpression("bottom"),
                        JassSyntaxFactory.VariableExpression("right"),
                        JassSyntaxFactory.VariableExpression("top"),
                        JassSyntaxFactory.VariableExpression("left"),
                        JassSyntaxFactory.VariableExpression("top"),
                        JassSyntaxFactory.VariableExpression("right"),
                        JassSyntaxFactory.VariableExpression("bottom"))),
                JassSyntaxFactory.CallStatement(
                    "SetDayNightModels",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.ConstantExpression(LightEnvironmentProvider.GetTerrainLightEnvironmentModel(tileset)),
                        JassSyntaxFactory.ConstantExpression(LightEnvironmentProvider.GetUnitLightEnvironmentModel(tileset)))),
                JassSyntaxFactory.CallStatement(
                    "NewSoundEnvironment",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetSoundEnvironment(sound))),
                JassSyntaxFactory.CallStatement(
                    "SetAmbientDaySound",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetAmbientDaySound(tileset))),
                JassSyntaxFactory.CallStatement(
                    "SetAmbientNightSound",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetAmbientNightSound(tileset))),
                JassSyntaxFactory.CallStatement(
                    "SetMapMusic",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.ConstantExpression("Music"),
                        JassSyntaxFactory.ConstantExpression(true),
                        JassSyntaxFactory.ConstantExpression(0))),
            };

            foreach (var initFunction in initFunctions)
            {
                statements.Add(JassSyntaxFactory.CallStatement(initFunction));
            }

            return(JassSyntaxFactory.Function(
                       JassSyntaxFactory.FunctionDeclaration("main"),
                       JassSyntaxFactory.LocalVariableList(
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "left",
                               JassSyntaxFactory.BinaryAdditionExpression(
                                   JassSyntaxFactory.ConstantExpression(left),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_LEFT"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "right",
                               JassSyntaxFactory.BinarySubtractionExpression(
                                   JassSyntaxFactory.ConstantExpression(right),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_RIGHT"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "top",
                               JassSyntaxFactory.BinarySubtractionExpression(
                                   JassSyntaxFactory.ConstantExpression(top),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_TOP"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "bottom",
                               JassSyntaxFactory.BinaryAdditionExpression(
                                   JassSyntaxFactory.ConstantExpression(bottom),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_BOTTOM")))))),
                       statements.ToArray()));
        }
Beispiel #3
0
        private FunctionSyntax GetConfigFunctionSyntax(string mapName, string mapDescription, string lobbyMusic, params PlayerSlot[] playerSlots)
        {
            var statements = new List <NewStatementSyntax>()
            {
                JassSyntaxFactory.CallStatement("SetMapName", JassSyntaxFactory.ConstantExpression(mapName)),
                JassSyntaxFactory.CallStatement("SetMapDescription", JassSyntaxFactory.ConstantExpression(mapDescription)),
                JassSyntaxFactory.CallStatement("SetPlayers", JassSyntaxFactory.ConstantExpression(playerSlots.Length)),
                JassSyntaxFactory.CallStatement("SetTeams", JassSyntaxFactory.ConstantExpression(playerSlots.Length)),
                JassSyntaxFactory.CallStatement("SetGamePlacement", JassSyntaxFactory.VariableExpression("MAP_PLACEMENT_TEAMS_TOGETHER")),
            };

            if (lobbyMusic != null)
            {
                statements.Add(JassSyntaxFactory.CallStatement("PlayMusic", JassSyntaxFactory.ConstantExpression(lobbyMusic)));
            }

            for (var i = 0; i < playerSlots.Length; i++)
            {
                var playerSlot = playerSlots[i];
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "DefineStartLocation",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.ConstantExpression(i),
                                       JassSyntaxFactory.ConstantExpression(playerSlot.StartLocationX),
                                       JassSyntaxFactory.ConstantExpression(playerSlot.StartLocationY))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerStartLocation",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.ConstantExpression(i))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "ForcePlayerStartLocation",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.ConstantExpression(i))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerColor",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.InvocationExpression("ConvertPlayerColor", JassSyntaxFactory.ConstantExpression(i)))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerRacePreference",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.VariableExpression(playerSlot.RacePreference))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerRaceSelectable",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.ConstantExpression(playerSlot.RaceSelectable))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerController",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.VariableExpression(playerSlot.Controller))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetPlayerTeam",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.InvocationExpression("Player", JassSyntaxFactory.ConstantExpression(i)),
                                       JassSyntaxFactory.ConstantExpression(playerSlot.Team))));
                statements.Add(JassSyntaxFactory.CallStatement(
                                   "SetStartLocPrioCount",
                                   JassSyntaxFactory.ArgumentList(
                                       JassSyntaxFactory.ConstantExpression(i),
                                       JassSyntaxFactory.ConstantExpression(0))));
            }

            return(JassSyntaxFactory.Function(
                       JassSyntaxFactory.FunctionDeclaration("config"),
                       statements.ToArray()));
        }